insertCreateGroupMessage static method

Future<void> insertCreateGroupMessage({
  1. required Group group,
  2. String? creator,
  3. int? timestamp,
})

Implementation

static Future<void> insertCreateGroupMessage({
  required Group group,
  String? creator,
  int? timestamp,
}) async {
  int time = timestamp ?? DateTime.now().millisecondsSinceEpoch - 1;
  Message timeMsg = Message.createCustomSendMessage(
    targetId: group.groupId,
    event: alertTimeKey,
    chatType: ChatType.GroupChat,
  );
  timeMsg.serverTime = time;
  timeMsg.localTime = time;
  timeMsg.status = MessageStatus.SUCCESS;

  await ChatSDKService.instance.insertMessage(
    message: timeMsg,
  );

  Message alertMsg = Message.createCustomSendMessage(
    targetId: group.groupId,
    event: alertGroupCreateKey,
    chatType: ChatType.GroupChat,
    params: {
      alertOperatorIdKey: group.owner ?? creator ?? '',
      alertOperatorNameKey: creator ?? group.owner ?? '',
      alertTargetIdKey: group.groupId,
      alertTargetNameKey: group.name ?? '',
    },
  );

  alertMsg.conversationId = group.groupId;
  alertMsg.serverTime = time + 1;
  alertMsg.localTime = time + 1;
  alertMsg.status = MessageStatus.SUCCESS;

  await ChatSDKService.instance.insertMessage(
    message: alertMsg,
    runMessageReceived: false,
    needUpdateConversationList: true,
  );
}