@@ -114,7 +114,7 @@ class GroupsNotifier extends Notifier<GroupsState> {
114114 await _loadGroupTypesForAllGroups (groups);
115115
116116 // Now calculate display names with member data available
117- await _calculateDisplayNames (groups, activePubkey );
117+ await _calculateDisplayNames (groups);
118118
119119 // Schedule message loading after the current build cycle completes
120120 Future .microtask (() async {
@@ -468,13 +468,13 @@ class GroupsNotifier extends Notifier<GroupsState> {
468468 }
469469
470470 /// Calculate display names for all groups
471- Future <void > _calculateDisplayNames (List <Group > groups, String currentUserPubkey ) async {
471+ Future <void > _calculateDisplayNames (List <Group > groups) async {
472472 final Map <String , String > displayNames = Map <String , String >.from (
473473 state.groupDisplayNames ?? {},
474474 );
475475
476476 for (final group in groups) {
477- final displayName = await _getDisplayNameForGroup (group, currentUserPubkey );
477+ final displayName = await _getDisplayNameForGroup (group);
478478 displayNames[group.mlsGroupId] = displayName;
479479 }
480480
@@ -490,7 +490,7 @@ class GroupsNotifier extends Notifier<GroupsState> {
490490 final activePubkey = ref.read (activePubkeyProvider) ?? '' ;
491491 if (activePubkey.isEmpty) return ;
492492
493- final displayName = await _getDisplayNameForGroup (group, activePubkey );
493+ final displayName = await _getDisplayNameForGroup (group);
494494 final updatedDisplayNames = Map <String , String >.from (state.groupDisplayNames ?? {});
495495 updatedDisplayNames[groupId] = displayName;
496496
@@ -588,13 +588,12 @@ class GroupsNotifier extends Notifier<GroupsState> {
588588 }
589589
590590 /// Get the appropriate display name for a group
591- Future <String > _getDisplayNameForGroup (Group group, String currentUserPubkey ) async {
591+ Future <String > _getDisplayNameForGroup (Group group) async {
592592 // For direct messages, use the other member's name
593593 final groupInformation = await getGroupInformation (groupId: group.mlsGroupId);
594594 if (groupInformation.groupType == GroupType .directMessage) {
595595 try {
596- final currentUserNpub = PubkeyFormatter (pubkey: currentUserPubkey).toNpub ();
597- final otherMember = getOtherGroupMember (group.mlsGroupId, currentUserNpub);
596+ final otherMember = getOtherGroupMember (group.mlsGroupId);
598597
599598 if (otherMember == null ) {
600599 _logger.warning (
@@ -804,7 +803,7 @@ class GroupsNotifier extends Notifier<GroupsState> {
804803 await _loadGroupTypesForAllGroups (actuallyNewGroups);
805804
806805 // Calculate display names for new groups
807- await _calculateDisplayNamesForSpecificGroups (actuallyNewGroups, activePubkey );
806+ await _calculateDisplayNamesForSpecificGroups (actuallyNewGroups);
808807
809808 _logger.info ('GroupsProvider: Added ${actuallyNewGroups .length } new groups' );
810809 }
@@ -852,14 +851,13 @@ class GroupsNotifier extends Notifier<GroupsState> {
852851 /// Calculate display names for specific groups (used for new groups)
853852 Future <void > _calculateDisplayNamesForSpecificGroups (
854853 List <Group > groups,
855- String currentUserPubkey,
856854 ) async {
857855 final Map <String , String > displayNames = Map <String , String >.from (
858856 state.groupDisplayNames ?? {},
859857 );
860858
861859 for (final group in groups) {
862- final displayName = await _getDisplayNameForGroup (group, currentUserPubkey );
860+ final displayName = await _getDisplayNameForGroup (group);
863861 displayNames[group.mlsGroupId] = displayName;
864862 }
865863
@@ -1025,18 +1023,25 @@ final groupsProvider = NotifierProvider<GroupsNotifier, GroupsState>(
10251023);
10261024
10271025extension GroupMemberUtils on GroupsNotifier {
1028- User ? getOtherGroupMember (String ? groupId, String ? currentUserNpub) {
1029- if (groupId == null || currentUserNpub == null ) return null ;
1026+ User ? getOtherGroupMember (String ? groupId) {
1027+ if (groupId == null ) return null ;
1028+ final activePubkey = ref.read (activePubkeyProvider);
1029+ if (activePubkey == null || activePubkey.isEmpty) return null ;
10301030 final members = getGroupMembers (groupId);
10311031 if (members == null || members.isEmpty) return null ;
10321032
1033- // Use safe filtering - never return the current user as fallback
1034- final otherMembers = members.where ((member) => member.publicKey != currentUserNpub).toList ();
1035-
1033+ final hexActivePubkey = PubkeyFormatter (pubkey: activePubkey).toHex ();
1034+ final otherMembers =
1035+ members
1036+ .where (
1037+ (member) => PubkeyFormatter (pubkey: member.publicKey).toHex () != hexActivePubkey,
1038+ )
1039+ .toList ();
1040+ final npubActivePubkey = PubkeyFormatter (pubkey: activePubkey).toNpub ();
10361041 if (otherMembers.isEmpty) {
10371042 _logger.warning (
10381043 'GroupsProvider: No other members found in DM group $groupId . '
1039- 'Total members: ${members .length }, Current user: $currentUserNpub ' ,
1044+ 'Total members: ${members .length }, Current user: $npubActivePubkey ' ,
10401045 );
10411046 return null ;
10421047 }
@@ -1047,7 +1052,7 @@ extension GroupMemberUtils on GroupsNotifier {
10471052 /// Get the display image for a group based on its type
10481053 /// For direct messages, returns the other member's image
10491054 /// For regular groups, returns null (can be extended for group avatars)
1050- String ? getGroupDisplayImage (String groupId, String currentUserNpub ) {
1055+ String ? getGroupDisplayImage (String groupId) {
10511056 final group = findGroupById (groupId);
10521057 if (group == null ) return null ;
10531058
@@ -1063,7 +1068,7 @@ extension GroupMemberUtils on GroupsNotifier {
10631068
10641069 // For direct messages, use the other member's image
10651070 if (groupType == GroupType .directMessage) {
1066- final otherMember = getOtherGroupMember (groupId, currentUserNpub );
1071+ final otherMember = getOtherGroupMember (groupId);
10671072 return otherMember? .imagePath;
10681073 }
10691074
0 commit comments