added settings to show part and join messages

This commit is contained in:
fourtf 2018-05-26 18:06:55 +02:00
parent 88c609df43
commit b016f0fb88
7 changed files with 104 additions and 8 deletions

View file

@ -246,6 +246,26 @@ void IrcMessageHandler::handleWriteConnectionNoticeMessage(Communi::IrcNoticeMes
this->handleNoticeMessage(message); this->handleNoticeMessage(message);
} }
void IrcMessageHandler::handleJoinMessage(Communi::IrcMessage *message)
{
auto app = getApp();
auto channel = app->twitch.server->getChannelOrEmpty(message->parameter(0).remove(0, 1));
if (TwitchChannel *twitchChannel = dynamic_cast<TwitchChannel *>(channel.get())) {
twitchChannel->addJoinedUser(message->nick());
}
}
void IrcMessageHandler::handlePartMessage(Communi::IrcMessage *message)
{
auto app = getApp();
auto channel = app->twitch.server->getChannelOrEmpty(message->parameter(0).remove(0, 1));
if (TwitchChannel *twitchChannel = dynamic_cast<TwitchChannel *>(channel.get())) {
twitchChannel->addPartedUser(message->nick());
}
}
} // namespace twitch } // namespace twitch
} // namespace providers } // namespace providers
} // namespace chatterino } // namespace chatterino

View file

@ -21,6 +21,9 @@ public:
void handleModeMessage(Communi::IrcMessage *message); void handleModeMessage(Communi::IrcMessage *message);
void handleNoticeMessage(Communi::IrcNoticeMessage *message); void handleNoticeMessage(Communi::IrcNoticeMessage *message);
void handleWriteConnectionNoticeMessage(Communi::IrcNoticeMessage *message); void handleWriteConnectionNoticeMessage(Communi::IrcNoticeMessage *message);
void handleJoinMessage(Communi::IrcMessage *message);
void handlePartMessage(Communi::IrcMessage *message);
}; };
} // namespace twitch } // namespace twitch

View file

