예제 #1
0
 void ClearInvalidChannels()
 {
     for (int i = channels.Count; --i >= 0;)
     {
         IMChannel ch = im.GetChannel(channels[i]);
         if (ch == null || ch.url != http.url)
         {
             channels.RemoveAt(i);
         }
     }
 }
예제 #2
0
        protected override Base_Upload MakeHeatbeatUL()
        {
            ClearInvalidChannels();
            UL_Chat_getNewChannelMsgs ul = new UL_Chat_getNewChannelMsgs();

            ul.lastIds = new Dictionary <string, long>();
            for (int i = channels.Count; --i >= 0;)
            {
                IMChannel ch = im.GetChannel(channels[i]);
                ul.lastIds[ch.id] = im.GetSession(ch).lastId;
            }
            return(ul);
        }
예제 #3
0
 void ClearAll()
 {
     foreach (var m in sendingMsgs)
     {
         m.Distributed = false;
     }
     sendingMsgs.Clear();
     for (int i = channels.Count; --i >= 0;)
     {
         IMChannel ch2 = im.GetChannel(channels[i]);
         ch2.SetOffline();
     }
     channels.Clear();
 }
예제 #4
0
        int SyncChannelMsgs(BonDocument chd, IMChannel ch)
        {
            IMChatSession session = im.GetSession(ch);

            session.lastId = chd["lastId"].AsLong;
            newMsgs.Clear();
            BonUtil.ToObj(chd["msgs"], newMsgs);
            for (int i = newMsgs.Count; --i >= 0;)
            {
                newMsgs[i].im     = im;
                newMsgs[i].recTgt = IMChatTarget.频道;
            }
            im.AddNewMsgs(newMsgs);
            return(newMsgs.Count);
        }
예제 #5
0
        protected override bool OnHeatbeatDone(IMHttpContext ctx)
        {
            ClearInvalidChannels();
            if (ctx.code != 0)
            {
                Debug.Log("获取频道新聊天失败");
                ClearAll();
                return(false);
            }

            BonDocument chds = ctx.response.GetBonDocument("channels");

            if (chds == null)
            {
                ClearAll();
                return(false);
            }
            bool haveMsg = false;

            for (int i = channels.Count; --i >= 0;)
            {
                IMChannel ch = im.GetChannel(channels[i]);
                try {
                    if (!chds.Contains(ch.id))
                    {
                        ch.SetOffline();
                        continue;
                    }
                    if (SyncChannelMsgs(chds[ch.id].AsBonDocument, ch) > 0)
                    {
                        haveMsg = true;
                    }
                } catch (Exception e) {
                    Debug.Log(e);
                    ch.SetOffline();
                    continue;
                }
            }
            return(haveMsg);
        }
예제 #6
0
        protected override void OnSendDone(IMMsgForSend msg, IMHttpContext ctx)
        {
            IMChannel ch = im.GetChannel(msg.recId);

            if (ch == null)
            {
                return;
            }
            ClearInvalidChannels();
            if (ctx.code < 0)
            {
                Debug.Log("发送聊天致命错误");
                msg.Distributed = false;
                ClearAll();
                return;
            }
            if (ctx.code > 0)
            {
                Debug.Log("发送聊天错误");
                msg.Distributed = false;
                ch.SetOffline();
                return;
            }
            msg.Sent = true;
            try {
                BonDocument chd = ctx.response.GetBonDocument("channel");
                if (chd == null)
                {
                    msg.Distributed = false;
                    ch.SetOffline();
                    return;
                }
                SyncChannelMsgs(chd, ch);
            } catch (Exception e) {
                Debug.Log(e);
                msg.Distributed = false;
                ch.SetOffline();
            }
        }