summaryrefslogtreecommitdiff
path: root/src/irc/irc_channel.cpp
diff options
context:
space:
mode:
authorlouiz’ <louiz@louiz.org>2017-06-28 14:41:33 +0200
committerlouiz’ <louiz@louiz.org>2017-06-28 14:41:33 +0200
commit13a1ab1878fd6312aea485ded3f5bad59c36f17f (patch)
tree071b90523126d677f714cbf13346507f2e500d69 /src/irc/irc_channel.cpp
parenta1349361d2c15929e8260536c9091f2a4c2048a4 (diff)
parent7e69d0387e85eeed10d605349feeba595c3fa0ee (diff)
downloadbiboumi-13a1ab1878fd6312aea485ded3f5bad59c36f17f.tar.gz
biboumi-13a1ab1878fd6312aea485ded3f5bad59c36f17f.tar.bz2
biboumi-13a1ab1878fd6312aea485ded3f5bad59c36f17f.tar.xz
biboumi-13a1ab1878fd6312aea485ded3f5bad59c36f17f.zip
Merge remote-tracking branch 'remotes/debian/master' into debian
Diffstat (limited to 'src/irc/irc_channel.cpp')
-rw-r--r--src/irc/irc_channel.cpp24
1 files changed, 18 insertions, 6 deletions
diff --git a/src/irc/irc_channel.cpp b/src/irc/irc_channel.cpp
index 40d7f54..53043c7 100644
--- a/src/irc/irc_channel.cpp
+++ b/src/irc/irc_channel.cpp
@@ -1,21 +1,25 @@
#include <irc/irc_channel.hpp>
#include <algorithm>
-void IrcChannel::set_self(const std::string& name)
+void IrcChannel::set_self(IrcUser* user)
{
- this->self = std::make_unique<IrcUser>(name);
+ this->self = user;
}
IrcUser* IrcChannel::add_user(const std::string& name,
const std::map<char, char>& prefix_to_mode)
{
- this->users.emplace_back(std::make_unique<IrcUser>(name, prefix_to_mode));
+ auto new_user = std::make_unique<IrcUser>(name, prefix_to_mode);
+ auto old_user = this->find_user(new_user->nick);
+ if (old_user)
+ return old_user;
+ this->users.emplace_back(std::move(new_user));
return this->users.back().get();
}
IrcUser* IrcChannel::get_self() const
{
- return this->self.get();
+ return this->self;
}
IrcUser* IrcChannel::find_user(const std::string& name) const
@@ -32,19 +36,27 @@ IrcUser* IrcChannel::find_user(const std::string& name) const
void IrcChannel::remove_user(const IrcUser* user)
{
const auto nick = user->nick;
+ const bool is_self = (user == this->self);
const auto it = std::find_if(this->users.begin(), this->users.end(),
[nick](const std::unique_ptr<IrcUser>& u)
{
return nick == u->nick;
});
if (it != this->users.end())
- this->users.erase(it);
+ {
+ this->users.erase(it);
+ if (is_self)
+ {
+ this->self = nullptr;
+ this->joined = false;
+ }
+ }
}
void IrcChannel::remove_all_users()
{
this->users.clear();
- this->self.reset();
+ this->self = nullptr;
}
DummyIrcChannel::DummyIrcChannel():