diff options
Diffstat (limited to 'xmpp/pylon.lua')
| -rw-r--r-- | xmpp/pylon.lua | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/xmpp/pylon.lua b/xmpp/pylon.lua index a3415dd..07568f9 100644 --- a/xmpp/pylon.lua +++ b/xmpp/pylon.lua @@ -14,6 +14,7 @@ local Xmpp = class.extend(BasePylon) function Xmpp.init(self) self:_check_fields"server component component_secret" self.channels = {} + self.pending_sent = {} end -- only use on local connections! @@ -96,13 +97,24 @@ function Xmpp.recving(self) self.log:warn("x was a string: ("..x..")") goto next end - local body = x'body' and x'body'[1] if x.label == 'message' then local from_bare_jid, from_nick if x.xarg.from then from_bare_jid, from_nick = x.xarg.from:match"(.*)/(.*)" end - local muc = self.channels[from_bare_jid] ; if muc then + local stanza_id + for _,c in ipairs(x) do + if c.label == 'stanza-id' and c.by == from_bare_jid + then stanza_id = c.id end end + assert(stanza_id) + local sent_message = self.pending_sent[x.xarg.id] + if sent_message then + sent_message.pylon_ids[self] = stanza_id + self.pending_sent[x.xarg.id] = nil + else + local muc = self.channels[from_bare_jid] + local body = x'body' and x'body'[1] if x.xarg.to == 'wilson@'..self.component + and muc and body and from_nick and not muc.nick_to_user[from_nick] then @@ -112,6 +124,7 @@ function Xmpp.recving(self) channel = Thing(self, from_bare_jid), author = Thing(self, x.xarg.from, from_nick), body = body, + pylon_ids = { [self]=stanza_id }, }) end end @@ -125,8 +138,10 @@ function Xmpp.sending(self) self.log:proto('>',dest_channel,message.author,message.body) local user, nick, user_jid, nick_jid = self:ensure_and_get_user( dest_channel.id, message.author:name_with_shortname(), message.pylon) + local temp_id = tostring(math.random()) -- TODO: Better id generation method + self.pending_sent[temp_id] = message self.sock:write(xmlify( - X.message{to=dest_channel.id, type='groupchat', from=user_jid, + X.message{to=dest_channel.id, type='groupchat', from=user_jid, id=temp_id, X.body{message.body}})) end end |
