Пример #1
0
        void notifyIcon1_MouseClick(object sender, MouseEventArgs e)
        {
            try
            {
                if (e.Button != MouseButtons.Left)
                {
                    return;
                }

                lock (this.locker)
                {
                    if (this.friendQueue.Count > 0)
                    {
                        UnhandleFriendMessageBox cache = this.friendQueue[0];
                        this.friendQueue.RemoveAt(0);
                        IChatForm form = this.twinkleNotifySupporter.GetChatForm(cache.User);
                        if (form != null) //如果为null,表示刚删除好友
                        {
                            form.HandleReceivedMessage(cache.MessageList);
                        }

                        this.DetectUnhandleMessage();

                        if (this.UnhandleMessageGone != null)
                        {
                            this.UnhandleMessageGone(UnhandleMessageType.Friend, cache.User);
                        }
                        return;
                    }

                    if (this.groupQueue.Count > 0)
                    {
                        UnhandleGroupMessageBox cache = this.groupQueue[0];
                        this.groupQueue.RemoveAt(0);
                        IGroupChatForm form = this.twinkleNotifySupporter.GetGroupChatForm(cache.Group);
                        form.HandleReceivedMessage(cache.MessageList);

                        this.DetectUnhandleMessage();

                        if (this.UnhandleMessageGone != null)
                        {
                            this.UnhandleMessageGone(UnhandleMessageType.Group, cache.Group);
                        }
                        return;
                    }
                }

                if (this.MouseClick != null)
                {
                    this.MouseClick(sender, e);
                }
            }
            catch (Exception ee)
            {
                MessageBox.Show(ee.Message + " - " + ee.StackTrace);
            }
        }
Пример #2
0
        public void PushFriendMessage(string userID, int informationType, byte[] info, object tag)
        {
            lock (this.locker)
            {
                try
                {
                    this.twinkleNotifySupporter.PlayAudioAsyn(); //播放消息提示音
                    //首先查看是否已经存在对应的聊天窗口
                    IChatForm form = this.twinkleNotifySupporter.GetExistedChatForm(userID);
                    if (form != null)
                    {
                        form.HandleReceivedMessage(informationType, info, tag);
                        return;
                    }

                    //接下来准备将消息压入queue
                    UnhandleFriendMessageBox cache = null;
                    lock (this.locker)
                    {
                        //先查看queue中目标好友对应的Cache是否存在
                        for (int i = 0; i < this.friendQueue.Count; i++)
                        {
                            if (this.friendQueue[i].User == userID)
                            {
                                cache = this.friendQueue[i];
                                break;
                            }
                        }

                        if (cache == null) //如果不存在,则为好友新建一个Cache
                        {
                            cache = new UnhandleFriendMessageBox(userID);
                            this.friendQueue.Add(cache);
                            //触发UnhandleMessageOccured事件
                            if (this.UnhandleMessageOccured != null)
                            {
                                this.UnhandleMessageOccured(UnhandleMessageType.Friend, userID);
                            }
                        }

                        cache.MessageList.Add(new Parameter <int, byte[], object>(informationType, info, tag));
                    }

                    string userName = this.twinkleNotifySupporter.GetFriendName(userID);
                    this.notifyIcon1.Text = string.Format("{0}({1})  {2}条消息", userName, userID, cache.MessageList.Count);
                    //获取好友的头像,将其作为托盘图标
                    this.twinkleIcon = this.twinkleNotifySupporter.GetHeadIcon(userID);
                    this.ControlTimer(true); //启动闪烁
                }
                catch (Exception ee)
                {
                    MessageBox.Show(ee.Message);
                }
            }
        }