getMessageDetails static method

Future<BaseMessage?> getMessageDetails(
  1. int messageId, {
  2. dynamic onSuccess(
    1. BaseMessage
    )?,
  3. dynamic onError(
    1. CometChatException excep
    )?,
})

Fetches a single message by messageId.

The fetch carries withThreadSubscribed=true, so the returned message's BaseMessage.threadSubscribed reflects the logged-in user's subscription state for its thread — this is the fetch the thread row-insert recipe builds on (fetch the root message, build the row, insert at the head, mark it seen on the active ThreadsRequest).

Implementation

static Future<BaseMessage?> getMessageDetails(
  int messageId, {
  Function(BaseMessage message)? onSuccess,
  Function(CometChatException e)? onError,
}) async {
  try {
    final sdk = SdkRegistry.getInstance();
    final message = await sdk.messages.getMessageDetails(
      messageId.toString(),
    );
    // BEH-MEDIA-18: the delivered message carries its cached local paths.
    await OfflineRuntime.instance.hydrateDelivered(message);
    if (onSuccess != null) onSuccess(message);
    return message;
  } on SdkException catch (sdkEx) {
    final cometChatEx = CometChatException(
      sdkEx.code,
      sdkEx.details ?? sdkEx.message,
      sdkEx.message,
    );
    _errorCallbackHandler(cometChatEx, null, null, onError);
  } catch (e) {
    _errorCallbackHandler(null, null, e, onError);
  }
  return null;
}