Implementation
@override
void addNativeCallback() {
_channel.setMethodCallHandler((call) async {
try {
if (call.method == ListenerType.simpleMsgListener) {
Map<String, dynamic> data = formatJson(call.arguments);
Map<String, dynamic> params = data['data'] == null ? formatJson({}) : formatJson(data["data"]);
String type = data['type'];
simpleMessageListenerList.forEach((key, value) {
final msgID = params['msgID'];
switch (type) {
case 'onRecvC2CCustomMessage':
// String msgID, V2TIMUserInfo sender, byte[] customData
final sender = V2TimUserInfo.fromJson(params['sender']);
_catchListenerError(() {
value.onRecvC2CCustomMessage(
msgID,
sender,
params['customData'],
);
});
log(
"onRecvC2CCustomMessage",
{"key": key},
json.encode(
{
"sender": sender.toLogString(),
"msgID": msgID,
"customData": params['customData'],
},
),
);
break;
case 'onRecvC2CTextMessage':
// String msgID, V2TIMUserInfo sender, String text
final sender = V2TimUserInfo.fromJson(params['sender']);
_catchListenerError(() {
value.onRecvC2CTextMessage(
msgID,
sender,
params['text'],
);
});
log(
"onRecvC2CTextMessage",
{"key": key},
json.encode(
{
"sender": sender.toLogString(),
"msgID": msgID,
"text": params['text'],
},
),
);
break;
case 'onRecvGroupCustomMessage':
// String msgID, String groupID, V2TIMGroupMemberInfo sender, byte[] customData
final groupSender = V2TimGroupMemberInfo.fromJson(params['sender']);
_catchListenerError(() {
value.onRecvGroupCustomMessage(
msgID,
params['groupID'],
groupSender,
params['customData'],
);
});
log(
"onRecvGroupCustomMessage",
{"key": key},
json.encode(
{
"groupID": params['groupID'],
"msgID": msgID,
"groupSender": groupSender.toLogString(),
"customData": params['customData'],
},
),
);
break;
case 'onRecvGroupTextMessage':
// String msgID, String groupID, V2TIMGroupMemberInfo sender, String text
final groupSender = V2TimGroupMemberInfo.fromJson(params['sender']);
_catchListenerError(() {
value.onRecvGroupTextMessage(
params['msgID'],
params['groupID'],
groupSender,
params['text'],
);
});
log(
"onRecvGroupTextMessage",
{"key": key},
json.encode(
{
"groupID": params['groupID'],
"msgID": params['msgID'],
"groupSender": groupSender.toLogString(),
"text": params['text'],
},
),
);
break;
}
});
} else if (call.method == ListenerType.initSDKListener) {
Map<String, dynamic> data = formatJson(call.arguments);
Map<String, dynamic> params = formatJson(data['data']);
String type = data['type'];
initSDKListenerList.forEach((key, value) {
switch (type) {
case 'onSelfInfoUpdated':
final userInfo = V2TimUserFullInfo.fromJson(params);
_catchListenerError(() {
value.onSelfInfoUpdated(userInfo);
});
log(
"onSelfInfoUpdated",
{"key": key},
json.encode(
{
"userInfo": userInfo.toLogString(),
},
),
);
break;
case 'onConnectFailed':
_catchListenerError(() {
value.onConnectFailed(
params['code'],
params['desc'],
);
});
log(
"onConnectFailed",
{"key": key},
json.encode(
{
"code": params['code'],
"desc": params['desc'],
},
),
);
break;
case 'onConnecting':
_catchListenerError(() {
value.onConnecting();
});
log(
"onConnecting",
{"key": key},
"",
);
break;
case 'onConnectSuccess':
_catchListenerError(() {
value.onConnectSuccess();
});
log(
"onConnectSuccess",
{"key": key},
"",
);
break;
case 'onKickedOffline':
_catchListenerError(() {
value.onKickedOffline();
});
log(
"onKickedOffline",
{"key": key},
"",
);
break;
case 'onUserSigExpired':
_catchListenerError(() {
value.onUserSigExpired();
});
log(
"onUserSigExpired",
{"key": key},
"",
);
break;
case 'onUserStatusChanged':
List<dynamic> statusList = params['statusList'];
List<V2TimUserStatus> list = List.empty(growable: true);
for (var element in statusList) {
list.add(V2TimUserStatus.fromJson(element));
}
_catchListenerError(() {
value.onUserStatusChanged(list);
});
log(
"onUserStatusChanged",
{"key": key},
json.encode(list.map((e) => e.toLogString()).toList()),
);
break;
case 'onLog':
int level = params['level'];
String log = params['content'];
_catchListenerError(() {
value.onLog(level, log);
});
break;
case "onExperimentalNotify":
String key = params["key"];
dynamic param = params["param"];
_catchListenerError(() {
value.onExperimentalNotify(key, param);
});
log(
"onExperimentalNotify",
{"key": key},
json.encode({"key": params["key"], "param": params["param"]}),
);
break;
case "onUserInfoChanged":
List<dynamic> userInfoList = params['userInfoList'];
List<V2TimUserFullInfo> list = List.empty(growable: true);
for (var element in userInfoList) {
list.add(V2TimUserFullInfo.fromJson(formatJson(element)));
}
_catchListenerError(() {
value.onUserInfoChanged(list);
});
log(
"onUserInfoChanged",
{"key": key},
json.encode(list.map((e) => e.toLogString()).toList()),
);
break;
case "onAllReceiveMessageOptChanged":
final receiveMessageOptInfo = V2TimReceiveMessageOptInfo.fromJson(params);
_catchListenerError(() {
value.onAllReceiveMessageOptChanged(receiveMessageOptInfo);
});
log(
"onAllReceiveMessageOptChanged",
{"key": key},
receiveMessageOptInfo.toLogString(),
);
break;
}
});
} else if (call.method == ListenerType.groupListener) {
Map<String, dynamic> data = formatJson(call.arguments);
String type = data['type'];
Map<String, dynamic> params = data['data'] == null ? formatJson({}) : formatJson(data['data']);
String groupID = params['groupID'] ?? '';
String opReason = params['opReason'] ?? '';
bool isAgreeJoin = params['isAgreeJoin'] ?? false;
String customData = params['customData'] ?? '';
String topicID = params["topicID"] ?? "";
List<String> topicIDList = params["topicIDList"] == null ? List.empty(growable: true) : List.castFrom(params["topicIDList"]);
V2TimTopicInfo topicInfo = params["topicInfo"] == null ? V2TimTopicInfo() : V2TimTopicInfo.fromJson(params['topicInfo']);
Map<String, String> groupAttributeMap = params['groupAttributeMap'] == null ? Map<String, String>.from({}) : Map<String, String>.from(params['groupAttributeMap']);
List<dynamic> memberListMap = params['memberList'] == null ? List.empty(growable: true) : List.from(params['memberList']);
List<dynamic> groupMemberChangeInfoListMap = params['groupMemberChangeInfoList'] == null ? List.empty(growable: true) : List.from(params['groupMemberChangeInfoList']);
List<dynamic> groupChangeInfoListMap = params['groupChangeInfoList'] == null ? List.empty(growable: true) : List.from(params['groupChangeInfoList']);
List<V2TimGroupChangeInfo> groupChangeInfoList = List.empty(growable: true);
List<V2TimGroupMemberChangeInfo> groupMemberChangeInfoList = List.empty(growable: true);
List<V2TimGroupMemberInfo> memberList = List.empty(growable: true);
if (memberListMap.isNotEmpty) {
for (var element in memberListMap) {
memberList.add(V2TimGroupMemberInfo.fromJson(element));
}
}
if (groupMemberChangeInfoListMap.isNotEmpty) {
for (var element in groupMemberChangeInfoListMap) {
groupMemberChangeInfoList.add(V2TimGroupMemberChangeInfo.fromJson(element));
}
}
if (groupChangeInfoListMap.isNotEmpty) {
for (var element in groupChangeInfoListMap) {
groupChangeInfoList.add(V2TimGroupChangeInfo.fromJson(element));
}
}
late V2TimGroupMemberInfo opUser;
late V2TimGroupMemberInfo member;
if (params['opUser'] != null) {
opUser = V2TimGroupMemberInfo.fromJson(params['opUser']);
}
if (params['member'] != null) {
member = V2TimGroupMemberInfo.fromJson(params['member']);
}
groupListenerList.forEach((key, value) {
switch (type) {
case 'onMemberEnter':
_catchListenerError(() {
value.onMemberEnter(
groupID,
memberList,
);
});
log(
"onMemberEnter",
{"key": key},
json.encode({"groupID": groupID, "memberList": memberList.map((e) => e.toLogString()).toList()}),
);
break;
case 'onMemberLeave':
_catchListenerError(() {
value.onMemberLeave(
groupID,
member,
);
});
log(
"onMemberLeave",
{"key": key},
json.encode({"groupID": groupID, "member": member.toLogString()}),
);
break;
case 'onMemberInvited':
_catchListenerError(() {
value.onMemberInvited(
groupID,
opUser,
memberList,
);
});
log(
"onMemberInvited",
{"key": key},
json.encode({
"groupID": groupID,
"member": opUser.toLogString(),
"memberList": memberList.map((e) => e.toLogString()).toList(),
}),
);
break;
case 'onMemberKicked':
_catchListenerError(() {
value.onMemberKicked(
groupID,
opUser,
memberList,
);
});
log(
"onMemberKicked",
{"key": key},
json.encode({
"groupID": groupID,
"member": opUser.toLogString(),
"memberList": memberList.map((e) => e.toLogString()).toList(),
}),
);
break;
case 'onMemberInfoChanged':
_catchListenerError(() {
value.onMemberInfoChanged(
groupID,
groupMemberChangeInfoList,
);
});
log(
"onMemberInfoChanged",
{"key": key},
json.encode({
"groupID": groupID,
"groupMemberChangeInfoList": groupMemberChangeInfoList.map((e) => e.toLogString()).toList(),
}),
);
break;
case 'onGroupCreated':
_catchListenerError(() {
value.onGroupCreated(groupID);
});
log(
"onGroupCreated",
{"key": key},
json.encode({}),
);
break;
case 'onGroupDismissed':
_catchListenerError(() {
value.onGroupDismissed(
groupID,
opUser,
);
});
log(
"onGroupDismissed",
{"key": key},
json.encode({
"groupID": groupID,
"opUser": opUser.toLogString(),
}),
);
break;
case 'onGroupRecycled':
_catchListenerError(() {
value.onGroupRecycled(
groupID,
opUser,
);
});
log(
"onGroupRecycled",
{"key": key},
json.encode({
"groupID": groupID,
"opUser": opUser.toLogString(),
}),
);
break;
case 'onGroupInfoChanged':
_catchListenerError(() {
value.onGroupInfoChanged(
groupID,
groupChangeInfoList,
);
});
log(
"onGroupInfoChanged",
{"key": key},
json.encode({
"groupID": groupID,
"groupChangeInfoList": groupChangeInfoList.map((e) => e.toLogString()).toList(),
}),
);
break;
case 'onReceiveJoinApplication':
_catchListenerError(() {
value.onReceiveJoinApplication(
groupID,
member,
opReason,
);
});
log(
"onGroupInfoChanged",
{"key": key},
json.encode({
"groupID": groupID,
"opReason": opReason,
"member": member.toLogString(),
}),
);
break;
case 'onApplicationProcessed':
_catchListenerError(() {
value.onApplicationProcessed(
groupID,
opUser,
isAgreeJoin,
opReason,
);
});
log(
"onApplicationProcessed",
{"key": key},
json.encode({
"groupID": groupID,
"isAgreeJoin": isAgreeJoin,
"opReason": opReason,
"opUser": opUser.toLogString(),
}),
);
break;
case 'onGrantAdministrator':
_catchListenerError(() {
value.onGrantAdministrator(
groupID,
opUser,
memberList,
);
});
log(
"onGrantAdministrator",
{"key": key},
json.encode({
"groupID": groupID,
"memberList": memberList.map((e) => e.toLogString()).toList(),
"opUser": opUser.toLogString(),
}),
);
break;
case 'onRevokeAdministrator':
_catchListenerError(() {
value.onRevokeAdministrator(
groupID,
opUser,
memberList,
);
});
log(
"onRevokeAdministrator",
{"key": key},
json.encode({
"groupID": groupID,
"memberList": memberList.map((e) => e.toLogString()).toList(),
"opUser": opUser.toLogString(),
}),
);
break;
case 'onQuitFromGroup':
_catchListenerError(() {
value.onQuitFromGroup(groupID);
});
log(
"onQuitFromGroup",
{"key": key},
json.encode({}),
);
break;
case 'onReceiveRESTCustomData':
_catchListenerError(() {
value.onReceiveRESTCustomData(
groupID,
customData,
);
});
log(
"onReceiveRESTCustomData",
{"key": key},
json.encode({
"groupID": groupID,
"customData": customData,
}),
);
break;
case 'onGroupAttributeChanged':
_catchListenerError(() {
value.onGroupAttributeChanged(
groupID,
groupAttributeMap,
);
});
log(
"onGroupAttributeChanged",
{"key": key},
json.encode({
"groupID": groupID,
"groupAttributeMap": groupAttributeMap,
}),
);
break;
case "onTopicCreated":
_catchListenerError(() {
value.onTopicCreated(
groupID,
topicID,
);
});
log(
"onTopicCreated",
{"key": key},
json.encode({
"groupID": groupID,
"topicID": topicID,
}),
);
break;
case "onTopicDeleted":
_catchListenerError(() {
value.onTopicDeleted(
groupID,
topicIDList,
);
});
log(
"onTopicDeleted",
{"key": key},
json.encode({
"groupID": groupID,
"topicIDList": topicIDList,
}),
);
break;
case "onTopicInfoChanged":
_catchListenerError(() {
value.onTopicInfoChanged(
groupID,
topicInfo,
);
});
log(
"onTopicInfoChanged",
{"key": key},
json.encode({
"groupID": groupID,
"topicInfo": topicInfo.toLogString(),
}),
);
break;
case "onGroupCounterChanged":
String key = params["key"] ?? "";
int vv = params["value"] ?? 0;
_catchListenerError(() {
value.onGroupCounterChanged(
groupID,
key,
vv,
);
});
log(
"onGroupCounterChanged",
{"key": key},
json.encode({
"groupID": groupID,
"key": key,
"vv": vv,
}),
);
break;
case "onAllGroupMembersMuted":
bool isMute = params["isMute"] ?? false;
_catchListenerError(() {
value.onAllGroupMembersMuted(
groupID,
isMute,
);
});
log(
"onAllGroupMembersMuted",
{"key": key},
json.encode({
"groupID": groupID,
"isMute": isMute,
}),
);
break;
case "onMemberMarkChanged":
bool enableMark = params["enableMark"] ?? false;
List<String> memberIDList = List.from(params["memberIDList"] ?? []);
int markType = params["markType"] ?? 0;
_catchListenerError(() {
value.onMemberMarkChanged(
groupID,
memberIDList,
markType,
enableMark,
);
});
log(
"onMemberMarkChanged",
{"key": key},
json.encode({
"groupID": groupID,
"memberIDList": memberIDList,
"markType": markType,
"enableMark": enableMark,
}),
);
break;
}
});
} else if (call.method == ListenerType.advancedMsgListener) {
Map<String, dynamic> data = formatJson(call.arguments);
String type = data['type'];
dynamic params = data['data'] ?? formatJson({});
switch (type) {
case 'onRecvNewMessage':
advancedMsgListenerList.forEach((key, listener) {
_catchListenerError(() {
listener.onRecvNewMessage(V2TimMessage.fromJson(params));
});
});
log(
"onRecvNewMessage",
{},
json.encode({
"message": V2TimMessage.fromJson(params).toLogString(),
}),
);
break;
case 'onRecvMessageModified':
advancedMsgListenerList.forEach((key, listener) {
_catchListenerError(() {
listener.onRecvMessageModified(V2TimMessage.fromJson(params));
});
});
log(
"onRecvMessageModified",
{},
json.encode({
"message": V2TimMessage.fromJson(params).toLogString(),
}),
);
break;
case 'onRecvC2CReadReceipt':
List<dynamic> dataList = params;
List<V2TimMessageReceipt> receiptList = List.empty(growable: true);
for (var element in dataList) {
receiptList.add(V2TimMessageReceipt.fromJson(element));
}
advancedMsgListenerList.forEach((key, listener) {
_catchListenerError(() {
listener.onRecvC2CReadReceipt(receiptList);
});
});
log(
"onRecvC2CReadReceipt",
{},
json.encode({
"receiptList": receiptList.map((e) => e.toLogString()).toList(),
}),
);
break;
case 'onRecvMessageRevoked':
advancedMsgListenerList.forEach((key, listener) {
_catchListenerError(() {
listener.onRecvMessageRevoked(params);
});
});
log(
"onRecvMessageRevoked",
{},
json.encode({
"params": params,
}),
);
break;
case 'onSendMessageProgress':
final message = V2TimMessage.fromJson(params['message']);
advancedMsgListenerList.forEach((key, listener) {
_catchListenerError(() {
listener.onSendMessageProgress(
message,
params['progress'],
);
});
});
log(
"onSendMessageProgress",
{},
json.encode({
"message": message.toLogString(),
"progress": params['progress'],
}),
);
break;
case 'onRecvMessageReadReceipts':
List<dynamic> dataList = List<dynamic>.from(params);
List<V2TimMessageReceipt> receiptList = List.empty(growable: true);
for (var element in dataList) {
receiptList.add(V2TimMessageReceipt.fromJson(element));
}
advancedMsgListenerList.forEach((key, listener) {
_catchListenerError(() {
listener.onRecvMessageReadReceipts(receiptList);
});
});
log(
"onRecvMessageReadReceipts",
{},
json.encode({
"receiptList": receiptList.map((e) => e.toLogString()).toList(),
}),
);
break;
case "onRecvMessageExtensionsChanged":
Map<String, dynamic> cbdata = Map<String, Object>.from(params);
String msgID = cbdata["msgID"] ?? "";
List<dynamic> extensions = List.from(cbdata["extensions"] ?? []);
List<V2TimMessageExtension> resList = List.empty(growable: true);
for (var element in extensions) {
var elem = formatJson(element);
resList.add(V2TimMessageExtension(
extensionKey: elem["extensionKey"] ?? "",
extensionValue: elem["extensionValue"] ?? "",
));
}
advancedMsgListenerList.forEach((key, listener) {
_catchListenerError(() {
listener.onRecvMessageExtensionsChanged(
msgID,
resList,
);
});
});
log(
"onRecvMessageExtensionsChanged",
{},
json.encode({
"msgID": msgID,
"resList": resList.map((e) => e.toLogString()).toList(),
}),
);
break;
case "onRecvMessageExtensionsDeleted":
Map<String, dynamic> cbdata = formatJson(params);
String msgID = cbdata["msgID"] ?? "";
List<String> extensionKeys = List<String>.from(cbdata["extensionKeys"] ?? []);
advancedMsgListenerList.forEach((key, listener) {
_catchListenerError(() {
listener.onRecvMessageExtensionsDeleted(
msgID,
extensionKeys,
);
});
});
log(
"onRecvMessageExtensionsDeleted",
{},
json.encode({
"msgID": msgID,
"extensionKeys": extensionKeys,
}),
);
break;
case "onMessageDownloadProgressCallback":
Map<String, dynamic> cbdata = formatJson(params);
advancedMsgListenerList.forEach((key, listener) {
_catchListenerError(() {
listener.onMessageDownloadProgressCallback(
V2TimMessageDownloadProgress.fromJson(cbdata),
);
});
});
log(
"onMessageDownloadProgressCallback",
{},
json.encode({
"progress": V2TimMessageDownloadProgress.fromJson(cbdata).toLogString(),
}),
);
break;
case "onRecvMessageReactionsChanged":
List<dynamic> changeInfosm = List<dynamic>.from(params["changeInfos"]);
List<V2TIMMessageReactionChangeInfo> infos = List.empty(growable: true);
changeInfosm.forEach(((element) {
infos.add(V2TIMMessageReactionChangeInfo.fromJson(element));
}));
advancedMsgListenerList.forEach((key, listener) {
_catchListenerError(() {
listener.onRecvMessageReactionsChanged(infos);
});
});
log(
"onRecvMessageReactionsChanged",
{},
json.encode({
"infos": infos.map((e) => e.toLogString()).toList(),
}),
);
break;
case "onRecvMessageRevokedWithInfo":
String msgID = params["msgID"];
V2TimUserFullInfo operateUser = V2TimUserFullInfo.fromJson(params['operateUser'] ?? {});
String reason = params["reason"];
advancedMsgListenerList.forEach((key, listener) {
_catchListenerError(() {
listener.onRecvMessageRevokedWithInfo(msgID, operateUser, reason);
});
});
log(
"onRecvMessageRevokedWithInfo",
{},
json.encode({
"msgID": msgID,
"operateUser": operateUser.toLogString(),
"reason": reason,
}),
);
break;
case "onGroupMessagePinned":
String groupID = params["groupID"] ?? "";
V2TimMessage message = V2TimMessage.fromJson(params['message'] ?? {});
bool isPinned = params["isPinned"] ?? true;
V2TimGroupMemberInfo opUser = V2TimGroupMemberInfo.fromJson(params['opUser'] ?? {});
advancedMsgListenerList.forEach((key, listener) {
_catchListenerError(() {
listener.onGroupMessagePinned(groupID, message, isPinned, opUser);
});
});
log(
"onGroupMessagePinned",
{},
json.encode({
"groupID": groupID,
"message": message.toLogString(),
"isPinned": isPinned,
"opUser": opUser.toLogString(),
}),
);
break;
}
} else if (call.method == ListenerType.conversationListener) {
Map<String, dynamic> data = formatJson(call.arguments);
String type = data['type'];
conversationListenerList.forEach((key, value) {
switch (type) {
case 'onSyncServerStart':
_catchListenerError(() {
value.onSyncServerStart();
});
log(
"onSyncServerStart",
{"key": key},
json.encode({}),
);
break;
case 'onSyncServerFinish':
_catchListenerError(() {
value.onSyncServerFinish();
});
log(
"onSyncServerFinish",
{"key": key},
json.encode({}),
);
break;
case 'onSyncServerFailed':
_catchListenerError(() {
value.onSyncServerFailed();
});
log(
"onSyncServerFailed",
{"key": key},
json.encode({}),
);
break;
case 'onNewConversation':
List<dynamic> params = data['data'] == null ? List.empty(growable: true) : List.from(data['data']);
List<V2TimConversation> conversationList = List.empty(growable: true);
for (var element in params) {
conversationList.add(V2TimConversation.fromJson(element));
}
_catchListenerError(() {
value.onNewConversation(conversationList);
});
log(
"onNewConversation",
{"key": key},
json.encode({"conversationList": conversationList.map((e) => e.toLogString()).toList()}),
);
break;
case 'onConversationChanged':
List<dynamic> params = data['data'] == null ? List.empty(growable: true) : List<dynamic>.from(data['data']);
List<V2TimConversation> conversationList = List.empty(growable: true);
for (var element in params) {
conversationList.add(V2TimConversation.fromJson(element));
}
_catchListenerError(() {
value.onConversationChanged(conversationList);
});
log(
"onConversationChanged",
{"key": key},
json.encode({"conversationList": conversationList.map((e) => e.toLogString()).toList()}),
);
break;
case 'onTotalUnreadMessageCountChanged':
int params = data['data'] ?? 0;
_catchListenerError(() {
value.onTotalUnreadMessageCountChanged(params);
});
log(
"onTotalUnreadMessageCountChanged",
{"key": key},
json.encode({"params": params}),
);
break;
case "onConversationGroupCreated":
Map<String, dynamic> param = formatJson(data["data"]);
String groupName = param["groupName"];
List<V2TimConversation> list = List.empty(growable: true);
for (var v in List.from(param["conversationList"])) {
list.add(V2TimConversation.fromJson(v));
}
_catchListenerError(() {
value.onConversationGroupCreated(groupName, list);
});
log(
"onConversationGroupCreated",
{"key": key},
json.encode({"groupName": groupName, "list": list.map((e) => e.toLogString()).toList()}),
);
break;
case "onConversationGroupDeleted":
_catchListenerError(() {
value.onConversationGroupDeleted(data["data"]);
});
log(
"onConversationGroupDeleted",
{"key": key},
json.encode({
"data": data["data"],
}),
);
break;
case "onConversationGroupNameChanged":
Map<String, dynamic> param = formatJson(data["data"]);
_catchListenerError(() {
value.onConversationGroupNameChanged(param["oldName"], param["newName"]);
});
log(
"onConversationGroupNameChanged",
{"key": key},
json.encode({
"oldName": data["oldName"],
"newName": data["newName"],
}),
);
break;
case "onConversationsAddedToGroup":
Map<String, dynamic> param = formatJson(data["data"]);
String groupName = param["groupName"];
List<V2TimConversation> list = List.empty(growable: true);
for (var v in List.from(param["conversationList"])) {
list.add(V2TimConversation.fromJson(v));
}
_catchListenerError(() {
value.onConversationsAddedToGroup(groupName, list);
});
log(
"onConversationsAddedToGroup",
{"key": key},
json.encode({
"groupName": groupName,
"list": list.map((e) => e.toLogString()).toList(),
}),
);
break;
case "onConversationsDeletedFromGroup":
Map<String, dynamic> param = formatJson(data["data"]);
String groupName = param["groupName"];
List<V2TimConversation> list = List.empty(growable: true);
for (var v in List.from(param["conversationList"])) {
list.add(V2TimConversation.fromJson(v));
}
_catchListenerError(() {
value.onConversationsDeletedFromGroup(groupName, list);
});
log(
"onConversationsDeletedFromGroup",
{"key": key},
json.encode({
"groupName": groupName,
"list": list.map((e) => e.toLogString()).toList(),
}),
);
break;
case "onConversationDeleted":
List<String> list = List<String>.from(data["data"] ?? []);
_catchListenerError(() {
value.onConversationDeleted(list);
});
log(
"onConversationDeleted",
{"key": key},
json.encode({
"list": list,
}),
);
break;
case "onUnreadMessageCountChangedByFilter":
Map<String, dynamic> param = formatJson(data["data"]);
V2TimConversationFilter filter = V2TimConversationFilter.fromJson(param["filter"] ?? {});
int totalUnreadCount = param["totalUnreadCount"] ?? 0;
_catchListenerError(() {
value.onUnreadMessageCountChangedByFilter(filter, totalUnreadCount);
});
log(
"onUnreadMessageCountChangedByFilter",
{"key": key},
json.encode({
"filter": filter.toLogString(),
"totalUnreadCount": totalUnreadCount,
}),
);
break;
}
});
} else if (call.method == ListenerType.friendListener) {
Map<String, dynamic> data = formatJson(call.arguments);
String type = data['type'];
dynamic params = data['data'] ?? formatJson({});
friendListenerList.forEach((key, value) {
switch (type) {
case "onMutualFollowersListChanged":
Map<String, dynamic> formatedData = formatJson(params);
List<V2TimUserFullInfo> usersinfo = List.empty(growable: true);
List<dynamic> usersinfomap = List<dynamic>.from(formatedData["userInfoList"] ?? []);
for (int i = 0; i < usersinfomap.length; i++) {
usersinfo.add(V2TimUserFullInfo.fromJson(usersinfomap[i]));
}
bool isAdd = formatedData["isAdd"] ?? false;
_catchListenerError(() {
value.onMutualFollowersListChanged(
usersinfo,
isAdd,
);
});
log(
"onMutualFollowersListChanged",
{"key": key},
json.encode({
"usersinfo": usersinfo.map((e) => e.toLogString()).toList(),
"isAdd": isAdd,
}),
);
break;
case "onMyFollowersListChanged":
Map<String, dynamic> formatedData = formatJson(params);
List<V2TimUserFullInfo> usersinfo = List.empty(growable: true);
List<dynamic> usersinfomap = List<dynamic>.from(formatedData["userInfoList"] ?? []);
for (int i = 0; i < usersinfomap.length; i++) {
usersinfo.add(V2TimUserFullInfo.fromJson(usersinfomap[i]));
}
bool isAdd = formatedData["isAdd"] ?? false;
_catchListenerError(() {
value.onMyFollowersListChanged(
usersinfo,
isAdd,
);
});
log(
"onMyFollowersListChanged",
{"key": key},
json.encode({
"usersinfo": usersinfo.map((e) => e.toLogString()).toList(),
"isAdd": isAdd,
}),
);
break;
case "onMyFollowingListChanged":
Map<String, dynamic> formatedData = formatJson(params);
List<V2TimUserFullInfo> usersinfo = List.empty(growable: true);
List<dynamic> usersinfomap = List<dynamic>.from(formatedData["userInfoList"] ?? []);
for (int i = 0; i < usersinfomap.length; i++) {
usersinfo.add(V2TimUserFullInfo.fromJson(usersinfomap[i]));
}
bool isAdd = formatedData["isAdd"] ?? false;
_catchListenerError(() {
value.onMyFollowingListChanged(
usersinfo,
isAdd,
);
});
log(
"onMyFollowingListChanged",
{"key": key},
json.encode({
"usersinfo": usersinfo.map((e) => e.toLogString()).toList(),
"isAdd": isAdd,
}),
);
break;
case "onOfficialAccountDeleted":
String officialAccountID = params;
_catchListenerError(() {
value.onOfficialAccountDeleted(
officialAccountID,
);
});
log(
"onOfficialAccountDeleted",
{"key": key},
json.encode({
"officialAccountID": officialAccountID,
}),
);
break;
case "onOfficialAccountInfoChanged":
_catchListenerError(() {
value.onOfficialAccountInfoChanged(
V2TimOfficialAccountInfo.fromJson(params),
);
});
log(
"onOfficialAccountInfoChanged",
{"key": key},
json.encode({
"data": V2TimOfficialAccountInfo.fromJson(params).toLogString(),
}),
);
break;
case "onOfficialAccountSubscribed":
_catchListenerError(() {
value.onOfficialAccountSubscribed(
V2TimOfficialAccountInfo.fromJson(params),
);
});
log(
"onOfficialAccountSubscribed",
{"key": key},
json.encode({
"data": V2TimOfficialAccountInfo.fromJson(params).toLogString(),
}),
);
break;
case "onOfficialAccountUnsubscribed":
String officialAccountID = params;
_catchListenerError(() {
value.onOfficialAccountUnsubscribed(
officialAccountID,
);
});
log(
"onOfficialAccountUnsubscribed",
{"key": key},
json.encode({
"officialAccountID": officialAccountID,
}),
);
break;
case 'onFriendApplicationListAdded':
List<dynamic> applicationListMap = params;
List<V2TimFriendApplication> applicationList = List.empty(growable: true);
for (var element in applicationListMap) {
applicationList.add(V2TimFriendApplication.fromJson(element));
}
_catchListenerError(() {
value.onFriendApplicationListAdded(applicationList);
});
log(
"onFriendApplicationListAdded",
{"key": key},
json.encode({
"applicationList": applicationList.map((e) => e.toLogString()).toList(),
}),
);
break;
case 'onFriendApplicationListDeleted':
List<String> userIDList = List.from(params);
_catchListenerError(() {
value.onFriendApplicationListDeleted(userIDList);
});
log(
"onFriendApplicationListDeleted",
{"key": key},
json.encode({
"userIDList": userIDList,
}),
);
break;
case 'onFriendApplicationListRead':
_catchListenerError(() {
value.onFriendApplicationListRead();
});
log(
"onFriendApplicationListRead",
{"key": key},
json.encode({}),
);
break;
case 'onFriendListAdded':
List<dynamic> userMap = List<dynamic>.from(params);
List<V2TimFriendInfo> users = List.empty(growable: true);
for (var element in userMap) {
users.add(V2TimFriendInfo.fromJson(element));
}
_catchListenerError(() {
value.onFriendListAdded(users);
});
log(
"onFriendListAdded",
{"key": key},
json.encode({"users": users.map((e) => e.toLogString()).toList()}),
);
break;
case 'onFriendListDeleted':
List<String> userList = List.from(params);
_catchListenerError(() {
value.onFriendListDeleted(userList);
});
log(
"onFriendListAdded",
{"key": key},
json.encode({"userList": userList}),
);
break;
case 'onBlackListAdd':
List<dynamic> infoListMap = List<dynamic>.from(params);
List<V2TimFriendInfo> infoList = List.empty(growable: true);
for (var element in infoListMap) {
infoList.add(V2TimFriendInfo.fromJson(element));
}
_catchListenerError(() {
value.onBlackListAdd(infoList);
});
log(
"onBlackListAdd",
{"key": key},
json.encode({"infoList": infoList.map((e) => e.toLogString()).toList()}),
);
break;
case 'onBlackListDeleted':
List<String> userList = List.from(params);
_catchListenerError(() {
value.onBlackListDeleted(userList);
});
log(
"onBlackListDeleted",
{"key": key},
json.encode({
"userList": userList,
}),
);
break;
case 'onFriendInfoChanged':
List<dynamic> infoListMap = List<dynamic>.from(params);
List<V2TimFriendInfo> infoList = List.empty(growable: true);
for (var element in infoListMap) {
infoList.add(V2TimFriendInfo.fromJson(element));
}
_catchListenerError(() {
value.onFriendInfoChanged(infoList);
});
log(
"onFriendInfoChanged",
{"key": key},
json.encode({"infoList": infoList.map((e) => e.toLogString()).toList()}),
);
break;
}
});
} else if (call.method == 'logFromSwift') {
} else if (call.method == ListenerType.signalingListener) {
Map<String, dynamic> d = formatJson(call.arguments);
String type = d['type'];
Map<String, dynamic> params = formatJson(d['data']);
String inviteID = params['inviteID'] ?? '';
String inviter = params['inviter'] ?? '';
String groupID = params['groupID'] ?? '';
List<String>? inviteeList = params['inviteeList'] == null ? null : List.from(params['inviteeList']);
String data = params['data'] ?? '';
String invitee = params['invitee'] ?? '';
signalingListenerList.forEach((key, value) {
switch (type) {
case 'onReceiveNewInvitation':
_catchListenerError(() {
value.onReceiveNewInvitation(inviteID, inviter, groupID, inviteeList ?? [], data);
});
log(
"onReceiveNewInvitation",
{"key": key},
json.encode({
"inviteID": inviteID,
"inviter": inviter,
"groupID": groupID,
"inviteeList": inviteeList ?? [],
"data": data,
}),
);
break;
case 'onInviteeAccepted':
_catchListenerError(() {
value.onInviteeAccepted(inviteID, invitee, data);
});
log(
"onInviteeAccepted",
{"key": key},
json.encode({
"inviteID": inviteID,
"invitee": invitee,
"data": data,
}),
);
break;
case 'onInviteeRejected':
_catchListenerError(() {
value.onInviteeRejected(inviteID, invitee, data);
});
log(
"onInviteeRejected",
{"key": key},
json.encode({
"inviteID": inviteID,
"invitee": invitee,
"data": data,
}),
);
break;
case 'onInvitationCancelled':
_catchListenerError(() {
value.onInvitationCancelled(inviteID, inviter, data);
});
log(
"onInvitationCancelled",
{"key": key},
json.encode({
"inviteID": inviteID,
"inviter": inviter,
"data": data,
}),
);
break;
case 'onInvitationTimeout':
_catchListenerError(() {
value.onInvitationTimeout(inviteID, inviteeList ?? []);
});
log(
"onInvitationTimeout",
{"key": key},
json.encode({
"inviteID": inviteID,
"inviteeList": inviteeList ?? [],
}),
);
break;
}
});
} else if (call.method == ListenerType.communityListener) {
Map<String, dynamic> data = formatJson(call.arguments);
Map<String, dynamic> params = data['data'] == null ? formatJson({}) : formatJson(data["data"]);
String type = data['type'];
communityListenerList.forEach((key, value) {
switch (type) {
case "onCreateTopic":
String groupID = params["groupID"] ?? "";
String topicID = params["topicID"] ?? "";
value.onCreateTopic(groupID, topicID);
log(
"onCreateTopic",
{"key": key},
json.encode({
"groupID": groupID,
"topicID": topicID,
}),
);
break;
case "onDeleteTopic":
String groupID = params["groupID"] ?? "";
List<String> topicIDList = params["topicIDList"] == null ? [] : List<String>.from(params["topicIDList"]);
value.onDeleteTopic(groupID, topicIDList);
log(
"onDeleteTopic",
{"key": key},
json.encode({
"groupID": groupID,
"topicIDList": topicIDList,
}),
);
break;
case "onChangeTopicInfo":
String groupID = params["groupID"] ?? "";
value.onChangeTopicInfo(groupID, V2TimTopicInfo.fromJson(params["topicInfo"] ?? {}));
log(
"onChangeTopicInfo",
{"key": key},
json.encode({
"groupID": groupID,
"into": V2TimTopicInfo.fromJson(params["topicInfo"] ?? {}).toLogString(),
}),
);
break;
case "onReceiveTopicRESTCustomData":
String topicID = params["topicID"] ?? "";
String customData = params["customData"] ?? "";
value.onReceiveTopicRESTCustomData(topicID, customData);
log(
"onReceiveTopicRESTCustomData",
{"key": key},
json.encode({
"topicID": topicID,
"customData": "customData",
}),
);
break;
case "onCreatePermissionGroup":
String groupID = params["groupID"] ?? "";
value.onCreatePermissionGroup(
groupID,
V2TimPermissionGroupInfo.fromJson(params["permissionGroupInfo"] ?? {}),
);
log(
"onCreatePermissionGroup",
{"key": key},
json.encode({
"groupID": groupID,
"info": V2TimPermissionGroupInfo.fromJson(params["permissionGroupInfo"] ?? {}).toLogString(),
}),
);
break;
case "onDeletePermissionGroup":
String groupID = params["groupID"] ?? "";
List<String> permissionGroupIDList = params["permissionGroupIDList"] == null ? [] : List<String>.from(params["permissionGroupIDList"]);
value.onDeletePermissionGroup(groupID, permissionGroupIDList);
log(
"onDeletePermissionGroup",
{"key": key},
json.encode({
"groupID": groupID,
"permissionGroupIDList": permissionGroupIDList,
}),
);
break;
case "onChangePermissionGroupInfo":
String groupID = params["groupID"] ?? "";
value.onChangePermissionGroupInfo(groupID, V2TimPermissionGroupInfo.fromJson(params["permissionGroupInfo"] ?? {}));
log(
"onChangePermissionGroupInfo",
{"key": key},
json.encode({
"groupID": groupID,
"permissionGroupInfo": V2TimPermissionGroupInfo.fromJson(params["permissionGroupInfo"] ?? {}).toLogString(),
}),
);
break;
case "onAddMembersToPermissionGroup":
String groupID = params["groupID"] ?? "";
String permissionGroupID = params["permissionGroupID"] ?? "";
List<String> memberIDList = params["memberIDList"] == null ? [] : List<String>.from(params["memberIDList"]);
value.onAddMembersToPermissionGroup(groupID, permissionGroupID, memberIDList);
log(
"onAddMembersToPermissionGroup",
{"key": key},
json.encode({
"groupID": groupID,
"permissionGroupID": permissionGroupID,
"memberIDList": memberIDList,
}),
);
break;
case "onRemoveMembersFromPermissionGroup":
String groupID = params["groupID"] ?? "";
String permissionGroupID = params["permissionGroupID"] ?? "";
List<String> memberIDList = params["memberIDList"] == null ? [] : List<String>.from(params["memberIDList"]);
value.onRemoveMembersFromPermissionGroup(groupID, permissionGroupID, memberIDList);
log(
"onRemoveMembersFromPermissionGroup",
{"key": key},
json.encode({
"groupID": groupID,
"permissionGroupID": permissionGroupID,
"memberIDList": memberIDList,
}),
);
break;
case "onAddTopicPermission":
String groupID = params["groupID"] ?? "";
String permissionGroupID = params["permissionGroupID"] ?? "";
value.onAddTopicPermission(groupID, permissionGroupID, params["topicPermissionMap"] ?? {});
log(
"onAddTopicPermission",
{"key": key},
json.encode({
"groupID": groupID,
"permissionGroupID": permissionGroupID,
"topicPermissionMap": params["topicPermissionMap"] ?? {},
}),
);
break;
case "onDeleteTopicPermission":
String groupID = params["groupID"] ?? "";
String permissionGroupID = params["permissionGroupID"] ?? "";
List<String> topicIDList = params["topicIDList"] == null ? [] : List<String>.from(params["topicIDList"]);
value.onDeleteTopicPermission(groupID, permissionGroupID, topicIDList);
log(
"onDeleteTopicPermission",
{"key": key},
json.encode({
"groupID": groupID,
"permissionGroupID": permissionGroupID,
"topicIDList": topicIDList,
}),
);
break;
case "onModifyTopicPermission":
String groupID = params["groupID"] ?? "";
String permissionGroupID = params["permissionGroupID"] ?? "";
value.onModifyTopicPermission(groupID, permissionGroupID, params["topicPermissionMap"] ?? {});
log(
"onModifyTopicPermission",
{"key": key},
json.encode({
"groupID": groupID,
"permissionGroupID": permissionGroupID,
}),
);
break;
}
});
}
} catch (err) {
debugPrint("重点关注,回调失败了,数据类型异常。$err ${call.method} ${call.arguments['type']} ${call.arguments['data']}");
}
});
}