sendMediaMessage method

Future<Map> sendMediaMessage(
  1. dynamic message,
  2. String toConversationID,
  3. dynamic conversationType,
  4. dynamic config,
  5. int messageID,
  6. int progressID,
  7. int messageAttachedCallbackID,
)

Implementation

Future<Map<dynamic, dynamic>> sendMediaMessage(
    dynamic message,
    String toConversationID,
    dynamic conversationType,
    dynamic config,
    int messageID,
    int progressID,
    int messageAttachedCallbackID) async {
  Object _message = mapToJSObj(message);

  Object _config = mapToJSObj(config);

  Map notification = {
    'onMessageAttached':
        allowInterop((message, currentFileSize, totalFileSize) {
      ZIMMessageAttachedCallback? callback = ZIMCommonData
          .zimMessageAttachedCallbackMap[messageAttachedCallbackID];

      if (callback != null) {
        ZIMMessage zimMessage = getZIMMessage(message);
        callback(zimMessage);
      }
    }),
    'onMediaUploadingProgress':
        allowInterop((message, currentFileSize, totalFileSize) {
      ZIMMediaDownloadingProgress? progress =
          ZIMCommonData.mediaDownloadingProgressMap[progressID];

      if (progress != null) {
        ZIMMessage zimMessage = getZIMMessage(message);
        progress(zimMessage, currentFileSize, totalFileSize);
      }
    })
  };

  ZIMMediaDownloadingProgress? progress =
      ZIMCommonData.mediaDownloadingProgressMap[progressID];

  final result = await promiseToFuture(ZIM.getInstance()!.sendMediaMessage(
          _message,
          toConversationID,
          conversationType,
          _config,
          mapToJSObj(notification)))
      .catchError((e) {
    throw PlatformException(code: e.code.toString(), message: e.message);
  });

  return jsObjectToMap(result);
}