checkInit method
Future<AbstractChat>
checkInit(
)
Implementation
Future<AbstractChat> checkInit() {
Completer<AbstractChat> completer = Completer();
if (CubeDialogType.PRIVATE == type) {
int recipientId = getRecipientId();
if (recipientId == -1) {
completer.completeError(IllegalStateException(
"Check you set participant and login to the chat"));
return completer.future;
}
PrivateChatManager? privateChatManager =
CubeChatConnection.instance.privateChatManager;
if (privateChatManager == null) {
completer.completeError(IllegalStateException(
"Need login to the chat before perform chat related operations"));
return completer.future;
}
PrivateChat privateChat = privateChatManager.getChat(recipientId);
completer.complete(privateChat);
} else {
if (isEmpty(dialogId)) {
completer.completeError(IllegalStateException(
"'dialog_id' can't be empty or null for this dialog type"));
return completer.future;
}
GroupChatManager? groupChatManager =
CubeChatConnection.instance.groupChatManager;
if (groupChatManager == null) {
completer.completeError(IllegalStateException(
"Need login to the chat before perform chat related operations"));
return completer.future;
}
GroupChat groupChat = groupChatManager.getChat(dialogId);
if (CubeSettings.instance.isJoinEnabled) {
_joinInternal(groupChat).then((groupChat) {
completer.complete(groupChat);
}).catchError((error) {
completer.completeError(error);
});
} else {
completer.complete(groupChat);
}
}
return completer.future;
}