public ChatForm GetChatForm(string friendID) { ChatForm form = this.chatFormManager.GetForm(friendID); if (form == null) { this.rapidPassiveEngine.P2PController.P2PConnectAsyn(friendID);//尝试P2P连接。 form = new ChatForm(this.rapidPassiveEngine, this.nDiskOutter, this.globalUserCache, this.globalUserCache.CurrentUser, this.globalUserCache.GetUser(friendID)); form.LastWordChanged += new CbGeneric <bool, string, LastWordsRecord>(form_LastWordChanged); this.chatFormManager.Add(form); form.TopMost = true; form.Show(); form.TopMost = SystemSettings.Singleton.ChatFormTopMost; UnhandleFriendMessageBox cache = this.notifyIcon.PickoutFriendMessageCache(friendID); if (cache != null) { form.HandleReceivedMessage(cache.MessageList); } } else { if (form.WindowState == FormWindowState.Minimized) { form.WindowState = FormWindowState.Normal; } form.Focus(); } return(form); }
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); } }
public void PushFriendMessage(string userID, int informationType, byte[] info, object tag) { lock (this.locker) { try { this.twinkleNotifySupporter.PlayAudioAsyn(); //播放消息提示音 //首先查看是否已经存在对应的聊天窗口 var form = this.twinkleNotifySupporter.GetExistedChatForm(userID); if (form != null) { form.HandleReceivedMessage(informationType, info, tag); return; } //接下来准备将消息压入queue UnhandleFriendMessageBox cache = null; lock (this.locker) { //先查看queue中目标好友对应的Cache是否存在 for (var 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)); } var 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); } } }
private void DetectUnhandleMessage() { if (this.friendQueue.Count == 0 && this.groupQueue.Count == 0) { this.ControlTimer(false); } else if (this.friendQueue.Count > 0) { UnhandleFriendMessageBox cache = this.friendQueue[0]; string userName = this.twinkleNotifySupporter.GetFriendName(cache.User); this.notifyIcon1.Text = string.Format("{0}({1}) {2}条消息", cache.User, userName, cache.MessageList.Count); this.twinkleIcon = this.twinkleNotifySupporter.GetHeadIcon(cache.User); } else { UnhandleGroupMessageBox cache = this.groupQueue[0]; string groupName = this.twinkleNotifySupporter.GetGroupName(cache.Group); this.notifyIcon1.Text = string.Format("{0}({1}) {2}条消息", groupName, cache.Group, cache.MessageList.Count); this.twinkleIcon = this.twinkleNotifySupporter.GroupIcon; } }
public UnhandleFriendMessageBox PickoutFriendMessageCache(string userID) { lock (this.locker) { for (int i = 0; i < this.friendQueue.Count; i++) { UnhandleFriendMessageBox tmp = this.friendQueue[i]; if (tmp.User == userID) { this.friendQueue.RemoveAt(i); this.DetectUnhandleMessage(); if (this.UnhandleMessageGone != null) { this.UnhandleMessageGone(UnhandleMessageType.Friend, userID); } return(tmp); } } } return(null); }