Пример #1
0
        private void OnMessageSend(ulong to, string msg)
        {
            ChatAppMsg chatMsg = new ChatAppMsg();

            chatMsg.Request                     = new ChatRequest();
            chatMsg.Request.SendRequest         = new ChatSend();
            chatMsg.Request.SendRequest.To      = to;
            chatMsg.Request.SendRequest.Message = msg;
            _api.App.SendAppMsg(_info, chatMsg.ToByteArray(),
                                AppMsgRecipient.PROVIDER).Exec();
        }
Пример #2
0
        private byte[] ListRequest(ulong userId, MsgContext ctx)
        {
            ChatAppMsg msg = new ChatAppMsg();

            msg.List = new ChatList();
            if (_chats.ContainsKey(userId))
            {
                msg.List.List.AddRange(_chats[userId].Select(x => x.Value.ToNetworkModel()));
                if (_newMsgs.TryGetValue(userId, out Queue <ChatObjMsg> updates))
                {
                    updates.Clear();
                }
            }
            return(msg.ToByteArray());
        }
Пример #3
0
        private IEnumerator ChatCoroutine()
        {
            ChatAppMsg msg = new ChatAppMsg();

            msg.Request             = new ChatRequest();
            msg.Request.ListRequest = true;
            var req = _api.App.SendAppMsg(_info, msg.ToByteArray(), AppMsgRecipient.PROVIDER);

            yield return(req.WaitCoroutine());

            if (req.HasException)
            {
                throw req.Exception;
            }
            if (req.Result != null)
            {
                ChatAppMsg response = ChatAppMsg.Parser.ParseFrom(req.Result);
                if (response == null || response.List == null)
                {
                    throw new ChatAppException("Unknown response.");
                }
                _chats = response.List.List
                         .Select(x => new ChatObj(x))
                         .ToDictionary(x => x.User1 == _userId ? x.User2 : x.User1, x => x);
                yield return(null);
            }
            else
            {
                _chats = new Dictionary <ulong, ChatObj>();
            }
            _recentBlock.SetChatList(_chats.Select(x => x.Value).ToList());
            yield return(null);

            while (true)
            {
                EventDataMsg updateReq = new EventDataMsg();
                updateReq.AppId     = APP_ID;
                updateReq.EventType = (uint)ChatAppEventType.GET_UPDATE;
                var updateReqService = _api.Event.SendEvent(updateReq, EventRecipient.PROVIDER);
                yield return(updateReqService.WaitCoroutine());

                if (updateReqService.HasException)
                {
                    yield return(new WaitForSeconds(UPDATE_INTERVAL_SEC));

                    continue;
                }
                ChatUpdateMsg updateMsg = ChatUpdateMsg.Parser.ParseFrom(updateReqService.Result);
                if (updateMsg == null)
                {
                    yield return(new WaitForSeconds(UPDATE_INTERVAL_SEC));

                    continue;
                }
                List <ChatObjMsg> msgs = updateMsg.Messages
                                         .Select(x => new ChatObjMsg(x))
                                         .ToList();
                Update(msgs);
                yield return(new WaitForSeconds(UPDATE_INTERVAL_SEC));
            }
        }