diff --git a/channel.cpp b/channel.cpp index 805683d..cf56f18 100644 --- a/channel.cpp +++ b/channel.cpp @@ -538,7 +538,7 @@ weechat::channel::member *weechat::channel::add_member(const char *id, const cha && type == weechat::channel::chat_type::MUC) weechat_printf_date_tags(buffer, 0, "xmpp_presence,enter,log4", "%s%s%s%s%s %s%s%s%s %s%s%s%s%s%s%s%s%s%s%s%s%s%s", weechat_prefix("join"), - user->as_prefix_raw(), + user->as_prefix_raw().data(), client ? " (" : "", client ? client : "", client ? ")" : "", @@ -561,8 +561,8 @@ weechat::channel::member *weechat::channel::add_member(const char *id, const cha else weechat_printf_date_tags(buffer, 0, "xmpp_presence,enter,log4", "%s%s (%s) %s%s%s%s %s%s%s%s%s%s%s%s%s", weechat_prefix("join"), - jid_resource ? user->as_prefix_raw() : "You", - jid_resource ? jid_resource : user->as_prefix_raw(), + jid_resource ? user->as_prefix_raw().data() : "You", + jid_resource ? jid_resource : user->as_prefix_raw().data(), user->profile.status ? "is " : "", weechat_color("irc.color.message_join"), user->profile.status ? user->profile.status : (user->profile.idle ? "idle" : "entered"), diff --git a/channel.hh b/channel.hh index 9f306f1..1c432f5 100644 --- a/channel.hh +++ b/channel.hh @@ -104,7 +104,7 @@ namespace weechat } pgp; struct { int enabled = 0; - } otr; + } otr; struct t_weelist *members_speaking[2] = { nullptr }; std::vector self_typings; std::vector typings; diff --git a/config/file.hh b/config/file.hh index e34d1d5..088ced3 100644 --- a/config/file.hh +++ b/config/file.hh @@ -18,7 +18,6 @@ namespace weechat { class config; - struct config_file; struct config_section; struct config_free { void operator() (struct t_config_file *ptr) { weechat_config_free(ptr); } }; diff --git a/connection.cpp b/connection.cpp index ae3013c..004dbed 100644 --- a/connection.cpp +++ b/connection.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include #include "plugin.hh" @@ -188,10 +189,15 @@ bool weechat::connection::presence_handler(xmpp_stanza_t *stanza) user = weechat::user::search(&account, binding.from->full.data()); if (!user) - user = new weechat::user(&account, binding.from->full.data(), - channel && binding.from->bare.data() == channel->id - ? (binding.from->resource.size() ? binding.from->resource.data() : "") - : binding.from->full.data()); + { + auto name = binding.from->full.data(); + user = &account.users.emplace(std::piecewise_construct, + std::forward_as_tuple(name), + std::forward_as_tuple(&account, channel, name, + channel && binding.from->bare.data() == channel->id + ? (binding.from->resource.size() ? binding.from->resource.data() : "") + : binding.from->full.data())).first->second; + } auto status = binding.status(); auto show = binding.show(); auto idle = binding.idle_since(); @@ -222,10 +228,15 @@ bool weechat::connection::presence_handler(xmpp_stanza_t *stanza) { user = user::search(&account, binding.from->full.data()); if (!user) - user = new weechat::user(&account, binding.from->full.data(), - channel && binding.from->bare.data() == channel->id - ? (binding.from->resource.size() ? binding.from->resource.data() : "") - : binding.from->full.data()); + { + auto name = binding.from->full.data(); + user = &account.users.emplace(std::piecewise_construct, + std::forward_as_tuple(name), + std::forward_as_tuple(&account, channel, name, + channel && binding.from->bare.data() == channel->id + ? (binding.from->resource.size() ? binding.from->resource.data() : "") + : binding.from->full.data())).first->second; + } auto status = binding.status(); auto show = binding.show(); auto idle = binding.idle_since(); @@ -308,9 +319,14 @@ bool weechat::connection::message_handler(xmpp_stanza_t *stanza) return 1; auto user = user::search(&account, from); if (!user) - user = new weechat::user(&account, from, - weechat_strcasecmp(from_bare, channel->id.data()) == 0 - ? nick : from); + { + auto name = from; + user = &account.users.emplace(std::piecewise_construct, + std::forward_as_tuple(name), + std::forward_as_tuple(&account, channel, name, + weechat_strcasecmp(from_bare, channel->id.data()) == 0 + ? nick : from)).first->second; + } channel->add_typing(user); weechat_printf(channel->buffer, "...\t%s%s typing", weechat_color("gray"), @@ -743,15 +759,15 @@ bool weechat::connection::message_handler(xmpp_stanza_t *stanza) } if (channel_id == from_bare && to == channel->id) weechat_printf_date_tags(channel->buffer, date, *dyn_tags, "%s%s\t[to %s]: %s", - edit, user::as_prefix_raw(&account, nick).data(), + edit, user::as_prefix_raw(&account, from).data(), to, difftext ? difftext : text ? text : ""); else if (weechat_string_match(text, "/me *", 0)) weechat_printf_date_tags(channel->buffer, date, *dyn_tags, "%s%s\t%s %s", - edit, weechat_prefix("action"), user::as_prefix_raw(&account, nick).data(), + edit, weechat_prefix("action"), user::as_prefix_raw(&account, from).data(), difftext ? difftext+4 : text ? text+4 : ""); else weechat_printf_date_tags(channel->buffer, date, *dyn_tags, "%s%s\t%s", - edit, user::as_prefix_raw(&account, nick).data(), + edit, user::as_prefix_raw(&account, from).data(), difftext ? difftext : text ? text : ""); weechat_string_dyn_free(dyn_tags, 1); diff --git a/user.cpp b/user.cpp index 7474cb1..49f3682 100644 --- a/user.cpp +++ b/user.cpp @@ -147,7 +147,7 @@ void weechat::user::nicklist_remove(weechat::account *account, weechat_nicklist_remove_nick(ptr_buffer, ptr_nick); } -weechat::user::user(weechat::account *account, +weechat::user::user(weechat::account *account, weechat::channel *channel, const char *id, const char *display_name) { if (!account || !id) @@ -155,8 +155,8 @@ weechat::user::user(weechat::account *account, throw nullptr; } - //if (account->users.empty()) - // channel::add_nicklist_groups(account, nullptr); + if (account->users.empty() && channel) + channel->add_nicklist_groups(); weechat::user *ptr_user = user::search(account, id); if (ptr_user) @@ -164,8 +164,6 @@ weechat::user::user(weechat::account *account, throw nullptr; } - //account->users += this; - this->id = strdup(id); this->profile.display_name = display_name ? diff --git a/user.hh b/user.hh index b81010e..510ff8c 100644 --- a/user.hh +++ b/user.hh @@ -41,7 +41,7 @@ namespace weechat struct profile profile; public: - user(weechat::account *account, const char *id, const char *display_name); + user(weechat::account *account, weechat::channel *channel, const char *id, const char *display_name); static std::string get_colour(const char *name); static std::string get_colour_for_nicklist(const char *name); @@ -53,11 +53,11 @@ namespace weechat std::string as_prefix(); static std::string as_prefix_raw(weechat::account *account, const char *id) { - auto found = std::unique_ptr(search(account, id)); + auto found = search(account, id); return found ? found->as_prefix_raw() : ""; } static std::string as_prefix(weechat::account *account, const char *id) { - auto found = std::unique_ptr(search(account, id)); + auto found = search(account, id); return found ? found->as_prefix() : ""; }