/// <summary>Received a presence message, type=unavailable means the user /// has gone offline, everything else means the user is online.</summary> protected void HandlePresence(object sender, Presence pres) { ProtocolLog.WriteIf(XmppLog, "Incoming: " + pres.ToString()); JID jid = pres.From; if (jid == null || jid.Resource == null) { return; } string key = jid.ToString(); if (jid.Resource.StartsWith(RESOURCE_NS)) { if (pres.Type == PresenceType.unavailable) { lock (_online) { _online.Remove(key); } } else if (!_online.ContainsKey(key)) { lock (_online) { _online[jid.ToString()] = jid; } } } }
public void OpenChatWindow(JID jid, bool isMucUser, bool focus, ChatHandlerEvent callback) { QApplication.Invoke(delegate { IChatHandler handler = null; string windowJid = isMucUser ? jid.ToString() : jid.Bare; lock (m_ChatWindows) { if (!m_ChatWindows.ContainsKey(windowJid)) { handler = new ChatHandler(m_Account, isMucUser, windowJid); var window = new ChatWindow(handler); window.Closed += HandleChatWindowClosed; m_ChatWindows.Add(windowJid, window); Gui.TabbedChatsWindow.AddChatWindow(window, focus); } else { var window = m_ChatWindows[windowJid]; if (focus) { Gui.TabbedChatsWindow.FocusChatWindow(window); } handler = (ChatHandler)window.Handler; } } if (callback != null) { callback(handler); } }); }
/// <summary>Is the peer online to the best of our knowledge.</summary> public bool IsUserOnline(JID jid) { if (!_online.ContainsKey(jid.ToString())) { return(jid.Equals(_jc.JID)); } return(true); }
/// <summary>Send a Query to a remote peer.</summary> public bool SendTo(Element msg, JID to) { if (!_online.ContainsKey(to.ToString())) { return(false); } SendByIQ(msg, to); return(true); }
public ChatHandler(Account account, bool isMucUser, JID jid) : base(account) { m_Jid = jid; m_IsMucUser = isMucUser; base.Account.ConnectionStateChanged += HandleConnectionStateChanged; base.Ready = (base.Account.ConnectionState == AccountConnectionState.Connected); base.AppendStatus(String.Format("Conversation with {0}.", jid.ToString())); }
private Message ReceiveMessage(JID inJId, NUnit.Framework.Constraints.Constraint inMatcher) { Message result; Assert.That(mQueue.TryPoll(TimeSpan.FromSeconds(5), out result), Is.True, "5秒間に何らかのメッセージが送られてこなければならない"); Assert.That(result, Is.Not.Null); Assert.That(result.Body, inMatcher); Assert.That(result.From.ToString(), Is.EqualTo(inJId.ToString())); return(result); }
[Test] public void Test_Create() { JID j = new JID("foo", "jabber.com", "there"); Assert.AreEqual("[email protected]/there", j.ToString()); j = new JID(null, "jabber.com", null); Assert.AreEqual("jabber.com", j.ToString()); j = new JID("foo", "jabber.com", null); Assert.AreEqual("*****@*****.**", j.ToString()); j = new JID(null, "jabber.com", "there"); Assert.AreEqual("jabber.com/there", j.ToString()); }
void ReceivedMood(JID from, string node, PubSubItem item) { Mood mood = (Mood)item["mood"]; m_FriendMoods[from.Bare] = mood; // Only show in feed if we know this is a recent event. if (mood["timestamp"] != null && DateTime.Now.Subtract(DateTime.Parse(mood["timestamp"].InnerText)).TotalSeconds <= 60) { m_Account.PostActivityFeedItem(from.ToString(), "mood", mood.MoodName, mood.Text); } }
/// <summary>We are not available for chatting, we're just online to take /// advantage of Xmpp!</summary> protected void HandleAuthenticate(object sender) { Presence presence = new Presence(new XmlDocument()); presence.Show = "dnd"; presence.Status = "Chat Disabled"; Write(presence); // We are online! lock (_online) { _online[JID.ToString()] = JID; } }
private void m_pres_OnPrimarySessionChange(object sender, JID bare) { Presence pres = m_pres[bare]; LinkedList nodelist = m_items[bare.ToString()] as LinkedList; if (nodelist == null) { return; } foreach (ItemNode n in nodelist) { n.ChangePresence(pres); } }
public string GetDisplayName(JID jid) { Item item = this.Roster[jid.Bare]; if (item != null && !String.IsNullOrEmpty(item.Nickname)) { return(item.Nickname); } else if (!String.IsNullOrEmpty(jid.User)) { return(jid.User); } else { return(jid.ToString()); } }
public SegmentSwitch SegSwitch; // the direction swich manger for the junction. public Junction(MainWindow MAINWINDOW) { InitializeComponent(); _MainWindow = MAINWINDOW; CurrentTraficSignal = TraficSignal.VerticalGreen; TraficSignalingTimer.Interval = TimeSpan.FromSeconds(Settings.Default.TraficSignalingTimerInterval); TraficSignalingTimer.Start(); TraficSignalingTimer.Tick += TraficSignalingTimer_Tick; Height = PublicParamerters.JunctionHeight; Width = PublicParamerters.JunctionWidth; JID = MAINWINDOW.MyJunctions.Count; MAINWINDOW.MyJunctions.Add(this); lbl_junction_id.Text = JID.ToString(); }
public void Test_Escape() { JID j = JID.Escape("d'artagnan", "gascon.fr", "elder"); Assert.AreEqual(@"d\[email protected]/elder", j.ToString()); j = JID.Escape("space cadet", "example.com", null); Assert.AreEqual(@"space\[email protected]", j.ToString()); j = JID.Escape("call me \"ishmael\"", "example.com", null); Assert.AreEqual(@"call\20me\20\22ishmael\[email protected]", j.ToString()); j = JID.Escape("at&t guy", "example.com", null); Assert.AreEqual(@"at\26t\[email protected]", j.ToString()); j = JID.Escape("/.fanboy", "example.com", null); Assert.AreEqual(@"\[email protected]", j.ToString()); j = JID.Escape("::foo::", "example.com", null); Assert.AreEqual(@"\3a\3afoo\3a\[email protected]", j.ToString()); j = JID.Escape("<foo>", "example.com", null); Assert.AreEqual(@"\3cfoo\[email protected]", j.ToString()); j = JID.Escape("user@host", "example.com", null); Assert.AreEqual(@"user\[email protected]", j.ToString()); j = JID.Escape(@"c:\net", "example.com", null); Assert.AreEqual(@"c\3a\[email protected]", j.ToString()); j = JID.Escape(@"c:\\net", "example.com", null); Assert.AreEqual(@"c\3a\5c\[email protected]", j.ToString()); j = JID.Escape(@"c:\cool stuff", "example.com", null); Assert.AreEqual(@"c\3a\5ccool\[email protected]", j.ToString()); j = JID.Escape(@"c:\5commas", "example.com", null); Assert.AreEqual(@"c\3a\[email protected]", j.ToString()); }
public void EscapeUsernameFromParts() { var id = new JID("d'artangan", "garcon.fr", "testing"); Assert.That(id.ToString(), Is.EqualTo(@"d\[email protected]/testing")); }
string GetSafeSubscriptionID(JID From, string LocalSubscriptionID) { return(From.ToString() + LocalSubscriptionID); }
/// <summary>Converts a JID into an XmppTA string.</summary> private static string GetString(JID jid) { return("brunet.xmpp://" + jid.ToString()); }