private IQ GetHistory(XmppStream stream, IQ iq, XmppHandlerContext context) { if (!iq.HasTo) { return(XmppStanzaError.ToServiceUnavailable(iq)); } FlushMessageBuffer(); var history = (History)iq.Query; history.RemoveAllChildNodes(); foreach (var m in archiveStore.GetMessages(iq.From, iq.To, history.From, history.To, history.Text, history.Count, history.StartIndex)) { if (m == null) { continue; } history.AddChild(HistoryItem.FromMessage(m)); } iq.Type = IqType.result; iq.SwitchDirection(); return(iq); }
public void MessagesTest() { var from = new Jid("jid1", "s", "R1"); var to = new Jid("jid2", "s", "R2"); var m1 = new Message(to, from, "to --> from"); var m2 = new Message(from, to, "from --> to"); store.SaveMessages(new[] { m1, m2 }); var messages = store.GetMessages(from, to, DateTime.MinValue, DateTime.MaxValue, 2); Assert.AreEqual(messages.Length, 2); Assert.AreEqual(m1.From, messages[0].From); Assert.AreEqual(m2.From, messages[1].From); messages = store.GetMessages(to, from, DateTime.MinValue, DateTime.MaxValue, 2); Assert.AreEqual(messages.Length, 2); Assert.AreEqual(m1.From, messages[0].From); Assert.AreEqual(m2.From, messages[1].From); }