Exemplo n.º 1
0
        /// <summary>
        /// Fetch message history from the server.
        ///
        /// The 'start' and 'end' attributes MAY be specified to indicate a date range.
        ///
        /// If the 'with' attribute is omitted then collections with any JID are returned.
        ///
        /// If only 'start' is specified then all collections on or after that date should be returned.
        ///
        /// If only 'end' is specified then all collections prior to that date should be returned.
        /// </summary>
        /// <param name="pageRequest">Paging options</param>
        /// <param name="start">Optional start date range to query</param>
        /// <param name="end">Optional enddate range to query</param>
        /// <param name="with">Optional JID to filter archive results by</param>
        public XmppPage <ArchivedChatId> GetArchivedChatIds(XmppPageRequest pageRequest, DateTimeOffset?start = null, DateTimeOffset?end = null, Jid with = null)
        {
            pageRequest.ThrowIfNull();

            var request = Xml.Element("list", xmlns);

            if (with != null)
            {
                request.Attr("with", with.ToString());
            }

            if (start != null)
            {
                request.Attr("start", start.Value.ToXmppDateTimeString());
            }

            if (end != null)
            {
                request.Attr("end", end.Value.ToXmppDateTimeString());
            }

            var setNode = pageRequest.ToXmlElement();

            request.Child(setNode);

            var response = IM.IqRequest(IqType.Get, null, null, request);

            if (response.Type == IqType.Error)
            {
                throw Util.ExceptionFromError(response, "Failed to get archived chat ids");
            }

            return(new XmppPage <ArchivedChatId>(response.Data["list"], GetChatIdsFromStanza));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Fetch message history from the server.
        ///
        /// The 'start' and 'end' attributes MAY be specified to indicate a date range.
        ///
        /// If the 'with' attribute is omitted then collections with any JID are returned.
        ///
        /// If only 'start' is specified then all collections on or after that date should be returned.
        ///
        /// If only 'end' is specified then all collections prior to that date should be returned.
        /// </summary>
        /// <param name="pageRequest">Paging options</param>
        /// <param name="start">Optional start date range to query</param>
        /// <param name="end">Optional enddate range to query</param>
        /// <param name="with">Optional JID to filter archive results by</param>
        public XmppPage<ArchivedChatId> GetArchivedChatIds(XmppPageRequest pageRequest, DateTimeOffset? start = null, DateTimeOffset? end = null, Jid with = null)
        {
            pageRequest.ThrowIfNull();

            var request = Xml.Element("list", xmlns);

            if (with != null)
            {
                request.Attr("with", with.ToString());
            }

            if (start != null)
            {
                request.Attr("start", start.Value.ToXmppDateTimeString());
            }

            if (end != null)
            {
                request.Attr("end", end.Value.ToXmppDateTimeString());
            }

            var setNode = pageRequest.ToXmlElement();
            request.Child(setNode);

            var response = IM.IqRequest(IqType.Get, null, null, request);

            if (response.Type == IqType.Error)
            {
                throw Util.ExceptionFromError(response, "Failed to get archived chat ids");
            }

            return new XmppPage<ArchivedChatId>(response.Data["list"], GetChatIdsFromStanza);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Fetch a page of archived messages
        /// </summary>
        /// <param name="pageRequest">Paging options</param>
        /// <param name="with">Optional filter to only return messages if they match the supplied JID</param>
        /// <param name="roomId">Optional filter to only return messages if they match the supplied JID</param>
        /// <param name="start">Optional filter to only return messages whose timestamp is equal to or later than the given timestamp.</param>
        /// <param name="end">Optional filter to only return messages whose timestamp is equal to or earlier than the timestamp given in the 'end' field.</param>
        internal Task <XmppPage <Message> > GetArchivedMessages(XmppPageRequest pageRequest, Jid with = null, Jid roomId = null, DateTimeOffset?start = null, DateTimeOffset?end = null)
        {
            string queryId = Guid.NewGuid().ToString().Replace("-", "");

            var request = Xml.Element("query", xmlns)
                          .Attr("queryid", queryId)
                          .Child(pageRequest.ToXmlElement());

            if (with != null || start != null || end != null)
            {
                var filterForm = new SubmitForm();

                filterForm.AddValue("FORM_TYPE", DataFieldType.Hidden, xmlns);

                if (with != null)
                {
                    filterForm.AddUntypedValue("with", with);
                }

                if (start != null)
                {
                    filterForm.AddUntypedValue("start", DateTimeProfiles.ToXmppDateTimeString(start.Value));
                }

                if (end != null)
                {
                    filterForm.AddUntypedValue("end", DateTimeProfiles.ToXmppDateTimeString(end.Value));
                }

                request.Child(filterForm.ToXmlElement());
            }

            var tcs       = new TaskCompletionSource <XmppPage <Message> >();
            var queryTask = pendingQueries[queryId] = new ArchiveQueryTask(tcs);

            var response = IM.IqRequest(Sharp.Xmpp.Core.IqType.Set, roomId, null, request);

            if (response.Type == Core.IqType.Error)
            {
                queryTask.SetException(Util.ExceptionFromError(response, "Failed to get archived messages"));
            }

            return(tcs.Task);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Fetch a page of archived messages from a chat
        /// </summary>
        /// <param name="pageRequest">Paging options</param>
        /// <param name="with">The id of the entity that the chat was with</param>
        /// <param name="start">The start time of the chat</param>
        public ArchivedChatPage GetArchivedChat(XmppPageRequest pageRequest, Jid with, DateTimeOffset start)
        {
            pageRequest.ThrowIfNull();
            with.ThrowIfNull();

            var request = Xml.Element("retrieve", xmlns);

            request.Attr("with", with.ToString());
            request.Attr("start", start.ToXmppDateTimeString());

            var setNode = pageRequest.ToXmlElement();

            request.Child(setNode);

            var response = IM.IqRequest(IqType.Get, null, null, request);

            if (response.Type == IqType.Error)
            {
                throw Util.ExceptionFromError(response, "Failed to get archived chat messages");
            }

            return(new ArchivedChatPage(response.Data["chat"]));
        }
Exemplo n.º 5
0
 /// <summary>
 /// Fetch a page of archived messages from a chat
 /// </summary>
 /// <param name="pageRequest">Paging options</param>
 /// <param name="chatId">The id of the chat</param>
 public ArchivedChatPage GetArchivedChat(XmppPageRequest pageRequest, ArchivedChatId chatId)
 {
     return messageArchiving.GetArchivedChat(pageRequest, chatId);
 }
Exemplo n.º 6
0
 /// <summary>
 /// Fetch a page of archived messages from a multi-user chat room
 /// </summary>
 /// <param name="pageRequest">Paging options</param>
 /// <param name="roomId">The JID of the room</param>
 /// <param name="start">Optional filter to only return messages whose timestamp is equal to or later than the given timestamp.</param>
 /// <param name="end">Optional filter to only return messages whose timestamp is equal to or earlier than the timestamp given in the 'end' field.</param>
 public Task<XmppPage<Message>> GetArchivedMucMessages(XmppPageRequest pageRequest, Jid roomId, DateTimeOffset? start = null, DateTimeOffset? end = null)
 {
     return messageArchiveManagement.GetArchivedMessages(pageRequest, roomId, roomId, start, end);
 }
Exemplo n.º 7
0
 /// <summary>
 /// Fetch a page of archived messages from a chat
 /// </summary>
 /// <param name="pageRequest">Paging options</param>
 /// <param name="with">The id of the entity that the chat was with</param>
 /// <param name="start">The start time of the chat</param>
 public ArchivedChatPage GetArchivedChat(XmppPageRequest pageRequest, Jid with, DateTimeOffset start)
 {
     return messageArchiving.GetArchivedChat(pageRequest, with, start);
 }
Exemplo n.º 8
0
 /// <summary>
 /// Fetch message history from the server.
 ///
 /// The 'start' and 'end' attributes MAY be specified to indicate a date range.
 ///
 /// If the 'with' attribute is omitted then collections with any JID are returned.
 ///
 /// If only 'start' is specified then all collections on or after that date should be returned.
 ///
 /// If only 'end' is specified then all collections prior to that date should be returned.
 /// </summary>
 /// <param name="pageRequest">Paging options</param>
 /// <param name="start">Optional start date range to query</param>
 /// <param name="end">Optional enddate range to query</param>
 /// <param name="with">Optional JID to filter archive results by</param>
 public XmppPage<ArchivedChatId> GetArchivedChatIds(XmppPageRequest pageRequest, DateTimeOffset? start = null, DateTimeOffset? end = null, Jid with = null)
 {
     return messageArchiving.GetArchivedChatIds(pageRequest, start, end, with);
 }
Exemplo n.º 9
0
        /// <summary>
        /// Fetch a page of archived messages from a chat
        /// </summary>
        /// <param name="pageRequest">Paging options</param>
        /// <param name="with">The id of the entity that the chat was with</param>
        /// <param name="start">The start time of the chat</param>
        public ArchivedChatPage GetArchivedChat(XmppPageRequest pageRequest, Jid with, DateTimeOffset start)
        {
            pageRequest.ThrowIfNull();
            with.ThrowIfNull();

            var request = Xml.Element("retrieve", xmlns);
            request.Attr("with", with.ToString());
            request.Attr("start", start.ToXmppDateTimeString());

            var setNode = pageRequest.ToXmlElement();
            request.Child(setNode);

            var response = IM.IqRequest(IqType.Get, null, null, request);

            if (response.Type == IqType.Error)
            {
                throw Util.ExceptionFromError(response, "Failed to get archived chat messages");
            }

            return new ArchivedChatPage(response.Data["chat"]);
        }
Exemplo n.º 10
0
 /// <summary>
 /// Fetch a page of archived messages from a chat
 /// </summary>
 /// <param name="pageRequest">Paging options</param>
 /// <param name="chatId">The id of the chat</param>
 public ArchivedChatPage GetArchivedChat(XmppPageRequest pageRequest, ArchivedChatId chatId)
 {
     return GetArchivedChat(pageRequest, chatId.With, chatId.Start);
 }
Exemplo n.º 11
0
 /// <summary>
 /// Fetch a page of archived messages from a chat
 /// </summary>
 /// <param name="pageRequest">Paging options</param>
 /// <param name="chatId">The id of the chat</param>
 public ArchivedChatPage GetArchivedChat(XmppPageRequest pageRequest, ArchivedChatId chatId)
 {
     return(GetArchivedChat(pageRequest, chatId.With, chatId.Start));
 }