diff -r 6a65142052c8 -r 73d4eb93657b client.lua --- a/client.lua Fri Mar 03 12:10:54 2023 +0000 +++ b/client.lua Thu Mar 16 11:41:52 2023 +0000 @@ -4,11 +4,21 @@ local jid_split = require "util.jid".split; local adns = require "net.adns"; local st = require "util.stanza"; +local new_id = require "util.id".short; + +math.randomseed((require"socket".gettime() * 1000000) % 0x80000000); -- Shortcuts to save having to load util.stanza verse.message, verse.presence, verse.iq, verse.stanza, verse.reply, verse.error_reply = st.message, st.presence, st.iq, st.stanza, st.reply, st.error_reply; +function verse.iq(attr) + if not attr.id then + attr.id = new_id(); + end + return st.iq(attr); +end + local new_xmpp_stream = require "util.xmppstream".new; local xmlns_stream = "http://etherx.jabber.org/streams"; @@ -208,13 +218,8 @@ end function stream:send_iq(iq, callback) - local id = self:new_id(); + local id = iq.attr.id or uuid.generate(); self.tracked_iqs[id] = callback; iq.attr.id = id; self:send(iq); end - -function stream:new_id() - self.curr_id = self.curr_id + 1; - return tostring(self.curr_id); -end