private UserInfo GetUser(Jid jid) { var bare = jid.GetBareJid(); var result = _client.GetRoster().FirstOrDefault(_ => _.Jid == bare); if (result == null) { Logger.Error($"Couldn't find user {jid} in Heyman friends. Try to clear XMPP server cache."); return(null); } return(new UserInfo { Id = jid.ToString(), Name = result.Name, }); }
/// <summary> /// Updates the status contact. /// </summary> /// <param name="jid">The jid of the contact.</param> /// <param name="status">The new status.</param> public void UpdateContact(Jid jid, S22.Xmpp.Im.Status status) { if (AllContacts.Count != 0) { foreach (var contact in AllContacts) { if (jid.GetBareJid() == contact.Jid.GetBareJid()) { contact.CurrentStatus = new S22.Xmpp.Im.Status(status.Availability, status.Messages, status.Priority); break; } } } else { } }
/// <summary> /// Gets a user or create it based on its JID. /// </summary> /// <param name="jid">The jid.</param> /// <returns>A user in the Contact List.</returns> public Models.UserViewModel GetUser(Jid jid) { foreach (var contact in AllContacts) { if (jid.GetBareJid() == contact.Jid.GetBareJid()) { return(contact); } } // Create a temporary contact if a non-roster user creates a conversation. // Allows administrator to talk to anyone. // Change ctor in user var tempContact = new Models.UserViewModel(jid, ""); UICollection.AddOnUI(AllContacts, tempContact); return(tempContact); }
/// <summary> /// Requests archived messages according options specified /// </summary> /// <param name="jid">The JID of the XMPP entity to get.</param> /// <param name="queryId">The Id related to this query - it will be used to identify this request</param> /// <param name="max">The maximum number of result expected /// <param name="isRoom">To know if we request archive from room /// <param name="before">Stanza ID - if not null search message before it /// <param name="max">Stanza ID - if not null search message before it /// <exception cref="ArgumentNullException">The jid parameter /// is null.</exception> /// <exception cref="NotSupportedException">The XMPP entity with /// the specified JID does not support the 'Ping' XMPP extension.</exception> /// <exception cref="XmppErrorException">The server returned an XMPP error code. /// Use the Error property of the XmppErrorException to obtain the specific /// error condition.</exception> /// <exception cref="XmppException">The server returned invalid data or another /// unspecified XMPP error occurred.</exception> public void RequestArchivedMessages(Jid jid, string queryId, int max, bool isRoom, string before = null, string after = null) { jid.ThrowIfNull("jid"); XmlElement rootElement; XmlElement subElement; XmlElement fieldElement; XmlElement valueElement; rootElement = Xml.Element("query", "urn:xmpp:mam:1"); rootElement.SetAttribute("queryid", queryId); subElement = Xml.Element("x", "jabber:x:data"); subElement.SetAttribute("type", "submit"); fieldElement = Xml.Element("field"); fieldElement.SetAttribute("var", "FORM_TYPE"); fieldElement.SetAttribute("type", "hidden"); valueElement = Xml.Element("value"); valueElement.InnerText = "urn:xmpp:mam:1"; fieldElement.Child(valueElement); subElement.Child(fieldElement); fieldElement = Xml.Element("field"); fieldElement.SetAttribute("var", "with"); valueElement = Xml.Element("value"); if (isRoom) { valueElement.InnerText = im.Jid.GetBareJid().ToString(); } else { valueElement.InnerText = jid.GetBareJid().ToString(); } fieldElement.Child(valueElement); subElement.Child(fieldElement); rootElement.Child(subElement); subElement = Xml.Element("set", "http://jabber.org/protocol/rsm"); if (max > 0) { subElement.Child(Xml.Element("max").Text(max.ToString())); } if (before == null) { subElement.Child(Xml.Element("before")); } else { subElement.Child(Xml.Element("before").Text(before)); } if (after != null) { subElement.Child(Xml.Element("after").Text(after)); } rootElement.Child(subElement); Jid to = null; if (isRoom) { to = jid; } //The Request is Async im.IqRequestAsync(IqType.Set, to, null, rootElement, null, (id, iq) => { //For any reply we execute the callback if (iq.Type == IqType.Error) { MessageArchiveManagementResult.Raise(this, new MessageArchiveManagementResultEventArgs()); return; } if (iq.Type == IqType.Result) { string queryid = ""; MamResult complete = MamResult.Error; int count = 0; string first = ""; string last = ""; try { if ((iq.Data["fin"] != null) && (iq.Data["fin"]["set"] != null)) { XmlElement e = iq.Data["fin"]; queryid = e.GetAttribute("queryid"); complete = (e.GetAttribute("complete") == "false") ? MamResult.InProgress : MamResult.Complete; if (e["set"]["count"] != null) { count = Int16.Parse(e["set"]["count"].InnerText); } if (e["set"]["first"] != null) { first = e["set"]["first"].InnerText; } if (e["set"]["last"] != null) { last = e["set"]["last"].InnerText; } MessageArchiveManagementResult.Raise(this, new MessageArchiveManagementResultEventArgs(queryid, complete, count, first, last)); return; } } catch (Exception) { log.LogError("RequestCustomIqAsync - an error occurred ..."); } MessageArchiveManagementResult.Raise(this, new MessageArchiveManagementResultEventArgs(queryid, MamResult.Error, count, first, last)); } }); }
private ChatUser GetByJid(Jid jid) { return(Users.FirstOrDefault(c => c.Id == jid.GetBareJid().ToString())); }