Пример #1
0
        string ScriptForAppendingContent(AbstractChatContent content, bool contentIsSimilar, bool willAddMoreContentObjects, bool replaceLastContent)
        {
            string newHTML = null;
            string script;

            if (!m_CombineConsecutive)
            {
                contentIsSimilar = false;
            }

            newHTML = TemplateForContent(content, contentIsSimilar);
            newHTML = FillKeywords(newHTML, content, contentIsSimilar);

            if (!m_UsingCustomTemplateHtml || m_StyleVersion >= 4)
            {
                if (replaceLastContent)
                {
                    script = REPLACE_LAST_MESSAGE;
                }
                else if (willAddMoreContentObjects)
                {
                    script = (contentIsSimilar ? APPEND_NEXT_MESSAGE_NO_SCROLL : APPEND_MESSAGE_NO_SCROLL);
                }
                else
                {
                    script = (contentIsSimilar ? APPEND_NEXT_MESSAGE : APPEND_MESSAGE);
                }
            }
            else if (m_StyleVersion >= 3)
            {
                if (willAddMoreContentObjects)
                {
                    script = (contentIsSimilar ? APPEND_NEXT_MESSAGE_NO_SCROLL : APPEND_MESSAGE_NO_SCROLL);
                }
                else
                {
                    script = (contentIsSimilar ? APPEND_NEXT_MESSAGE : APPEND_MESSAGE);
                }
            }
            else if (m_StyleVersion >= 1)
            {
                script = (contentIsSimilar ? APPEND_NEXT_MESSAGE : APPEND_MESSAGE);
            }
            else
            {
                if (m_UsingCustomTemplateHtml && content is ChatContentStatus)
                {
                    script = APPEND_MESSAGE_WITH_SCROLL;
                }
                else
                {
                    script = (contentIsSimilar ? APPEND_NEXT_MESSAGE_WITH_SCROLL : APPEND_MESSAGE_WITH_SCROLL);
                }
            }

            return(String.Format(script, Util.EscapeJavascript(newHTML)));
        }
Пример #2
0
        public void AppendContent(AbstractChatContent content, bool contentIsSimilar, bool willAddMoreContentObjects,
                                  bool replaceLastContent)
        {
            if (content == null)
            {
                throw new ArgumentNullException("content");
            }

            if (!m_ThemeLoaded)
            {
                throw new Exception("Call LoadTheme() first!");
            }

            var js = ScriptForAppendingContent(content, contentIsSimilar, willAddMoreContentObjects, replaceLastContent);

            Page().MainFrame().EvaluateJavaScript(js);
        }
Пример #3
0
        string TemplateForContent(AbstractChatContent content, bool contentIsSimilar)
        {
            string template = null;

            if (content.Type == ChatContentType.Message || content.Type == ChatContentType.Notification)
            {
                if (content.IsOutgoing)
                {
                    template = (contentIsSimilar ? m_NextContentOutHtml : m_ContentOutHtml);
                }
                else
                {
                    template = (contentIsSimilar ? m_NextContentInHtml : m_ContentInHtml);
                }
            }
            else if (content.Type == ChatContentType.Context)
            {
                if (content.IsOutgoing)
                {
                    template = (contentIsSimilar ? m_NextContextOutHtml : m_ContextOutHtml);
                }
                else
                {
                    template = (contentIsSimilar ? m_NextContextInHtml : m_ContextInHtml);
                }
            }
            else if (content.Type == ChatContentType.FileTransfer)
            {
                template = m_FileTransferHtml;
            }
            else
            {
                template = m_StatusHtml;
            }

            if (String.IsNullOrEmpty(template))
            {
                throw new Exception("Failed to get template for content: " + content.Type);
            }

            return(template);
        }
