Skip to content

Commit 6ccf18e

Browse files
Merge pull request #1404 from jbsession/fix/ses-3437
SES-3437 : Community Mentions Inconsistent
2 parents c265b7e + 1734de6 commit 6ccf18e

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

app/src/main/java/org/thoughtcrime/securesms/conversation/v2/mention/MentionViewModel.kt

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -163,11 +163,11 @@ class MentionViewModel(
163163
true
164164
)
165165

166-
// Other members from this groupv2
166+
// Get other members
167167
val otherMembers = if (recipient.isGroupV2Recipient) {
168168
val groupId = AccountId(recipient.address.toString())
169169

170-
// Get members of the group
170+
// Get members of the group from the config
171171
val rawMembers = configFactory.withGroupConfigs(groupId) {
172172
it.groupMembers.allWithStatus()
173173
}
@@ -183,12 +183,16 @@ class MentionViewModel(
183183
) // returns contact name or blank
184184
.takeIf { it.isNotBlank() } ?: id // fallback to id
185185
buildMember(id, name, id in moderatorIDs, false)
186-
}
186+
}.sortedBy { it.name }
187187
} else {
188-
// Fallback to only local contacts
189-
contactDatabase.getContacts(memberIDs)
190-
.asSequence()
191-
.filter { it.accountID != myId }
188+
// For communities and one-on-one conversations
189+
val contacts = contactDatabase.getContacts(memberIDs) // Get members from contacts based on memberIDs
190+
val contactMap = contacts.associateBy { it.accountID }
191+
192+
// Map using memberIDs to preserve the order of members
193+
memberIDs.asSequence()
194+
.filter { it != myId }
195+
.mapNotNull { contactMap[it] }
192196
.map { contact ->
193197
val id = contact.accountID
194198
val name = contact.displayName(contactContext)
@@ -348,7 +352,6 @@ class MentionViewModel(
348352
companion object {
349353
val MENTION_LIST_COMPARATOR = compareBy<Candidate> { !it.member.isMe }
350354
.thenBy { it.matchScore }
351-
.then(compareBy { it.member.name })
352355
}
353356
}
354357

0 commit comments

Comments
 (0)