mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-25 11:05:25 +00:00
Use config's contact directly
This commit is contained in:
parent
1b9b5dd42c
commit
e0ea98abdd
@ -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 }
|
||||
|
@ -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) } }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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) }
|
||||
}
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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,
|
||||
),
|
||||
),
|
||||
|
@ -9,5 +9,8 @@ data class Contact(
|
||||
var blocked: Boolean = false,
|
||||
var profilePicture: UserPic = UserPic.DEFAULT,
|
||||
var priority: Long = 0,
|
||||
var expiryMode: ExpiryMode,
|
||||
)
|
||||
var expiryMode: ExpiryMode = ExpiryMode.NONE,
|
||||
) {
|
||||
val displayName: String
|
||||
get() = nickname.ifEmpty { name }
|
||||
}
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user