Skip to content

Commit 19f8cda

Browse files
committed
add group manager handler events.
1 parent da6686b commit 19f8cda

File tree

6 files changed

+96
-3
lines changed

6 files changed

+96
-3
lines changed

android/src/main/java/com/easemob/im_flutter_sdk/EMGroupManagerWrapper.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1121,6 +1121,31 @@ public void onSharedFileDeleted(String groupId, String fileId) {
11211121
}
11221122
);
11231123
}
1124+
1125+
@Override
1126+
public void onSpecificationChanged(EMGroup group) {
1127+
EMListenerHandle.getInstance().addHandle(
1128+
()-> {
1129+
Map<String, Object> data = new HashMap<>();
1130+
data.put("type", "groupSpecificationDidUpdate");
1131+
data.put("group", EMGroupHelper.toJson(group));
1132+
post(() -> channel.invokeMethod(EMSDKMethod.onGroupChanged, data));
1133+
}
1134+
);
1135+
}
1136+
1137+
@Override
1138+
public void onStateChanged(EMGroup group, boolean isDisabled) {
1139+
EMListenerHandle.getInstance().addHandle(
1140+
()-> {
1141+
Map<String, Object> data = new HashMap<>();
1142+
data.put("type", "groupStateChanged");
1143+
data.put("groupId", group.getGroupId());
1144+
data.put("isDisabled", isDisabled);
1145+
post(() -> channel.invokeMethod(EMSDKMethod.onGroupChanged, data));
1146+
}
1147+
);
1148+
}
11241149
};
11251150
EMClient.getInstance().groupManager().addGroupChangeListener(groupChangeListener);
11261151
}

ios/Classes/EMGroupManagerWrapper.m

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1287,8 +1287,6 @@ - (void)groupFileListDidUpdate:(EMGroup *)aGroup
12871287

12881288
- (void)groupFileListDidUpdate:(EMGroup *)aGroup
12891289
removedSharedFile:(NSString *)aFileId {
1290-
1291-
12921290
__weak typeof(self) weakSelf = self;
12931291
[EMListenerHandle.sharedInstance addHandle:^{
12941292
NSDictionary *map = @{
@@ -1302,4 +1300,29 @@ - (void)groupFileListDidUpdate:(EMGroup *)aGroup
13021300
}
13031301

13041302

1303+
- (void)groupSpecificationDidUpdate:(EMGroup *)aGroup {
1304+
__weak typeof(self) weakSelf = self;
1305+
[EMListenerHandle.sharedInstance addHandle:^{
1306+
NSDictionary *map = @{
1307+
@"type":@"groupSpecificationDidUpdate",
1308+
@"group": [aGroup toJson]
1309+
};
1310+
[weakSelf.channel invokeMethod:ChatOnGroupChanged
1311+
arguments:map];
1312+
}];
1313+
}
1314+
- (void)groupStateChanged:(EMGroup *)aGroup
1315+
isDisabled:(BOOL)aDisabled {
1316+
__weak typeof(self) weakSelf = self;
1317+
[EMListenerHandle.sharedInstance addHandle:^{
1318+
NSDictionary *map = @{
1319+
@"type":@"groupStateChanged",
1320+
@"groupId":aGroup.groupId,
1321+
@"isDisabled":@(aDisabled)
1322+
};
1323+
[weakSelf.channel invokeMethod:ChatOnGroupChanged
1324+
arguments:map];
1325+
}];
1326+
}
1327+
13051328
@end

lib/src/em_group_manager.dart

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// ignore_for_file: deprecated_member_use_from_same_package
22

33
import 'dart:async';
4+
import 'dart:js_util';
45

56
import 'package:flutter/services.dart';
67
import 'internal/inner_headers.dart';
@@ -1383,6 +1384,15 @@ class EMGroupManager {
13831384
bool isAllMuted = map["isMuted"] as bool;
13841385
element.onAllGroupMemberMuteStateChanged?.call(groupId, isAllMuted);
13851386
break;
1387+
case EMGroupChangeEvent.ON_SPECIFICATION_DID_UPDATE:
1388+
EMGroup group = EMGroup.fromJson(map["group"]);
1389+
element.onSpecificationDidUpdate?.call(group);
1390+
break;
1391+
case EMGroupChangeEvent.ON_STATE_CHANGED:
1392+
String groupId = map["groupId"];
1393+
bool isDisable = map["isDisabled"] as bool;
1394+
element.onDisableChanged?.call(groupId, isDisable);
1395+
break;
13861396
}
13871397
});
13881398

@@ -1517,6 +1527,15 @@ class EMGroupManager {
15171527
bool isAllMuted = map["isMuted"] as bool;
15181528
listener.onAllGroupMemberMuteStateChanged(groupId, isAllMuted);
15191529
break;
1530+
case EMGroupChangeEvent.ON_SPECIFICATION_DID_UPDATE:
1531+
EMGroup group = EMGroup.fromJson(map["group"]);
1532+
listener.onSpecificationDidUpdate(group);
1533+
break;
1534+
case EMGroupChangeEvent.ON_STATE_CHANGED:
1535+
String groupId = map["groupId"];
1536+
bool isDisable = map["isDisable"] as bool;
1537+
listener.onDisableChange(groupId, isDisable);
1538+
break;
15201539
}
15211540
}
15221541
}

