diff --git a/app/src/main/java/org/thoughtcrime/securesms/database/Storage.kt b/app/src/main/java/org/thoughtcrime/securesms/database/Storage.kt index 95b37e641d..82153f898c 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/database/Storage.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/database/Storage.kt @@ -310,6 +310,7 @@ open class Storage @Inject constructor( } } } + override fun deleteMessagesByUser(threadId: Long, userSessionId: String) { val userMessages = mmsSmsDatabase.getUserMessages(threadId, userSessionId) val (mmsMessages, smsMessages) = userMessages.partition { it.isMms } diff --git a/app/src/main/java/org/thoughtcrime/securesms/groups/EditGroupViewModel.kt b/app/src/main/java/org/thoughtcrime/securesms/groups/EditGroupViewModel.kt index 7150e2e7f8..bade85203c 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/groups/EditGroupViewModel.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/groups/EditGroupViewModel.kt @@ -9,7 +9,6 @@ import dagger.assisted.AssistedInject import dagger.hilt.android.lifecycle.HiltViewModel import dagger.hilt.android.qualifiers.ApplicationContext import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.async import kotlinx.coroutines.flow.MutableStateFlow @@ -25,10 +24,10 @@ import kotlinx.coroutines.flow.update import kotlinx.coroutines.launch import kotlinx.coroutines.withContext import network.loki.messenger.R +import network.loki.messenger.libsession_util.util.Contact import network.loki.messenger.libsession_util.util.GroupDisplayInfo import network.loki.messenger.libsession_util.util.GroupMember import org.session.libsession.database.StorageProtocol -import org.session.libsession.messaging.contacts.Contact import org.session.libsession.messaging.groups.GroupManagerV2 import org.session.libsession.utilities.ConfigUpdateNotification import org.session.libsignal.utilities.AccountId @@ -196,17 +195,17 @@ class EditGroupViewModel @AssistedInject constructor( try { // Mark the contacts as pending memberPendingState.update { states -> - states + contacts.associate { AccountId(it.accountID) to MemberPendingState.Inviting } + states + contacts.associate { AccountId(it.id) to MemberPendingState.Inviting } } groupManager.inviteMembers( groupId, - contacts.map { AccountId(it.accountID) }, + contacts.map { AccountId(it.id) }, shareHistory = false ) } finally { // Remove pending state (so the real state will be revealed) - memberPendingState.update { states -> states - contacts.mapTo(hashSetOf()) { AccountId(it.accountID) } } + memberPendingState.update { states -> states - contacts.mapTo(hashSetOf()) { AccountId(it.id) } } } } } diff --git a/app/src/main/java/org/thoughtcrime/securesms/groups/GroupManagerV2Impl.kt b/app/src/main/java/org/thoughtcrime/securesms/groups/GroupManagerV2Impl.kt index d3edeceb8f..513ac4525d 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/groups/GroupManagerV2Impl.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/groups/GroupManagerV2Impl.kt @@ -8,6 +8,7 @@ import kotlinx.coroutines.SupervisorJob import kotlinx.coroutines.async import kotlinx.coroutines.withContext import network.loki.messenger.libsession_util.ConfigBase.Companion.PRIORITY_VISIBLE +import network.loki.messenger.libsession_util.util.Contact import network.loki.messenger.libsession_util.util.Conversation import network.loki.messenger.libsession_util.util.GroupInfo import network.loki.messenger.libsession_util.util.GroupMember @@ -16,7 +17,6 @@ import network.loki.messenger.libsession_util.util.INVITE_STATUS_SENT import network.loki.messenger.libsession_util.util.UserPic import org.session.libsession.database.StorageProtocol import org.session.libsession.database.userAuth -import org.session.libsession.messaging.contacts.Contact import org.session.libsession.messaging.groups.GroupManagerV2 import org.session.libsession.messaging.jobs.InviteContactsJob import org.session.libsession.messaging.jobs.JobQueue @@ -116,7 +116,7 @@ class GroupManagerV2Impl @Inject constructor( for (member in members) { configs.groupMembers.set( GroupMember( - sessionId = member.accountID, + sessionId = member.id, name = member.name, profilePicture = member.profilePicture ?: UserPic.DEFAULT, inviteStatus = INVITE_STATUS_SENT @@ -165,7 +165,7 @@ class GroupManagerV2Impl @Inject constructor( JobQueue.shared.add( InviteContactsJob( groupSessionId = groupId.hexString, - memberSessionIds = members.map { it.accountID }.toTypedArray() + memberSessionIds = members.map { it.id }.toTypedArray() ) ) @@ -207,9 +207,12 @@ class GroupManagerV2Impl @Inject constructor( existing } } - ?: configs.groupMembers.getOrConstruct(newMember.hexString).let { - val contact = storage.getContactWithAccountID(newMember.hexString) - it.copy( + ?: configs.groupMembers.getOrConstruct(newMember.hexString).let { member -> + val contact = configFactory.withUserConfigs { configs -> + configs.contacts.get(newMember.hexString) + } + + member.copy( name = contact?.name, profilePicture = contact?.profilePicture ?: UserPic.DEFAULT, inviteStatus = INVITE_STATUS_SENT, @@ -931,17 +934,6 @@ class GroupManagerV2Impl @Inject constructor( require(firstError == null) { "$errorMessage: ${firstError!!.body}" } } - private val Contact.profilePicture: UserPic? - get() { - val url = this.profilePictureURL - val key = this.profilePictureEncryptionKey - return if (url != null && key != null) { - UserPic(url, key) - } else { - null - } - } - private val Profile.profilePicture: UserPic? get() { val url = this.profilePictureURL diff --git a/app/src/main/java/org/thoughtcrime/securesms/groups/SelectContactsViewModel.kt b/app/src/main/java/org/thoughtcrime/securesms/groups/SelectContactsViewModel.kt index 68cce86e0a..1d5ffa65e2 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/groups/SelectContactsViewModel.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/groups/SelectContactsViewModel.kt @@ -21,10 +21,10 @@ import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.onStart import kotlinx.coroutines.flow.stateIn import kotlinx.coroutines.withContext +import network.loki.messenger.libsession_util.util.Contact import org.session.libsession.database.StorageProtocol -import org.session.libsession.messaging.contacts.Contact +import org.session.libsession.utilities.truncateIdForDisplay import org.thoughtcrime.securesms.dependencies.ConfigFactory -import org.thoughtcrime.securesms.home.search.getSearchName @OptIn(FlowPreview::class) @HiltViewModel(assistedFactory = SelectContactsViewModel.Factory::class) @@ -70,12 +70,14 @@ class SelectContactsViewModel @AssistedInject constructor( .onStart { emit(Unit) } .map { withContext(Dispatchers.Default) { - val allContacts = storage.getAllContacts() + val allContacts = configFactory.withUserConfigs { + it.contacts.all() + } if (excludingAccountIDs.isEmpty()) { allContacts } else { - allContacts.filterNot { it.accountID in excludingAccountIDs } + allContacts.filterNot { it.id in excludingAccountIDs } } } } @@ -90,13 +92,13 @@ class SelectContactsViewModel @AssistedInject constructor( .asSequence() .filter { query.isBlank() || - it.name?.contains(query, ignoreCase = true) == true || - it.nickname?.contains(query, ignoreCase = true) == true + it.name.contains(query, ignoreCase = true) || + it.nickname.contains(query, ignoreCase = true) } .map { contact -> ContactItem( contact = contact, - selected = selectedAccountIDs.contains(contact.accountID) + selected = selectedAccountIDs.contains(contact.id) ) } .toList() @@ -127,6 +129,6 @@ data class ContactItem( val contact: Contact, val selected: Boolean, ) { - val accountID: String get() = contact.accountID - val name: String get() = contact.getSearchName() + val accountID: String get() = contact.id + val name: String get() = contact.displayName.ifEmpty { truncateIdForDisplay(contact.id) } } \ No newline at end of file diff --git a/app/src/main/java/org/thoughtcrime/securesms/groups/compose/Components.kt b/app/src/main/java/org/thoughtcrime/securesms/groups/compose/Components.kt index cac20ccec4..abae0e7c80 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/groups/compose/Components.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/groups/compose/Components.kt @@ -38,7 +38,7 @@ import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import network.loki.messenger.R -import org.session.libsession.messaging.contacts.Contact +import network.loki.messenger.libsession_util.util.Contact import org.session.libsession.utilities.Address import org.session.libsession.utilities.recipients.Recipient import org.thoughtcrime.securesms.groups.ContactItem diff --git a/app/src/main/java/org/thoughtcrime/securesms/groups/compose/CreateGroupScreen.kt b/app/src/main/java/org/thoughtcrime/securesms/groups/compose/CreateGroupScreen.kt index 09b7d02a3d..9a6e41556c 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/groups/compose/CreateGroupScreen.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/groups/compose/CreateGroupScreen.kt @@ -21,7 +21,7 @@ import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import androidx.hilt.navigation.compose.hiltViewModel import network.loki.messenger.R -import org.session.libsession.messaging.contacts.Contact +import network.loki.messenger.libsession_util.util.Contact import org.thoughtcrime.securesms.groups.ContactItem import org.thoughtcrime.securesms.groups.CreateGroupEvent import org.thoughtcrime.securesms.groups.CreateGroupViewModel diff --git a/app/src/main/java/org/thoughtcrime/securesms/groups/compose/SelectContactsScreen.kt b/app/src/main/java/org/thoughtcrime/securesms/groups/compose/SelectContactsScreen.kt index 22fec95cf0..882faf2112 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/groups/compose/SelectContactsScreen.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/groups/compose/SelectContactsScreen.kt @@ -23,7 +23,7 @@ import androidx.compose.ui.unit.dp import androidx.hilt.navigation.compose.hiltViewModel import kotlinx.serialization.Serializable import network.loki.messenger.R -import org.session.libsession.messaging.contacts.Contact +import network.loki.messenger.libsession_util.util.Contact import org.thoughtcrime.securesms.groups.ContactItem import org.thoughtcrime.securesms.groups.SelectContactsViewModel import org.thoughtcrime.securesms.ui.SearchBar @@ -121,11 +121,11 @@ private fun PreviewSelectContacts() { SelectContacts( contacts = listOf( ContactItem( - contact = Contact(accountID = "123", name = "User 1"), + contact = Contact(id = "123", name = "User 1"), selected = false, ), ContactItem( - contact = Contact(accountID = "124", name = "User 2"), + contact = Contact(id = "124", name = "User 2"), selected = true, ), ), diff --git a/libsession-util/src/main/java/network/loki/messenger/libsession_util/util/Contact.kt b/libsession-util/src/main/java/network/loki/messenger/libsession_util/util/Contact.kt index de2075fd19..7f0c290647 100644 --- a/libsession-util/src/main/java/network/loki/messenger/libsession_util/util/Contact.kt +++ b/libsession-util/src/main/java/network/loki/messenger/libsession_util/util/Contact.kt @@ -9,5 +9,8 @@ data class Contact( var blocked: Boolean = false, var profilePicture: UserPic = UserPic.DEFAULT, var priority: Long = 0, - var expiryMode: ExpiryMode, -) \ No newline at end of file + var expiryMode: ExpiryMode = ExpiryMode.NONE, +) { + val displayName: String + get() = nickname.ifEmpty { name } +} \ No newline at end of file diff --git a/libsession/src/main/java/org/session/libsession/messaging/groups/GroupManagerV2.kt b/libsession/src/main/java/org/session/libsession/messaging/groups/GroupManagerV2.kt index 7c5b58801d..8e40f9c9a8 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/groups/GroupManagerV2.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/groups/GroupManagerV2.kt @@ -1,6 +1,6 @@ package org.session.libsession.messaging.groups -import org.session.libsession.messaging.contacts.Contact +import network.loki.messenger.libsession_util.util.Contact import org.session.libsession.messaging.messages.control.GroupUpdated import org.session.libsession.utilities.recipients.Recipient import org.session.libsignal.protos.SignalServiceProtos.DataMessage.GroupUpdateDeleteMemberContentMessage