fixed rename

This commit is contained in:
fourtf 2018-06-26 17:47:44 +02:00
parent 604e5ed682
commit fb230423f6
3 changed files with 114 additions and 18 deletions

View file

@ -0,0 +1,97 @@
#pragma once
#include <QMap>
#include <QMutex>
#include <QMutexLocker>
#include <functional>
#include <map>
#include <memory>
namespace chatterino {
template <typename TKey, typename TValue>
class ConcurrentMap
{
public:
ConcurrentMap() = default;
bool tryGet(const TKey &name, TValue &value) const
{
QMutexLocker lock(&this->mutex);
auto a = this->data.find(name);
if (a == this->data.end()) {
return false;
}
value = a.value();
return true;
}
TValue getOrAdd(const TKey &name, std::function<TValue()> addLambda)
{
QMutexLocker lock(&this->mutex);
auto a = this->data.find(name);
if (a == this->data.end()) {
TValue value = addLambda();
this->data.insert(name, value);
return value;
}
return a.value();
}
TValue &operator[](const TKey &name)
{
QMutexLocker lock(&this->mutex);
return this->data[name];
}
void clear()
{
QMutexLocker lock(&this->mutex);
this->data.clear();
}
void insert(const TKey &name, const TValue &value)
{
QMutexLocker lock(&this->mutex);
this->data.insert(name, value);
}
void each(std::function<void(const TKey &name, const TValue &value)> func) const
{
QMutexLocker lock(&this->mutex);
QMapIterator<TKey, TValue> it(this->data);
while (it.hasNext()) {
it.next();
func(it.key(), it.value());
}
}
void each(std::function<void(const TKey &name, TValue &value)> func)
{
QMutexLocker lock(&this->mutex);
QMutableMapIterator<TKey, TValue> it(this->data);
while (it.hasNext()) {
it.next();
func(it.key(), it.value());
}
}
private:
mutable QMutex mutex;
QMap<TKey, TValue> data;
};
} // namespace chatterino

View file

