public static void RemoveContact(Contact contact) { try { var account = Frontend.Accounts[contact.account]; if (account != null) { Unsubscribe(contact); Unsubscribed(contact); // Remove hin from the roster var iq = new Tags.jabber.client.iq(); iq.from = account.CurrentJID; iq.type = Tags.jabber.client.iq.typeEnum.set; var query = new Tags.jabber.iq.roster.query(); var item = new Tags.jabber.iq.roster.item(); item.jid = contact.jid; item.subscription = Tags.jabber.iq.roster.item.subscriptionEnum.remove; query.Add(item); iq.Add(query); Frontend.Backend.SendTag(account.jid, iq); } } catch (Exception uiEx) { Frontend.UIError(uiEx); } }
public static void RequestRoster(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 query = new Tags.jabber.iq.roster.query(); iq.Add(query); #if DEBUG System.Diagnostics.Debug.WriteLine("[Frontend] Requesting Roster for: " + currentJID.ToString() + " id " + iq.id); #endif Runtime.Interface.SendTag(currentJID.Bare, iq); }
public static string GetErrorMessage(Tags.jabber.client.iq iq) { var error = iq.Element <Tags.jabber.client.error>(Tags.jabber.client.Namespace.error); if (error != null) { return(GetErrorMessage(error)); } return(Translate("UnknownError")); }
private bool Process(Tags.jabber.client.iq iq) { if (iq.type == Tags.jabber.client.iq.typeEnum.error) { var errorMessage = Helper.GetErrorMessage(iq); NotifyError(XMPP.ErrorPolicyType.Informative, Helper.Translate("ErrorTagIq") + ": " + errorMessage); return(false); } return(true); }
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); }
public static void EditContact(Account account, XMPP.JID jid, string alias = "") { try { if (account != null) { var iq = new Tags.jabber.client.iq(); iq.from = account.CurrentJID; iq.type = Tags.jabber.client.iq.typeEnum.set; var query = new Tags.jabber.iq.roster.query(); var item = new Tags.jabber.iq.roster.item(); item.jid = jid.Bare; item.name = alias; query.Add(item); iq.Add(query); Frontend.Backend.SendTag(account.jid, iq); } } catch (Exception uiEx) { Frontend.UIError(uiEx); } }
public void CheckKeepAlive(ControlChannelTrigger trigger) { // Send keepalive for the next check var pingIq = new XMPP.tags.jabber.client.iq(); pingIq.type = Tags.jabber.client.iq.typeEnum.get; pingIq.from = Id; pingIq.Add(new XMPP.tags.xmpp.ping.ping()); Send(pingIq); // Check how long since the last packet var diffTime = DateTime.Now - _lastReceiveTime; var diffTimeMinutes = (uint)diffTime.TotalMinutes; var keepAliveMinutes = (trigger != null) ? trigger.CurrentKeepAliveIntervalInMinutes : 15; // 15 is default if (diffTimeMinutes > keepAliveMinutes) { trigger.DecreaseNetworkKeepAliveInterval(); OnError(this, new ErrorEventArgs("Connection to server lost", ErrorType.NotConnected, ErrorPolicyType.Reconnect)); } }
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); } }
public static void CreateContact(Account account, XMPP.JID jid, string alias = "") { try { if (account != null) { var contact = account.Roster[jid.Bare]; if (contact == null) { contact = account.Roster.CreateContact(account.jid, jid.Bare); } if (contact == null) { return; } var iq = new Tags.jabber.client.iq(); iq.from = account.CurrentJID; iq.type = Tags.jabber.client.iq.typeEnum.set; var query = new Tags.jabber.iq.roster.query(); var item = new Tags.jabber.iq.roster.item(); item.jid = jid.Bare; if (!string.IsNullOrEmpty(alias)) { item.name = alias; } query.Add(item); iq.Add(query); Frontend.Backend.SendTag(account.jid, iq); Subscribe(contact); } } catch (Exception uiEx) { Frontend.UIError(uiEx); } }
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); }
private bool Process(Tags.jabber.client.iq iq) { try { if (iq.type == Tags.jabber.client.iq.typeEnum.error) { var errorMessage = Helper.Translate("ErrorTagIq") + ": " + Helper.GetErrorMessage(iq); Frontend.Notifications.CreateError(ErrorPolicyType.Informative, iq.Account, errorMessage); return(false); } Account account = Frontend.Accounts[iq.Account]; if (account == null) { return(false); } if (iq.type == Tags.jabber.client.iq.typeEnum.result || iq.type == Tags.jabber.client.iq.typeEnum.set) { #region query var query = iq.Element <Tags.jabber.iq.roster.query>(Tags.jabber.iq.roster.Namespace.query); if (query != null) { if (iq.type == Tags.jabber.client.iq.typeEnum.result) // This is a roster { account.Roster.ClearOffline(); #if DEBUG System.Diagnostics.Debug.WriteLine("[Frontend] Received Roster: " + iq.id); #endif } foreach (var item in query.itemElements) { Backend.Data.Contact contact = account.Roster[item.jid]; if (contact == null) { contact = account.Roster.CreateContact(account.jid, item.jid); } if (contact == null) { continue; } contact.LockUpdates(); // Remove if (item.subscription == Tags.jabber.iq.roster.item.subscriptionEnum.remove) { account.Roster.Remove(contact); } // Add or update else { contact.name = item.name; contact.subscription = item.subscription; contact.ask = item.ask; contact.Groups.Clear(); foreach (var group in item.groupElements) { contact.Groups.Add(group.Value); } } contact.UnlockUpdates(); } Frontend.Events.ContactsChanged(); } #endregion var bind = iq.Element <Tags.xmpp_bind.bind>(Tags.xmpp_bind.Namespace.bind); if (bind != null) { var jid = new JID(bind.jid.Value); if (!string.IsNullOrEmpty(jid)) { account.serverJID = jid; account.OwnResource = jid.Resource; account.OwnContact.SetResource(jid.Resource); } } #region vcard var vcard = iq.Element <Tags.vcard_temp.vCard>(Tags.vcard_temp.Namespace.vCard); if (vcard != null) { if (string.IsNullOrEmpty(iq.from) || new JID(iq.from).Bare == iq.Account) { account.CurrentVCard = vcard; } var photo = vcard.Element(XName.Get("PHOTO", "vcard-temp")); if (photo != null) { var type = photo.Element(XName.Get("TYPE", "vcard-temp")); var binval = photo.Element(XName.Get("BINVAL", "vcard-temp")); if (iq.from == null) { iq.from = iq.Account; } var jid = new JID(iq.from).Bare; if (type != null && binval != null) { Backend.Data.Contact contact = account.Roster[jid]; if (contact == null) { contact = account.Roster.CreateContact(account.jid, jid); } if (contact == null) { return(false); } contact.LockUpdates(); contact.SetAvatar(binval.Bytes); contact.vCardRequested = false; contact.UnlockUpdates(); } } } #endregion } return(true); } catch (Exception uiEx) { Frontend.UIError(uiEx); } return(false); }
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); } }
public static void RequestRoster(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 query = new Tags.jabber.iq.roster.query(); iq.Add(query); #if DEBUG System.Diagnostics.Debug.WriteLine("[Frontend] Requesting Roster for: " + account.CurrentJID.ToString() + " id " + iq.id); #endif Runtime.Interface.SendTag(new XMPP.JID(account.jid).Bare, iq); }
public static void CreateContact(Account account, XMPP.JID jid, string alias = "") { try { if (account != null) { var contact = account.Roster[jid.Bare]; if (contact == null) contact = account.Roster.CreateContact(account.jid, jid.Bare); if (contact == null) return; var iq = new Tags.jabber.client.iq(); iq.from = account.CurrentJID; iq.type = Tags.jabber.client.iq.typeEnum.set; var query = new Tags.jabber.iq.roster.query(); var item = new Tags.jabber.iq.roster.item(); item.jid = jid.Bare; if (!string.IsNullOrEmpty(alias)) item.name = alias; query.Add(item); iq.Add(query); Frontend.Backend.SendTag(account.jid, iq); Subscribe(contact); } } catch (Exception uiEx) { Frontend.UIError(uiEx); } }
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); }