private void SendOfflineMessages(XmppSession session)
        {
            if (!session.IsSignalRFake)
            {
                var domain = session.Stream.Domain;
                foreach (var m in offlineStore.GetOfflineMessages(session.Jid))
                {
                    var delay = new Element("delay");
                    delay.SetNamespace("urn:xmpp:delay");
                    delay.SetAttribute("From", domain);
                    delay.SetAttribute("stamp", Time.Date(m.XDelay.Stamp));
                    delay.Value = "Offline Storage";
                    m.AddChild(delay);

                    m.XDelay.From  = new Jid(domain);
                    m.XDelay.Value = "Offline Storage";

                    sender.SendTo(session, m);
                }
                if (session.Jid.Resource != "TMTalk")
                {
                    offlineStore.RemoveAllOfflineMessages(session.Jid);
                }
            }
        }
Beispiel #2
0
        public void OfflineMessagesTest()
        {
            store.RemoveAllOfflineMessages(userName);
            var messages = store.GetOfflineMessages(userName);

            Assert.AreEqual(0, messages.Count);

            var m = new OfflineMessage()
            {
                To   = "x",
                From = "y",
                When = DateTime.Now,
                Body = "xy"
            };

            store.SaveOfflineMessage(userName, m);

            messages = store.GetOfflineMessages(userName);
            Assert.AreEqual(1, messages.Count);
            Assert.AreEqual("x", messages[0].To);
            Assert.AreEqual("y", messages[0].From);
            Assert.AreNotEqual(DateTime.MinValue, messages[0].When);
            Assert.AreEqual("xy", messages[0].Body);

            store.SaveOfflineMessage(userName, m);
            messages = store.GetOfflineMessages(userName);
            Assert.AreEqual(2, messages.Count);

            store.RemoveAllOfflineMessages(userName);

            store.SaveOfflineMessage(userName, new OfflineMessage());
            messages = store.GetOfflineMessages(userName);
            Assert.AreEqual(1, messages.Count);
            Assert.IsNull(messages[0].To);
            Assert.IsNull(messages[0].From);
            Assert.AreEqual(DateTime.MinValue, messages[0].When);
            Assert.IsNull(messages[0].Body);
        }