示例#1
0
        private void SendMessage()
        {
            ChatSession tmplChatSession = (ChatSession)myChatSessions[myChatSessionsTabControl.SelectedTab.Tag];
            if (tmplChatSession != null)
            {

                if ((myClientForm.myBuddyPresence[tmplChatSession.JabberUser.JID] == null || (int)myClientForm.myBuddyPresence[tmplChatSession.JabberUser.JID] == 0))
                {
                    if (!tmplChatSession.OfflineMessageNotified)
                    {
                        tmplChatSession.OfflineMessageNotified = true;
                        AddNotification(
                             tmplChatSession.JabberUser.JID,
                             "INFO",
                             Properties.Localization.txtChatInfoUserOfflineMessage,
                             DateTime.Now,
                             Guid.NewGuid().ToString(),
                             false,
                             true
                             );
                    }
                }
                else
                {
                    tmplChatSession.OfflineMessageNotified = false;
                }

                IMMessage messageOutgoing = new IMMessage(tmplChatSession.JabberUser.Nick, tmplChatSession.ChatBox.ChatTabMessage.Text, Guid.NewGuid().ToString(),DateTime.Now, tmplChatSession.OutgoingStyle, MessageTemplateType.Outgoing, null);

                if (!myClientForm.SendMessage(tmplChatSession.JabberUser, messageOutgoing.Text, messageOutgoing.HTML)) return;

                AddToConversation(tmplChatSession.JabberUser.JID, 
                    myClientForm.mUserAccount.JabberUser.JID, 
                    tmplChatSession.ChatBox.ChatTabMessage.Text.Trim().Replace(@"&", @"&amp;").Replace(@"<", @"&lt;").Replace(@">", @"&gt;"),
                    "", 
                    DateTime.Now, 
                    Guid.NewGuid().ToString(), 
                    false, 
                    false
                    );
                tmplChatSession.ChatBox.ChatTabMessage.Text = "";
            }
        }
示例#2
0
        internal void IncomingMessage(String jid, String messageText, String messageHTML)
        {
            if (messageText != "" || messageHTML != "")
            {
                JabberUser jabberUser = new JabberUser(jid);

                IMMessage messageIncoming = new IMMessage(jabberUser.Nick, messageText, Guid.NewGuid().ToString(), DateTime.Now, new MessageStyle(), MessageTemplateType.Incoming, null);
                AddToConversation(jabberUser.JID, jabberUser.JID, messageIncoming.Text, messageIncoming.HTML, messageIncoming.Time, messageIncoming.ID, false, true);
                myClientForm.myStorage.AddMessageToArchive(jabberUser.JID, myClientForm.myStorage.StorageGUID(), messageIncoming.Text, messageIncoming.HTML, false);
                SetComposing(false, jabberUser.JID);

#if(TRACE)
                Console.WriteLine("IM-Message:" + "(" + jabberUser.JID + ")" + messageIncoming.Text);
#endif
            }
        }
