예제 #1
0
        public IMMessage(String senderName, String messageText, String messageGUID, DateTime messageDateTime, MessageStyle style, MessageTemplateType template, Emoticons emoticons)
        {
            if (messageDateTime == null || messageDateTime == DateTime.MinValue)
            {
                messageDateTime = DateTime.Now;
            }
            this.Time = messageDateTime;
            if (messageGUID == null)
            {
                messageGUID = Guid.NewGuid().ToString();
            }
            this.ID = NormalizeGUID(messageGUID);
            MessageTemplate tmplMessageTemplate = new MessageTemplate(template);

            tmplMessageTemplate.Message = tmplMessageTemplate.Message
                                          .Replace("<HEADER_ROW_STYLE>", tmplMessageTemplate.BuildStyle(style.Font, style.ForeColor, Color.White))
                                          .Replace("<DATETIME_STYLE>", tmplMessageTemplate.BuildStyle(style.Font, Color.Gray, Color.White))
                                          .Replace("<HEADER_STYLE>", tmplMessageTemplate.BuildStyle(style.Font, style.HeaderColor, Color.White))
                                          .Replace("<ROW_STYLE>", tmplMessageTemplate.BuildStyle(style.Font, style.ForeColor, style.BackColor))
                                          .Replace("<MESSAGE_STYLE>", tmplMessageTemplate.BuildStyle(style.Font, style.ForeColor, style.BackColor))
                                          .Replace("<HEADER_TEXT>", senderName != "" ? senderName : "")
                                          .Replace("<DATETIME_TEXT>", messageDateTime.ToShortDateString() + " " + messageDateTime.ToShortTimeString())
                                          .Replace("<GUID>", this.ID)
                                          .Replace("<MESSAGE_TEXT>", messageText.Replace("\r\n", "<BR />").Replace("\n", "<BR />"));
            tmplMessageTemplate.ProcessEmoticons(emoticons);

            this.HTML  = tmplMessageTemplate.Message;
            this.Text  = messageText;
            this.Style = style;
        }
예제 #2
0
        public void loadArchiveSelectedUser(string selectedUser, string search)
        {
            if (this.InvokeRequired)
            {
                BeginInvoke(new loadArchiveSelectedUserDelegate(loadArchiveSelectedUser), new object[] { selectedUser, search });
                return;
            }
            wbConversation.Document.OpenNew(true);

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

            List<Remwave.Client.Storage.StorageMessage> list = mStorage.GetMessageFromArchive(selectedUser, search, 2048);
            ChatController.MessageTemplate tmplMessageTemplate = new MessageTemplate(MessageTemplateType.Notification);
            wbConversation.Document.Write(tmplMessageTemplate.Message);
            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);
                wbConversation.Document.Write(message.HTML);
            }
        }
예제 #3
0
        public IMMessage(String senderName, String messageText, String messageGUID, DateTime messageDateTime, MessageStyle style, MessageTemplateType template, Emoticons emoticons)
        {
            if (messageDateTime == null || messageDateTime == DateTime.MinValue) messageDateTime = DateTime.Now;
            this.Time = messageDateTime;
            if (messageGUID == null) messageGUID = Guid.NewGuid().ToString();
            this.ID = NormalizeGUID(messageGUID);
            MessageTemplate tmplMessageTemplate = new MessageTemplate(template);
            tmplMessageTemplate.Message = tmplMessageTemplate.Message
                     .Replace("<HEADER_ROW_STYLE>", tmplMessageTemplate.BuildStyle(style.Font, style.ForeColor, Color.White))
                     .Replace("<DATETIME_STYLE>", tmplMessageTemplate.BuildStyle(style.Font, Color.Gray, Color.White))
                     .Replace("<HEADER_STYLE>", tmplMessageTemplate.BuildStyle(style.Font, style.HeaderColor, Color.White))
                     .Replace("<ROW_STYLE>", tmplMessageTemplate.BuildStyle(style.Font, style.ForeColor, style.BackColor))
                     .Replace("<MESSAGE_STYLE>", tmplMessageTemplate.BuildStyle(style.Font, style.ForeColor, style.BackColor))
                     .Replace("<HEADER_TEXT>", senderName != "" ? senderName : "")
                     .Replace("<DATETIME_TEXT>", messageDateTime.ToShortDateString() + " " + messageDateTime.ToShortTimeString())
                     .Replace("<GUID>", this.ID)
                     .Replace("<MESSAGE_TEXT>", messageText.Replace("\r\n", "<BR />").Replace("\n", "<BR />"));
            tmplMessageTemplate.ProcessEmoticons(emoticons);

            this.HTML = tmplMessageTemplate.Message;
            this.Text = messageText;
            this.Style = style;

        }
예제 #4
0
 public ChatSession()
 {
     this.IncomingStyle = new MessageStyle(Color.White, new System.Drawing.Font("Trebuchet MS", 8.5F, System.Drawing.FontStyle.Regular), Color.Black, Color.Red);
     this.OutgoingStyle = new MessageStyle(Color.White, new System.Drawing.Font("Trebuchet MS", 8.5F, System.Drawing.FontStyle.Regular), Color.Black, Color.Blue);
 }
예제 #5
0
 public ChatSession()
 {
     this.IncomingStyle = new MessageStyle(Color.White, new System.Drawing.Font("Trebuchet MS", 8.5F, System.Drawing.FontStyle.Regular), Color.Black, Color.Red);
     this.OutgoingStyle = new MessageStyle(Color.White, new System.Drawing.Font("Trebuchet MS", 8.5F, System.Drawing.FontStyle.Regular), Color.Black, Color.Blue);
 }
예제 #6
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();
                }
            }
        }
예제 #7
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();
                }
            }
        }
예제 #8
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);
         }
     }
 }