From 0fdbf1d62c1add8800ffc7171a1911e1e243ac2a Mon Sep 17 00:00:00 2001 From: Roderic Morris Date: Tue, 3 Jun 2008 16:29:11 +0000 Subject: channel announcements and leave / enter messages, chat code refactoring --- src/channel.cpp | 38 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 20 deletions(-) (limited to 'src/channel.cpp') diff --git a/src/channel.cpp b/src/channel.cpp index 3204b3b2..2bebcf51 100644 --- a/src/channel.cpp +++ b/src/channel.cpp @@ -21,35 +21,33 @@ * $Id$ */ +#include #include "channel.h" -Channel::Channel(short id) : -mID(id) +Channel::Channel(short id, + const std::string &name, + const std::string &announcement) : + mId(id), + mName(name), + mAnnouncement(announcement) { } -std::string Channel::getName() const +void Channel::addUser(const std::string &user) { - return mName; + // Check if the user already exists in the channel + ChannelUsers::const_iterator i = mUserList.begin(), + i_end = mUserList.end(); + if (std::find(i, i_end, user) != i_end) return; + mUserList.push_back(user); } -void Channel::setName(const std::string &channelName) +void Channel::removeUser(const std::string &user) { - mName = channelName; -} - -int Channel::getUserListSize() const -{ - return userList.size(); -} - -std::string Channel::getUser(unsigned int id) const -{ - if(id <= userList.size()) - { - return userList[id]; - } - return ""; + ChannelUsers::iterator i_end = mUserList.end(), + i = std::find(mUserList.begin(), i_end, user); + if (i == i_end) return; + mUserList.erase(i); } -- cgit v1.2.3-60-g2f50