summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorolive <olive@olive.ooo>2026-09-27 01:29:02 +0100
committerolive <olive@olive.ooo>2026-09-27 01:29:02 +0100
commit59d210c7139358f769441db8c5c0d92db17065f1 (patch)
treec9abd266f4285c641943c9f4436c3171fd3a0ad4
parente18625310d9e71a1297634e46ea60bde8a782d44 (diff)
Pylon Message IDsolive
Not stored. Not IRC.
-rw-r--r--discord/pylon.lua4
-rw-r--r--message.lua2
-rw-r--r--nanochat/pylon.lua7
-rw-r--r--quaddle/pylon.lua4
-rw-r--r--xmpp/pylon.lua21
-rw-r--r--xmpp/xml.lua16
6 files changed, 37 insertions, 17 deletions
diff --git a/discord/pylon.lua b/discord/pylon.lua
index c2afc3a..bc55826 100644
--- a/discord/pylon.lua
+++ b/discord/pylon.lua
@@ -130,6 +130,7 @@ function Discord.handle_dispatch(self, event)
channel = Thing(self, d.channel_id, 'TODO discord channel names'),
author = Thing(self, d.author.id, d.author.username),
body = d.content,
+ pylon_ids = { [self]=d.id },
})
end
end
@@ -139,10 +140,11 @@ function Discord.sending(self)
for dest_channel, message in self.inbox:iter() do
self.log:proto('>',dest_channel,message.author,message.body)
local wh = self.channels[dest_channel.id].wh
- self:_req('webhooks/'..wh.id..'/'..wh.token, {
+ local res = self:_req('webhooks/'..wh.id..'/'..wh.token, {
username = message.author:name_with_shortname(),
content = message.body,
})
+ message.pylon_ids[self] = message.id
end
end
diff --git a/message.lua b/message.lua
index 092f332..834208e 100644
--- a/message.lua
+++ b/message.lua
@@ -13,6 +13,8 @@ function Message.make(cls, self)
author=Thing,
} do assert(class.is(self[k],v), 'field '..k..' missing or wrong') end
assert(type(self.body)=='string','field body missing or wrong')
+ assert(type(self.pylon_ids)=='table','field pylon_ids missing or wrong')
+ assert(self.pylon_ids[self.pylon],'missing pylon_ids id for originating pylon!')
assert(self.pylon == self.channel.pylon and self.pylon == self.author.pylon,
"inconsistent pylons!")
return self end
diff --git a/nanochat/pylon.lua b/nanochat/pylon.lua
index 6fbd725..c92897d 100644
--- a/nanochat/pylon.lua
+++ b/nanochat/pylon.lua
@@ -44,9 +44,8 @@ function Nanochat:recving()
body=msg:sub(msgi,-1)
}
end
- else -- luacheck: ignore 542
- -- ignore messages without a channel, they stay nanochat-local
end
+ -- else ignore messages without a channel, they stay nanochat-local
end
local s = self.sock:read("*l")
self.lastid = tonumber(assert(s))
@@ -58,6 +57,7 @@ function Nanochat:recving()
self.usids[id] = nil
else
self.log:proto('<', msg.channel.id, msg.author, msg.body)
+ msg.pylon_ids = { [self]=id }
self.wilson:deliver(msg)
end
end
@@ -76,7 +76,8 @@ function Nanochat:sending()
..message.author:name_with_shortname()
..": "..message.body
.."\n"))
- local id = tonumber(assert(self.sock:read("*l")))
+ local id = assert(tonumber(self.sock:read("*l")))
+ message.pylon_ids[self] = id
self.usids[id] = true
end
end
diff --git a/quaddle/pylon.lua b/quaddle/pylon.lua
index 20eeb3a..f3c244f 100644
--- a/quaddle/pylon.lua
+++ b/quaddle/pylon.lua
@@ -81,6 +81,7 @@ function Quaddle.handle_message(self, msg)
channel = Thing(self, msg.channel),
author = Thing(self,msg.author.id,msg.author.username),
body = msg.content,
+ pylon_ids = { [self] = msg.id },
})
end
end
@@ -88,9 +89,10 @@ end
function Quaddle.sending(self)
for dest_channel, message in self.inbox:iter() do
self.log:proto('>', dest_channel, message.author, message.body)
- self:_req('channels/'..dest_channel.id..'/messages', {
+ local res = self:_req('channels/'..dest_channel.id..'/messages', {
content = message.author:name_with_shortname()..": "..message.body,
})
+ message.pylon_ids[self] = res.id
end
end
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
diff --git a/xmpp/xml.lua b/xmpp/xml.lua
index e54f27f..93186f6 100644
--- a/xmpp/xml.lua
+++ b/xmpp/xml.lua
@@ -26,17 +26,15 @@ local function parseargs(s)
return arg
end
-local function tag(x)
- return setmetatable(x, {__call=function(x, label)
- -- search for child with given label
- for _,c in ipairs(x) do
- if c.label == label then
- return c
- end
+local tag_mt = {
+ __call = function(self, label)
+ for _,child in ipairs(self) do
+ if child.label == label then return child end
end
return nil
- end})
-end
+ end,
+}
+local function tag(x) return setmetatable(x, tag_mt) end
local psingle