示例#3
0
        public void AddToConversation(String chatJID, String senderJID, string messageText, string messageHTML, DateTime messageDateTime, string messageGUID, bool forceEmpty, bool flashWindow)
        {

            if (InvokeRequired)
            {
                this.Invoke(new AddToConversationDelegate(this.AddToConversation), new object[] { chatJID, senderJID, messageText, messageDateTime, messageGUID, forceEmpty, flashWindow });
                return;
            }

            //IMMessage parameters

            MessageStyle style = new MessageStyle(Color.White, new System.Drawing.Font("Trebuchet MS", 8.5F, System.Drawing.FontStyle.Regular), Color.Gray, Color.Gray);
            MessageTemplateType template = MessageTemplateType.Notification;
            ChatSession tmplChatSession = (ChatSession)myChatSessions[chatJID];
            JabberUser chatJabberUser = null;
            JabberUser senderJabberUser = null;

            if (tmplChatSession == null)
            {
                try
                {
                    ContactList contactList = myClientForm.mContactBook.getCandidatesForJabberID(chatJID);
                    if (contactList.Count > 0)
                    {
                        NTContact ntContact = (NTContact)contactList[0];
                        chatJabberUser = new JabberUser(ntContact.NTJabberID, ntContact.NTNickname);
                    }
                    else
                    {
                        chatJabberUser = new JabberUser(chatJID);
                    }

                    NewChat(chatJabberUser, false);
                    tmplChatSession = (ChatSession)myChatSessions[chatJabberUser.JID];
                    if (tmplChatSession == null) return;
                }
                catch (Exception)
                {
                    return;
                }
            }
            if (forceEmpty)
            {
                tmplChatSession.ChatBox.ResetHTML();
            }
            if (senderJID == myClientForm.mUserAccount.JabberUser.JID)
            {
                //outgoing message
                senderJabberUser = myClientForm.mUserAccount.JabberUser;
                style = tmplChatSession.OutgoingStyle;
                template = MessageTemplateType.Out;

            }
            else
            { //incomming message
                senderJabberUser = tmplChatSession.JabberUser;
                if (flashWindow)
                {
                    FlashWindow(this.Handle, true);
                    myClientForm.mClientEvents.RaiseEvent(Remwave.Client.Events.ClientEvent.IncomingInstantMessage);
                    ShowIt();
                    mMessageInTimeout = 360;
                    myNotifyIcon.Visible = true;
                }
                style = tmplChatSession.IncomingStyle;
                template = MessageTemplateType.In;
            }

            //if chat session exist display content in conversation window
            if (tmplChatSession != null)
            {
                if (tmplChatSession.ChatBox.ChatTabConversation != null)
                {
                    SetComposing(false, senderJID);
                    if (messageHTML == "") messageHTML = messageText;

                    IMMessage message = new IMMessage(senderJabberUser.Nick, messageHTML, messageGUID, messageDateTime, style, template, myEmoticons);
                    tmplChatSession.ChatBox.ChatTabConversation.Document.Body.InnerHtml += message.HTML;
                    tmplChatSession.ChatBox.ChatTabConversation.Document.Window.ScrollTo(0, tmplChatSession.ChatBox.ChatTabConversation.Document.Body.ScrollRectangle.Height);
                    tmplChatSession.ChatBox.AttachEvents();
                }
            }
        }
