Commit 04d28f96 authored by louiz’'s avatar louiz’

Forward the topic authors, handle the author from 333 messages

fix #2
parent 64f341ee
...@@ -388,11 +388,14 @@ void XmppComponent::send_invalid_user_error(const std::string& user_name, const ...@@ -388,11 +388,14 @@ void XmppComponent::send_invalid_user_error(const std::string& user_name, const
this->send_stanza(message); this->send_stanza(message);
} }
void XmppComponent::send_topic(const std::string& from, Xmpp::body&& topic, const std::string& to) void XmppComponent::send_topic(const std::string& from, Xmpp::body&& topic, const std::string& to, const std::string& who)
{ {
XmlNode message("message"); XmlNode message("message");
message["to"] = to; message["to"] = to;
message["from"] = from + "@" + this->served_hostname; if (who.empty())
message["from"] = from + "@" + this->served_hostname;
else
message["from"] = from + "@" + this->served_hostname + "/" + who;
message["type"] = "groupchat"; message["type"] = "groupchat";
XmlNode subject("subject"); XmlNode subject("subject");
subject.set_inner(std::get<0>(topic)); subject.set_inner(std::get<0>(topic));
......
...@@ -124,7 +124,7 @@ public: ...@@ -124,7 +124,7 @@ public:
/** /**
* Send the MUC topic to the user * Send the MUC topic to the user
*/ */
void send_topic(const std::string& from, Xmpp::body&& xmpp_topic, const std::string& to); void send_topic(const std::string& from, Xmpp::body&& xmpp_topic, const std::string& to, const std::string& who);
/** /**
* Send a (non-private) message to the MUC * Send a (non-private) message to the MUC
*/ */
......
...@@ -634,10 +634,11 @@ void Bridge::send_user_join(const std::string& hostname, ...@@ -634,10 +634,11 @@ void Bridge::send_user_join(const std::string& hostname,
affiliation, role, this->user_jid, self); affiliation, role, this->user_jid, self);
} }
void Bridge::send_topic(const std::string& hostname, const std::string& chan_name, const std::string& topic) void Bridge::send_topic(const std::string& hostname, const std::string& chan_name, const std::string& topic, const std::string& who)
{ {
const auto encoding = in_encoding_for(*this, {chan_name + '%' + hostname}); const auto encoding = in_encoding_for(*this, {chan_name + '%' + hostname});
this->xmpp.send_topic(chan_name + utils::empty_if_fixed_server("%" + hostname), this->make_xmpp_body(topic, encoding), this->user_jid); this->xmpp.send_topic(chan_name + utils::empty_if_fixed_server(
"%" + hostname), this->make_xmpp_body(topic, encoding), this->user_jid, who);
} }
std::string Bridge::get_own_nick(const Iid& iid) std::string Bridge::get_own_nick(const Iid& iid)
......
...@@ -122,7 +122,7 @@ public: ...@@ -122,7 +122,7 @@ public:
/** /**
* Send the topic of the MUC to the user * Send the topic of the MUC to the user
*/ */
void send_topic(const std::string& hostname, const std::string& chan_name, const std::string& topic); void send_topic(const std::string& hostname, const std::string& chan_name, const std::string& topic, const std::string& who);
/** /**
* Send a MUC message from some participant * Send a MUC message from some participant
*/ */
......
...@@ -18,6 +18,7 @@ public: ...@@ -18,6 +18,7 @@ public:
bool joined; bool joined;
std::string topic; std::string topic;
std::string topic_author;
void set_self(const std::string& name); void set_self(const std::string& name);
IrcUser* get_self() const; IrcUser* get_self() const;
IrcUser* add_user(const std::string& name, IrcUser* add_user(const std::string& name,
......
...@@ -55,6 +55,8 @@ static const std::unordered_map<std::string, ...@@ -55,6 +55,8 @@ static const std::unordered_map<std::string,
{"353", {&IrcClient::set_and_forward_user_list, {4, 0}}}, {"353", {&IrcClient::set_and_forward_user_list, {4, 0}}},
{"332", {&IrcClient::on_topic_received, {2, 0}}}, {"332", {&IrcClient::on_topic_received, {2, 0}}},
{"TOPIC", {&IrcClient::on_topic_received, {2, 0}}}, {"TOPIC", {&IrcClient::on_topic_received, {2, 0}}},
{"333", {&IrcClient::on_topic_who_time_received, {4, 0}}},
{"RPL_TOPICWHOTIME", {&IrcClient::on_topic_who_time_received, {4, 0}}},
{"366", {&IrcClient::on_channel_completely_joined, {2, 0}}}, {"366", {&IrcClient::on_channel_completely_joined, {2, 0}}},
{"432", {&IrcClient::on_erroneous_nickname, {2, 0}}}, {"432", {&IrcClient::on_erroneous_nickname, {2, 0}}},
{"433", {&IrcClient::on_nickname_conflict, {2, 0}}}, {"433", {&IrcClient::on_nickname_conflict, {2, 0}}},
...@@ -723,10 +725,20 @@ void IrcClient::send_motd(const IrcMessage&) ...@@ -723,10 +725,20 @@ void IrcClient::send_motd(const IrcMessage&)
void IrcClient::on_topic_received(const IrcMessage& message) void IrcClient::on_topic_received(const IrcMessage& message)
{ {
const std::string chan_name = utils::tolower(message.arguments[message.arguments.size() - 2]); const std::string chan_name = utils::tolower(message.arguments[message.arguments.size() - 2]);
IrcUser author(message.prefix);
IrcChannel* channel = this->get_channel(chan_name); IrcChannel* channel = this->get_channel(chan_name);
channel->topic = message.arguments[message.arguments.size() - 1]; channel->topic = message.arguments[message.arguments.size() - 1];
channel->topic_author = author.nick;
if (channel->joined) if (channel->joined)
this->bridge.send_topic(this->hostname, chan_name, channel->topic); this->bridge.send_topic(this->hostname, chan_name, channel->topic, channel->topic_author);
}
void IrcClient::on_topic_who_time_received(const IrcMessage& message)
{
IrcUser author(message.arguments[2]);
const std::string chan_name = utils::tolower(message.arguments[1]);
IrcChannel* channel = this->get_channel(chan_name);
channel->topic_author = author.nick;
} }
void IrcClient::on_channel_completely_joined(const IrcMessage& message) void IrcClient::on_channel_completely_joined(const IrcMessage& message)
...@@ -737,7 +749,7 @@ void IrcClient::on_channel_completely_joined(const IrcMessage& message) ...@@ -737,7 +749,7 @@ void IrcClient::on_channel_completely_joined(const IrcMessage& message)
this->bridge.send_user_join(this->hostname, chan_name, channel->get_self(), this->bridge.send_user_join(this->hostname, chan_name, channel->get_self(),
channel->get_self()->get_most_significant_mode(this->sorted_user_modes), channel->get_self()->get_most_significant_mode(this->sorted_user_modes),
true); true);
this->bridge.send_topic(this->hostname, chan_name, channel->topic); this->bridge.send_topic(this->hostname, chan_name, channel->topic, channel->topic_author);
} }
void IrcClient::on_erroneous_nickname(const IrcMessage& message) void IrcClient::on_erroneous_nickname(const IrcMessage& message)
......
...@@ -198,6 +198,10 @@ public: ...@@ -198,6 +198,10 @@ public:
* Save the topic in the IrcChannel * Save the topic in the IrcChannel
*/ */
void on_topic_received(const IrcMessage& message); void on_topic_received(const IrcMessage& message);
/**
* Save the topic author in the IrcChannel
*/
void on_topic_who_time_received(const IrcMessage& message);
/** /**
* Empty the topic * Empty the topic
*/ */
......
...@@ -409,7 +409,7 @@ if __name__ == '__main__': ...@@ -409,7 +409,7 @@ if __name__ == '__main__':
# First user sets the topic # First user sets the topic
partial(send_stanza, partial(send_stanza,
"<message from='{jid_one}/{resource_one}' to='#foo%{irc_server_one}' type='groupchat'><subject>TOPIC TEST</subject></message>"), "<message from='{jid_one}/{resource_one}' to='#foo%{irc_server_one}' type='groupchat'><subject>TOPIC TEST</subject></message>"),
partial(expect_stanza, "/message[@from='#foo%{irc_server_one}'][@type='groupchat'][@to='{jid_one}/{resource_one}']/subject[text()='TOPIC TEST']"), partial(expect_stanza, "/message[@from='#foo%{irc_server_one}/{nick_one}'][@type='groupchat'][@to='{jid_one}/{resource_one}']/subject[text()='TOPIC TEST']"),
# Second user joins # Second user joins
partial(send_stanza, partial(send_stanza,
...@@ -426,7 +426,7 @@ if __name__ == '__main__': ...@@ -426,7 +426,7 @@ if __name__ == '__main__':
("/presence[@to='{jid_two}/{resource_one}'][@from='#foo%{irc_server_one}/{nick_two}']/muc_user:x/muc_user:item[@affiliation='none'][@jid='~bobby@localhost'][@role='participant']", ("/presence[@to='{jid_two}/{resource_one}'][@from='#foo%{irc_server_one}/{nick_two}']/muc_user:x/muc_user:item[@affiliation='none'][@jid='~bobby@localhost'][@role='participant']",
"/presence/muc_user:x/muc_user:status[@code='110']") "/presence/muc_user:x/muc_user:status[@code='110']")
), ),
partial(expect_stanza, "/message[@from='#foo%{irc_server_one}'][@type='groupchat']/subject[text()='TOPIC TEST']"), partial(expect_stanza, "/message[@from='#foo%{irc_server_one}/{nick_one}'][@type='groupchat']/subject[text()='TOPIC TEST']"),
]), ]),
) )
......
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