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) {
|
override fun deleteMessagesByUser(threadId: Long, userSessionId: String) {
|
||||||
val userMessages = mmsSmsDatabase.getUserMessages(threadId, userSessionId)
|
val userMessages = mmsSmsDatabase.getUserMessages(threadId, userSessionId)
|
||||||
val (mmsMessages, smsMessages) = userMessages.partition { it.isMms }
|
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.lifecycle.HiltViewModel
|
||||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
|
||||||
import kotlinx.coroutines.GlobalScope
|
import kotlinx.coroutines.GlobalScope
|
||||||
import kotlinx.coroutines.async
|
import kotlinx.coroutines.async
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
@ -25,10 +24,10 @@ import kotlinx.coroutines.flow.update
|
|||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
import network.loki.messenger.R
|
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.GroupDisplayInfo
|
||||||
import network.loki.messenger.libsession_util.util.GroupMember
|
import network.loki.messenger.libsession_util.util.GroupMember
|
||||||
import org.session.libsession.database.StorageProtocol
|
import org.session.libsession.database.StorageProtocol
|
||||||
import org.session.libsession.messaging.contacts.Contact
|
|
||||||
import org.session.libsession.messaging.groups.GroupManagerV2
|
import org.session.libsession.messaging.groups.GroupManagerV2
|
||||||
import org.session.libsession.utilities.ConfigUpdateNotification
|
import org.session.libsession.utilities.ConfigUpdateNotification
|
||||||
import org.session.libsignal.utilities.AccountId
|
import org.session.libsignal.utilities.AccountId
|
||||||
@ -196,17 +195,17 @@ class EditGroupViewModel @AssistedInject constructor(
|
|||||||
try {
|
try {
|
||||||
// Mark the contacts as pending
|
// Mark the contacts as pending
|
||||||
memberPendingState.update { states ->
|
memberPendingState.update { states ->
|
||||||
states + contacts.associate { AccountId(it.accountID) to MemberPendingState.Inviting }
|
states + contacts.associate { AccountId(it.id) to MemberPendingState.Inviting }
|
||||||
}
|
}
|
||||||
|
|
||||||
groupManager.inviteMembers(
|
groupManager.inviteMembers(
|
||||||
groupId,
|
groupId,
|
||||||
contacts.map { AccountId(it.accountID) },
|
contacts.map { AccountId(it.id) },
|
||||||
shareHistory = false
|
shareHistory = false
|
||||||
)
|
)
|
||||||
} finally {
|
} finally {
|
||||||
// Remove pending state (so the real state will be revealed)
|
// 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.async
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
import network.loki.messenger.libsession_util.ConfigBase.Companion.PRIORITY_VISIBLE
|
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.Conversation
|
||||||
import network.loki.messenger.libsession_util.util.GroupInfo
|
import network.loki.messenger.libsession_util.util.GroupInfo
|
||||||
import network.loki.messenger.libsession_util.util.GroupMember
|
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 network.loki.messenger.libsession_util.util.UserPic
|
||||||
import org.session.libsession.database.StorageProtocol
|
import org.session.libsession.database.StorageProtocol
|
||||||
import org.session.libsession.database.userAuth
|
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.groups.GroupManagerV2
|
||||||
import org.session.libsession.messaging.jobs.InviteContactsJob
|
import org.session.libsession.messaging.jobs.InviteContactsJob
|
||||||
import org.session.libsession.messaging.jobs.JobQueue
|
import org.session.libsession.messaging.jobs.JobQueue
|
||||||
@ -116,7 +116,7 @@ class GroupManagerV2Impl @Inject constructor(
|
|||||||
for (member in members) {
|
for (member in members) {
|
||||||
configs.groupMembers.set(
|
configs.groupMembers.set(
|
||||||
GroupMember(
|
GroupMember(
|
||||||
sessionId = member.accountID,
|
sessionId = member.id,
|
||||||
name = member.name,
|
name = member.name,
|
||||||
profilePicture = member.profilePicture ?: UserPic.DEFAULT,
|
profilePicture = member.profilePicture ?: UserPic.DEFAULT,
|
||||||
inviteStatus = INVITE_STATUS_SENT
|
inviteStatus = INVITE_STATUS_SENT
|
||||||
@ -165,7 +165,7 @@ class GroupManagerV2Impl @Inject constructor(
|
|||||||
JobQueue.shared.add(
|
JobQueue.shared.add(
|
||||||
InviteContactsJob(
|
InviteContactsJob(
|
||||||
groupSessionId = groupId.hexString,
|
groupSessionId = groupId.hexString,
|
||||||
memberSessionIds = members.map { it.accountID }.toTypedArray()
|
memberSessionIds = members.map { it.id }.toTypedArray()
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -207,9 +207,12 @@ class GroupManagerV2Impl @Inject constructor(
|
|||||||
existing
|
existing
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
?: configs.groupMembers.getOrConstruct(newMember.hexString).let {
|
?: configs.groupMembers.getOrConstruct(newMember.hexString).let { member ->
|
||||||
val contact = storage.getContactWithAccountID(newMember.hexString)
|
val contact = configFactory.withUserConfigs { configs ->
|
||||||
it.copy(
|
configs.contacts.get(newMember.hexString)
|
||||||
|
}
|
||||||
|
|
||||||
|
member.copy(
|
||||||
name = contact?.name,
|
name = contact?.name,
|
||||||
profilePicture = contact?.profilePicture ?: UserPic.DEFAULT,
|
profilePicture = contact?.profilePicture ?: UserPic.DEFAULT,
|
||||||
inviteStatus = INVITE_STATUS_SENT,
|
inviteStatus = INVITE_STATUS_SENT,
|
||||||
@ -931,17 +934,6 @@ class GroupManagerV2Impl @Inject constructor(
|
|||||||
require(firstError == null) { "$errorMessage: ${firstError!!.body}" }
|
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?
|
private val Profile.profilePicture: UserPic?
|
||||||
get() {
|
get() {
|
||||||
val url = this.profilePictureURL
|
val url = this.profilePictureURL
|
||||||
|
@ -21,10 +21,10 @@ import kotlinx.coroutines.flow.map
|
|||||||
import kotlinx.coroutines.flow.onStart
|
import kotlinx.coroutines.flow.onStart
|
||||||
import kotlinx.coroutines.flow.stateIn
|
import kotlinx.coroutines.flow.stateIn
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
|
import network.loki.messenger.libsession_util.util.Contact
|
||||||
import org.session.libsession.database.StorageProtocol
|
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.dependencies.ConfigFactory
|
||||||
import org.thoughtcrime.securesms.home.search.getSearchName
|
|
||||||
|
|
||||||
@OptIn(FlowPreview::class)
|
@OptIn(FlowPreview::class)
|
||||||
@HiltViewModel(assistedFactory = SelectContactsViewModel.Factory::class)
|
@HiltViewModel(assistedFactory = SelectContactsViewModel.Factory::class)
|
||||||
@ -70,12 +70,14 @@ class SelectContactsViewModel @AssistedInject constructor(
|
|||||||
.onStart { emit(Unit) }
|
.onStart { emit(Unit) }
|
||||||
.map {
|
.map {
|
||||||
withContext(Dispatchers.Default) {
|
withContext(Dispatchers.Default) {
|
||||||
val allContacts = storage.getAllContacts()
|
val allContacts = configFactory.withUserConfigs {
|
||||||
|
it.contacts.all()
|
||||||
|
}
|
||||||
|
|
||||||
if (excludingAccountIDs.isEmpty()) {
|
if (excludingAccountIDs.isEmpty()) {
|
||||||
allContacts
|
allContacts
|
||||||
} else {
|
} else {
|
||||||
allContacts.filterNot { it.accountID in excludingAccountIDs }
|
allContacts.filterNot { it.id in excludingAccountIDs }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -90,13 +92,13 @@ class SelectContactsViewModel @AssistedInject constructor(
|
|||||||
.asSequence()
|
.asSequence()
|
||||||
.filter {
|
.filter {
|
||||||
query.isBlank() ||
|
query.isBlank() ||
|
||||||
it.name?.contains(query, ignoreCase = true) == true ||
|
it.name.contains(query, ignoreCase = true) ||
|
||||||
it.nickname?.contains(query, ignoreCase = true) == true
|
it.nickname.contains(query, ignoreCase = true)
|
||||||
}
|
}
|
||||||
.map { contact ->
|
.map { contact ->
|
||||||
ContactItem(
|
ContactItem(
|
||||||
contact = contact,
|
contact = contact,
|
||||||
selected = selectedAccountIDs.contains(contact.accountID)
|
selected = selectedAccountIDs.contains(contact.id)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
.toList()
|
.toList()
|
||||||
@ -127,6 +129,6 @@ data class ContactItem(
|
|||||||
val contact: Contact,
|
val contact: Contact,
|
||||||
val selected: Boolean,
|
val selected: Boolean,
|
||||||
) {
|
) {
|
||||||
val accountID: String get() = contact.accountID
|
val accountID: String get() = contact.id
|
||||||
val name: String get() = contact.getSearchName()
|
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.tooling.preview.Preview
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import network.loki.messenger.R
|
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.Address
|
||||||
import org.session.libsession.utilities.recipients.Recipient
|
import org.session.libsession.utilities.recipients.Recipient
|
||||||
import org.thoughtcrime.securesms.groups.ContactItem
|
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.compose.ui.unit.dp
|
||||||
import androidx.hilt.navigation.compose.hiltViewModel
|
import androidx.hilt.navigation.compose.hiltViewModel
|
||||||
import network.loki.messenger.R
|
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.ContactItem
|
||||||
import org.thoughtcrime.securesms.groups.CreateGroupEvent
|
import org.thoughtcrime.securesms.groups.CreateGroupEvent
|
||||||
import org.thoughtcrime.securesms.groups.CreateGroupViewModel
|
import org.thoughtcrime.securesms.groups.CreateGroupViewModel
|
||||||
|
@ -23,7 +23,7 @@ import androidx.compose.ui.unit.dp
|
|||||||
import androidx.hilt.navigation.compose.hiltViewModel
|
import androidx.hilt.navigation.compose.hiltViewModel
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
import network.loki.messenger.R
|
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.ContactItem
|
||||||
import org.thoughtcrime.securesms.groups.SelectContactsViewModel
|
import org.thoughtcrime.securesms.groups.SelectContactsViewModel
|
||||||
import org.thoughtcrime.securesms.ui.SearchBar
|
import org.thoughtcrime.securesms.ui.SearchBar
|
||||||
@ -121,11 +121,11 @@ private fun PreviewSelectContacts() {
|
|||||||
SelectContacts(
|
SelectContacts(
|
||||||
contacts = listOf(
|
contacts = listOf(
|
||||||
ContactItem(
|
ContactItem(
|
||||||
contact = Contact(accountID = "123", name = "User 1"),
|
contact = Contact(id = "123", name = "User 1"),
|
||||||
selected = false,
|
selected = false,
|
||||||
),
|
),
|
||||||
ContactItem(
|
ContactItem(
|
||||||
contact = Contact(accountID = "124", name = "User 2"),
|
contact = Contact(id = "124", name = "User 2"),
|
||||||
selected = true,
|
selected = true,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
@ -9,5 +9,8 @@ data class Contact(
|
|||||||
var blocked: Boolean = false,
|
var blocked: Boolean = false,
|
||||||
var profilePicture: UserPic = UserPic.DEFAULT,
|
var profilePicture: UserPic = UserPic.DEFAULT,
|
||||||
var priority: Long = 0,
|
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
|
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.messaging.messages.control.GroupUpdated
|
||||||
import org.session.libsession.utilities.recipients.Recipient
|
import org.session.libsession.utilities.recipients.Recipient
|
||||||
import org.session.libsignal.protos.SignalServiceProtos.DataMessage.GroupUpdateDeleteMemberContentMessage
|
import org.session.libsignal.protos.SignalServiceProtos.DataMessage.GroupUpdateDeleteMemberContentMessage
|
||||||
|
Loading…
Reference in New Issue
Block a user