示例#4
0
        public void AddNotification(String jid, String senderEvent, string messageText, DateTime messageDateTime, string messageGUID, bool flashWindow, bool forceChat)
        {
            if (InvokeRequired)
            {
                this.Invoke(new AddNotificationDelegate(this.AddNotification), new object[] { jid, senderEvent, messageText, messageDateTime, messageGUID, flashWindow });
                return;
            }

            //IMMessage parameters
            MessageStyle style = new MessageStyle(Color.White, new System.Drawing.Font("Trebuchet MS", 8.5F, System.Drawing.FontStyle.Regular), Color.Gray, Color.Gray);
            MessageTemplateType template = MessageTemplateType.Notification;
            ChatSession tmplChatSession = (ChatSession)myChatSessions[jid];
            JabberUser jabberUser = new JabberUser(jid);
            switch (senderEvent)
            {
                case "INFO":
                    senderEvent = "";
                    if (flashWindow) myClientForm.myNotifyIcon.ShowBalloonTip(10, jabberUser.Nick, messageText, ToolTipIcon.Info);
                    break;
                case "CLIENT":
                case "SERVER":
                case "PRESENCE":
                case "BUDDYUPDATE":
                    senderEvent = Properties.Localization.txtChatInfoSenderSystem;
                    break;
                case "NUDGE":
                    senderEvent = "";
                    myClientForm.mClientEvents.RaiseEvent(Remwave.Client.Events.ClientEvent.IncomingNudge);
                    FlashWindow(this.Handle, true);
                    #region Shake Window
                    Random rand = new Random();
                    int left = this.Left;
                    int top = this.Top;
                    for (int i = 0; i < 30; i++)
                    {
                        int randLeft = rand.Next(-10, 10);
                        int randTop = rand.Next(-10, 10);
                        this.Left = (left + randLeft) > 0 ? left + randLeft : 0;
                        this.Top = (top + randTop) > 0 ? left + randLeft : 0;
                        Thread.Sleep(50);
                    }
                    this.Left = left;
                    this.Top = top;
                    #endregion
                    break;
                case "INVITE":
                    senderEvent = Properties.Localization.txtChatInfoSenderUser;
                    myClientForm.mClientEvents.RaiseEvent(Remwave.Client.Events.ClientEvent.IncomingInstantMessage);
                    break;
            }

            if (forceChat && tmplChatSession == null)
            {
                try
                {
                    JabberUser chatJabberUser;
                    ContactList contactList = myClientForm.mContactBook.getCandidatesForJabberID(jid);
                    if (contactList.Count > 0)
                    {
                        NTContact ntContact = (NTContact)contactList[0];
                        chatJabberUser = new JabberUser(ntContact.NTJabberID, ntContact.NTNickname);
                    }
                    else
                    {
                        chatJabberUser = new JabberUser(jid);
                    }

                    NewChat(chatJabberUser, false);
                    tmplChatSession = (ChatSession)myChatSessions[chatJabberUser.JID];
                    if (tmplChatSession == null) return;
                }
                catch (Exception)
                {
                    return;
                }
            }

            //if chat session exist display content in conversation window
            if (tmplChatSession != null)
            {
                if (tmplChatSession.ChatBox.ChatTabConversation != null)
                {
                    IMMessage message = new IMMessage(senderEvent, messageText, messageGUID, messageDateTime, style, template, myEmoticons);
                    tmplChatSession.ChatBox.ChatTabConversation.Document.Body.InnerHtml += message.HTML;
                    tmplChatSession.ChatBox.ChatTabConversation.Document.Window.ScrollTo(0, tmplChatSession.ChatBox.ChatTabConversation.Document.Body.ScrollRectangle.Height);
                    tmplChatSession.ChatBox.AttachEvents();
                }
            }
        }
示例#5
0
        public void loadArchiveSelectedUserDate(string selectedUser, string search, string date)
        {
            String HTMLResult = "<p></p>";
            if (this.InvokeRequired)
            {
                BeginInvoke(new loadArchiveSelectedUserDateDelegate(loadArchiveSelectedUserDate), new object[] { selectedUser, search });
                return;
            }
            ResetHTML();

            Emoticons myEmoticons = new Emoticons(Directory.GetCurrentDirectory() + "\\Emoticons\\");

            List<Remwave.Client.Storage.StorageMessage> list = mStorage.GetMessageFromArchiveByDate(selectedUser, search, 2048,date);
            for (int i = list.Count - 1; i >= 0; i--)
            {
                JabberUser jabberUser = null;

                MessageStyle incomingStyle = new MessageStyle(Color.White, new System.Drawing.Font("Trebuchet MS", 8.5F, System.Drawing.FontStyle.Regular), Color.Black, Color.Red);
                MessageStyle outgoingStyle = new MessageStyle(Color.White, new System.Drawing.Font("Trebuchet MS", 8.5F, System.Drawing.FontStyle.Regular), Color.Black, Color.Blue);
                MessageTemplateType template = MessageTemplateType.Notification;
                MessageStyle style = new MessageStyle(Color.White, new System.Drawing.Font("Trebuchet MS", 8.5F, System.Drawing.FontStyle.Regular), Color.Gray, Color.Gray);

                String messageHTML = "";


                if (list[i].ContentHTML != "")
                {

                    messageHTML = list[i].ContentHTML;
                }
                else
                {
                    messageHTML = list[i].ContentText;
                }





                //Compatibility with legacy text only messages
                if (list[i].Direction == StorageItemDirection.In)
                {
                    style = incomingStyle;
                    template = MessageTemplateType.In;
                    jabberUser = new JabberUser(list[i].JID);
                }
                else
                {
                    style = outgoingStyle;
                    template = MessageTemplateType.Out;
                    jabberUser = new JabberUser(mStorage.Username);
                }
                IMMessage message = new IMMessage(jabberUser.Nick, messageHTML, list[i].GUID, list[i].Created, style, template, myEmoticons);
                HTMLResult += message.HTML;
            }
            wbConversation.Document.Body.InnerHtml += HTMLResult;
        }
