private string ProcessEmoticons(string messageText) { //handle text processing for emoticons replacement: MessageTemplate myMessageTemplate = new MessageTemplate(); if (messageText != null) { foreach (Emoticon myEmoticon in myEmoticons.List) { messageText = messageText //upper case .Replace(myEmoticon.Tag.ToUpper(), myMessageTemplate.Emoticon .Replace("<FILENAME>", Directory.GetCurrentDirectory() + "\\Emoticons\\" + myEmoticon.Filename) .Replace("<WIDTH>", myEmoticon.Width.ToString()) .Replace("<HEIGHT>", myEmoticon.Height.ToString())) //lower case .Replace(myEmoticon.Tag.ToLower(), myMessageTemplate.Emoticon .Replace("<FILENAME>", Directory.GetCurrentDirectory() + "\\Emoticons\\" + myEmoticon.Filename) .Replace("<WIDTH>", myEmoticon.Width.ToString()) .Replace("<HEIGHT>", myEmoticon.Height.ToString())) ; } } return messageText; }
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); } }
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; }
private void Search(string search) { ChatSession tmplChatSession = (ChatSession)myChatSessions[myChatSessionsTabControl.SelectedTab.Tag]; if (tmplChatSession != null) { tmplChatSession.ChatBox.ResetHTML(); ChatController.MessageTemplate tmplMessageTemplate = new MessageTemplate(MessageTemplateType.Notification); tmplChatSession.ChatBox.AttachEvents(); List<Remwave.Client.Storage.StorageMessage> list = myClientForm.myStorage.GetMessageFromArchive(tmplChatSession.JabberUser.JID, search, 50); if (list != null && list.Count > 0) { for (int i = list.Count - 1; i >= 0; i--) { if (list[i].Direction == StorageItemDirection.In) { AddToConversation(tmplChatSession.JabberUser.JID, tmplChatSession.JabberUser.JID, list[i].ContentText, list[i].ContentHTML, list[i].Created, list[i].GUID, false, false); } else { AddToConversation(tmplChatSession.JabberUser.JID, myClientForm.mUserAccount.JabberUser.JID, list[i].ContentText, list[i].ContentHTML, list[i].Created, list[i].GUID, false, false); } } } } }
public void AddToConversation(string chatSessionID, string jabberID, string messageText) { ChatSession tmplChatSession = (ChatSession)myChatSessions.List[chatSessionID]; //remove whitespaces //preset font and bg color Color myHeaderColor = Color.Gray; Color myFontColor = Color.Black; Color myBgColor = Color.White; Font myFont = new System.Drawing.Font("Trebuchet MS", 9F, System.Drawing.FontStyle.Regular); switch (jabberID) { case "CLIENT": case "SERVER": case "INFO": case "PRESENCE": case "BUDDYUPDATE": jabberID = "System"; if (tmplChatSession != null) myFontColor = Color.Gray; myHeaderColor = Color.Gray; break; case "INVITE": jabberID = "User"; if (tmplChatSession != null) myFontColor = Color.Gray; myHeaderColor = Color.Gray; break; default: if (tmplChatSession == null) { try { NewChat(jabberID, false); tmplChatSession = (ChatSession)myChatSessions.List[chatSessionID]; if (tmplChatSession == null) return; } catch (Exception) { return; } } if (jabberID == myClientForm.myUserAccount.Username) { //my message myHeaderColor = Color.Blue; myFont = tmplChatSession.ChatTabMessage.Font; myFontColor = tmplChatSession.ChatTabMessage.ForeColor; myBgColor = tmplChatSession.ChatTabMessage.BackColor; } else { //incomming message myHeaderColor = Color.Red; } SetComposing(false, jabberID); break; } //if chat session exist display content in conversation window if (tmplChatSession != null) { //messageText = messageText.Trim().Replace("<", "<").Replace(">", "&rt;").Replace("\"", """).Replace("&", "&").Replace("\r\n", "<BR />").Replace("\n", "<BR />"); messageText = messageText.Trim().Replace("\r\n", "<BR />").Replace("\n", "<BR />"); ChatController.MessageTemplate tmplMessageTemplate = new MessageTemplate(); //<ROW_STYLE> //<HEADER_STYLE> //<MESSAGE_STYLE> if (tmplChatSession.ChatTabConversation != null) { tmplChatSession.ChatTabConversation.Document.Write(ProcessEmoticons(tmplMessageTemplate.DefaultMessage .Replace("<ROW_STYLE>", BuildStyle(myFont, myFontColor, myBgColor)) .Replace("<HEADER_STYLE>", BuildStyle(myFont, myHeaderColor, myBgColor)) .Replace("<MESSAGE_STYLE>", BuildStyle(myFont, myFontColor, myBgColor)) .Replace("<HEADER_TEXT>", jabberID) .Replace("<MESSAGE_TEXT>", messageText)) ); tmplChatSession.ChatTabConversation.Document.Window.ScrollTo(0, tmplChatSession.ChatTabConversation.Document.Body.ScrollRectangle.Height); } } }