Esempio n. 1
0
        public static void RequestVCard(XMPP.JID currentJID)
        {
            var iq = new Tags.jabber.client.iq();

            if (!string.IsNullOrEmpty(currentJID.Bare))
            {
                iq.from = currentJID;
            }
            else
            {
                return;
            }

            iq.type = Tags.jabber.client.iq.typeEnum.get;

            var vcard = new Tags.vcard_temp.vCard();

            iq.Add(vcard);

            Runtime.Interface.SendTag(currentJID.Bare, iq);
        }
Esempio n. 2
0
        public static void PublishAvatar(string filetype, byte[] image)
        {
            try
            {
                foreach (var account in Frontend.Accounts.Enabled)
                {
                    if (account.CurrentVCard != null)
                    {
                        var iq = new Tags.jabber.client.iq();
                        iq.from = account.CurrentJID;
                        iq.type = Tags.jabber.client.iq.typeEnum.set;

                        var vcard = new Tags.vcard_temp.vCard();

                        foreach (var element in account.CurrentVCard.Elements())
                        {
                            if (element.Name != XName.Get("PHOTO", "vcard-temp") &&     // I know how ugly this is, but I have to get this done~!
                                element.Name != XName.Get("TYPE", "vcard-temp") &&
                                element.Name != XName.Get("BINVAL", "vcard-temp"))
                            {
                                vcard.Add(element);
                            }
                        }

                        var photo = new XElement(XName.Get("PHOTO", "vcard-temp"));
                        photo.Add(new XElement(XName.Get("TYPE", "vcard-temp"), filetype));
                        photo.Add(new XElement(XName.Get("BINVAL", "vcard-temp"), System.Convert.ToBase64String(image)));
                        vcard.Add(photo);

                        iq.Add(vcard);

                        Frontend.Backend.SendTag(account.jid, iq);

                        account.OwnContact.SetAvatar(image);
                    }
                }
            }
            catch (Exception uiEx) { Frontend.UIError(uiEx); }
        }
Esempio n. 3
0
        private bool Process(Tags.jabber.client.presence presence)
        {
            var settings = Frontend.Settings;

            try
            {
                if (presence.type == Tags.jabber.client.presence.typeEnum.error)
                {
                    var errorMessage = Helper.Translate("ErrorTagPresence") + ": " + Helper.GetErrorMessage(presence);
                    Frontend.Notifications.CreateError(ErrorPolicyType.Informative, presence.Account, errorMessage);
                    return(false);
                }

                if (presence.from == null)
                {
                    presence.from = presence.Account;
                }

                var from = new XMPP.JID(presence.from);
                // The rest of the application only accepts to = jid
                var to = new XMPP.JID(presence.Account);


                // Get matching Account
                Account account = Frontend.Accounts[presence.Account];
                if (account == null)
                {
                    return(false);
                }

                Backend.Data.Contact contact = account.Roster[from.Bare];
                if (contact == null)
                {
                    contact = account.Roster.CreateContact(account.jid, from.Bare);
                }

                if (contact == null)
                {
                    return(false);
                }

                contact.LockUpdates();

                // Get nick if any
                var nick = presence.Element <Tags.jabber.protocol.nick.nick>(Tags.jabber.protocol.nick.Namespace.nick);
                if (nick != null)
                {
                    contact.nick = nick.Value;
                }

                // Get avatar hash if any
                if (settings.autoDownloadAvatars)
                {
                    var x = presence.Element <Tags.vcard_temp.x.update.x>(Tags.vcard_temp.x.update.Namespace.x);
                    if (x != null)
                    {
                        var photo = x.Element <Tags.vcard_temp.x.update.photo>(Tags.vcard_temp.x.update.Namespace.photo);
                        if (photo != null)
                        {
                            if (!string.IsNullOrEmpty(photo.Value))
                            {
                                // Request new photo if available
                                if (contact.photohash != photo.Value)
                                {
                                    if (!contact.vCardRequested)
                                    {
                                        contact.vCardRequested = true;
                                        var iq = new Tags.jabber.client.iq();

                                        iq.from = account.CurrentJID;
                                        iq.to   = new XMPP.JID(presence.from).Bare;
                                        iq.type = Tags.jabber.client.iq.typeEnum.get;
                                        var vcard = new Tags.vcard_temp.vCard();
                                        iq.Add(vcard);

                                        iq.Timestamp = DateTime.Now;
                                        iq.Account   = presence.Account;

                                        Frontend.Backend.SendTag(iq.Account, iq);
                                    }
                                }
                            }
                        }
                    }
                }

                // No resource, fix it
                if (string.IsNullOrEmpty(from.Resource))
                {
                    from.Resource = from.Bare;
                }

                // Set resource and status
                switch (presence.type)
                {
                case Tags.jabber.client.presence.typeEnum.none:
                {
                    // Get Show
                    var showElement = presence.showElements.FirstOrDefault();
                    var status      = showElement != null ? showElement.Value : Tags.jabber.client.show.valueEnum.none;

                    // Get status message
                    var statusElement = presence.statusElements.FirstOrDefault();
                    var statusMessage = statusElement != null ? statusElement.Value : string.Empty;

                    // Get priority
                    var priorityElement = presence.priorityElements.FirstOrDefault();
                    var priority        = priorityElement != null ? priorityElement.Value : 0;

                    contact.SetResource(from.Resource, priority, status, statusMessage);
                    break;
                }

                case Tags.jabber.client.presence.typeEnum.unavailable:
                {
                    contact.RemoveResource(from.Resource);
                    break;
                }

                case Tags.jabber.client.presence.typeEnum.subscribe:
                {
                    contact.subscriptionRequest = Backend.Data.Contact.SubscriptionRequestType.Subscribe;
                    Frontend.Notifications.CreateRequest(NotificationRequestType.Subscribe, presence.Account, presence.from);
                    break;
                }

                case Tags.jabber.client.presence.typeEnum.subscribed:
                {
                    Frontend.Notifications.CreateInformative(NotificationInfoType.Subscribed, presence.Account, presence.from);
                    break;
                }

                case Tags.jabber.client.presence.typeEnum.unsubscribe:
                {
                    contact.subscriptionRequest = Backend.Data.Contact.SubscriptionRequestType.Unsubscribe;
                    Frontend.Notifications.CreateInformative(NotificationInfoType.Unsubscribe, presence.Account, presence.from);
                    break;
                }

                case Tags.jabber.client.presence.typeEnum.unsubscribed:
                {
                    Frontend.Notifications.CreateInformative(NotificationInfoType.Unsubscribed, presence.Account, presence.from);
                    break;
                }
                }

                contact.UnlockUpdates();
                Frontend.Events.ContactsChanged();

                return(true);
            }
            catch (Exception uiEx) { Frontend.UIError(uiEx); }

            return(false);
        }
Esempio n. 4
0
        public static void PublishAvatar(string filetype, byte[] image)
        {
            try
            {
                foreach (var account in Frontend.Accounts.Enabled)
                {
                    if (account.CurrentVCard != null)
                    {
                        var iq = new Tags.jabber.client.iq();
                        iq.from = account.CurrentJID;
                        iq.type = Tags.jabber.client.iq.typeEnum.set;

                        var vcard = new Tags.vcard_temp.vCard();

                        foreach (var element in account.CurrentVCard.Elements())
                        {
                            if (element.Name != XName.Get("PHOTO", "vcard-temp") &&     // I know how ugly this is, but I have to get this done~!
                                element.Name != XName.Get("TYPE", "vcard-temp") &&
                                element.Name != XName.Get("BINVAL", "vcard-temp"))
                                vcard.Add(element);
                        }

                        var photo = new XElement(XName.Get("PHOTO", "vcard-temp"));
                        photo.Add(new XElement(XName.Get("TYPE", "vcard-temp"), filetype));
                        photo.Add(new XElement(XName.Get("BINVAL", "vcard-temp"), System.Convert.ToBase64String(image)));
                        vcard.Add(photo);

                        iq.Add(vcard);

                        Frontend.Backend.SendTag(account.jid, iq);

                        account.OwnContact.SetAvatar(image);
                    }
                }
            }
            catch (Exception uiEx) { Frontend.UIError(uiEx); }
        }
Esempio n. 5
0
        public static void RequestVCard(Account account)
        {
            var iq = new Tags.jabber.client.iq();

            if (!string.IsNullOrEmpty(account.CurrentJID.Bare))
                iq.from = account.CurrentJID;
            else
                return;

            iq.type = Tags.jabber.client.iq.typeEnum.get;

            var vcard = new Tags.vcard_temp.vCard();
            iq.Add(vcard);

            Runtime.Interface.SendTag(new XMPP.JID(account.jid).Bare, iq);
        }