convertGroupNoticeMessage static method

Future<NoticeMessageListenner?> convertGroupNoticeMessage(
  1. Map<String, dynamic> message
)

Implementation

static Future<NoticeMessageListenner?> convertGroupNoticeMessage(
    Map<String, dynamic> message) async {
  final messagePayload = jsToMap(message['payload']);
  final operationType = messagePayload['operationType'];
  final optId = messagePayload['operatorID'];
  final member = await _getMemberInfo(optId);

  // 有用户申请加入群
  if (operationType == 1) {
    return NoticeMessageListenner(
        listennerName: 'onReceiveJoinApplication',
        groupID: jsToMap(messagePayload['groupProfile'])['groupID'],
        opUser: member,
        opReason: messagePayload['handleMessage']);
  }

  // 申请加群被同意或拒绝
  if (operationType == 2 || operationType == 3) {
    return NoticeMessageListenner(
        listennerName: 'onApplicationProcessed',
        groupID: jsToMap(messagePayload['groupProfile'])['groupID'],
        opUser: member,
        isAgreeJoin: operationType == 2,
        opReason: messagePayload['handleMessage']);
  }

  // 群解散
  if (operationType == 5) {
    return NoticeMessageListenner(
        listennerName: 'onGroupDismissed',
        groupID: jsToMap(messagePayload['groupProfile'])['groupID'],
        opUser: member);
  }
  // 创建群组
  if (operationType == 6) {
    return NoticeMessageListenner(
        listennerName: 'onGroupCreated',
        opUser: member,
        groupID: jsToMap(messagePayload['groupProfile'])['groupID']);
  }

  // 群回收
  if (operationType == 11) {
    return NoticeMessageListenner(
        listennerName: 'onGroupRecycled',
        groupID: jsToMap(messagePayload['groupProfile'])['groupID'],
        opUser: member);
  }

  // 用户自定义通知
  if (operationType == 255) {
    return NoticeMessageListenner(
        opUser: member,
        listennerName: 'onReceiveRESTCustomData',
        groupID: jsToMap(messagePayload['groupProfile'])['groupID'],
        customData: messagePayload['userDefinedField']);
  }

  // 群消息提醒变更
  if (operationType == 20) {
    return NoticeMessageListenner(
      opUser: member,
      listennerName: 'onGroupInfoChange',
      groupID: jsToMap(messagePayload['groupProfile'])['groupID'],
      recvOpt: GroupRecvMsgOpt.convertMsgRecvOpt(
          messagePayload['messageRemindType']),
    );
  }

  return null;
}