Commit bb596582 authored by louiz’'s avatar louiz’

Add a <item/> node in the presence of a leaving participant

fix #3339
parent 158d743b
...@@ -419,7 +419,7 @@ void Bridge::leave_irc_channel(Iid&& iid, const std::string& status_message, con ...@@ -419,7 +419,7 @@ void Bridge::leave_irc_channel(Iid&& iid, const std::string& status_message, con
} }
else if (channel->joined) else if (channel->joined)
{ {
this->send_muc_leave(iid, channel->get_self()->nick, "", true, true, resource); this->send_muc_leave(iid, *channel->get_self(), "", true, true, resource);
} }
if (persistent) if (persistent)
this->remove_resource_from_chan(key, resource); this->remove_resource_from_chan(key, resource);
...@@ -430,7 +430,7 @@ void Bridge::leave_irc_channel(Iid&& iid, const std::string& status_message, con ...@@ -430,7 +430,7 @@ void Bridge::leave_irc_channel(Iid&& iid, const std::string& status_message, con
else else
{ {
if (channel && channel->joined) if (channel && channel->joined)
this->send_muc_leave(iid, channel->get_self()->nick, this->send_muc_leave(iid, *channel->get_self(),
"Biboumi note: " + std::to_string(resources - 1) + " resources are still in this channel.", "Biboumi note: " + std::to_string(resources - 1) + " resources are still in this channel.",
true, true, resource); true, true, resource);
this->remove_resource_from_chan(key, resource); this->remove_resource_from_chan(key, resource);
...@@ -847,19 +847,29 @@ void Bridge::send_presence_error(const Iid& iid, const std::string& nick, ...@@ -847,19 +847,29 @@ void Bridge::send_presence_error(const Iid& iid, const std::string& nick,
this->xmpp.send_presence_error(std::to_string(iid), nick, this->user_jid, type, condition, error_code, text); this->xmpp.send_presence_error(std::to_string(iid), nick, this->user_jid, type, condition, error_code, text);
} }
void Bridge::send_muc_leave(const Iid& iid, const std::string& nick, void Bridge::send_muc_leave(const Iid& iid, const IrcUser& user,
const std::string& message, const bool self, const std::string& message, const bool self,
const bool user_requested, const bool user_requested,
const std::string& resource) const std::string& resource)
{ {
const IrcClient* client = this->find_irc_client(iid.get_server());
if (!client)
{
log_error("Tried to send an unavailable presence for non existant client: ", std::to_string(iid));
return;
  • I can see this potentially troublesome (but this is really just a nit to pick). All the call sites have a client available, so why not hand it down on the call instead of doing another search?

  • Fixed, thanks.

Please register or sign in to reply
}
std::string affiliation;
std::string role;
std::tie(role, affiliation) = get_role_affiliation_from_irc_mode(user.get_most_significant_mode(client->get_sorted_user_modes()));
if (!resource.empty()) if (!resource.empty())
this->xmpp.send_muc_leave(std::to_string(iid), nick, this->make_xmpp_body(message), this->xmpp.send_muc_leave(std::to_string(iid), user.nick, this->make_xmpp_body(message),
this->user_jid + "/" + resource, self, user_requested); this->user_jid + "/" + resource, self, user_requested, affiliation, role);
else else
{ {
for (const auto &res: this->resources_in_chan[iid.to_tuple()]) for (const auto &res: this->resources_in_chan[iid.to_tuple()])
this->xmpp.send_muc_leave(std::to_string(iid), nick, this->make_xmpp_body(message), this->xmpp.send_muc_leave(std::to_string(iid), user.nick, this->make_xmpp_body(message),
this->user_jid + "/" + res, self, user_requested); this->user_jid + "/" + res, self, user_requested, affiliation, role);
if (self) if (self)
{ {
// Copy the resources currently in that channel // Copy the resources currently in that channel
......
...@@ -170,7 +170,7 @@ public: ...@@ -170,7 +170,7 @@ public:
/** /**
* Send an unavailable presence from this participant * Send an unavailable presence from this participant
*/ */
void send_muc_leave(const Iid& iid, const std::string& nick, void send_muc_leave(const Iid& iid, const IrcUser& nick,
const std::string& message, const bool self, const std::string& message, const bool self,
const bool user_requested, const bool user_requested,
const std::string& resource=""); const std::string& resource="");
......
...@@ -33,8 +33,9 @@ IrcUser* IrcChannel::find_user(const std::string& name) const ...@@ -33,8 +33,9 @@ IrcUser* IrcChannel::find_user(const std::string& name) const
return nullptr; return nullptr;
} }
void IrcChannel::remove_user(const IrcUser* user) std::unique_ptr<IrcUser> IrcChannel::remove_user(const IrcUser* user)
{ {
std::unique_ptr<IrcUser> result{};
const auto nick = user->nick; const auto nick = user->nick;
const bool is_self = (user == this->self); const bool is_self = (user == this->self);
const auto it = std::find_if(this->users.begin(), this->users.end(), const auto it = std::find_if(this->users.begin(), this->users.end(),
...@@ -44,6 +45,7 @@ void IrcChannel::remove_user(const IrcUser* user) ...@@ -44,6 +45,7 @@ void IrcChannel::remove_user(const IrcUser* user)
}); });
if (it != this->users.end()) if (it != this->users.end())
{ {
result = std::move(*it);
this->users.erase(it); this->users.erase(it);
if (is_self) if (is_self)
{ {
...@@ -57,4 +59,5 @@ void IrcChannel::remove_all_users() ...@@ -57,4 +59,5 @@ void IrcChannel::remove_all_users()
{ {
this->users.clear(); this->users.clear();
this->self = nullptr; this->self = nullptr;
return result;
} }
...@@ -32,8 +32,8 @@ public: ...@@ -32,8 +32,8 @@ public:
IrcUser* add_user(const std::string& name, IrcUser* add_user(const std::string& name,
const std::map<char, char>& prefix_to_mode); const std::map<char, char>& prefix_to_mode);
IrcUser* find_user(const std::string& name) const; IrcUser* find_user(const std::string& name) const;
void remove_user(const IrcUser* user);
void remove_all_users(); void remove_all_users();
std::unique_ptr<IrcUser> remove_user(const IrcUser* user);
const std::vector<std::unique_ptr<IrcUser>>& get_users() const const std::vector<std::unique_ptr<IrcUser>>& get_users() const
{ return this->users; } { return this->users; }
......
...@@ -951,18 +951,18 @@ void IrcClient::on_part(const IrcMessage& message) ...@@ -951,18 +951,18 @@ void IrcClient::on_part(const IrcMessage& message)
{ {
std::string nick = user->nick; std::string nick = user->nick;
bool self = channel->get_self() && channel->get_self()->nick == nick; bool self = channel->get_self() && channel->get_self()->nick == nick;
channel->remove_user(user); auto user_ptr = channel->remove_user(user);
Iid iid;
iid.set_local(chan_name);
iid.set_server(this->hostname);
iid.type = Iid::Type::Channel;
if (self) if (self)
{ {
this->channels.erase(utils::tolower(chan_name)); this->channels.erase(utils::tolower(chan_name));
// channel pointer is now invalid // channel pointer is now invalid
channel = nullptr; channel = nullptr;
} }
this->bridge.send_muc_leave(iid, std::move(nick), txt, self, true); Iid iid;
iid.set_local(chan_name);
iid.set_server(this->hostname);
iid.type = Iid::Type::Channel;
this->bridge.send_muc_leave(iid, *user_ptr, txt, self, true);
} }
} }
...@@ -979,8 +979,7 @@ void IrcClient::on_error(const IrcMessage& message) ...@@ -979,8 +979,7 @@ void IrcClient::on_error(const IrcMessage& message)
IrcChannel* channel = pair.second.get(); IrcChannel* channel = pair.second.get();
if (!channel->joined) if (!channel->joined)
continue; continue;
std::string own_nick = channel->get_self()->nick; this->bridge.send_muc_leave(iid, *channel->get_self(), leave_message, true, false);
this->bridge.send_muc_leave(iid, std::move(own_nick), leave_message, true, false);
} }
this->channels.clear(); this->channels.clear();
this->send_gateway_message("ERROR: " + leave_message); this->send_gateway_message("ERROR: " + leave_message);
...@@ -1005,7 +1004,7 @@ void IrcClient::on_quit(const IrcMessage& message) ...@@ -1005,7 +1004,7 @@ void IrcClient::on_quit(const IrcMessage& message)
iid.set_local(chan_name); iid.set_local(chan_name);
iid.set_server(this->hostname); iid.set_server(this->hostname);
iid.type = Iid::Type::Channel; iid.type = Iid::Type::Channel;
this->bridge.send_muc_leave(iid, user->nick, txt, self, false); this->bridge.send_muc_leave(iid, *user, txt, self, false);
channel->remove_user(user); channel->remove_user(user);
} }
} }
......
...@@ -425,7 +425,8 @@ void XmppComponent::send_history_message(const std::string& muc_name, const std: ...@@ -425,7 +425,8 @@ void XmppComponent::send_history_message(const std::string& muc_name, const std:
#endif #endif
void XmppComponent::send_muc_leave(const std::string& muc_name, const std::string& nick, Xmpp::body&& message, void XmppComponent::send_muc_leave(const std::string& muc_name, const std::string& nick, Xmpp::body&& message,
const std::string& jid_to, const bool self, const bool user_requested) const std::string& jid_to, const bool self, const bool user_requested,
const std::string& affiliation, const std::string& role)
{ {
Stanza presence("presence"); Stanza presence("presence");
{ {
...@@ -447,6 +448,9 @@ void XmppComponent::send_muc_leave(const std::string& muc_name, const std::strin ...@@ -447,6 +448,9 @@ void XmppComponent::send_muc_leave(const std::string& muc_name, const std::strin
status["code"] = "332"; status["code"] = "332";
} }
} }
XmlSubNode item(x, "item");
item["affiliation"] = affiliation;
item["role"] = role;
if (!message_str.empty()) if (!message_str.empty())
{ {
XmlSubNode status(presence, "status"); XmlSubNode status(presence, "status");
......
...@@ -150,7 +150,8 @@ public: ...@@ -150,7 +150,8 @@ public:
Xmpp::body&& message, Xmpp::body&& message,
const std::string& jid_to, const std::string& jid_to,
const bool self, const bool self,
const bool user_requested); const bool user_requested,
const std::string& affiliation, const std::string& role);
/** /**
* Indicate that a participant changed his nick * Indicate that a participant changed his nick
*/ */
......
...@@ -1149,7 +1149,8 @@ if __name__ == '__main__': ...@@ -1149,7 +1149,8 @@ if __name__ == '__main__':
"<presence from='{jid_one}/{resource_one}' to='#foo%{irc_server_one}/{nick_one}' type='unavailable' />"), "<presence from='{jid_one}/{resource_one}' to='#foo%{irc_server_one}/{nick_one}' type='unavailable' />"),
# Only user 1 receives the unavailable presence # Only user 1 receives the unavailable presence
partial(expect_stanza, partial(expect_stanza,
"/presence[@from='#foo%{irc_server_one}/{nick_one}'][@to='{jid_one}/{resource_one}'][@type='unavailable']/muc_user:x/muc_user:status[@code='110']"), ("/presence[@from='#foo%{irc_server_one}/{nick_one}'][@to='{jid_one}/{resource_one}'][@type='unavailable']/muc_user:x/muc_user:status[@code='110']",
"/presence/muc_user:x/muc_user:item[@affiliation='admin'][@role='moderator']")),
# Second user sends a channel message # Second user sends a channel message
partial(send_stanza, "<message type='groupchat' from='{jid_two}/{resource_one}' to='#foo%{irc_server_one}'><body>coucou</body></message>"), partial(send_stanza, "<message type='groupchat' from='{jid_two}/{resource_one}' to='#foo%{irc_server_one}'><body>coucou</body></message>"),
......
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