convertGroupTipsMessage static method

Future<V2TimGroupTipsElem?> convertGroupTipsMessage(
  1. Map<String, dynamic> message, {
  2. String groupID = "",
})

Implementation

static Future<V2TimGroupTipsElem?> convertGroupTipsMessage(
    Map<String, dynamic> message,
    {String groupID = ""}) async {
  final messagePayload = jsToMap(message['payload']);
  final operationType = messagePayload['operationType'];
  final optId = messagePayload['operatorID'];

  final opMember = await _getMemberInfo(optId);

  // 群资料变更
  if (operationType == GroupTips.GRP_TIP_GRP_PROFILE_UPDATED) {
    final groupInfoChangeList = _convertGroupTipsProfileUpdated(message);
    return V2TimGroupTipsElem(
        memberCount: 0,
        memberList: [],
        memberChangeInfoList: [],
        groupID:
            jsToMap(messagePayload['groupProfile'])['groupID'] ?? groupID,
        groupChangeInfoList: groupInfoChangeList,
        type: GroupTipsElemType.V2TIM_GROUP_TIPS_TYPE_GROUP_INFO_CHANGE,
        opMember: opMember);
  }

  // 踢人出群
  if (operationType == GroupTips.GRP_TIP_MBR_KICKED_OUT) {
    final List<V2TimGroupMemberInfo> memberList =
        await _getGroupMemberInfo(message);
    return V2TimGroupTipsElem(
        memberCount: messagePayload['memberCount'],
        memberList: memberList,
        memberChangeInfoList: [],
        groupID:
            jsToMap(messagePayload['groupProfile'])['groupID'] ?? groupID,
        groupChangeInfoList: [],
        type: GroupTipsElemType.V2TIM_GROUP_TIPS_TYPE_KICKED,
        opMember: opMember);
  }

  //成员加群
  if (operationType == GroupTips.GRP_TIP_MBR_JOIN) {
    final isJoinGroup =
        messagePayload['operatorID'] == messagePayload['userIDList'][0];
    final List<V2TimGroupMemberInfo> memberList =
        await _getGroupMemberInfo(message);
    return V2TimGroupTipsElem(
        memberCount: messagePayload['memberCount'],
        memberList: memberList,
        memberChangeInfoList: [],
        groupID:
            jsToMap(messagePayload['groupProfile'])['groupID'] ?? groupID,
        groupChangeInfoList: [],
        type: isJoinGroup
            ? GroupTipsElemType.V2TIM_GROUP_TIPS_TYPE_JOIN
            : GroupTipsElemType.V2TIM_GROUP_TIPS_TYPE_INVITE,
        opMember: opMember);
  }

  //成员退群
  if (operationType == GroupTips.GRP_TIP_MBR_QUIT) {
    final List<V2TimGroupMemberInfo> memberList =
        await _getGroupMemberInfo(message);
    return V2TimGroupTipsElem(
        memberCount: messagePayload['memberCount'],
        memberList: memberList,
        memberChangeInfoList: [],
        groupID:
            jsToMap(messagePayload['groupProfile'])['groupID'] ?? groupID,
        groupChangeInfoList: [],
        type: GroupTipsElemType.V2TIM_GROUP_TIPS_TYPE_QUIT,
        opMember: opMember);
  }

  //指定管理员身份
  if (operationType == GroupTips.GRP_TIP_MBR_SET_ADMIN) {
    final List<V2TimGroupMemberInfo> memberList =
        await _getGroupMemberInfo(message);
    return V2TimGroupTipsElem(
        memberCount: messagePayload['memberCount'],
        memberList: memberList,
        memberChangeInfoList: [],
        groupID:
            jsToMap(messagePayload['groupProfile'])['groupID'] ?? groupID,
        groupChangeInfoList: [],
        type: GroupTipsElemType.V2TIM_GROUP_TIPS_TYPE_SET_ADMIN,
        opMember: opMember);
  }

  // 撤销管理员身份
  if (operationType == GroupTips.GRP_TIP_MBR_CANCELED_ADMIN) {
    final List<V2TimGroupMemberInfo> memberList =
        await _getGroupMemberInfo(message);
    return V2TimGroupTipsElem(
        memberCount: messagePayload['memberCount'],
        memberList: memberList,
        memberChangeInfoList: [],
        groupID:
            jsToMap(messagePayload['groupProfile'])['groupID'] ?? groupID,
        groupChangeInfoList: [],
        type: GroupTipsElemType.V2TIM_GROUP_TIPS_TYPE_CANCEL_ADMIN,
        opMember: opMember);
  }

  // 群成员资料变更,例如:群成员被禁言
  if (operationType == GroupTips.GRP_TIP_MBR_PROFILE_UPDATED) {
    final List<V2TimGroupMemberChangeInfo> groupMemberChangeInfoList =
        _convertGroupMemberInfoChanged(message);
    return V2TimGroupTipsElem(
        memberCount: messagePayload['memberCount'],
        memberList: [],
        memberChangeInfoList: groupMemberChangeInfoList,
        groupID:
            jsToMap(messagePayload['groupProfile'])['groupID'] ?? groupID,
        groupChangeInfoList: [],
        type: GroupTipsElemType.V2TIM_GROUP_TIPS_TYPE_MEMBER_INFO_CHANGE,
        opMember: opMember);
  }
  return null;
}