public static string GetErrorMessage(Tags.jabber.client.presence presence) { var error = presence.Element <Tags.jabber.client.error>(Tags.jabber.client.Namespace.error); if (error != null) { return(GetErrorMessage(error)); } return(Translate("UnknownError")); }
public static void Subscribe(Contact contact) { try { // Unsubscribe from the contact var subscribe = new Tags.jabber.client.presence(); subscribe.type = Tags.jabber.client.presence.typeEnum.subscribe; subscribe.to = contact.jid; Frontend.Backend.SendTag(contact.account, subscribe); } catch (Exception uiEx) { Frontend.UIError(uiEx); } }
private bool Process(Tags.jabber.client.presence presence) { if (presence.type == Tags.jabber.client.presence.typeEnum.error) { var errorMessage = Helper.GetErrorMessage(presence); NotifyError(XMPP.ErrorPolicyType.Informative, Helper.Translate("ErrorTagPresence") + ": " + errorMessage); } else if (presence.type == Tags.jabber.client.presence.typeEnum.subscribe) { var fromJid = new XMPP.JID(presence.from); Notify(presence.Account, presence.from, fromJid + " " + Helper.Translate("SubscriptionRequest")); } return(false); }
public static void Unsubscribe(Contact contact) { try { // Unsubscribe from the contact var unsubscribe = new Tags.jabber.client.presence(); unsubscribe.type = Tags.jabber.client.presence.typeEnum.unsubscribe; unsubscribe.to = contact.jid; Frontend.Backend.SendTag(contact.account, unsubscribe); contact.subscriptionRequest = Contact.SubscriptionRequestType.None; } catch (Exception uiEx) { Frontend.UIError(uiEx); } }
public static void Subscribed(Contact contact) { try { // Unsubscribe to the contact var subscribed = new Tags.jabber.client.presence(); subscribed.type = Tags.jabber.client.presence.typeEnum.subscribed; subscribed.to = contact.jid; Frontend.Backend.SendTag(contact.account, subscribed); contact.subscriptionRequest = Contact.SubscriptionRequestType.None; } catch (Exception uiEx) { Frontend.UIError(uiEx); } }
public static void Unsubscribed(Contact contact) { try { // Unsubscribe to the contact var unsubscribed = new Tags.jabber.client.presence(); unsubscribed.type = Tags.jabber.client.presence.typeEnum.unsubscribed; unsubscribed.to = contact.jid; Frontend.Backend.SendTag(contact.account, unsubscribed); contact.subscriptionRequest = Contact.SubscriptionRequestType.None; } catch (Exception uiEx) { Frontend.UIError(uiEx); } }
public static void PublishState(string account, Tags.jabber.client.show.valueEnum statusValue, string message) { #if DEBUG System.Diagnostics.Debug.WriteLine("[Frontend] Publishing State for: " + account); #endif var presence = new Tags.jabber.client.presence(); if (!string.IsNullOrEmpty(message)) { var status = new Tags.jabber.client.status(); status.Value = message; presence.Add(status); } if (statusValue != Tags.jabber.client.show.valueEnum.none) { var show = new Tags.jabber.client.show(); show.Value = statusValue; presence.Add(show); } Runtime.Interface.SendTag(account, presence); }
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); }