Implementation
void processCommand(Command cmd) {
final unreadCountPayload = cmd.payload['unread_cnt'];
if (unreadCountPayload != null) {
final info = UnreadCountInfo.fromJson(unreadCountPayload);
_updateSubscribedUnreadCountInfo(info);
}
if (cmd.requestId != null) {
_ackTimers.remove(cmd.requestId)?.cancel();
final completer = _completers.remove(cmd.requestId);
// final completer2 = _completers2.remove(cmd.requestId);
if (cmd.isError || cmd.hasError) {
if (cmd.errorCode == ErrorCode.accessTokenNotValid) {
sdk.eventManager.notifySessionTokenRequired();
}
completer?.completeError(SBError(
code: cmd.errorCode,
message: cmd.errorMessage,
));
// completer2?.completeError(SBError(
// code: cmd.errorCode,
// message: cmd.errorMessage,
// ));
return;
} else {
completer?.complete(cmd);
// completer2?.complete(cmd.event);
}
}
final cmdString = '-- Command: ${cmd.cmd}';
final encoder = JsonEncoder.withIndent(' ');
final payloadString = '-- Payload: ${encoder.convert(cmd.payload)}';
logger.i('Processing Socket event\n$cmdString\n$payloadString');
// cmd.event?.handleEvent();
// final handler = cmd.event?.handleEvent;
// if (handler != null) {
// _queue.enqueue(AsyncSimpleTask(handler));
// }
Future Function(Command)? fnc;
if (cmd.isError || cmd.hasError) {
fnc = _processError;
} else if (cmd.isLogin && cmd.requestId != null) {
fnc = _processSessionRefresh;
} else if (cmd.isLogin) {
fnc = _processLogin;
} else if (cmd.isSessionExpired) {
fnc = _processSessionExpired;
} else if (cmd.isNewMessage) {
fnc = _processNewMessage;
} else if (cmd.isUpdatedMessage) {
fnc = _processUpdateMessage;
} else if (cmd.isDeletedMessage) {
fnc = _processDeleteMessage;
} else if (cmd.isMemberCountChange) {
fnc = _processMemberCountChange;
} else if (cmd.isRead) {
fnc = _processRead;
} else if (cmd.isDelivery) {
fnc = _processDelivery;
} else if (cmd.isThread) {
fnc = _processThread;
} else if (cmd.isReaction) {
fnc = _processReaction;
} else if (cmd.isUserEvent) {
fnc = _processUserEvent;
} else if (cmd.isSystemEvent) {
fnc = _processSystemEvent;
} else if (cmd.isUpdatedPoll) {
fnc = _processUpdatePoll;
} else if (cmd.isVote) {
fnc = _processVote;
} else {/*not handle command*/}
if (fnc != null) {
final op = AsyncTask<Command>(func: fnc, arg: cmd);
_queue.enqueue(op);
}
}