1 local st = require "util.stanza"; |
|
2 |
|
3 local xmlns_sm = "urn:xmpp:sm:2"; |
1 local xmlns_sm = "urn:xmpp:sm:2"; |
4 |
2 |
5 function verse.plugins.smacks(stream) |
3 function verse.plugins.smacks(stream) |
6 -- State for outgoing stanzas |
4 -- State for outgoing stanzas |
7 local outgoing_queue = {}; |
5 local outgoing_queue = {}; |
73 end |
71 end |
74 |
72 |
75 local function on_bind_success() |
73 local function on_bind_success() |
76 if not stream.smacks then |
74 if not stream.smacks then |
77 --stream:unhook("bind-success", on_bind_success); |
75 --stream:unhook("bind-success", on_bind_success); |
78 stream:send(st.stanza("enable", { xmlns = xmlns_sm, resume = "true" })); |
76 stream:send(verse.stanza("enable", { xmlns = xmlns_sm, resume = "true" })); |
79 end |
77 end |
80 end |
78 end |
81 |
79 |
82 local function on_features(features) |
80 local function on_features(features) |
83 if features:get_child("sm", xmlns_sm) then |
81 if features:get_child("sm", xmlns_sm) then |
84 stream.stream_management_supported = true; |
82 stream.stream_management_supported = true; |
85 if stream.smacks and stream.bound then -- Already enabled in a previous session - resume |
83 if stream.smacks and stream.bound then -- Already enabled in a previous session - resume |
86 stream:send(st.stanza("resume", { xmlns = xmlns_sm, |
84 stream:send(verse.stanza("resume", { xmlns = xmlns_sm, |
87 h = handled_stanza_count, previd = stream.resumption_token })); |
85 h = handled_stanza_count, previd = stream.resumption_token })); |
88 else |
86 else |
89 stream:hook("bind-success", on_bind_success); |
87 stream:hook("bind-success", on_bind_success); |
90 end |
88 end |
91 return true; |
89 return true; |