class

XMPP::MessageArchives

Inherits Reference / Object

MessageArchives is a high-level client for XEP-0313 - Message Archive Management.

MAM lets a client query the server for its archived messages, optionally filtered by chat partner and time range and paged with RSM. The IQ returns a MAMFin; each archived message is then streamed as a normal Message stanza carrying a Stanza::MAMResult payload, which is handled like any other message:

archives = XMPP::MessageArchives.new(client) return unless archives.supported? fin = archives.query(with: "juliet@capulet.lit", limit: 10) fin.try(&.complete) # true when all results were streamed

client.on("message") do |s, m| if result = m.as(XMPP::Stanza::Message).get(XMPP::Stanza::MAMResult) archived = result.as(XMPP::Stanza::MAMResult).forwarded.try(&.stanza) end end

See: https://xmpp.org/extensions/xep-0313.html

Constants

NS_MAM = "urn:xmpp:mam:2"

Disco feature advertised by servers that support MAM.

Constructors

new(client : Client)
Source

Instance methods

query(with_jid : String | Nil = nil, since : Time | Nil = nil, until_time : Time | Nil = nil, limit : Int32 = 0, after : String | Nil = nil, queryid : String = Random::Secure.hex(8), timeout : Time::Span = 5.seconds) : Stanza::MAMFin | Nil

query requests archived messages and returns the MAMFin IQ payload (nil on error or timeout). The archived messages themselves arrive as Message stanzas carrying Stanza::MAMResult and are delivered to the client's normal message handling. Filters: with restricts to a chat partner; since/until bound the time range; limit and after page the result set.

Source
supported?(jid : String | Nil = nil, timeout : Time::Span = 5.seconds) : Bool

supported? queries the server for MAM support and returns true when the urn:xmpp:mam:2 feature is advertised on the given JID (defaults to the user's bare JID).

Source