示例#6
0
        private void SendMessage()
        {
            ChatSession tmplChatSession = (ChatSession)myChatSessions[myChatSessionsTabControl.SelectedTab.Tag];
            if (tmplChatSession != null)
            {

                IMMessage messageOutgoing = new IMMessage(tmplChatSession.JabberUser.Nick, tmplChatSession.ChatTabMessage.Text, Guid.NewGuid().ToString(), "", tmplChatSession.OutgoingStyle, MessageTemplateType.Outgoing, null);

                if (!myClientForm.SendMessage(tmplChatSession.JabberUser, messageOutgoing.Text, messageOutgoing.HTML)) return;

                AddToConversation(tmplChatSession.JabberUser.JID, myClientForm.mUserAccount.JabberUser.JID, tmplChatSession.ChatTabMessage.Text, "", "", Guid.NewGuid().ToString(), false, false);
                tmplChatSession.ChatTabMessage.Text = "";
            }
        }
示例#7
0
 public void AddNotification(String jid, String senderEvent, string messageText, string messageDateTime, string messageGUID, bool flashWindow)
 {
     if (InvokeRequired)
     {
         this.Invoke(new AddNotificationDelegate(this.AddNotification), new object[] { jid, senderEvent, messageText, messageDateTime, messageGUID, flashWindow });
         return;
     }
     
     //IMMessage parameters
     MessageStyle style = new MessageStyle(Color.White, new System.Drawing.Font("Trebuchet MS", 8.5F, System.Drawing.FontStyle.Regular), Color.Gray, Color.Gray);
     MessageTemplateType template = MessageTemplateType.Notification;
     ChatSession tmplChatSession = (ChatSession)myChatSessions[jid];
     
     switch (senderEvent)
     {
         case "INFO":
             senderEvent = "";
             myClientForm.myNotifyIcon.ShowBalloonTip(10, jid, messageText, ToolTipIcon.Info);
             break;
         case "CLIENT":
         case "SERVER":
         case "PRESENCE":
         case "BUDDYUPDATE":
             senderEvent = Properties.Localization.txtChatInfoSenderSystem;
             break;
         case "NUDGE":
             senderEvent = "";
             myClientForm.myClientEvents.RaiseEvent(Remwave.Client.Events.ClientEvent.IncomingNudge);
             FlashWindow(this.Handle, true);
             #region Shake Window
             Random rand = new Random();
             int left = this.Left;
             int top = this.Top;
             for (int i = 0; i < 30; i++)
             {
                 int randLeft = rand.Next(-10, 10);
                 int randTop = rand.Next(-10, 10);
                 this.Left = (left + randLeft) > 0 ? left + randLeft : 0;
                 this.Top = (top + randTop) > 0 ? left + randLeft : 0;
                 Thread.Sleep(50);
             }
             this.Left = left;
             this.Top = top;
             #endregion
             break;
         case "INVITE":
             senderEvent = Properties.Localization.txtChatInfoSenderUser;
             myClientForm.myClientEvents.RaiseEvent(Remwave.Client.Events.ClientEvent.IncomingInstantMessage);
             break;
     }
     //if chat session exist display content in conversation window
     if (tmplChatSession != null)
     {
         if (tmplChatSession.ChatTabConversation != null)
         {
             IMMessage message = new IMMessage(senderEvent, messageText, messageGUID, messageDateTime, style, template, myEmoticons);
             tmplChatSession.ChatTabConversation.Document.Write(message.HTML);
             tmplChatSession.ChatTabConversation.Document.Window.ScrollTo(0, tmplChatSession.ChatTabConversation.Document.Body.ScrollRectangle.Height);
         }
     }
 }