2017-01-16 03:15:07 +01:00
|
|
|
#include "channels.h"
|
2017-01-17 00:15:44 +01:00
|
|
|
#include "ircmanager.h"
|
2017-01-16 03:15:07 +01:00
|
|
|
|
|
|
|
Channel Channels::m_whispers(QString("/whispers"));
|
|
|
|
Channel Channels::m_mentions(QString("/mentions"));
|
2017-01-17 00:15:44 +01:00
|
|
|
Channel Channels::m_empty(QString(""));
|
2017-01-16 03:15:07 +01:00
|
|
|
|
|
|
|
QMap<QString, std::tuple<Channel *, int>> Channels::m_channels;
|
|
|
|
|
|
|
|
Channel *
|
|
|
|
Channels::addChannel(const QString &channel)
|
|
|
|
{
|
2017-01-17 00:15:44 +01:00
|
|
|
QString c = channel.toLower();
|
2017-01-16 03:15:07 +01:00
|
|
|
|
2017-01-17 00:15:44 +01:00
|
|
|
auto a = m_channels.find(c);
|
2017-01-16 03:15:07 +01:00
|
|
|
|
2017-01-17 00:15:44 +01:00
|
|
|
if (a == m_channels.end()) {
|
|
|
|
auto _c = new Channel(c);
|
|
|
|
m_channels.insert(c, std::tuple<Channel *, int>(_c, 1));
|
|
|
|
|
|
|
|
IrcManager::joinChannel(c);
|
|
|
|
|
|
|
|
return _c;
|
|
|
|
} else {
|
|
|
|
std::get<1>(a.value())++;
|
2017-01-16 03:15:07 +01:00
|
|
|
}
|
|
|
|
|
2017-01-17 00:15:44 +01:00
|
|
|
return std::get<0>(a.value());
|
2017-01-16 03:15:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Channel *
|
|
|
|
Channels::getChannel(const QString &channel)
|
|
|
|
{
|
2017-01-17 00:15:44 +01:00
|
|
|
QString c = channel.toLower();
|
|
|
|
|
|
|
|
if (channel.length() > 1 && channel.at(0) == '/') {
|
|
|
|
if (c == "/whispers") {
|
|
|
|
return &m_whispers;
|
|
|
|
}
|
2017-01-16 03:15:07 +01:00
|
|
|
|
2017-01-17 00:15:44 +01:00
|
|
|
if (c == "/mentions") {
|
|
|
|
return &m_mentions;
|
|
|
|
}
|
|
|
|
|
|
|
|
return &m_empty;
|
2017-01-16 03:15:07 +01:00
|
|
|
}
|
|
|
|
|
2017-01-17 00:15:44 +01:00
|
|
|
auto a = m_channels.find(c);
|
2017-01-16 03:15:07 +01:00
|
|
|
|
|
|
|
if (a == m_channels.end()) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return std::get<0>(a.value());
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Channels::removeChannel(const QString &channel)
|
|
|
|
{
|
2017-01-17 00:15:44 +01:00
|
|
|
if (channel.length() > 1 && channel.at(0) == '/') {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString c = channel.toLower();
|
|
|
|
|
|
|
|
auto a = m_channels.find(c);
|
2017-01-16 03:15:07 +01:00
|
|
|
|
|
|
|
if (a == m_channels.end()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::get<1>(a.value())--;
|
|
|
|
|
|
|
|
if (std::get<1>(a.value()) == 0) {
|
2017-01-17 00:15:44 +01:00
|
|
|
IrcManager::partChannel(c);
|
|
|
|
m_channels.remove(c);
|
2017-01-16 03:15:07 +01:00
|
|
|
delete std::get<0>(a.value());
|
|
|
|
}
|
|
|
|
}
|