createMessage<T, F> method

Future<V2TimValueCallback<V2TimMsgCreateInfoResult>> createMessage<T, F>({
  1. required String type,
  2. required Map<String, dynamic> params,
})

Implementation

Future<V2TimValueCallback<V2TimMsgCreateInfoResult>> createMessage<T, F>({required String type, required Map<String, dynamic> params}) async {
  var messageSimpleElem = {};
  switch (type) {
    case "text":
      {
        var text = params['text'] ?? '';
        messageSimpleElem = CreateMessage.createSimpleTextMessage(text);
        break;
      }
    case "custom":
      {
        String data = params['data'] ?? '';
        String desc = params['desc'] ?? "";
        String extension = params['extension'];
        messageSimpleElem = CreateMessage.createSimpleCustomMessage(data, desc, extension);
        break;
      }
    case "face":
      {
        int index = params['index'] ?? '';
        String data = params['data'] ?? '';
        messageSimpleElem = CreateMessage.createSimpleFaceMessage(index: index, data: data);
        break;
      }
    case "image":
      {
        messageSimpleElem = await CreateMessage.createSimpleImageMessage(params);
        break;
      }
    case "textAt":
      {
        String text = params['text'] ?? '';
        List<String> atUserList = params['atUserList'] ?? [];
        messageSimpleElem = CreateMessage.createSimpleAtText(atUserList: atUserList, text: text);
        break;
      }
    case "location":
      {
        String desc = params['description'] ?? '';
        double longitude = params['longitude'] ?? 0;
        double latitude = params['latitude'] ?? 0;
        messageSimpleElem = CreateMessage.createSimpleLoaction(description: desc, longitude: longitude, latitude: latitude);
        break;
      }
    case "mergeMessage":
      {
        List<String> msgIDList = params['msgIDList'] ?? [];
        String title = params['title'] ?? "";
        List<String> abstractList = params['abstractList'] ?? '';
        String compatibleText = params['compatibleText'];
        messageSimpleElem = CreateMessage.createSimpleMergeMessage(msgIDList: msgIDList, title: title, abstractList: abstractList, compatibleText: compatibleText);
        break;
      }
    case "forwardMessage":
      {
        final webRawMessage = timeweb!.findMessage(params['msgID']);
        messageSimpleElem = await CreateMessage.createSimpleForwardMessage(webRawMessage: webRawMessage);
        break;
      }
    case "video":
      {
        String videoFilePath = params['videoFilePath'] ?? '';
        dynamic file = params['inputElement'];
        messageSimpleElem = await CreateMessage.createSimpleVideoMessage(
          videoFilePath,
          file,
        );
        break;
      }
    case "file":
      {
        messageSimpleElem = await CreateMessage.createSimpleFileMessage(filePath: params['filePath'] ?? '', fileName: params['fileName'] ?? "", file: params['inputElement']);
        break;
      }
  }
  var result = handleSetMessageMap(messageSimpleElem);
  return CommonUtils.returnSuccess<V2TimMsgCreateInfoResult>(result);
}