// Alireza: inja type ro as string misze ke hatman ye child az BacktoryMatchMessage e. override internal void NotifyMessageReceived(string jsonMessage, string _type) { if (_type != null) { Type clazz = BacktoryRealtimeMessageFactory.GetType(_type); // TODO uncomment, if it is important??????? // JsonElement mJson = new JsonParser().parse(jsonMessage.toJSONstring()); // if (mJson == null) { // // TODO: 7/18/16 AD What to do? // } var message = (BacktoryMatchMessage)Backtory.FromJson(jsonMessage, clazz); //(new Gson()).fromJson(mJson, clazz); // TODO: 7/18/16 AD Use better mechanism for checking requestId: if (connectorClient.CheckRequestId(jsonMessage, _type)) { // TODO IMPORTANT : move this action on main thread if (BacktoryRealtimeMessageFactory.GetTypeCategory(_type).Equals(BacktoryRealtimeMessageFactory.TypeCategory.Challenge) && MatchListener != null) { message.OnMessageReceived(MatchListener); } else if (BacktoryRealtimeMessageFactory.GetTypeCategory(_type).Equals(BacktoryRealtimeMessageFactory.TypeCategory.General) && connectorClient.sdkListener != null) { message.OnMessageReceived(connectorClient.sdkListener); } else { // TODO: 7/20/16 AD What to do? } } } else { // TODO: 7/23/16 AD What to do? // connectorClient.sdkListener.OnMessage (jsonMessage); } }
private static LoginResponse GetStoredLoginResponse() { string loginResponseString = Backtory.Storage.Get(KeyLoginInfo); /*if (loginResponseString == null) * throw new IllegalStateException("no auth token exists");*/ return(Backtory.FromJson <LoginResponse>(loginResponseString)); }
public static GroupChatHistoryResponse Get(string responseJson) { A a = Backtory.FromJson <A> (responseJson); GroupChatHistoryResponse response = new GroupChatHistoryResponse(); List <ChatMessage> messageList = new List <ChatMessage>(); for (int i = 0; i < a.MessageList.Count; i++) { ComprehensiveChatMessage cCM = a.MessageList [i]; string cCMJson = Backtory.ToJson(cCM); if (cCM._type == ".SimpleChatMessage") { SimpleChatMessage sCM = Backtory.FromJson <SimpleChatMessage> (cCMJson); messageList.Add(sCM); } else if (cCM._type == ".ChatGroupUserAddedMessage") { UserAddedMessage sCM = Backtory.FromJson <UserAddedMessage> (cCMJson); messageList.Add(sCM); } else if (cCM._type == ".ChatGroupUserJoinedMessage") { UserJoinedMessage sCM = Backtory.FromJson <UserJoinedMessage> (cCMJson); messageList.Add(sCM); } else if (cCM._type == ".ChatGroupUserLeftMessage") { UserLeftMessage sCM = Backtory.FromJson <UserLeftMessage> (cCMJson); messageList.Add(sCM); } else if (cCM._type == ".ChatGroupUserRemovedMessage") { UserRemovedMessage sCM = Backtory.FromJson <UserRemovedMessage> (cCMJson); messageList.Add(sCM); } else if (cCM._type == ".ChatGroupInvitationMessage") { ChatInvitationMessage sCM = Backtory.FromJson <ChatInvitationMessage> (cCMJson); messageList.Add(sCM); } else { // ERROR } } response.ChatMessageList = messageList; return(response); }
internal void NotifyMessageReceived(string jsonMessage, string _type) { Debug.Log("==::::=> "); if (_type != null) { Type clazz = BacktoryConnectivityMessageFactory.GetType(_type); BacktoryConnectivityMessage message = (BacktoryConnectivityMessage)Backtory.FromJson(jsonMessage, clazz); if (connectorClient.CheckRequestId(jsonMessage, _type)) { // TODO IMPORTANT : move this action on main thread if (BacktoryConnectivityMessageFactory.GetTypeCategory(_type).Equals(BacktoryConnectivityMessageFactory.TypeCategory.Matchmaking) && matchmakingListener != null) { if (_type.Equals(BacktoryConnectivityMessage.MATCH_FOUND_MESSAGE)) { GenerateRealtimeMatch((MatchFoundMessage)message); } message.OnMessageReceived(matchmakingListener); } else if (BacktoryConnectivityMessageFactory.GetTypeCategory(_type).Equals(BacktoryConnectivityMessageFactory.TypeCategory.Challenge) && challengeListener != null) { if (_type.Equals(BacktoryConnectivityMessage.CHALLENGE_READY_MESSAGE)) { GenerateRealtimeMatch((ChallengeReadyMessage)message); } message.OnMessageReceived(challengeListener); } else if (BacktoryConnectivityMessageFactory.GetTypeCategory(_type).Equals(BacktoryConnectivityMessageFactory.TypeCategory.Chat) && chatListener != null) { message.OnMessageReceived(chatListener); JSONNode jsonNode = JSON.Parse(jsonMessage); SendDelivery((string)jsonNode ["deliveryId"]); } else if (BacktoryConnectivityMessageFactory.GetTypeCategory(_type).Equals(BacktoryConnectivityMessageFactory.TypeCategory.General) && connectorClient.sdkListener != null) { message.OnMessageReceived(connectorClient.sdkListener); } else { // TODO: 7/20/16 AD What to do? } } } else { // TODO: 7/23/16 AD What to do? // connectorClient.sdkListener.OnMessage (jsonMessage); } }
private BacktoryResponse <T> GenerateBacktoryResponse <T> (string responseJson, Type clazz) where T : class { Debug.Log("jsonnode: " + responseJson); if (responseJson == null) { return(BacktoryResponse <T> .Error((int)BacktoryHttpStatusCode.RequestTimeout, null)); } JSONNode jsonNode = JSONNode.Parse(responseJson); string _type = jsonNode ["_type"]; if (_type.Equals(".ExceptionResponse")) { ExceptionResponse exceptionResponse = Backtory.FromJson <ExceptionResponse> (responseJson); string message = exceptionResponse.Exception.Message; int errorCode = (int)exceptionResponse.Exception.Code; return(BacktoryResponse <T> .Error(errorCode, message)); } else if (typeof(T).Equals(typeof(GroupChatHistoryResponse))) { T body = GroupChatHistoryResponse.Get(responseJson) as T; return(BacktoryResponse <T> .Success(200, body)); } else if (typeof(T).Equals(typeof(UserChatHistoryResponse))) { T body = UserChatHistoryResponse.Get(responseJson) as T; return(BacktoryResponse <T> .Success(200, body)); } else if (typeof(T).Equals(typeof(OfflineMessageResponse))) { T body = OfflineMessageResponse.Get(responseJson) as T; return(BacktoryResponse <T> .Success(200, body)); } else { T body; if (clazz != typeof(BacktoryVoid)) { body = Backtory.FromJson(responseJson, clazz) as T; } else { body = default(BacktoryVoid) as T; } return(BacktoryResponse <T> .Success(200, body)); } }
public static BacktoryUser GetCurrentUser() { // from memory if (currentUser != null) { return(currentUser); } // from storage (mostly disk) string userJson = Backtory.Storage.Get(KeyCurrentUser); if (!userJson.IsEmpty()) { return(Backtory.FromJson <BacktoryUser>(userJson)); } // indicating a login is required because a user info must be exist in all conditions if user // access token is present in storage return(null); }