@ -213,6 +213,58 @@ void TwitchChannel::addRecentChatter(const std::shared_ptr<messages::Message> &m
this->completionModel.addUser(message->displayName); this->completionModel.addUser(message->displayName);
} }
void TwitchChannel::addJoinedUser(const QString &user)
{
auto *app = getApp();
if (user == app->accounts->Twitch.getCurrent()->getUserName() ||
!app->settings->showJoins.getValue()) {
return;
}
std::lock_guard<std::mutex> guard(this->joinedUserMutex);
joinedUsers << user;
if (!this->joinedUsersMergeQueued) {
this->joinedUsersMergeQueued = true;
QTimer::singleShot(500, &this->object, [this] {
std::lock_guard<std::mutex> guard(this->joinedUserMutex);
this->addMessage(messages::Message::createSystemMessage("Users joined: " +
this->joinedUsers.join(", ")));
this->joinedUsersMergeQueued = false;
});
}
}
void TwitchChannel::addPartedUser(const QString &user)
{
auto *app = getApp();
if (user == app->accounts->Twitch.getCurrent()->getUserName() ||
!app->settings->showJoins.getValue()) {
return;
}
std::lock_guard<std::mutex> guard(this->partedUserMutex);
partedUsers << user;
if (!this->partedUsersMergeQueued) {
this->partedUsersMergeQueued = true;
QTimer::singleShot(500, &this->object, [this] {
std::lock_guard<std::mutex> guard(this->partedUserMutex);
this->addMessage(messages::Message::createSystemMessage("Users parted: " +
this->partedUsers.join(", ")));
this->partedUsersMergeQueued = false;
});
}
}
TwitchChannel::RoomModes TwitchChannel::getRoomModes() TwitchChannel::RoomModes TwitchChannel::getRoomModes()
{ {
std::lock_guard<std::mutex> lock(this->roomModeMutex); std::lock_guard<std::mutex> lock(this->roomModeMutex);

View file

@ -63,6 +63,8 @@ public:
bool hasModRights(); bool hasModRights();
void addRecentChatter(const std::shared_ptr<messages::Message> &message) final; void addRecentChatter(const std::shared_ptr<messages::Message> &message) final;
void addJoinedUser(const QString &user);
void addPartedUser(const QString &user);
const std::shared_ptr<chatterino::util::EmoteMap> bttvChannelEmotes; const std::shared_ptr<chatterino::util::EmoteMap> bttvChannelEmotes;
const std::shared_ptr<chatterino::util::EmoteMap> ffzChannelEmotes; const std::shared_ptr<chatterino::util::EmoteMap> ffzChannelEmotes;
@ -113,6 +115,14 @@ private:
RoomModes roomModes; RoomModes roomModes;
std::mutex roomModeMutex; std::mutex roomModeMutex;
QObject object;
std::mutex joinedUserMutex;
QStringList joinedUsers;
bool joinedUsersMergeQueued = false;
std::mutex partedUserMutex;
QStringList partedUsers;
bool partedUsersMergeQueued = false;
Communi::IrcConnection *readConnection; Communi::IrcConnection *readConnection;
friend class TwitchServer; friend class TwitchServer;

View file

@ -114,21 +114,26 @@ void TwitchServer::messageReceived(IrcMessage *message)
const QString &command = message->command(); const QString &command = message->command();
auto &handler = IrcMessageHandler::getInstance();
if (command == "ROOMSTATE") { if (command == "ROOMSTATE") {
IrcMessageHandler::getInstance().handleRoomStateMessage(message); handler.handleRoomStateMessage(message);
} else if (command == "CLEARCHAT") { } else if (command == "CLEARCHAT") {
IrcMessageHandler::getInstance().handleClearChatMessage(message); handler.handleClearChatMessage(message);
} else if (command == "USERSTATE") { } else if (command == "USERSTATE") {
IrcMessageHandler::getInstance().handleUserStateMessage(message); handler.handleUserStateMessage(message);
} else if (command == "WHISPER") { } else if (command == "WHISPER") {
IrcMessageHandler::getInstance().handleWhisperMessage(message); handler.handleWhisperMessage(message);
} else if (command == "USERNOTICE") { } else if (command == "USERNOTICE") {
IrcMessageHandler::getInstance().handleUserNoticeMessage(message); handler.handleUserNoticeMessage(message);
} else if (command == "MODE") { } else if (command == "MODE") {
IrcMessageHandler::getInstance().handleModeMessage(message); handler.handleModeMessage(message);
} else if (command == "NOTICE") { } else if (command == "NOTICE") {
IrcMessageHandler::getInstance().handleNoticeMessage( handler.handleNoticeMessage(static_cast<IrcNoticeMessage *>(message));
static_cast<IrcNoticeMessage *>(message)); } else if (command == "JOIN") {
handler.handleJoinMessage(message);
} else if (command == "PART") {
handler.handlePartMessage(message);
} }
} }

View file

@ -55,6 +55,8 @@ public:
/// Behaviour /// Behaviour
BoolSetting allowDuplicateMessages = {"/behaviour/allowDuplicateMessages", true}; BoolSetting allowDuplicateMessages = {"/behaviour/allowDuplicateMessages", true};
BoolSetting mentionUsersWithAt = {"/behaviour/mentionUsersWithAt", false}; BoolSetting mentionUsersWithAt = {"/behaviour/mentionUsersWithAt", false};
BoolSetting showJoins = {"/behaviour/showJoins", false};
BoolSetting showParts = {"/behaviour/showParts", false};
FloatSetting mouseScrollMultiplier = {"/behaviour/mouseScrollMultiplier", 1.0}; FloatSetting mouseScrollMultiplier = {"/behaviour/mouseScrollMultiplier", 1.0};
// Auto-completion // Auto-completion

View file

@ -34,6 +34,10 @@ BehaviourPage::BehaviourPage()
{ {
form->addRow("Window:", this->createCheckBox(WINDOW_TOPMOST, app->settings->windowTopMost)); form->addRow("Window:", this->createCheckBox(WINDOW_TOPMOST, app->settings->windowTopMost));
form->addRow("Messages:", this->createCheckBox(INPUT_EMPTY, app->settings->hideEmptyInput)); form->addRow("Messages:", this->createCheckBox(INPUT_EMPTY, app->settings->hideEmptyInput));
form->addRow("", this->createCheckBox("Show which users joined the channel",
app->settings->showJoins));
form->addRow("", this->createCheckBox("Show which users parted the channel",
app->settings->showParts));
form->addRow("Pause chat:", form->addRow("Pause chat:",
this->createCheckBox(PAUSE_HOVERING, app->settings->pauseChatHover)); this->createCheckBox(PAUSE_HOVERING, app->settings->pauseChatHover));