getConversationFromMessage static method
- @Deprecated('This function is deprecated and moved into CometChatHelper class. Use CometChatHelper.getConversationFromMessage() instead.')
- BaseMessage message, {
- required dynamic onSuccess(
- Conversation conversation
- required dynamic onError(
- CometChatException excep
get the conversation object from message object.
method could throw PlatformException with error codes specifying the cause
Implementation
@Deprecated(
'This function is deprecated and moved into CometChatHelper class. Use CometChatHelper.getConversationFromMessage() instead.')
static Future<Conversation?> getConversationFromMessage(BaseMessage message,
{required Function(Conversation conversation)? onSuccess,
required Function(CometChatException excep)? onError}) async {
try {
String conversationType = message.receiverType;
User? loggedInUser = await getLoggedInUser();
String? conversationId = message.conversationId;
if (loggedInUser != null) {
AppEntity appEntity = AppEntity();
if (conversationType == CometChatReceiverType.user) {
if (loggedInUser.uid == message.sender!.uid) {
appEntity = message.receiver!;
} else {
appEntity = message.sender!;
}
} else {
appEntity = message.receiver!;
}
Conversation conversation = Conversation(
conversationId: conversationId,
conversationType: conversationType,
conversationWith: appEntity,
lastMessage: message,
updatedAt: message.updatedAt);
if (onSuccess != null) onSuccess(conversation);
return conversation;
} else {
_errorCallbackHandler(
CometChatException(
ErrorCode.errorUserNotLoggedIn,
ErrorMessage.errorMessageUserNotLoggedIn,
ErrorMessage.errorMessageUserNotLoggedIn),
null,
null,
onError);
return null;
}
} on PlatformException catch (p) {
_errorCallbackHandler(null, p, null, onError);
} catch (e) {
_errorCallbackHandler(null, null, e, onError);
}
return null;
}