@ -179,7 +179,7 @@ PubSub::PubSub()
this->moderationActionHandlers["clear"] = [this](const auto &data, const auto &roomID) { this->moderationActionHandlers["clear"] = [this](const auto &data, const auto &roomID) {
ClearChatAction action(data, roomID); ClearChatAction action(data, roomID);
this->sig.moderation.chatCleared.invoke(action); this->signals_.moderation.chatCleared.invoke(action);
}; };
this->moderationActionHandlers["slowoff"] = [this](const auto &data, const auto &roomID) { this->moderationActionHandlers["slowoff"] = [this](const auto &data, const auto &roomID) {
@ -188,7 +188,7 @@ PubSub::PubSub()
action.mode = ModeChangedAction::Mode::Slow; action.mode = ModeChangedAction::Mode::Slow;
action.state = ModeChangedAction::State::Off; action.state = ModeChangedAction::State::Off;
this->sig.moderation.modeChanged.invoke(action); this->signals_.moderation.modeChanged.invoke(action);
}; };
this->moderationActionHandlers["slow"] = [this](const auto &data, const auto &roomID) { this->moderationActionHandlers["slow"] = [this](const auto &data, const auto &roomID) {
@ -225,7 +225,7 @@ PubSub::PubSub()
action.duration = QString(durationArg.GetString()).toUInt(&ok, 10); action.duration = QString(durationArg.GetString()).toUInt(&ok, 10);
this->sig.moderation.modeChanged.invoke(action); this->signals_.moderation.modeChanged.invoke(action);
}; };
this->moderationActionHandlers["r9kbetaoff"] = [this](const auto &data, const auto &roomID) { this->moderationActionHandlers["r9kbetaoff"] = [this](const auto &data, const auto &roomID) {
@ -234,7 +234,7 @@ PubSub::PubSub()
action.mode = ModeChangedAction::Mode::R9K; action.mode = ModeChangedAction::Mode::R9K;
action.state = ModeChangedAction::State::Off; action.state = ModeChangedAction::State::Off;
this->sig.moderation.modeChanged.invoke(action); this->signals_.moderation.modeChanged.invoke(action);
}; };
this->moderationActionHandlers["r9kbeta"] = [this](const auto &data, const auto &roomID) { this->moderationActionHandlers["r9kbeta"] = [this](const auto &data, const auto &roomID) {
@ -243,7 +243,7 @@ PubSub::PubSub()
action.mode = ModeChangedAction::Mode::R9K; action.mode = ModeChangedAction::Mode::R9K;
action.state = ModeChangedAction::State::On; action.state = ModeChangedAction::State::On;
this->sig.moderation.modeChanged.invoke(action); this->signals_.moderation.modeChanged.invoke(action);
}; };
this->moderationActionHandlers["subscribersoff"] = [this](const auto &data, this->moderationActionHandlers["subscribersoff"] = [this](const auto &data,
@ -253,7 +253,7 @@ PubSub::PubSub()
action.mode = ModeChangedAction::Mode::SubscribersOnly; action.mode = ModeChangedAction::Mode::SubscribersOnly;
action.state = ModeChangedAction::State::Off; action.state = ModeChangedAction::State::Off;
this->sig.moderation.modeChanged.invoke(action); this->signals_.moderation.modeChanged.invoke(action);
}; };
this->moderationActionHandlers["subscribers"] = [this](const auto &data, const auto &roomID) { this->moderationActionHandlers["subscribers"] = [this](const auto &data, const auto &roomID) {
@ -262,7 +262,7 @@ PubSub::PubSub()
action.mode = ModeChangedAction::Mode::SubscribersOnly; action.mode = ModeChangedAction::Mode::SubscribersOnly;
action.state = ModeChangedAction::State::On; action.state = ModeChangedAction::State::On;
this->sig.moderation.modeChanged.invoke(action); this->signals_.moderation.modeChanged.invoke(action);
}; };
this->moderationActionHandlers["emoteonlyoff"] = [this](const auto &data, const auto &roomID) { this->moderationActionHandlers["emoteonlyoff"] = [this](const auto &data, const auto &roomID) {
@ -271,7 +271,7 @@ PubSub::PubSub()
action.mode = ModeChangedAction::Mode::EmoteOnly; action.mode = ModeChangedAction::Mode::EmoteOnly;
action.state = ModeChangedAction::State::Off; action.state = ModeChangedAction::State::Off;
this->sig.moderation.modeChanged.invoke(action); this->signals_.moderation.modeChanged.invoke(action);
}; };
this->moderationActionHandlers["emoteonly"] = [this](const auto &data, const auto &roomID) { this->moderationActionHandlers["emoteonly"] = [this](const auto &data, const auto &roomID) {
@ -280,7 +280,7 @@ PubSub::PubSub()
action.mode = ModeChangedAction::Mode::EmoteOnly; action.mode = ModeChangedAction::Mode::EmoteOnly;
action.state = ModeChangedAction::State::On; action.state = ModeChangedAction::State::On;
this->sig.moderation.modeChanged.invoke(action); this->signals_.moderation.modeChanged.invoke(action);
}; };
this->moderationActionHandlers["unmod"] = [this](const auto &data, const auto &roomID) { this->moderationActionHandlers["unmod"] = [this](const auto &data, const auto &roomID) {
@ -304,7 +304,7 @@ PubSub::PubSub()
action.modded = false; action.modded = false;
this->sig.moderation.moderationStateChanged.invoke(action); this->signals_.moderation.moderationStateChanged.invoke(action);
}; };
this->moderationActionHandlers["mod"] = [this](const auto &data, const auto &roomID) { this->moderationActionHandlers["mod"] = [this](const auto &data, const auto &roomID) {
@ -328,7 +328,7 @@ PubSub::PubSub()
action.modded = true; action.modded = true;
this->sig.moderation.moderationStateChanged.invoke(action); this->signals_.moderation.moderationStateChanged.invoke(action);
}; };
this->moderationActionHandlers["timeout"] = [this](const auto &data, const auto &roomID) { this->moderationActionHandlers["timeout"] = [this](const auto &data, const auto &roomID) {
@ -361,7 +361,7 @@ PubSub::PubSub()
} }
} }
this->sig.moderation.userBanned.invoke(action); this->signals_.moderation.userBanned.invoke(action);
} catch (const std::runtime_error &ex) { } catch (const std::runtime_error &ex) {
Log("Error parsing moderation action: {}", ex.what()); Log("Error parsing moderation action: {}", ex.what());
} }
@ -390,7 +390,7 @@ PubSub::PubSub()
} }
} }
this->sig.moderation.userBanned.invoke(action); this->signals_.moderation.userBanned.invoke(action);
} catch (const std::runtime_error &ex) { } catch (const std::runtime_error &ex) {
Log("Error parsing moderation action: {}", ex.what()); Log("Error parsing moderation action: {}", ex.what());
} }
@ -415,7 +415,7 @@ PubSub::PubSub()
return; return;
} }
this->sig.moderation.userUnbanned.invoke(action); this->signals_.moderation.userUnbanned.invoke(action);
} catch (const std::runtime_error &ex) { } catch (const std::runtime_error &ex) {
Log("Error parsing moderation action: {}", ex.what()); Log("Error parsing moderation action: {}", ex.what());
} }
@ -440,7 +440,7 @@ PubSub::PubSub()
return; return;
} }
this->sig.moderation.userUnbanned.invoke(action); this->signals_.moderation.userUnbanned.invoke(action);
} catch (const std::runtime_error &ex) { } catch (const std::runtime_error &ex) {
Log("Error parsing moderation action: {}", ex.what()); Log("Error parsing moderation action: {}", ex.what());
} }
@ -725,9 +725,9 @@ void PubSub::handleMessageResponse(const rapidjson::Value &outerData)
} }
if (whisperType == "whisper_received") { if (whisperType == "whisper_received") {
this->sig.whisper.received.invoke(msg); this->signals_.whisper.received.invoke(msg);
} else if (whisperType == "whisper_sent") { } else if (whisperType == "whisper_sent") {
this->sig.whisper.sent.invoke(msg); this->signals_.whisper.sent.invoke(msg);
} else if (whisperType == "thread") { } else if (whisperType == "thread") {
// Handle thread? // Handle thread?
} else { } else {

View file

@ -5,7 +5,6 @@
#include "debug/Log.hpp" #include "debug/Log.hpp"
#include "singletons/SettingsManager.hpp" #include "singletons/SettingsManager.hpp"
#include "singletons/WindowManager.hpp" #include "singletons/WindowManager.hpp"
#include "util/NativeEventHelper.hpp"
#include "util/PostToThread.hpp" #include "util/PostToThread.hpp"
#include "util/WindowsHelper.hpp" #include "util/WindowsHelper.hpp"
#include "widgets/Label.hpp" #include "widgets/Label.hpp"