@@ -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