From 30bcf4894f1da0db8dde15329260c801f748a019 Mon Sep 17 00:00:00 2001 From: Attila Molnar Date: Sat, 24 Jan 2015 14:55:10 +0100 Subject: Implement User::WriteCommonRaw() using ForEachNeighbor() --- src/users.cpp | 54 +++++++++++++++++++++--------------------------------- 1 file changed, 21 insertions(+), 33 deletions(-) (limited to 'src/users.cpp') diff --git a/src/users.cpp b/src/users.cpp index 5be3963b4..4dffe6056 100644 --- a/src/users.cpp +++ b/src/users.cpp @@ -845,6 +845,25 @@ void User::WriteFrom(User *user, const char* text, ...) this->WriteFrom(user, textbuffer); } +namespace +{ + class WriteCommonRawHandler : public User::ForEachNeighborHandler + { + const std::string& msg; + + void Execute(LocalUser* user) CXX11_OVERRIDE + { + user->Write(msg); + } + + public: + WriteCommonRawHandler(const std::string& message) + : msg(message) + { + } + }; +} + void User::WriteCommon(const char* text, ...) { if (this->registered != REG_ALL || quitting) @@ -861,39 +880,8 @@ void User::WriteCommonRaw(const std::string &line, bool include_self) if (this->registered != REG_ALL || quitting) return; - LocalUser::already_sent_id++; - - IncludeChanList include_c(chans.begin(), chans.end()); - std::map exceptions; - - exceptions[this] = include_self; - - FOREACH_MOD(OnBuildNeighborList, (this, include_c, exceptions)); - - for (std::map::iterator i = exceptions.begin(); i != exceptions.end(); ++i) - { - LocalUser* u = IS_LOCAL(i->first); - if (u && !u->quitting) - { - u->already_sent = LocalUser::already_sent_id; - if (i->second) - u->Write(line); - } - } - for (IncludeChanList::const_iterator v = include_c.begin(); v != include_c.end(); ++v) - { - Channel* c = (*v)->chan; - const Channel::MemberMap& ulist = c->GetUsers(); - for (Channel::MemberMap::const_iterator i = ulist.begin(); i != ulist.end(); ++i) - { - LocalUser* u = IS_LOCAL(i->first); - if (u && u->already_sent != LocalUser::already_sent_id) - { - u->already_sent = LocalUser::already_sent_id; - u->Write(line); - } - } - } + WriteCommonRawHandler handler(line); + ForEachNeighbor(handler, include_self); } void User::ForEachNeighbor(ForEachNeighborHandler& handler, bool include_self) -- cgit v1.2.3