private void OnUnfriendHandler(XmppClient Client, XmlElement Element, string From, string To) { string Jid = XmppClient.StripResource(XmlUtilities.GetAttribute(Element, "jid", string.Empty)); JidEventHandler h = this.OnUnfriend; if (h == null) { XmppContact Contact = this.client.GetLocalContact(Jid); if (Contact != null) { this.client.DeleteContact(Contact); } } else { JidEventArgs e = new JidEventArgs(Jid); try { h(this, e); } catch (Exception ex) { Log.Exception(ex); } } }
/// <summary> /// Initializes a new instance of the <see cref = "XmppUserTuneEvent">XmppUserTuneEvent</see> class. /// </summary> /// <param name = "user">User contact</param> /// <param name = "tune">User tune</param> public XmppUserTuneEvent(XmppContact user, Tune tune) : base(user) { artist = tune.Artist; length = tune.Length; rating = tune.Rating; source = tune.Source; title = tune.Title; track = tune.Track; uri = tune.Uri; }
public override void SendChatMessage(string Message, string ThreadId, MarkdownDocument Markdown) { if (Markdown is null) { this.MucClient.SendGroupChatMessage(this.roomId, this.domain, Message, string.Empty, ThreadId); } else { this.MucClient.SendCustomGroupChatMessage(this.roomId, this.domain, XmppContact.MultiFormatMessage(Message, Markdown), string.Empty, ThreadId); } }
private void DisownDevice_Click(object sender, RoutedEventArgs e) { MenuItem Item = (MenuItem)sender; XmppContact Contact = (XmppContact)Item.Tag; this.registryClient.Disown(Contact.BareJID, (sender2, e2) => { if (e2.Ok) { MainWindow.SuccessBox(Contact.BareJID + " has been disowned."); } else { MainWindow.ErrorBox(string.IsNullOrEmpty(e2.ErrorText) ? "Unable to disown " + Contact.BareJID + "." : e2.ErrorText); } }, null); }
private void ReconfigureDevice_Click(object sender, RoutedEventArgs e) { MenuItem Item = (MenuItem)sender; XmppContact Contact = (XmppContact)Item.Tag; this.provisioningClient.DeleteDeviceRules(Contact.BareJID, (sender2, e2) => { if (e2.Ok) { MainWindow.SuccessBox("The rules in " + Contact.BareJID + " have been deleted."); } else { MainWindow.ErrorBox(string.IsNullOrEmpty(e2.ErrorText) ? "Unable to delete the rules in " + Contact.BareJID + "." : e2.ErrorText); } }, null); }
private void ClearRuleCache_Click(object sender, RoutedEventArgs e) { MenuItem Item = (MenuItem)sender; XmppContact Contact = (XmppContact)Item.Tag; this.provisioningClient.ClearDeviceCache(Contact.BareJID, (sender2, e2) => { if (e2.Ok) { MainWindow.SuccessBox("The rule cache in " + Contact.BareJID + " has been cleared."); } else { MainWindow.ErrorBox(string.IsNullOrEmpty(e2.ErrorText) ? "Unable to clear the rule cache in " + Contact.BareJID + "." : e2.ErrorText); } }, null); }
/// <summary> /// Invites the given contact to the chat room /// </summary> /// <param name = "contact"></param> public XmppChatRoom Invite(XmppContact contact) { var user = new MucUser(); var message = new Message { From = Session.UserId, To = Identifier.BareIdentifier, }; var invite = new MucUserInvite { To = contact.ContactId.BareIdentifier, Reason = "Ninja invite" }; user.Items.Add(invite); message.Items.Add(user); Session.Send(message); return(this); }
/// <summary> /// Creates an xmpp event with the give user and pubsub event /// </summary> /// <param name = "user"></param> /// <param name = "xmppevent"></param> /// <returns></returns> public static XmppEvent Create(XmppContact user, PubSubEvent xmppevent) { if (xmppevent.Item is PubSubEventItems) { var items = (PubSubEventItems)xmppevent.Item; if (items.Items.Count == 1) { var item = (PubSubItem)items.Items[0]; if (item.Item is Tune) { return(new XmppUserTuneEvent(user, (Tune)item.Item)); } else if (item.Item is Mood) { return(new XmppUserMoodEvent(user, (Mood)item.Item)); } } } return(null); }
/// <summary> /// Creates an xmpp event with the give user and pubsub event /// </summary> /// <param name = "user"></param> /// <param name = "xmppevent"></param> /// <returns></returns> public static XmppEvent Create(XmppContact user, PubSubEvent xmppevent) { if (xmppevent.Item is PubSubEventItems) { var items = (PubSubEventItems) xmppevent.Item; if (items.Items.Count == 1) { var item = (PubSubItem) items.Items[0]; if (item.Item is Tune) { return new XmppUserTuneEvent(user, (Tune) item.Item); } else if (item.Item is Mood) { return new XmppUserMoodEvent(user, (Mood) item.Item); } } } return null; }
/// <summary> /// Initializes a new instance of the <see cref = "XmppUserMoodEvent">XmppUserMoodEvent</see> class. /// </summary> /// <param name = "user">User contact</param> /// <param name = "mood">User mood</param> public XmppUserMoodEvent(XmppContact user, Mood mood) : base(user) { this.mood = mood.MoodType.ToString(); text = mood.Text; }
private void ChatMessageReceived(object P) { MessageEventArgs e = (MessageEventArgs)P; ChatView ChatView; string Message = e.Body; bool IsMarkdown = false; foreach (XmlNode N in e.Message.ChildNodes) { if (N.LocalName == "content" && N.NamespaceURI == "urn:xmpp:content") { string Type = XML.Attribute((XmlElement)N, "type"); if (Type == "text/markdown") { IsMarkdown = true; Type = N.InnerText; if (!string.IsNullOrEmpty(Type)) { Message = Type; } break; } } } foreach (TabItem TabItem in this.Tabs.Items) { ChatView = TabItem.Content as ChatView; if (ChatView == null) { continue; } XmppContact XmppContact = ChatView.Node as XmppContact; if (XmppContact == null) { continue; } if (XmppContact.BareJID != e.FromBareJID) { continue; } XmppAccountNode XmppAccountNode = XmppContact.XmppAccountNode; if (XmppAccountNode == null) { continue; } if (XmppAccountNode.BareJID != XmppClient.GetBareJID(e.To)) { continue; } ChatView.ChatMessageReceived(Message, IsMarkdown, this); return; } foreach (TreeNode Node in this.MainView.ConnectionTree.Items) { XmppAccountNode XmppAccountNode = Node as XmppAccountNode; if (XmppAccountNode == null) { continue; } if (XmppAccountNode.BareJID != XmppClient.GetBareJID(e.To)) { continue; } if (XmppAccountNode.TryGetChild(e.FromBareJID, out TreeNode ContactNode)) { TabItem TabItem2 = new TabItem(); this.Tabs.Items.Add(TabItem2); ChatView = new ChatView(ContactNode); TabItem2.Header = e.FromBareJID; TabItem2.Content = ChatView; ChatView.ChatMessageReceived(Message, IsMarkdown, this); return; } } }
/// <summary> /// Invites the given contact to the chat room /// </summary> /// <param name = "contact"></param> public XmppChatRoom Invite(XmppContact contact) { var user = new MucUser(); var message = new Message { From = Session.UserId, To = Identifier.BareIdentifier, }; var invite = new MucUserInvite { To = contact.ContactId.BareIdentifier, Reason = "Ninja invite" }; user.Items.Add(invite); message.Items.Add(user); Session.Send(message); return this; }
/// <summary> /// Initializes a new instance of the <see cref = "XmppUserEvent" /> class. /// </summary> /// <param name = "user"></param> protected XmppUserEvent(XmppContact user) { this.user = user; }
/// <summary> /// Initializes a new instance of the <see cref="XmppUserTuneEvent">XmppUserTuneEvent</see> class. /// </summary> /// <param name="user">User contact</param> /// <param name="tune">User tune</param> public XmppUserTuneEvent(XmppContact user, Tune tune) : base(user) { this.artist = tune.Artist; this.length = tune.Length; this.rating = tune.Rating; this.source = tune.Source; this.title = tune.Title; this.track = tune.Track; this.uri = tune.Uri; }