示例#1
0
        void conn_OnPresence(object sender, agsXMPP.protocol.client.Presence pres)
        {
            if (pres.HasTag(typeof(agsXMPP.protocol.x.muc.User), true) ||
                (pres.Type == agsXMPP.protocol.client.PresenceType.error && pres.HasTag(typeof(agsXMPP.protocol.x.muc.Muc), true)))
            {
                return;
            }
            if (pres.Type == agsXMPP.protocol.client.PresenceType.available || pres.Type == agsXMPP.protocol.client.PresenceType.unavailable)
            {
                if (!contacts.ContainsKey(pres.From.Bare))
                {
                    contacts.Add(pres.From.Bare, new JabberContact(pres.From));
                }
                JabberContact contact = contacts[pres.From.Bare];
                if (!contact.resources.Contains(pres.From.Resource))
                {
                    contact.resources.Add(pres.From.Resource);
                }
                if (pres.Type == agsXMPP.protocol.client.PresenceType.unavailable)
                {
                    contact.available = false;
                }
                else
                {
                    contact.available = true;
                }
                if (OnContactPresence != null)
                {
                    OnContactPresence(this, new JabberEventArgs(pres.From.Bare));
                }
            }
            else if (pres.Type == PresenceType.subscribe || pres.Type == PresenceType.subscribed ||
                     pres.Type == PresenceType.unsubscribe || pres.Type == PresenceType.unsubscribed)
            {
                Program.MainWnd.Invoke(new Action <object>((x) => {
                    var f = new InvitationForm();
                    switch (pres.Type)
                    {
                    case PresenceType.subscribe:
                        f.setContactRequest(pres.From);
                        break;

                    case PresenceType.subscribed:
                        f.setContactSubscriptionApproved(pres.From);
                        break;

                    case PresenceType.unsubscribe:
                        f.setContactUnsubscribe(pres.From);
                        break;

                    case PresenceType.unsubscribed:
                        f.setContactSubscriptionCancelled(pres.From);
                        break;
                    }
                    f.Show();
                }), this);
            }
        }
示例#2
0
        public void addMessageToView(string from, string text, DateTime time, string editDt, string jabberId, string id, HtmlElementInsertionOrientation where = HtmlElementInsertionOrientation.BeforeEnd)
        {
            updateLastTime(where, time);
            var div = this.Document.CreateElement("p");

            div.Id = "MSGID_" + id;
            text   = prepareInnerHtml(text);
            var me     = Regex.Match(text, "^/me\\s+");
            var timeEl = "<i title=" + time.ToShortDateString() + " " + time.ToLongTimeString() + "><u>[</u>" + (highlightString != "" ? time.ToShortDateString() : "") + " " + time.ToLongTimeString() + "<u>] </u></i>";

            if (!String.IsNullOrEmpty(editDt))
            {
                timeEl += "<i class='edited' title='" + editDt + "'>(Edited)</i>";
            }
            var    color      = JabberContact.getColorForNickname(from);
            string cssColor   = ColorTranslator.ToHtml(color);
            string classNames = "from_" + from + " ";

            if (from == "self" || (!String.IsNullOrEmpty(jabberId) && jabberId.StartsWith(this.selfNickname)))
            {
                classNames += "self ";
            }
            if (me.Success)
            {
                div.InnerHtml = timeEl + "<span> *** <strong>" + from + "</strong> " + text.Substring(me.Length) + "</span>";
            }
            else
            {
                classNames += "msg ";
                string avatar         = "<tt class='avatar' style='background-color: " + cssColor + "; '></tt>";
                string avatarFilename = Program.Jabber.avatar.GetAvatarIfAvailabe(jabberId);
                if (!string.IsNullOrEmpty(avatarFilename))
                {
                    avatar = "<tt class='avatar'><img src='" + avatarFilename + "'></tt>";
                }

                div.InnerHtml = avatar + "<span class='wrap'>" + timeEl +
                                "<strong style='color: " + cssColor + "'>" + from + ":</strong><span class='body'> "
                                + text + "</span></span>";
            }
            div.SetAttribute("className", classNames);
            //this.Document.Body.AppendChild(div);
            this.Document.GetElementById("m").InsertAdjacentElement(where, div);
            if (where == HtmlElementInsertionOrientation.BeforeEnd)
            {
                scrollDown();
            }
        }