Always send direct messages to the user’s bare JID
This has the following advantages: - Works while all resources are offline (persistent channels) - Helps with combating duplicate messages when sent to different resources, resources going offline, carbon-copying etc. etc. As a side effect, this also makes the MUC PMs not be MUC PMs and always be emitted from the server-wide JID of the sending user. Fixes #3313.
This commit is contained in:
+4
-15
@@ -872,21 +872,10 @@ void Bridge::send_message(const Iid& iid, const std::string& nick, const std::st
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
const auto it = this->preferred_user_from.find(iid.get_local());
|
this->xmpp.send_message(std::to_string(iid),
|
||||||
if (it != this->preferred_user_from.end())
|
this->make_xmpp_body(body, encoding),
|
||||||
{
|
this->user_jid,
|
||||||
const auto chan_name = Iid(Jid(it->second).local, {}).get_local();
|
"chat", false, true);
|
||||||
for (const auto& resource: this->resources_in_chan[ChannelKey{chan_name, iid.get_server()}])
|
|
||||||
this->xmpp.send_message(it->second, this->make_xmpp_body(body, encoding),
|
|
||||||
this->user_jid + "/"
|
|
||||||
+ resource, "chat", true, true, true);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
for (const auto& resource: this->resources_in_server[iid.get_server()])
|
|
||||||
this->xmpp.send_message(std::to_string(iid), this->make_xmpp_body(body, encoding),
|
|
||||||
this->user_jid + "/" + resource, "chat", false, true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -37,12 +37,12 @@ scenario = (
|
|||||||
# Send a private message, to a in-room JID
|
# Send a private message, to a in-room JID
|
||||||
send_stanza("<message from='{jid_one}/{resource_one}' to='#foo%{irc_server_one}/{nick_two}' type='chat'><body>coucou in private</body></message>"),
|
send_stanza("<message from='{jid_one}/{resource_one}' to='#foo%{irc_server_one}/{nick_two}' type='chat'><body>coucou in private</body></message>"),
|
||||||
# Message is received with a server-wide JID
|
# Message is received with a server-wide JID
|
||||||
expect_stanza("/message[@from='{lower_nick_one}%{irc_server_one}'][@to='{jid_two}/{resource_one}'][@type='chat']/body[text()='coucou in private']"),
|
expect_stanza("/message[@from='{lower_nick_one}%{irc_server_one}'][@to='{jid_two}'][@type='chat']/body[text()='coucou in private']"),
|
||||||
# Respond to the message, to the server-wide JID
|
# Respond to the message, to the server-wide JID
|
||||||
send_stanza("<message from='{jid_two}/{resource_one}' to='{lower_nick_one}%{irc_server_one}' type='chat'><body>yes</body></message>"),
|
send_stanza("<message from='{jid_two}/{resource_one}' to='{lower_nick_one}%{irc_server_one}' type='chat'><body>yes</body></message>"),
|
||||||
# The response is received from the in-room JID
|
# The response is received from the server-wide JID without MUC PM marker
|
||||||
expect_stanza("/message[@from='#foo%{irc_server_one}/{nick_two}'][@to='{jid_one}/{resource_one}'][@type='chat']/body[text()='yes']",
|
expect_stanza("/message[@from='{lower_nick_two}%{irc_server_one}'][@to='{jid_one}'][@type='chat']/body[text()='yes']",
|
||||||
"/message/muc_user:x"),
|
"!/message/muc_user:x"),
|
||||||
# Do the exact same thing, from a different chan,
|
# Do the exact same thing, from a different chan,
|
||||||
# to check if the response comes from the right JID
|
# to check if the response comes from the right JID
|
||||||
send_stanza("<presence from='{jid_one}/{resource_one}' to='#dummy%{irc_server_one}/{nick_one}' ><x xmlns='http://jabber.org/protocol/muc'/></presence>"),
|
send_stanza("<presence from='{jid_one}/{resource_one}' to='#dummy%{irc_server_one}/{nick_one}' ><x xmlns='http://jabber.org/protocol/muc'/></presence>"),
|
||||||
@@ -52,12 +52,12 @@ scenario = (
|
|||||||
send_stanza("<message from='{jid_one}/{resource_one}' to='#dummy%{irc_server_one}/{nick_two}' type='chat'><body>re in private</body></message>"),
|
send_stanza("<message from='{jid_one}/{resource_one}' to='#dummy%{irc_server_one}/{nick_two}' type='chat'><body>re in private</body></message>"),
|
||||||
|
|
||||||
# Message is received with a server-wide JID
|
# Message is received with a server-wide JID
|
||||||
expect_stanza("/message[@from='{lower_nick_one}%{irc_server_one}'][@to='{jid_two}/{resource_one}'][@type='chat']/body[text()='re in private']"),
|
expect_stanza("/message[@from='{lower_nick_one}%{irc_server_one}'][@to='{jid_two}'][@type='chat']/body[text()='re in private']"),
|
||||||
|
|
||||||
# Respond to the message, to the server-wide JID
|
# Respond to the message, to the server-wide JID
|
||||||
send_stanza("<message from='{jid_two}/{resource_one}' to='{lower_nick_one}%{irc_server_one}' type='chat'><body>re</body></message>"),
|
send_stanza("<message from='{jid_two}/{resource_one}' to='{lower_nick_one}%{irc_server_one}' type='chat'><body>re</body></message>"),
|
||||||
# The response is received from the in-room JID
|
# The response is received from the server-wide JID
|
||||||
expect_stanza("/message[@from='#dummy%{irc_server_one}/{nick_two}'][@to='{jid_one}/{resource_one}'][@type='chat']/body[text()='re']"),
|
expect_stanza("/message[@from='{lower_nick_two}%{irc_server_one}'][@to='{jid_one}'][@type='chat']/body[text()='re']"),
|
||||||
|
|
||||||
# Now we leave the room, to check if the subsequent private messages are still received properly
|
# Now we leave the room, to check if the subsequent private messages are still received properly
|
||||||
send_stanza("<presence from='{jid_one}/{resource_one}' to='#dummy%{irc_server_one}/{nick_one}' type='unavailable' />"),
|
send_stanza("<presence from='{jid_one}/{resource_one}' to='#dummy%{irc_server_one}/{nick_one}' type='unavailable' />"),
|
||||||
@@ -65,5 +65,5 @@ scenario = (
|
|||||||
|
|
||||||
# The private messages from this nick should now come (again) from the server-wide JID
|
# The private messages from this nick should now come (again) from the server-wide JID
|
||||||
send_stanza("<message from='{jid_two}/{resource_one}' to='{lower_nick_one}%{irc_server_one}' type='chat'><body>hihihoho</body></message>"),
|
send_stanza("<message from='{jid_two}/{resource_one}' to='{lower_nick_one}%{irc_server_one}' type='chat'><body>hihihoho</body></message>"),
|
||||||
expect_stanza("/message[@from='{lower_nick_two}%{irc_server_one}'][@to='{jid_one}/{resource_one}']"),
|
expect_stanza("/message[@from='{lower_nick_two}%{irc_server_one}'][@to='{jid_one}']"),
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -51,20 +51,10 @@ scenario = (
|
|||||||
# That second user sends a private message to the first one
|
# That second user sends a private message to the first one
|
||||||
send_stanza("<message from='{jid_two}/{resource_one}' to='#foo%{irc_server_one}/{nick_one}' type='chat'><body>RELLO</body></message>"),
|
send_stanza("<message from='{jid_two}/{resource_one}' to='#foo%{irc_server_one}/{nick_one}' type='chat'><body>RELLO</body></message>"),
|
||||||
|
|
||||||
# Message is received with a server-wide JID, by the two resources behind nick_one
|
# Message is received with a server-wide JID to the bare JID as non-MUC-PM
|
||||||
expect_unordered(
|
expect_stanza(
|
||||||
[
|
"/message[@from='{lower_nick_two}%{irc_server_one}'][@to='{jid_one}'][@type='chat']/body[text()='RELLO']",
|
||||||
"/message[@from='{lower_nick_two}%{irc_server_one}'][@to='{jid_one}/{resource_one}'][@type='chat']/body[text()='RELLO']",
|
"!/message/muc_user:x",
|
||||||
"/message/hints:no-copy",
|
|
||||||
"/message/carbon:private",
|
|
||||||
"!/message/muc_user:x",
|
|
||||||
],
|
|
||||||
[
|
|
||||||
"/message[@from='{lower_nick_two}%{irc_server_one}'][@to='{jid_one}/{resource_two}'][@type='chat']/body[text()='RELLO']",
|
|
||||||
"/message/hints:no-copy",
|
|
||||||
"/message/carbon:private",
|
|
||||||
"!/message/muc_user:x",
|
|
||||||
]
|
|
||||||
),
|
),
|
||||||
|
|
||||||
# First occupant (with the two resources) changes her/his nick to a conflicting one
|
# First occupant (with the two resources) changes her/his nick to a conflicting one
|
||||||
@@ -117,9 +107,9 @@ scenario = (
|
|||||||
send_stanza("<message from='{jid_two}/{resource_one}' to='#foo%{irc_server_one}/{nick_three}' type='chat'><body>first</body></message>"),
|
send_stanza("<message from='{jid_two}/{resource_one}' to='#foo%{irc_server_one}/{nick_three}' type='chat'><body>first</body></message>"),
|
||||||
send_stanza("<message from='{jid_two}/{resource_one}' to='#foo%{irc_server_one}/{nick_three}' type='chat'><body>second</body></message>"),
|
send_stanza("<message from='{jid_two}/{resource_one}' to='#foo%{irc_server_one}/{nick_three}' type='chat'><body>second</body></message>"),
|
||||||
|
|
||||||
# The first user receives the two messages, on the connected resource, once each
|
# The first user receives the two messages to the bare JID
|
||||||
expect_unordered(
|
expect_unordered(
|
||||||
["/message[@from='{lower_nick_two}%{irc_server_one}'][@to='{jid_one}/{resource_one}'][@type='chat']/body[text()='first']"],
|
["/message[@from='{lower_nick_two}%{irc_server_one}'][@to='{jid_one}'][@type='chat']/body[text()='first']"],
|
||||||
["/message[@from='{lower_nick_two}%{irc_server_one}'][@to='{jid_one}/{resource_one}'][@type='chat']/body[text()='second']"]
|
["/message[@from='{lower_nick_two}%{irc_server_one}'][@to='{jid_one}'][@type='chat']/body[text()='second']"]
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user