Beispiel #1
0
 public ConversationItem(ConversationSender sender, JID identifier, DateTime timestamp)
 {
     Sender = sender;
     Identifier = identifier;
     Timestamp = timestamp;
     Messages = new ObservableCollection<ConversationMessage>();
 }
Beispiel #2
0
        public void AddMessage(Tags.jabber.client.message message)
        {
            JID senderJid = new JID(message.from);
            string sender = null;
            
            // Get the contact the message is from
            if( senderJid.Bare == Self )
                sender = Self;
            else if( senderJid.Bare == Other )
                sender = Other;
            else
                return;

            // The conversationitem we will be adding items to
            ConversationItem current = null;

            // Look if we have to add a new item or reuse an old one
            if (Items.Count > 0)
            {
                ConversationItem last = Items.First();
                if (last != null && last.Identifier == senderJid) // The last item is from the same sender as this item
                {
                    if (last.Messages.Count > 0) // It has messages
                    {
                        ConversationMessage lastMessage = last.Messages.Last();
                        if ((message.Timestamp - lastMessage.Timestamp).Minutes < 1) // The last messag is no older than two minutes
                            current = last;
                    }
                    else // It has no messages, we don't know why but we should add our items to it because an emtpy item looks bad
                    {
                        current = last;
                    }
                }
            }

            if (current == null)
            {
                current = new ConversationItem(new ConversationSender(Self, sender), senderJid, message.Timestamp);
                Items.Insert(0, current);
            }

            current.AddMessage(message);
        }
Beispiel #3
0
        public void CreateInformative(NotificationInfoType infoType, string account, string from)
        {
            try
            {
                var accountObj = Frontend.Accounts[account];
                if (accountObj == null)
                    return;

                var fromJID = new JID(from);
                var contact = accountObj.Roster[fromJID.Bare];
                if (contact == null)
                    return;


                var notification = new Notification();
                notification.Account = account;
                notification.Type = NotificationType.Request;

                switch (infoType)
                {
                    case NotificationInfoType.Subscribed:    // Notify that he now sends you updates to his status
                        notification.Message = fromJID.Bare + " " + Helper.Translate("SubscriptionAllowed");
                        break;

                    case NotificationInfoType.Unsubscribed:  // Notify that he dosn't send you updates to his status anymore
                        notification.Message = fromJID.Bare + " " + Helper.Translate("SubscriptionRevoked");
                        break;
                    case NotificationInfoType.Unsubscribe:   // Notify that he dosn't want to see your updates anymore
                        notification.Message = fromJID.Bare + " " + Helper.Translate("SubscriptionUnsubscribed");
                        break;
                }

                notification.Action = FlyoutType.Subscription;
                notification.Data = contact;
                AddNotification(notification);
            }
            catch (Exception uiEx) { Frontend.UIError(uiEx); }
        }
Beispiel #4
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);
        }
Beispiel #5
0
        public void CreateRequest(NotificationRequestType requestType, string account, string from)
        {
            try
            {
                var accountObj = Frontend.Accounts[account];
                if (accountObj == null)
                    return;

                var fromJID = new JID(from);
                var contact = accountObj.Roster[fromJID.Bare];
                if (contact == null)
                    return;


                var notification = new Notification();
                notification.Account = account;
                notification.Type = NotificationType.Request;

                if (requestType == NotificationRequestType.Subscribe)
                {
                    notification.Message = fromJID.Bare + " " + Helper.Translate("SubscriptionRequest");
                    notification.Action = FlyoutType.Subscription;
                    notification.Data = contact;
                }

                AddNotification(notification);
            }
            catch (Exception uiEx) { Frontend.UIError(uiEx); }
        }