lib/src/em_listeners.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,12 @@ abstract class EMGroupManagerListener {
621621
/// - `false`: No.
622622
///
623623
void onAllGroupMemberMuteStateChanged(String groupId, bool isAllMuted);
624+
625+
/// Occurs when the group detail information is updated.
626+
void onSpecificationDidUpdate(EMGroup group);
627+
628+
/// Occurs when the group is enabled or disabled.
629+
void onDisableChange(String groupId, bool isDisable);
624630
}
625631

626632
///

lib/src/event_handler/manager_event_handler.dart

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ class EMChatRoomEventHandler {
407407
String? roomName,
408408
String? participant,
409409
)? onRemovedFromChatRoom;
410-
410+
411411
/// Occurs when the chat room specifications changes. All chat room members receive this event.
412412
final void Function(EMChatRoom room)? onSpecificationChanged;
413413

@@ -818,6 +818,17 @@ class EMGroupEventHandler {
818818
EMGroupSharedFile sharedFile,
819819
)? onSharedFileAddedFromGroup;
820820

821+
/// Occurs when the group detail information is updated.
822+
final void Function(
823+
EMGroup group,
824+
)? onSpecificationDidUpdate;
825+
826+
/// Occurs when the group is enabled or disabled.
827+
final void Function(
828+
String groupId,
829+
bool isDisable,
830+
)? onDisableChanged;
831+
821832
///
822833
/// Occurs when a shared file is removed from a group.
823834
///
@@ -881,6 +892,10 @@ class EMGroupEventHandler {
881892
///
882893
/// Param [onUserRemovedFromGroup] Current user is removed from the group by the group admin callback.
883894
///
895+
/// Param [onSpecificationDidUpdate] Occurs when the group detail information is updated.
896+
///
897+
/// Param [onDisableChanged] /// Occurs when the group is enabled or disabled.
898+
///
884899
EMGroupEventHandler({
885900
this.onAdminAddedFromGroup,
886901
this.onAdminRemovedFromGroup,
@@ -904,6 +919,8 @@ class EMGroupEventHandler {
904919
this.onSharedFileAddedFromGroup,
905920
this.onSharedFileDeletedFromGroup,
906921
this.onUserRemovedFromGroup,
922+
this.onSpecificationDidUpdate,
923+
this.onDisableChanged,
907924
});
908925
}
909926

lib/src/internal/em_event_keys.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,7 @@ class EMGroupChangeEvent {
5353
static const String ON_WHITE_LIST_ADDED = "groupWhiteListAdded";
5454
static const String ON_ALL_MEMBER_MUTE_STATE_CHANGED =
5555
"groupAllMemberMuteStateChanged";
56+
static const String ON_SPECIFICATION_DID_UPDATE =
57+
"groupSpecificationDidUpdate";
58+
static const String ON_STATE_CHANGED = "groupStateChanged";
5659
}

0 commit comments

Comments
 (0)