Пример #4
0
        void HandleNewContent(IChatHandler handler,AbstractChatContent content)
        {
            if (content is ChatContentTyping)
            {
                var typingContent = (ChatContentTyping)content;
                if (m_Handler is ChatHandler)
                {
                    var chatHandler = (ChatHandler)m_Handler;
                    if (!chatHandler.IsMucMessage)
                    {
                        string title = null;
                        if (typingContent.TypingState != TypingState.None && typingContent.TypingState != TypingState.Active)
                        {
                            title = String.Format("{0} ({1})",chatHandler.Account.GetDisplayName(chatHandler.Jid),typingContent.TypingState.ToString());
                        }
                        else
                        {
                            title = chatHandler.Account.GetDisplayName(chatHandler.Jid);
                        }
                        QApplication.Invoke(delegate {
                            Gui.TabbedChatsWindow.SetTabTitle(this,title);
                        });
                    }
                }
            }
            else
            {
                bool isSimilar = (!(content is ChatContentStatus)) && m_PreviousContent != null && content.IsSimilarToContent(m_PreviousContent);
                //bool replaceLast = m_PreviousContent is ChatContentStatus &&
                //	               content is ChatContentStatus &&
                //	               ((ChatContentStatus)m_PreviousContent).CoalescingKey == ((ChatContentStatus)content).CoalescingKey;
                bool replaceLast = m_PreviousContent is ChatContentTyping;

                m_PreviousContent = content;
                QApplication.Invoke(delegate {
                    m_ConversationWidget.AppendContent(content,isSimilar,false,replaceLast);

                    if (content is ChatContentMessage && !IsActive)
                    {
                        UrgencyHint = true;

                        if (m_Notification == null)
                        {
                            try {
                                string plainText = HtmlSanitizer.ToPlainText(((ChatContentMessage)content).MessageHtml);
                                // Only show notifications for MUC messages that contain your name.
                                if (m_Handler is ChatHandler || (m_Handler is MucHandler && plainText.Contains(((MucHandler)m_Handler).Room.Nickname)))
                                {
                                    if (m_Handler is MucHandler)
                                    {
                                        Gdk.Pixbuf pixbuf = Gdk.Pixbuf.LoadFromResource("internet-group-chat__32.png");
                                        string roomName   = ((MucHandler)m_Handler).Room.JID.Bare;
                                        m_Notification    = new Notification(String.Format("Message from {0} in {1}",content.SourceDisplayName,roomName),plainText,pixbuf);
                                    }
                                    else
                                    {
                                        // FIXME: Too much logic outside of AvatarManager.
                                        Gdk.Pixbuf pixbuf = null;
                                        string fileName   = AvatarManager.GetAvatarFileName(content.Source.BareJID);
                                        if (System.IO.File.Exists(fileName))
                                        {
                                            pixbuf = new Gdk.Pixbuf(fileName);
                                        }
                                        else
                                        {
                                            pixbuf = Gdk.Pixbuf.LoadFromResource("default-avatar.png");
                                        }
                                        m_Notification = new Notification(String.Format("Message from {0}",content.SourceDisplayName),plainText,pixbuf);
                                    }
                                    m_Notification.Show();
                                    m_Notification.Closed += delegate {
                                        m_Notification = null;
                                    };
                                }
                            } catch (Exception ex) {
                                Console.WriteLine("FAILED TO DISPLAY NOTIFICATION: " + ex);
                                m_Notification = null;
                            }
                        }
                    }

                    if (m_Handler is ChatHandler)
                    {
                        if (content is ChatContentMessage && (content.Source.Bare == ((ChatHandler)m_Handler).Jid.Bare))
                        {
                            // Select this resource so our replies go to it.
                            int i = m_ToComboBox.FindData(((ChatContentMessage)content).Source.Resource);
                            m_ToComboBox.CurrentIndex = (i > -1) ? i : 0;
                        }
                    }
                });
            }
        }
Пример #5
0
        string FillKeywords(string inString, AbstractChatContent content, bool contentIsSimilar)
        {
            if (inString == null)
            {
                throw new ArgumentNullException("inString");
            }

            if (content == null)
            {
                throw new ArgumentNullException("content");
            }

            inString = inString.Replace("%time%", content.Date.ToShortTimeString());
            inString = inString.Replace("%shortTime%", content.Date.ToString("%h:%m"));

            string senderStatusIcon = (content.Source != null) ? String.Format("avatar:/{0}", AvatarManager.GetAvatarHash(content.Source.Bare)) : String.Empty;

            inString = inString.Replace("%senderStatusIcon%", senderStatusIcon);

            // FIXME do %localized{x}% replacements

            inString = inString.Replace("%messageClasses%", (contentIsSimilar ? "consecutive " : "") + String.Join(" ", content.DisplayClasses));

            // FIXME: sender colors

            inString = inString.Replace("%messageDirection%", inString.Contains("<DIV dir=\"rtl\">") ? "rtl" : "ltr");

            Regex regex = new Regex(@"%time\{(.*)\}%");

            inString = regex.Replace(inString, delegate(Match match) {
                string pattern = match.Groups[1].Value;
                return(Util.Strftime(pattern, content.Date));
            });

            if (content is ChatContentMessage)
            {
                string userIconPath = null;
                if (ShowUserIcons)
                {
                    userIconPath = String.Format("avatar:/{0}", AvatarManager.GetAvatarHash(content.Source.Bare));
                }
                else
                {
                    userIconPath = (content.IsOutgoing) ? "Outgoing/buddy_icon.png" : "Incoming/buddy_icon.png";
                }

                inString = inString.Replace("%userIconPath%", userIconPath);
                inString = inString.Replace("%senderScreenName%", content.Source.ToString());
                inString = inString.Replace("%sender%", content.SourceDisplayName);
                inString = inString.Replace("%senderDisplayName%", content.SourceDisplayName);
                inString = inString.Replace("%service%", String.Empty);

                // FIXME: %textbackgroundcolor{

                // FIXME: File transfers
            }
            else if (content is ChatContentStatus)
            {
                inString = inString.Replace("%status%", ((ChatContentStatus)content).StatusType);
                inString = inString.Replace("%statusSender%", (content.Source != null) ? content.Source.ToString() : String.Empty);

                // FIXME: %statusPhrase%
            }

            inString = inString.Replace("%message%", content.MessageHtml);

            return(inString);
        }