Commit 7f2127a7 authored by louiz’'s avatar louiz’

Add the archive ID to messages when they are sent to users

This makes us compatible with mam 6.0

fix #3249
parent 1090f3ce
...@@ -10,6 +10,7 @@ Version 5.0 ...@@ -10,6 +10,7 @@ Version 5.0
an IRC bouncer. an IRC bouncer.
- Use the udns library instead of c-ares, for asynchronous DNS resolution. - Use the udns library instead of c-ares, for asynchronous DNS resolution.
It’s still fully optional. It’s still fully optional.
- Update MAM implementation to version 6.0 (namespace mam:2)
Version 4.1 - 2017-03-21 Version 4.1 - 2017-03-21
======================== ========================
......
...@@ -254,15 +254,16 @@ void Bridge::send_channel_message(const Iid& iid, const std::string& body) ...@@ -254,15 +254,16 @@ void Bridge::send_channel_message(const Iid& iid, const std::string& body)
else else
irc->send_channel_message(iid.get_local(), line); irc->send_channel_message(iid.get_local(), line);
std::string uuid;
#ifdef USE_DATABASE #ifdef USE_DATABASE
const auto xmpp_body = this->make_xmpp_body(line); const auto xmpp_body = this->make_xmpp_body(line);
if (this->record_history) if (this->record_history)
Database::store_muc_message(this->get_bare_jid(), iid, std::chrono::system_clock::now(), uuid = Database::store_muc_message(this->get_bare_jid(), iid, std::chrono::system_clock::now(),
std::get<0>(xmpp_body), irc->get_own_nick()); std::get<0>(xmpp_body), irc->get_own_nick());
#endif #endif
for (const auto& resource: this->resources_in_chan[iid.to_tuple()]) for (const auto& resource: this->resources_in_chan[iid.to_tuple()])
this->xmpp.send_muc_message(std::to_string(iid), irc->get_own_nick(), this->xmpp.send_muc_message(std::to_string(iid), irc->get_own_nick(), this->make_xmpp_body(line),
this->make_xmpp_body(line), this->user_jid + "/" + resource); this->user_jid + "/" + resource, uuid);
} }
} }
...@@ -839,8 +840,8 @@ void Bridge::send_message(const Iid& iid, const std::string& nick, const std::st ...@@ -839,8 +840,8 @@ void Bridge::send_message(const Iid& iid, const std::string& nick, const std::st
#endif #endif
for (const auto& resource: this->resources_in_chan[iid.to_tuple()]) for (const auto& resource: this->resources_in_chan[iid.to_tuple()])
{ {
this->xmpp.send_muc_message(std::to_string(iid), nick, this->xmpp.send_muc_message(std::to_string(iid), nick, this->make_xmpp_body(body, encoding),
this->make_xmpp_body(body, encoding), this->user_jid + "/" + resource); this->user_jid + "/" + resource, {});
} }
} }
......
...@@ -119,14 +119,16 @@ db::IrcChannelOptions Database::get_irc_channel_options_with_server_and_global_d ...@@ -119,14 +119,16 @@ db::IrcChannelOptions Database::get_irc_channel_options_with_server_and_global_d
return coptions; return coptions;
} }
void Database::store_muc_message(const std::string& owner, const Iid& iid, std::string Database::store_muc_message(const std::string& owner, const Iid& iid,
Database::time_point date, Database::time_point date,
const std::string& body, const std::string& body,
const std::string& nick) const std::string& nick)
{ {
db::MucLogLine line(*Database::db); db::MucLogLine line(*Database::db);
line.uuid = Database::gen_uuid(); auto uuid = Database::gen_uuid();
line.uuid = uuid;
line.owner = owner; line.owner = owner;
line.ircChanName = iid.get_local(); line.ircChanName = iid.get_local();
line.ircServerName = iid.get_server(); line.ircServerName = iid.get_server();
...@@ -135,6 +137,8 @@ void Database::store_muc_message(const std::string& owner, const Iid& iid, ...@@ -135,6 +137,8 @@ void Database::store_muc_message(const std::string& owner, const Iid& iid,
line.nick = nick; line.nick = nick;
line.update(); line.update();
return uuid;
} }
std::vector<db::MucLogLine> Database::get_muc_logs(const std::string& owner, const std::string& chan_name, const std::string& server, std::vector<db::MucLogLine> Database::get_muc_logs(const std::string& owner, const std::string& chan_name, const std::string& server,
......
...@@ -50,7 +50,7 @@ public: ...@@ -50,7 +50,7 @@ public:
const std::string& channel); const std::string& channel);
static std::vector<db::MucLogLine> get_muc_logs(const std::string& owner, const std::string& chan_name, const std::string& server, static std::vector<db::MucLogLine> get_muc_logs(const std::string& owner, const std::string& chan_name, const std::string& server,
int limit=-1, const std::string& start="", const std::string& end=""); int limit=-1, const std::string& start="", const std::string& end="");
static void store_muc_message(const std::string& owner, const Iid& iid, static std::string store_muc_message(const std::string& owner, const Iid& iid,
time_point date, const std::string& body, const std::string& nick); time_point date, const std::string& body, const std::string& nick);
static void close(); static void close();
......
...@@ -380,7 +380,7 @@ void XmppComponent::send_topic(const std::string& from, Xmpp::body&& topic, cons ...@@ -380,7 +380,7 @@ void XmppComponent::send_topic(const std::string& from, Xmpp::body&& topic, cons
this->send_stanza(message); this->send_stanza(message);
} }
void XmppComponent::send_muc_message(const std::string& muc_name, const std::string& nick, Xmpp::body&& xmpp_body, const std::string& jid_to) void XmppComponent::send_muc_message(const std::string& muc_name, const std::string& nick, Xmpp::body&& xmpp_body, const std::string& jid_to, std::string uuid)
{ {
Stanza message("message"); Stanza message("message");
message["to"] = jid_to; message["to"] = jid_to;
...@@ -402,6 +402,15 @@ void XmppComponent::send_muc_message(const std::string& muc_name, const std::str ...@@ -402,6 +402,15 @@ void XmppComponent::send_muc_message(const std::string& muc_name, const std::str
// Pass the ownership of the pointer to this xmlnode // Pass the ownership of the pointer to this xmlnode
html.add_child(std::move(std::get<1>(xmpp_body))); html.add_child(std::move(std::get<1>(xmpp_body)));
} }
if (!uuid.empty())
{
XmlSubNode stanza_id(message, "stanza-id");
stanza_id["xmlns"] = STABLE_ID_NS;
stanza_id["by"] = muc_name + "@" + this->served_hostname;
stanza_id["id"] = std::move(uuid);
}
this->send_stanza(message); this->send_stanza(message);
} }
......
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#define DATAFORM_NS "jabber:x:data" #define DATAFORM_NS "jabber:x:data"
#define RSM_NS "http://jabber.org/protocol/rsm" #define RSM_NS "http://jabber.org/protocol/rsm"
#define MUC_TRAFFIC_NS "http://jabber.org/protocol/muc#traffic" #define MUC_TRAFFIC_NS "http://jabber.org/protocol/muc#traffic"
#define STABLE_ID_NS "urn:xmpp:sid:0"
/** /**
* An XMPP component, communicating with an XMPP server using the protocole * An XMPP component, communicating with an XMPP server using the protocole
...@@ -134,7 +135,8 @@ public: ...@@ -134,7 +135,8 @@ public:
/** /**
* Send a (non-private) message to the MUC * Send a (non-private) message to the MUC
*/ */
void send_muc_message(const std::string& muc_name, const std::string& nick, Xmpp::body&& body, const std::string& jid_to); void send_muc_message(const std::string& muc_name, const std::string& nick, Xmpp::body&& body, const std::string& jid_to,
std::string uuid);
/** /**
* Send a message, with a <delay/> element, part of a MUC history * Send a message, with a <delay/> element, part of a MUC history
*/ */
......
...@@ -132,7 +132,8 @@ def match(stanza, xpath): ...@@ -132,7 +132,8 @@ def match(stanza, xpath):
'rsm': 'http://jabber.org/protocol/rsm', 'rsm': 'http://jabber.org/protocol/rsm',
'carbon': 'urn:xmpp:carbons:2', 'carbon': 'urn:xmpp:carbons:2',
'hints': 'urn:xmpp:hints', 'hints': 'urn:xmpp:hints',
'stanza': 'urn:ietf:params:xml:ns:xmpp-stanzas'}) 'stanza': 'urn:ietf:params:xml:ns:xmpp-stanzas',
'stable_id': 'urn:xmpp:sid:0'})
return matched return matched
...@@ -1483,7 +1484,10 @@ if __name__ == '__main__': ...@@ -1483,7 +1484,10 @@ if __name__ == '__main__':
# Send two channel messages # Send two channel messages
partial(send_stanza, "<message from='{jid_one}/{resource_one}' to='#foo%{irc_server_one}' type='groupchat'><body>coucou</body></message>"), partial(send_stanza, "<message from='{jid_one}/{resource_one}' to='#foo%{irc_server_one}' type='groupchat'><body>coucou</body></message>"),
partial(expect_stanza, "/message[@from='#foo%{irc_server_one}/{nick_one}'][@to='{jid_one}/{resource_one}'][@type='groupchat']/body[text()='coucou']"), partial(expect_stanza,
("/message[@from='#foo%{irc_server_one}/{nick_one}'][@to='{jid_one}/{resource_one}'][@type='groupchat']/body[text()='coucou']",
"/message/stable_id:stanza-id[@by='#foo%{irc_server_one}'][@id]",)
),
partial(send_stanza, "<message from='{jid_one}/{resource_one}' to='#foo%{irc_server_one}' type='groupchat'><body>coucou 2</body></message>"), partial(send_stanza, "<message from='{jid_one}/{resource_one}' to='#foo%{irc_server_one}' type='groupchat'><body>coucou 2</body></message>"),
partial(expect_stanza, "/message[@from='#foo%{irc_server_one}/{nick_one}'][@to='{jid_one}/{resource_one}'][@type='groupchat']/body[text()='coucou 2']"), partial(expect_stanza, "/message[@from='#foo%{irc_server_one}/{nick_one}'][@to='{jid_one}/{resource_one}'][@type='groupchat']/body[text()='coucou 2']"),
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment