mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
Compare commits
8 commits
0bd80f4886
...
6f3a0a1845
Author | SHA1 | Date | |
---|---|---|---|
|
6f3a0a1845 | ||
|
db8047ea7b | ||
|
101a45fd3a | ||
|
5f76f5b755 | ||
|
ecfb35c9b7 | ||
|
f54bdf939a | ||
|
adf124c11b | ||
|
74101d40f5 |
39 changed files with 1533 additions and 945 deletions
|
@ -37,6 +37,7 @@
|
|||
- Minor: Indicate when subscriptions and resubscriptions are for multiple months. (#5642)
|
||||
- Minor: Proxy URL information is now included in the `/debug-env` command. (#5648)
|
||||
- Minor: Make raid entry message usernames clickable. (#5651)
|
||||
- Minor: Tabs unhighlight when their content is read in other tabs. (#5649)
|
||||
- Bugfix: Fixed tab move animation occasionally failing to start after closing a tab. (#5426, #5612)
|
||||
- Bugfix: If a network request errors with 200 OK, Qt's error code is now reported instead of the HTTP status. (#5378)
|
||||
- Bugfix: Fixed restricted users usernames not being clickable. (#5405)
|
||||
|
@ -63,6 +64,7 @@
|
|||
- Bugfix: Fixed double-click selection not working when clicking outside a message. (#5617)
|
||||
- Bugfix: Fixed emotes starting with ":" not tab-completing. (#5603)
|
||||
- Bugfix: Fixed 7TV emotes messing with Qt's HTML. (#5677)
|
||||
- Bugfix: Fixed incorrect messages getting replaced visually. (#5683)
|
||||
- Dev: Update Windows build from Qt 6.5.0 to Qt 6.7.1. (#5420)
|
||||
- Dev: Update vcpkg build Qt from 6.5.0 to 6.7.0, boost from 1.83.0 to 1.85.0, openssl from 3.1.3 to 3.3.0. (#5422)
|
||||
- Dev: Unsingletonize `ISoundController`. (#5462)
|
||||
|
@ -72,10 +74,11 @@
|
|||
- Dev: Refactor and document `Scrollbar`. (#5334, #5393)
|
||||
- Dev: Refactor `TwitchIrcServer`, making it abstracted. (#5421, #5435)
|
||||
- Dev: Reduced the amount of scale events. (#5404, #5406)
|
||||
- Dev: Refactored settings widget creation. (#5585)
|
||||
- Dev: Removed unused timegate settings. (#5361)
|
||||
- Dev: Add `Channel::addSystemMessage` helper function, allowing us to avoid the common `channel->addMessage(makeSystemMessage(...));` pattern. (#5500)
|
||||
- Dev: Unsingletonize `Resources2`. (#5460)
|
||||
- Dev: All Lua globals now show in the `c2` global in the LuaLS metadata. (#5385)
|
||||
- Dev: All Lua globals now show in the `c2` global in the LuaLS metadata. (#5385, #5682)
|
||||
- Dev: Images are now loaded in worker threads. (#5431)
|
||||
- Dev: Fixed broken `SignalVector::operator[]` implementation. (#5556)
|
||||
- Dev: Qt Creator now auto-configures Conan when loading the project and skips vcpkg. (#5305)
|
||||
|
@ -110,11 +113,12 @@
|
|||
- Dev: Twitch messages are now sent using Twitch's Helix API instead of IRC by default. (#5607)
|
||||
- Dev: `GIFTimer` is no longer initialized in tests. (#5608)
|
||||
- Dev: Emojis now use flags instead of a set of strings for capabilities. (#5616)
|
||||
- Dev: Move plugins to Sol2. (#5622)
|
||||
- Dev: Move plugins to Sol2. (#5622, #5682)
|
||||
- Dev: Refactored static `MessageBuilder` helpers to standalone functions. (#5652)
|
||||
- Dev: Decoupled reply parsing from `MessageBuilder`. (#5660, #5668)
|
||||
- Dev: Refactored IRC message building. (#5663)
|
||||
- Dev: Fixed some compiler warnings. (#5672)
|
||||
- Dev: Unified parsing of historic and live IRC messages. (#5678)
|
||||
|
||||
## 2.5.1
|
||||
|
||||
|
|
|
@ -5,20 +5,20 @@
|
|||
-- Add the folder this file is in to "Lua.workspace.library".
|
||||
|
||||
c2 = {}
|
||||
---@alias c2.LogLevel.Debug "c2.LogLevel.Debug"
|
||||
---@alias c2.LogLevel.Info "c2.LogLevel.Info"
|
||||
---@alias c2.LogLevel.Warning "c2.LogLevel.Warning"
|
||||
---@alias c2.LogLevel.Critical "c2.LogLevel.Critical"
|
||||
---@alias c2.LogLevel c2.LogLevel.Debug|c2.LogLevel.Info|c2.LogLevel.Warning|c2.LogLevel.Critical
|
||||
---@type { Debug: c2.LogLevel.Debug, Info: c2.LogLevel.Info, Warning: c2.LogLevel.Warning, Critical: c2.LogLevel.Critical }
|
||||
c2.LogLevel = {}
|
||||
---@enum c2.LogLevel
|
||||
c2.LogLevel = {
|
||||
Debug = {}, ---@type c2.LogLevel.Debug
|
||||
Info = {}, ---@type c2.LogLevel.Info
|
||||
Warning = {}, ---@type c2.LogLevel.Warning
|
||||
Critical = {}, ---@type c2.LogLevel.Critical
|
||||
}
|
||||
|
||||
-- Begin src/controllers/plugins/api/EventType.hpp
|
||||
|
||||
---@alias c2.EventType.CompletionRequested "c2.EventType.CompletionRequested"
|
||||
---@alias c2.EventType c2.EventType.CompletionRequested
|
||||
---@type { CompletionRequested: c2.EventType.CompletionRequested }
|
||||
c2.EventType = {}
|
||||
---@enum c2.EventType
|
||||
c2.EventType = {
|
||||
CompletionRequested = {}, ---@type c2.EventType.CompletionRequested
|
||||
}
|
||||
|
||||
-- End src/controllers/plugins/api/EventType.hpp
|
||||
|
||||
|
@ -38,19 +38,19 @@ c2.EventType = {}
|
|||
|
||||
-- Begin src/common/Channel.hpp
|
||||
|
||||
---@alias c2.ChannelType.None "c2.ChannelType.None"
|
||||
---@alias c2.ChannelType.Direct "c2.ChannelType.Direct"
|
||||
---@alias c2.ChannelType.Twitch "c2.ChannelType.Twitch"
|
||||
---@alias c2.ChannelType.TwitchWhispers "c2.ChannelType.TwitchWhispers"
|
||||
---@alias c2.ChannelType.TwitchWatching "c2.ChannelType.TwitchWatching"
|
||||
---@alias c2.ChannelType.TwitchMentions "c2.ChannelType.TwitchMentions"
|
||||
---@alias c2.ChannelType.TwitchLive "c2.ChannelType.TwitchLive"
|
||||
---@alias c2.ChannelType.TwitchAutomod "c2.ChannelType.TwitchAutomod"
|
||||
---@alias c2.ChannelType.TwitchEnd "c2.ChannelType.TwitchEnd"
|
||||
---@alias c2.ChannelType.Misc "c2.ChannelType.Misc"
|
||||
---@alias c2.ChannelType c2.ChannelType.None|c2.ChannelType.Direct|c2.ChannelType.Twitch|c2.ChannelType.TwitchWhispers|c2.ChannelType.TwitchWatching|c2.ChannelType.TwitchMentions|c2.ChannelType.TwitchLive|c2.ChannelType.TwitchAutomod|c2.ChannelType.TwitchEnd|c2.ChannelType.Misc
|
||||
---@type { None: c2.ChannelType.None, Direct: c2.ChannelType.Direct, Twitch: c2.ChannelType.Twitch, TwitchWhispers: c2.ChannelType.TwitchWhispers, TwitchWatching: c2.ChannelType.TwitchWatching, TwitchMentions: c2.ChannelType.TwitchMentions, TwitchLive: c2.ChannelType.TwitchLive, TwitchAutomod: c2.ChannelType.TwitchAutomod, TwitchEnd: c2.ChannelType.TwitchEnd, Misc: c2.ChannelType.Misc }
|
||||
c2.ChannelType = {}
|
||||
---@enum c2.ChannelType
|
||||
c2.ChannelType = {
|
||||
None = {}, ---@type c2.ChannelType.None
|
||||
Direct = {}, ---@type c2.ChannelType.Direct
|
||||
Twitch = {}, ---@type c2.ChannelType.Twitch
|
||||
TwitchWhispers = {}, ---@type c2.ChannelType.TwitchWhispers
|
||||
TwitchWatching = {}, ---@type c2.ChannelType.TwitchWatching
|
||||
TwitchMentions = {}, ---@type c2.ChannelType.TwitchMentions
|
||||
TwitchLive = {}, ---@type c2.ChannelType.TwitchLive
|
||||
TwitchAutomod = {}, ---@type c2.ChannelType.TwitchAutomod
|
||||
TwitchEnd = {}, ---@type c2.ChannelType.TwitchEnd
|
||||
Misc = {}, ---@type c2.ChannelType.Misc
|
||||
}
|
||||
|
||||
-- End src/common/Channel.hpp
|
||||
|
||||
|
@ -174,90 +174,97 @@ function c2.Channel.by_twitch_id(id) end
|
|||
|
||||
-- Begin src/controllers/plugins/api/HTTPResponse.hpp
|
||||
|
||||
---@class HTTPResponse
|
||||
HTTPResponse = {}
|
||||
---@class c2.HTTPResponse
|
||||
c2.HTTPResponse = {}
|
||||
|
||||
--- Returns the data. This is not guaranteed to be encoded using any
|
||||
--- particular encoding scheme. It's just the bytes the server returned.
|
||||
---
|
||||
function HTTPResponse:data() end
|
||||
---@return string
|
||||
---@nodiscard
|
||||
function c2.HTTPResponse:data() end
|
||||
|
||||
--- Returns the status code.
|
||||
---
|
||||
function HTTPResponse:status() end
|
||||
---@return number|nil
|
||||
---@nodiscard
|
||||
function c2.HTTPResponse:status() end
|
||||
|
||||
--- A somewhat human readable description of an error if such happened
|
||||
---
|
||||
function HTTPResponse:error() end
|
||||
---@return string
|
||||
---@nodiscard
|
||||
function c2.HTTPResponse:error() end
|
||||
|
||||
---@return string
|
||||
function HTTPResponse:__tostring() end
|
||||
---@nodiscard
|
||||
function c2.HTTPResponse:__tostring() end
|
||||
|
||||
-- End src/controllers/plugins/api/HTTPResponse.hpp
|
||||
|
||||
-- Begin src/controllers/plugins/api/HTTPRequest.hpp
|
||||
|
||||
---@alias HTTPCallback fun(result: HTTPResponse): nil
|
||||
---@class HTTPRequest
|
||||
HTTPRequest = {}
|
||||
---@alias c2.HTTPCallback fun(result: c2.HTTPResponse): nil
|
||||
---@class c2.HTTPRequest
|
||||
c2.HTTPRequest = {}
|
||||
|
||||
--- Sets the success callback
|
||||
---
|
||||
---@param callback HTTPCallback Function to call when the HTTP request succeeds
|
||||
function HTTPRequest:on_success(callback) end
|
||||
---@param callback c2.HTTPCallback Function to call when the HTTP request succeeds
|
||||
function c2.HTTPRequest:on_success(callback) end
|
||||
|
||||
--- Sets the failure callback
|
||||
---
|
||||
---@param callback HTTPCallback Function to call when the HTTP request fails or returns a non-ok status
|
||||
function HTTPRequest:on_error(callback) end
|
||||
---@param callback c2.HTTPCallback Function to call when the HTTP request fails or returns a non-ok status
|
||||
function c2.HTTPRequest:on_error(callback) end
|
||||
|
||||
--- Sets the finally callback
|
||||
---
|
||||
---@param callback fun(): nil Function to call when the HTTP request finishes
|
||||
function HTTPRequest:finally(callback) end
|
||||
function c2.HTTPRequest:finally(callback) end
|
||||
|
||||
--- Sets the timeout
|
||||
---
|
||||
---@param timeout integer How long in milliseconds until the times out
|
||||
function HTTPRequest:set_timeout(timeout) end
|
||||
function c2.HTTPRequest:set_timeout(timeout) end
|
||||
|
||||
--- Sets the request payload
|
||||
---
|
||||
---@param data string
|
||||
function HTTPRequest:set_payload(data) end
|
||||
function c2.HTTPRequest:set_payload(data) end
|
||||
|
||||
--- Sets a header in the request
|
||||
---
|
||||
---@param name string
|
||||
---@param value string
|
||||
function HTTPRequest:set_header(name, value) end
|
||||
function c2.HTTPRequest:set_header(name, value) end
|
||||
|
||||
--- Executes the HTTP request
|
||||
---
|
||||
function HTTPRequest:execute() end
|
||||
function c2.HTTPRequest:execute() end
|
||||
|
||||
---@return string
|
||||
function HTTPRequest:__tostring() end
|
||||
function c2.HTTPRequest:__tostring() end
|
||||
|
||||
--- Creates a new HTTPRequest
|
||||
---
|
||||
---@param method HTTPMethod Method to use
|
||||
---@param method c2.HTTPMethod Method to use
|
||||
---@param url string Where to send the request to
|
||||
---@return HTTPRequest
|
||||
function HTTPRequest.create(method, url) end
|
||||
---@return c2.HTTPRequest
|
||||
function c2.HTTPRequest.create(method, url) end
|
||||
|
||||
-- End src/controllers/plugins/api/HTTPRequest.hpp
|
||||
|
||||
-- Begin src/common/network/NetworkCommon.hpp
|
||||
|
||||
---@alias HTTPMethod.Get "HTTPMethod.Get"
|
||||
---@alias HTTPMethod.Post "HTTPMethod.Post"
|
||||
---@alias HTTPMethod.Put "HTTPMethod.Put"
|
||||
---@alias HTTPMethod.Delete "HTTPMethod.Delete"
|
||||
---@alias HTTPMethod.Patch "HTTPMethod.Patch"
|
||||
---@alias HTTPMethod HTTPMethod.Get|HTTPMethod.Post|HTTPMethod.Put|HTTPMethod.Delete|HTTPMethod.Patch
|
||||
---@type { Get: HTTPMethod.Get, Post: HTTPMethod.Post, Put: HTTPMethod.Put, Delete: HTTPMethod.Delete, Patch: HTTPMethod.Patch }
|
||||
HTTPMethod = {}
|
||||
---@enum c2.HTTPMethod
|
||||
c2.HTTPMethod = {
|
||||
Get = {}, ---@type c2.HTTPMethod.Get
|
||||
Post = {}, ---@type c2.HTTPMethod.Post
|
||||
Put = {}, ---@type c2.HTTPMethod.Put
|
||||
Delete = {}, ---@type c2.HTTPMethod.Delete
|
||||
Patch = {}, ---@type c2.HTTPMethod.Patch
|
||||
}
|
||||
|
||||
-- End src/common/network/NetworkCommon.hpp
|
||||
|
||||
|
|
|
@ -61,6 +61,11 @@ chatterino--DescriptionLabel {
|
|||
color: #999;
|
||||
}
|
||||
|
||||
QLabel#description {
|
||||
color: #999;
|
||||
padding-left: 10px;
|
||||
}
|
||||
|
||||
chatterino--NavigationLabel {
|
||||
font-family: "Segoe UI light";
|
||||
font-size: 15px;
|
||||
|
|
23
scripts/make_luals_meta.py
Normal file → Executable file
23
scripts/make_luals_meta.py
Normal file → Executable file
|
@ -1,3 +1,4 @@
|
|||
#!/usr/bin/env python3
|
||||
"""
|
||||
This script generates docs/plugin-meta.lua. It accepts no arguments
|
||||
|
||||
|
@ -242,25 +243,19 @@ def read_file(path: Path, out: TextIOWrapper):
|
|||
)
|
||||
name = header[0].split(" ", 1)[1]
|
||||
printmsg(path, reader.line_no(), f"enum {name}")
|
||||
variants = reader.read_enum_variants()
|
||||
|
||||
vtypes = []
|
||||
for variant in variants:
|
||||
vtype = f'{name}.{variant}'
|
||||
vtypes.append(vtype)
|
||||
out.write(f'---@alias {vtype} "{vtype}"\n')
|
||||
|
||||
out.write(f"---@alias {name} {'|'.join(vtypes)}\n")
|
||||
if header_comment:
|
||||
out.write(f"--- {header_comment}\n")
|
||||
out.write("---@type { ")
|
||||
out.write(f"---@enum {name}\n")
|
||||
out.write(f"{name} = {{\n")
|
||||
out.write(
|
||||
", ".join(
|
||||
[f"{variant}: {typ}" for variant, typ in zip(variants,vtypes)]
|
||||
"\n".join(
|
||||
[
|
||||
f" {variant} = {{}}, ---@type {name}.{variant}"
|
||||
for variant in reader.read_enum_variants()
|
||||
]
|
||||
)
|
||||
)
|
||||
out.write(" }\n")
|
||||
out.write(f"{name} = {{}}\n\n")
|
||||
out.write("\n}\n\n")
|
||||
continue
|
||||
|
||||
# class
|
||||
|
|
|
@ -40,6 +40,7 @@ set(SOURCE_FILES
|
|||
common/WindowDescriptors.cpp
|
||||
common/WindowDescriptors.hpp
|
||||
|
||||
common/enums/MessageContext.hpp
|
||||
common/enums/MessageOverflow.hpp
|
||||
|
||||
common/network/NetworkCommon.cpp
|
||||
|
@ -282,6 +283,9 @@ set(SOURCE_FILES
|
|||
messages/MessageElement.cpp
|
||||
messages/MessageElement.hpp
|
||||
messages/MessageFlag.hpp
|
||||
messages/MessageSimilarity.cpp
|
||||
messages/MessageSimilarity.hpp
|
||||
messages/MessageSink.hpp
|
||||
messages/MessageThread.cpp
|
||||
messages/MessageThread.hpp
|
||||
|
||||
|
@ -527,6 +531,8 @@ set(SOURCE_FILES
|
|||
util/Twitch.hpp
|
||||
util/TypeName.hpp
|
||||
util/Variant.hpp
|
||||
util/VectorMessageSink.cpp
|
||||
util/VectorMessageSink.hpp
|
||||
util/WidgetHelpers.cpp
|
||||
util/WidgetHelpers.hpp
|
||||
util/WindowsHelper.cpp
|
||||
|
@ -714,6 +720,8 @@ set(SOURCE_FILES
|
|||
widgets/settingspages/PluginsPage.hpp
|
||||
widgets/settingspages/SettingsPage.cpp
|
||||
widgets/settingspages/SettingsPage.hpp
|
||||
widgets/settingspages/SettingWidget.cpp
|
||||
widgets/settingspages/SettingWidget.hpp
|
||||
|
||||
widgets/splits/ClosedSplits.cpp
|
||||
widgets/splits/ClosedSplits.hpp
|
||||
|
|
|
@ -3,7 +3,9 @@
|
|||
#include "Application.hpp"
|
||||
#include "messages/Message.hpp"
|
||||
#include "messages/MessageBuilder.hpp"
|
||||
#include "messages/MessageSimilarity.hpp"
|
||||
#include "providers/twitch/IrcMessageHandler.hpp"
|
||||
#include "providers/twitch/TwitchIrcServer.hpp"
|
||||
#include "singletons/Emotes.hpp"
|
||||
#include "singletons/Logging.hpp"
|
||||
#include "singletons/Settings.hpp"
|
||||
|
@ -121,10 +123,10 @@ void Channel::addSystemMessage(const QString &contents)
|
|||
this->addMessage(msg, MessageContext::Original);
|
||||
}
|
||||
|
||||
void Channel::addOrReplaceTimeout(MessagePtr message)
|
||||
void Channel::addOrReplaceTimeout(MessagePtr message, QTime now)
|
||||
{
|
||||
addOrReplaceChannelTimeout(
|
||||
this->getMessageSnapshot(), std::move(message), QTime::currentTime(),
|
||||
this->getMessageSnapshot(), std::move(message), now,
|
||||
[this](auto /*idx*/, auto msg, auto replacement) {
|
||||
this->replaceMessage(msg, replacement);
|
||||
},
|
||||
|
@ -253,21 +255,33 @@ void Channel::fillInMissingMessages(const std::vector<MessagePtr> &messages)
|
|||
}
|
||||
}
|
||||
|
||||
void Channel::replaceMessage(MessagePtr message, MessagePtr replacement)
|
||||
void Channel::replaceMessage(const MessagePtr &message,
|
||||
const MessagePtr &replacement)
|
||||
{
|
||||
int index = this->messages_.replaceItem(message, replacement);
|
||||
|
||||
if (index >= 0)
|
||||
{
|
||||
this->messageReplaced.invoke((size_t)index, replacement);
|
||||
this->messageReplaced.invoke((size_t)index, message, replacement);
|
||||
}
|
||||
}
|
||||
|
||||
void Channel::replaceMessage(size_t index, MessagePtr replacement)
|
||||
void Channel::replaceMessage(size_t index, const MessagePtr &replacement)
|
||||
{
|
||||
if (this->messages_.replaceItem(index, replacement))
|
||||
MessagePtr prev;
|
||||
if (this->messages_.replaceItem(index, replacement, &prev))
|
||||
{
|
||||
this->messageReplaced.invoke(index, replacement);
|
||||
this->messageReplaced.invoke(index, prev, replacement);
|
||||
}
|
||||
}
|
||||
|
||||
void Channel::replaceMessage(size_t hint, const MessagePtr &message,
|
||||
const MessagePtr &replacement)
|
||||
{
|
||||
auto index = this->messages_.replaceItem(hint, message, replacement);
|
||||
if (index >= 0)
|
||||
{
|
||||
this->messageReplaced.invoke(hint, message, replacement);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -287,10 +301,15 @@ void Channel::clearMessages()
|
|||
}
|
||||
|
||||
MessagePtr Channel::findMessage(QString messageID)
|
||||
{
|
||||
return this->findMessageByID(messageID);
|
||||
}
|
||||
|
||||
MessagePtr Channel::findMessageByID(QStringView messageID)
|
||||
{
|
||||
MessagePtr res;
|
||||
|
||||
if (auto msg = this->messages_.rfind([&messageID](const MessagePtr &msg) {
|
||||
if (auto msg = this->messages_.rfind([messageID](const MessagePtr &msg) {
|
||||
return msg->id == messageID;
|
||||
});
|
||||
msg)
|
||||
|
@ -301,6 +320,19 @@ MessagePtr Channel::findMessage(QString messageID)
|
|||
return res;
|
||||
}
|
||||
|
||||
void Channel::applySimilarityFilters(const MessagePtr &message) const
|
||||
{
|
||||
setSimilarityFlags(message, this->messages_.getSnapshot());
|
||||
}
|
||||
|
||||
MessageSinkTraits Channel::sinkTraits() const
|
||||
{
|
||||
return {
|
||||
MessageSinkTrait::AddMentionsToGlobalChannel,
|
||||
MessageSinkTrait::RequiresKnownChannelPointReward,
|
||||
};
|
||||
}
|
||||
|
||||
bool Channel::canSendMessage() const
|
||||
{
|
||||
return false;
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
#pragma once
|
||||
|
||||
#include "common/enums/MessageContext.hpp"
|
||||
#include "controllers/completion/TabCompletionModel.hpp"
|
||||
#include "messages/LimitedQueue.hpp"
|
||||
#include "messages/MessageFlag.hpp"
|
||||
#include "messages/MessageSink.hpp"
|
||||
|
||||
#include <magic_enum/magic_enum.hpp>
|
||||
#include <pajlada/signals/signal.hpp>
|
||||
|
@ -26,15 +28,7 @@ enum class TimeoutStackStyle : int {
|
|||
Default = DontStackBeyondUserMessage,
|
||||
};
|
||||
|
||||
/// Context of the message being added to a channel
|
||||
enum class MessageContext {
|
||||
/// This message is the original
|
||||
Original,
|
||||
/// This message is a repost of a message that has already been added in a channel
|
||||
Repost,
|
||||
};
|
||||
|
||||
class Channel : public std::enable_shared_from_this<Channel>
|
||||
class Channel : public std::enable_shared_from_this<Channel>, public MessageSink
|
||||
{
|
||||
public:
|
||||
// This is for Lua. See scripts/make_luals_meta.py
|
||||
|
@ -55,7 +49,7 @@ public:
|
|||
};
|
||||
|
||||
explicit Channel(const QString &name, Type type);
|
||||
virtual ~Channel();
|
||||
~Channel() override;
|
||||
|
||||
// SIGNALS
|
||||
pajlada::Signals::Signal<const QString &, const QString &, bool &>
|
||||
|
@ -66,7 +60,9 @@ public:
|
|||
pajlada::Signals::Signal<MessagePtr &, std::optional<MessageFlags>>
|
||||
messageAppended;
|
||||
pajlada::Signals::Signal<std::vector<MessagePtr> &> messagesAddedAtStart;
|
||||
pajlada::Signals::Signal<size_t, MessagePtr &> messageReplaced;
|
||||
/// (index, prev-message, replacement)
|
||||
pajlada::Signals::Signal<size_t, const MessagePtr &, const MessagePtr &>
|
||||
messageReplaced;
|
||||
/// Invoked when some number of messages were filled in using time received
|
||||
pajlada::Signals::Signal<const std::vector<MessagePtr> &> filledInMessages;
|
||||
pajlada::Signals::NoArgSignal destroyed;
|
||||
|
@ -85,8 +81,9 @@ public:
|
|||
// overridingFlags can be filled in with flags that should be used instead
|
||||
// of the message's flags. This is useful in case a flag is specific to a
|
||||
// type of split
|
||||
void addMessage(MessagePtr message, MessageContext context,
|
||||
std::optional<MessageFlags> overridingFlags = std::nullopt);
|
||||
void addMessage(
|
||||
MessagePtr message, MessageContext context,
|
||||
std::optional<MessageFlags> overridingFlags = std::nullopt) final;
|
||||
void addMessagesAtStart(const std::vector<MessagePtr> &messages_);
|
||||
|
||||
void addSystemMessage(const QString &contents);
|
||||
|
@ -94,19 +91,28 @@ public:
|
|||
/// Inserts the given messages in order by Message::serverReceivedTime.
|
||||
void fillInMissingMessages(const std::vector<MessagePtr> &messages);
|
||||
|
||||
void addOrReplaceTimeout(MessagePtr message);
|
||||
void disableAllMessages();
|
||||
void replaceMessage(MessagePtr message, MessagePtr replacement);
|
||||
void replaceMessage(size_t index, MessagePtr replacement);
|
||||
void addOrReplaceTimeout(MessagePtr message, QTime now) final;
|
||||
void disableAllMessages() final;
|
||||
void replaceMessage(const MessagePtr &message,
|
||||
const MessagePtr &replacement);
|
||||
void replaceMessage(size_t index, const MessagePtr &replacement);
|
||||
void replaceMessage(size_t hint, const MessagePtr &message,
|
||||
const MessagePtr &replacement);
|
||||
void deleteMessage(QString messageID);
|
||||
|
||||
/// Removes all messages from this channel and invokes #messagesCleared
|
||||
void clearMessages();
|
||||
|
||||
MessagePtr findMessage(QString messageID);
|
||||
[[deprecated("Use findMessageByID instead")]] MessagePtr findMessage(
|
||||
QString messageID);
|
||||
MessagePtr findMessageByID(QStringView messageID) final;
|
||||
|
||||
bool hasMessages() const;
|
||||
|
||||
void applySimilarityFilters(const MessagePtr &message) const final;
|
||||
|
||||
MessageSinkTraits sinkTraits() const final;
|
||||
|
||||
// CHANNEL INFO
|
||||
virtual bool canSendMessage() const;
|
||||
virtual bool isWritable() const; // whether split input will be usable
|
||||
|
|
13
src/common/enums/MessageContext.hpp
Normal file
13
src/common/enums/MessageContext.hpp
Normal file
|
@ -0,0 +1,13 @@
|
|||
#pragma once
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
/// Context of the message being added to a channel
|
||||
enum class MessageContext {
|
||||
/// This message is the original
|
||||
Original,
|
||||
/// This message is a repost of a message that has already been added in a channel
|
||||
Repost,
|
||||
};
|
||||
|
||||
} // namespace chatterino
|
|
@ -16,7 +16,7 @@ using NetworkErrorCallback = std::function<void(NetworkResult)>;
|
|||
using NetworkFinallyCallback = std::function<void()>;
|
||||
|
||||
/**
|
||||
* @exposeenum HTTPMethod
|
||||
* @exposeenum c2.HTTPMethod
|
||||
*/
|
||||
enum class NetworkRequestType {
|
||||
Get,
|
||||
|
|
|
@ -16,11 +16,11 @@ namespace chatterino::lua::api {
|
|||
// NOLINTBEGIN(readability-identifier-naming)
|
||||
|
||||
/**
|
||||
* @lua@alias HTTPCallback fun(result: HTTPResponse): nil
|
||||
* @lua@alias c2.HTTPCallback fun(result: c2.HTTPResponse): nil
|
||||
*/
|
||||
|
||||
/**
|
||||
* @lua@class HTTPRequest
|
||||
* @lua@class c2.HTTPRequest
|
||||
*/
|
||||
class HTTPRequest : public std::enable_shared_from_this<HTTPRequest>
|
||||
{
|
||||
|
@ -61,16 +61,16 @@ public:
|
|||
/**
|
||||
* Sets the success callback
|
||||
*
|
||||
* @lua@param callback HTTPCallback Function to call when the HTTP request succeeds
|
||||
* @exposed HTTPRequest:on_success
|
||||
* @lua@param callback c2.HTTPCallback Function to call when the HTTP request succeeds
|
||||
* @exposed c2.HTTPRequest:on_success
|
||||
*/
|
||||
void on_success(sol::protected_function func);
|
||||
|
||||
/**
|
||||
* Sets the failure callback
|
||||
*
|
||||
* @lua@param callback HTTPCallback Function to call when the HTTP request fails or returns a non-ok status
|
||||
* @exposed HTTPRequest:on_error
|
||||
* @lua@param callback c2.HTTPCallback Function to call when the HTTP request fails or returns a non-ok status
|
||||
* @exposed c2.HTTPRequest:on_error
|
||||
*/
|
||||
void on_error(sol::protected_function func);
|
||||
|
||||
|
@ -78,7 +78,7 @@ public:
|
|||
* Sets the finally callback
|
||||
*
|
||||
* @lua@param callback fun(): nil Function to call when the HTTP request finishes
|
||||
* @exposed HTTPRequest:finally
|
||||
* @exposed c2.HTTPRequest:finally
|
||||
*/
|
||||
void finally(sol::protected_function func);
|
||||
|
||||
|
@ -86,7 +86,7 @@ public:
|
|||
* Sets the timeout
|
||||
*
|
||||
* @lua@param timeout integer How long in milliseconds until the times out
|
||||
* @exposed HTTPRequest:set_timeout
|
||||
* @exposed c2.HTTPRequest:set_timeout
|
||||
*/
|
||||
void set_timeout(int timeout);
|
||||
|
||||
|
@ -94,7 +94,7 @@ public:
|
|||
* Sets the request payload
|
||||
*
|
||||
* @lua@param data string
|
||||
* @exposed HTTPRequest:set_payload
|
||||
* @exposed c2.HTTPRequest:set_payload
|
||||
*/
|
||||
void set_payload(QByteArray payload);
|
||||
|
||||
|
@ -103,19 +103,19 @@ public:
|
|||
*
|
||||
* @lua@param name string
|
||||
* @lua@param value string
|
||||
* @exposed HTTPRequest:set_header
|
||||
* @exposed c2.HTTPRequest:set_header
|
||||
*/
|
||||
void set_header(QByteArray name, QByteArray value);
|
||||
|
||||
/**
|
||||
* Executes the HTTP request
|
||||
*
|
||||
* @exposed HTTPRequest:execute
|
||||
* @exposed c2.HTTPRequest:execute
|
||||
*/
|
||||
void execute(sol::this_state L);
|
||||
/**
|
||||
* @lua@return string
|
||||
* @exposed HTTPRequest:__tostring
|
||||
* @exposed c2.HTTPRequest:__tostring
|
||||
*/
|
||||
QString to_string();
|
||||
|
||||
|
@ -126,11 +126,11 @@ public:
|
|||
/**
|
||||
* Creates a new HTTPRequest
|
||||
*
|
||||
* @lua@param method HTTPMethod Method to use
|
||||
* @lua@param method c2.HTTPMethod Method to use
|
||||
* @lua@param url string Where to send the request to
|
||||
*
|
||||
* @lua@return HTTPRequest
|
||||
* @exposed HTTPRequest.create
|
||||
* @lua@return c2.HTTPRequest
|
||||
* @exposed c2.HTTPRequest.create
|
||||
*/
|
||||
static std::shared_ptr<HTTPRequest> create(sol::this_state L,
|
||||
NetworkRequestType method,
|
||||
|
|
|
@ -15,7 +15,7 @@ namespace chatterino::lua::api {
|
|||
// NOLINTBEGIN(readability-identifier-naming)
|
||||
|
||||
/**
|
||||
* @lua@class HTTPResponse
|
||||
* @lua@class c2.HTTPResponse
|
||||
*/
|
||||
class HTTPResponse
|
||||
{
|
||||
|
@ -38,26 +38,34 @@ public:
|
|||
* Returns the data. This is not guaranteed to be encoded using any
|
||||
* particular encoding scheme. It's just the bytes the server returned.
|
||||
*
|
||||
* @exposed HTTPResponse:data
|
||||
* @lua@return string
|
||||
* @lua@nodiscard
|
||||
* @exposed c2.HTTPResponse:data
|
||||
*/
|
||||
QByteArray data();
|
||||
|
||||
/**
|
||||
* Returns the status code.
|
||||
*
|
||||
* @exposed HTTPResponse:status
|
||||
* @lua@return number|nil
|
||||
* @lua@nodiscard
|
||||
* @exposed c2.HTTPResponse:status
|
||||
*/
|
||||
std::optional<int> status();
|
||||
|
||||
/**
|
||||
* A somewhat human readable description of an error if such happened
|
||||
* @exposed HTTPResponse:error
|
||||
*
|
||||
* @lua@return string
|
||||
* @lua@nodiscard
|
||||
* @exposed c2.HTTPResponse:error
|
||||
*/
|
||||
QString error();
|
||||
|
||||
/**
|
||||
* @lua@return string
|
||||
* @exposed HTTPResponse:__tostring
|
||||
* @lua@nodiscard
|
||||
* @exposed c2.HTTPResponse:__tostring
|
||||
*/
|
||||
QString to_string();
|
||||
};
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include <mutex>
|
||||
#include <optional>
|
||||
#include <shared_mutex>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
namespace chatterino {
|
||||
|
@ -212,9 +213,10 @@ public:
|
|||
*
|
||||
* @param[in] index the index of the item to replace
|
||||
* @param[in] replacement the item to put in place of the item at index
|
||||
* @param[out] prev (optional) the item located at @a index before replacing
|
||||
* @return true if a replacement took place
|
||||
*/
|
||||
bool replaceItem(size_t index, const T &replacement)
|
||||
bool replaceItem(size_t index, const T &replacement, T *prev = nullptr)
|
||||
{
|
||||
std::unique_lock lock(this->mutex_);
|
||||
|
||||
|
@ -223,10 +225,46 @@ public:
|
|||
return false;
|
||||
}
|
||||
|
||||
this->buffer_[index] = replacement;
|
||||
if (prev)
|
||||
{
|
||||
*prev = std::exchange(this->buffer_[index], replacement);
|
||||
}
|
||||
else
|
||||
{
|
||||
this->buffer_[index] = replacement;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Replace the needle with the given item
|
||||
*
|
||||
* @param hint A hint on where the needle _might_ be
|
||||
* @param[in] needle the item to search for
|
||||
* @param[in] replacement the item to replace needle with
|
||||
* @return the index of the replaced item, or -1 if no replacement took place
|
||||
*/
|
||||
int replaceItem(size_t hint, const T &needle, const T &replacement)
|
||||
{
|
||||
std::unique_lock lock(this->mutex_);
|
||||
|
||||
if (hint < this->buffer_.size() && this->buffer_[hint] == needle)
|
||||
{
|
||||
this->buffer_[hint] = replacement;
|
||||
return static_cast<int>(hint);
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < this->buffer_.size(); ++i)
|
||||
{
|
||||
if (this->buffer_[i] == needle)
|
||||
{
|
||||
this->buffer_[i] = replacement;
|
||||
return static_cast<int>(i);
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Inserts the given item before another item
|
||||
*
|
||||
|
@ -315,6 +353,32 @@ public:
|
|||
return std::nullopt;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Find an item with a hint
|
||||
*
|
||||
* @param hint A hint on where the needle _might_ be
|
||||
* @param predicate that will used to find the item
|
||||
* @return the item and its index or none if it's not found
|
||||
*/
|
||||
std::optional<std::pair<size_t, T>> find(size_t hint, auto &&predicate)
|
||||
{
|
||||
std::unique_lock lock(this->mutex_);
|
||||
|
||||
if (hint < this->buffer_.size() && predicate(this->buffer_[hint]))
|
||||
{
|
||||
return std::pair{hint, this->buffer_[hint]};
|
||||
};
|
||||
|
||||
for (size_t i = 0; i < this->buffer_.size(); i++)
|
||||
{
|
||||
if (predicate(this->buffer_[i]))
|
||||
{
|
||||
return std::pair{i, this->buffer_[i]};
|
||||
}
|
||||
}
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns the first item matching a predicate, checking in reverse
|
||||
*
|
||||
|
|
121
src/messages/MessageSimilarity.cpp
Normal file
121
src/messages/MessageSimilarity.cpp
Normal file
|
@ -0,0 +1,121 @@
|
|||
#include "messages/MessageSimilarity.hpp"
|
||||
|
||||
#include "Application.hpp"
|
||||
#include "controllers/accounts/AccountController.hpp"
|
||||
#include "messages/LimitedQueueSnapshot.hpp" // IWYU pragma: keep
|
||||
#include "providers/twitch/TwitchAccount.hpp"
|
||||
#include "singletons/Settings.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
|
||||
namespace {
|
||||
|
||||
using namespace chatterino;
|
||||
|
||||
float relativeSimilarity(QStringView str1, QStringView str2)
|
||||
{
|
||||
using SizeType = QStringView::size_type;
|
||||
|
||||
// Longest Common Substring Problem
|
||||
std::vector<std::vector<int>> tree(str1.size(),
|
||||
std::vector<int>(str2.size(), 0));
|
||||
int z = 0;
|
||||
|
||||
for (SizeType i = 0; i < str1.size(); ++i)
|
||||
{
|
||||
for (SizeType j = 0; j < str2.size(); ++j)
|
||||
{
|
||||
if (str1[i] == str2[j])
|
||||
{
|
||||
if (i == 0 || j == 0)
|
||||
{
|
||||
tree[i][j] = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
tree[i][j] = tree[i - 1][j - 1] + 1;
|
||||
}
|
||||
z = std::max(tree[i][j], z);
|
||||
}
|
||||
else
|
||||
{
|
||||
tree[i][j] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ensure that no div by 0
|
||||
if (z == 0)
|
||||
{
|
||||
return 0.F;
|
||||
}
|
||||
|
||||
auto div = std::max<>({static_cast<SizeType>(1), str1.size(), str2.size()});
|
||||
|
||||
return float(z) / float(div);
|
||||
}
|
||||
|
||||
template <std::ranges::bidirectional_range T>
|
||||
float inMessages(const MessagePtr &msg, const T &messages)
|
||||
{
|
||||
float similarityPercent = 0.0F;
|
||||
|
||||
for (const auto &prevMsg :
|
||||
messages | std::views::reverse |
|
||||
std::views::take(getSettings()->hideSimilarMaxMessagesToCheck))
|
||||
{
|
||||
if (prevMsg->parseTime.secsTo(QTime::currentTime()) >=
|
||||
getSettings()->hideSimilarMaxDelay)
|
||||
{
|
||||
break;
|
||||
}
|
||||
if (getSettings()->hideSimilarBySameUser &&
|
||||
msg->loginName != prevMsg->loginName)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
similarityPercent = std::max(
|
||||
similarityPercent,
|
||||
relativeSimilarity(msg->messageText, prevMsg->messageText));
|
||||
}
|
||||
|
||||
return similarityPercent;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
template <std::ranges::bidirectional_range T>
|
||||
void setSimilarityFlags(const MessagePtr &message, const T &messages)
|
||||
{
|
||||
if (getSettings()->similarityEnabled)
|
||||
{
|
||||
bool isMyself =
|
||||
message->loginName ==
|
||||
getApp()->getAccounts()->twitch.getCurrent()->getUserName();
|
||||
bool hideMyself = getSettings()->hideSimilarMyself;
|
||||
|
||||
if (isMyself && !hideMyself)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (inMessages(message, messages) > getSettings()->similarityPercentage)
|
||||
{
|
||||
message->flags.set(MessageFlag::Similar);
|
||||
if (getSettings()->colorSimilarDisabled)
|
||||
{
|
||||
message->flags.set(MessageFlag::Disabled);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template void setSimilarityFlags<std::vector<MessagePtr>>(
|
||||
const MessagePtr &msg, const std::vector<MessagePtr> &messages);
|
||||
template void setSimilarityFlags<LimitedQueueSnapshot<MessagePtr>>(
|
||||
const MessagePtr &msg, const LimitedQueueSnapshot<MessagePtr> &messages);
|
||||
|
||||
} // namespace chatterino
|
11
src/messages/MessageSimilarity.hpp
Normal file
11
src/messages/MessageSimilarity.hpp
Normal file
|
@ -0,0 +1,11 @@
|
|||
#pragma once
|
||||
|
||||
#include "messages/Message.hpp"
|
||||
|
||||
#include <ranges>
|
||||
namespace chatterino {
|
||||
|
||||
template <std::ranges::bidirectional_range T>
|
||||
void setSimilarityFlags(const MessagePtr &message, const T &messages);
|
||||
|
||||
} // namespace chatterino
|
67
src/messages/MessageSink.hpp
Normal file
67
src/messages/MessageSink.hpp
Normal file
|
@ -0,0 +1,67 @@
|
|||
#pragma once
|
||||
|
||||
#include "common/enums/MessageContext.hpp"
|
||||
#include "common/FlagsEnum.hpp"
|
||||
#include "messages/MessageFlag.hpp"
|
||||
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
|
||||
class QStringView;
|
||||
class QTime;
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
struct Message;
|
||||
using MessagePtr = std::shared_ptr<const Message>;
|
||||
|
||||
enum class MessageSinkTrait : uint8_t {
|
||||
None = 0,
|
||||
|
||||
/// Messages with the `Highlighted` and `ShowInMentions` flags should be
|
||||
/// added to the global mentions channel when encountered.
|
||||
AddMentionsToGlobalChannel = 1 << 0,
|
||||
|
||||
/// A channel-point redemption whose reward is not yet known should not be
|
||||
/// added to this sink, but queued in the corresponding TwitchChannel
|
||||
/// (`addQueuedRedemption`).
|
||||
RequiresKnownChannelPointReward = 1 << 1,
|
||||
};
|
||||
using MessageSinkTraits = FlagsEnum<MessageSinkTrait>;
|
||||
|
||||
/// A generic interface for a managed buffer of `Message`s
|
||||
class MessageSink
|
||||
{
|
||||
public:
|
||||
virtual ~MessageSink() = default;
|
||||
|
||||
/// Add a message to this sink
|
||||
///
|
||||
/// @param message The message to add (non-null)
|
||||
/// @param ctx The context in which this message is being added.
|
||||
/// @param overridingFlags
|
||||
virtual void addMessage(
|
||||
MessagePtr message, MessageContext ctx,
|
||||
std::optional<MessageFlags> overridingFlags = std::nullopt) = 0;
|
||||
|
||||
/// Adds a timeout message or merges it into an existing one
|
||||
virtual void addOrReplaceTimeout(MessagePtr clearchatMessage,
|
||||
QTime now) = 0;
|
||||
|
||||
/// Flags all messages as `Disabled`
|
||||
virtual void disableAllMessages() = 0;
|
||||
|
||||
/// Searches for similar messages and flags this message as similar
|
||||
/// (based on the current settings).
|
||||
virtual void applySimilarityFilters(const MessagePtr &message) const = 0;
|
||||
|
||||
/// @brief Searches for a message by an ID
|
||||
///
|
||||
/// If there is no message found, an empty shared-pointer is returned.
|
||||
virtual MessagePtr findMessageByID(QStringView id) = 0;
|
||||
|
||||
/// Behaviour to be exercised when parsing/building messages for this sink.
|
||||
virtual MessageSinkTraits sinkTraits() const = 0;
|
||||
};
|
||||
|
||||
} // namespace chatterino
|
|
@ -3,7 +3,9 @@
|
|||
#include "common/Env.hpp"
|
||||
#include "messages/MessageBuilder.hpp"
|
||||
#include "providers/twitch/IrcMessageHandler.hpp"
|
||||
#include "providers/twitch/TwitchChannel.hpp"
|
||||
#include "util/Helpers.hpp"
|
||||
#include "util/VectorMessageSink.hpp"
|
||||
|
||||
#include <QJsonArray>
|
||||
#include <QUrlQuery>
|
||||
|
@ -40,7 +42,13 @@ std::vector<Communi::IrcMessage *> parseRecentMessages(
|
|||
std::vector<MessagePtr> buildRecentMessages(
|
||||
std::vector<Communi::IrcMessage *> &messages, Channel *channel)
|
||||
{
|
||||
std::vector<MessagePtr> allBuiltMessages;
|
||||
VectorMessageSink sink({}, MessageFlag::RecentMessage);
|
||||
|
||||
auto *twitchChannel = dynamic_cast<TwitchChannel *>(channel);
|
||||
if (!twitchChannel)
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
for (auto *message : messages)
|
||||
{
|
||||
|
@ -58,24 +66,16 @@ std::vector<MessagePtr> buildRecentMessages(
|
|||
auto msg = makeSystemMessage(
|
||||
QLocale().toString(msgDate, QLocale::LongFormat),
|
||||
QTime(0, 0));
|
||||
msg->flags.set(MessageFlag::RecentMessage);
|
||||
allBuiltMessages.emplace_back(msg);
|
||||
sink.addMessage(msg, MessageContext::Original);
|
||||
}
|
||||
}
|
||||
|
||||
auto builtMessages = IrcMessageHandler::parseMessageWithReply(
|
||||
channel, message, allBuiltMessages);
|
||||
|
||||
for (const auto &builtMessage : builtMessages)
|
||||
{
|
||||
builtMessage->flags.set(MessageFlag::RecentMessage);
|
||||
allBuiltMessages.emplace_back(builtMessage);
|
||||
}
|
||||
IrcMessageHandler::parseMessageInto(message, sink, twitchChannel);
|
||||
|
||||
message->deleteLater();
|
||||
}
|
||||
|
||||
return allBuiltMessages;
|
||||
return std::move(sink).takeMessages();
|
||||
}
|
||||
|
||||
// Returns the URL to be used for querying the Recent Messages API for the
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -16,6 +16,7 @@ struct Message;
|
|||
using MessagePtr = std::shared_ptr<const Message>;
|
||||
class TwitchChannel;
|
||||
class TwitchMessageBuilder;
|
||||
class MessageSink;
|
||||
|
||||
struct ClearChatMessage {
|
||||
MessagePtr message;
|
||||
|
@ -33,30 +34,34 @@ public:
|
|||
* Parse an IRC message into 0 or more Chatterino messages
|
||||
* Takes previously loaded messages into consideration to add reply contexts
|
||||
**/
|
||||
static std::vector<MessagePtr> parseMessageWithReply(
|
||||
Channel *channel, Communi::IrcMessage *message,
|
||||
std::vector<MessagePtr> &otherLoaded);
|
||||
static void parseMessageInto(Communi::IrcMessage *message,
|
||||
MessageSink &sink, TwitchChannel *channel);
|
||||
|
||||
void handlePrivMessage(Communi::IrcPrivateMessage *message,
|
||||
ITwitchIrcServer &twitchServer);
|
||||
static void parsePrivMessageInto(Communi::IrcPrivateMessage *message,
|
||||
MessageSink &sink, TwitchChannel *channel);
|
||||
|
||||
void handleRoomStateMessage(Communi::IrcMessage *message);
|
||||
void handleClearChatMessage(Communi::IrcMessage *message);
|
||||
void handleClearMessageMessage(Communi::IrcMessage *message);
|
||||
void handleUserStateMessage(Communi::IrcMessage *message);
|
||||
void handleWhisperMessage(Communi::IrcMessage *ircMessage);
|
||||
|
||||
void handleWhisperMessage(Communi::IrcMessage *ircMessage);
|
||||
void handleUserNoticeMessage(Communi::IrcMessage *message,
|
||||
ITwitchIrcServer &twitchServer);
|
||||
static void parseUserNoticeMessageInto(Communi::IrcMessage *message,
|
||||
MessageSink &sink,
|
||||
TwitchChannel *channel);
|
||||
|
||||
void handleNoticeMessage(Communi::IrcNoticeMessage *message);
|
||||
|
||||
void handleJoinMessage(Communi::IrcMessage *message);
|
||||
void handlePartMessage(Communi::IrcMessage *message);
|
||||
|
||||
void addMessage(Communi::IrcMessage *message, const ChannelPtr &chan,
|
||||
const QString &originalContent, ITwitchIrcServer &server,
|
||||
bool isSub, bool isAction);
|
||||
static void addMessage(Communi::IrcMessage *message, MessageSink &sink,
|
||||
TwitchChannel *chan, const QString &originalContent,
|
||||
ITwitchIrcServer &twitch, bool isSub, bool isAction);
|
||||
|
||||
private:
|
||||
static float similarity(const MessagePtr &msg,
|
||||
|
|
|
@ -452,8 +452,8 @@ void TwitchChannel::addChannelPointReward(const ChannelPointReward &reward)
|
|||
if (reward.id == msg.rewardID)
|
||||
{
|
||||
IrcMessageHandler::instance().addMessage(
|
||||
msg.message.get(), shared_from_this(),
|
||||
msg.originalContent, *server, false, false);
|
||||
msg.message.get(), *this, this, msg.originalContent,
|
||||
*server, false, false);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -1356,8 +1356,6 @@ void TwitchChannel::loadRecentMessages()
|
|||
{
|
||||
msgs.push_back(msg);
|
||||
}
|
||||
|
||||
tc->addRecentChatter(msg->displayName);
|
||||
}
|
||||
|
||||
getApp()->getTwitch()->getMentionsChannel()->fillInMissingMessages(
|
||||
|
|
|
@ -312,7 +312,7 @@ void TwitchIrcServer::initialize()
|
|||
postToThread([chan, action] {
|
||||
MessageBuilder msg(action);
|
||||
msg->flags.set(MessageFlag::PubSub);
|
||||
chan->addOrReplaceTimeout(msg.release());
|
||||
chan->addOrReplaceTimeout(msg.release(), QTime::currentTime());
|
||||
});
|
||||
});
|
||||
|
||||
|
|
86
src/util/VectorMessageSink.cpp
Normal file
86
src/util/VectorMessageSink.cpp
Normal file
|
@ -0,0 +1,86 @@
|
|||
#include "util/VectorMessageSink.hpp"
|
||||
|
||||
#include "messages/MessageSimilarity.hpp"
|
||||
#include "util/ChannelHelpers.hpp"
|
||||
|
||||
#include <cassert>
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
VectorMessageSink::VectorMessageSink(MessageSinkTraits traits,
|
||||
MessageFlags additionalFlags)
|
||||
: additionalFlags(additionalFlags)
|
||||
, traits(traits){};
|
||||
VectorMessageSink::~VectorMessageSink() = default;
|
||||
|
||||
void VectorMessageSink::addMessage(MessagePtr message, MessageContext ctx,
|
||||
std::optional<MessageFlags> overridingFlags)
|
||||
{
|
||||
assert(!overridingFlags.has_value());
|
||||
assert(ctx == MessageContext::Original);
|
||||
|
||||
message->flags.set(this->additionalFlags);
|
||||
this->messages_.emplace_back(std::move(message));
|
||||
}
|
||||
|
||||
void VectorMessageSink::addOrReplaceTimeout(MessagePtr clearchatMessage,
|
||||
QTime now)
|
||||
{
|
||||
addOrReplaceChannelTimeout(
|
||||
this->messages_, std::move(clearchatMessage), now,
|
||||
[&](auto idx, auto /*msg*/, auto &&replacement) {
|
||||
replacement->flags.set(this->additionalFlags);
|
||||
this->messages_[idx] = replacement;
|
||||
},
|
||||
[&](auto &&msg) {
|
||||
this->messages_.emplace_back(msg);
|
||||
},
|
||||
false);
|
||||
}
|
||||
|
||||
void VectorMessageSink::disableAllMessages()
|
||||
{
|
||||
if (this->additionalFlags.has(MessageFlag::RecentMessage))
|
||||
{
|
||||
return; // don't disable recent messages
|
||||
}
|
||||
|
||||
for (const auto &msg : this->messages_)
|
||||
{
|
||||
msg->flags.set(MessageFlag::Disabled);
|
||||
}
|
||||
}
|
||||
|
||||
void VectorMessageSink::applySimilarityFilters(const MessagePtr &message) const
|
||||
{
|
||||
setSimilarityFlags(message, this->messages_);
|
||||
}
|
||||
|
||||
MessagePtr VectorMessageSink::findMessageByID(QStringView id)
|
||||
{
|
||||
for (const auto &msg : this->messages_ | std::views::reverse)
|
||||
{
|
||||
if (msg->id == id)
|
||||
{
|
||||
return msg;
|
||||
}
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
const std::vector<MessagePtr> &VectorMessageSink::messages() const
|
||||
{
|
||||
return this->messages_;
|
||||
}
|
||||
|
||||
std::vector<MessagePtr> VectorMessageSink::takeMessages() &&
|
||||
{
|
||||
return std::move(this->messages_);
|
||||
}
|
||||
|
||||
MessageSinkTraits VectorMessageSink::sinkTraits() const
|
||||
{
|
||||
return this->traits;
|
||||
}
|
||||
|
||||
} // namespace chatterino
|
36
src/util/VectorMessageSink.hpp
Normal file
36
src/util/VectorMessageSink.hpp
Normal file
|
@ -0,0 +1,36 @@
|
|||
#pragma once
|
||||
|
||||
#include "messages/MessageSink.hpp"
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
class VectorMessageSink final : public MessageSink
|
||||
{
|
||||
public:
|
||||
VectorMessageSink(MessageSinkTraits traits = {},
|
||||
MessageFlags additionalFlags = {});
|
||||
~VectorMessageSink() override;
|
||||
|
||||
void addMessage(
|
||||
MessagePtr message, MessageContext ctx,
|
||||
std::optional<MessageFlags> overridingFlags = std::nullopt) override;
|
||||
void addOrReplaceTimeout(MessagePtr clearchatMessage, QTime now) override;
|
||||
|
||||
void disableAllMessages() override;
|
||||
|
||||
void applySimilarityFilters(const MessagePtr &message) const override;
|
||||
|
||||
MessagePtr findMessageByID(QStringView id) override;
|
||||
|
||||
MessageSinkTraits sinkTraits() const override;
|
||||
|
||||
const std::vector<MessagePtr> &messages() const;
|
||||
std::vector<MessagePtr> takeMessages() &&;
|
||||
|
||||
private:
|
||||
std::vector<MessagePtr> messages_;
|
||||
MessageFlags additionalFlags;
|
||||
MessageSinkTraits traits;
|
||||
};
|
||||
|
||||
} // namespace chatterino
|
|
@ -204,7 +204,7 @@ void Notebook::duplicatePage(QWidget *page)
|
|||
{
|
||||
newTabPosition = tabPosition + 1;
|
||||
}
|
||||
auto newTabHighlightState = item->tab->highlightState();
|
||||
|
||||
QString newTabTitle = "";
|
||||
if (item->tab->hasCustomTitle())
|
||||
{
|
||||
|
@ -213,7 +213,7 @@ void Notebook::duplicatePage(QWidget *page)
|
|||
|
||||
auto *tab =
|
||||
this->addPageAt(newContainer, newTabPosition, newTabTitle, false);
|
||||
tab->setHighlightState(newTabHighlightState);
|
||||
tab->copyHighlightStateAndSourcesFrom(item->tab);
|
||||
|
||||
newContainer->setTab(tab);
|
||||
}
|
||||
|
|
|
@ -967,10 +967,10 @@ void ChannelView::setChannel(const ChannelPtr &underlyingChannel)
|
|||
|
||||
this->channelConnections_.managedConnect(
|
||||
underlyingChannel->messageReplaced,
|
||||
[this](auto index, const auto &replacement) {
|
||||
[this](auto index, const auto &prev, const auto &replacement) {
|
||||
if (this->shouldIncludeMessage(replacement))
|
||||
{
|
||||
this->channel_->replaceMessage(index, replacement);
|
||||
this->channel_->replaceMessage(index, prev, replacement);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -1051,8 +1051,9 @@ void ChannelView::setChannel(const ChannelPtr &underlyingChannel)
|
|||
// on message replaced
|
||||
this->channelConnections_.managedConnect(
|
||||
this->channel_->messageReplaced,
|
||||
[this](size_t index, MessagePtr replacement) {
|
||||
this->messageReplaced(index, replacement);
|
||||
[this](size_t index, const MessagePtr &prev,
|
||||
const MessagePtr &replacement) {
|
||||
this->messageReplaced(index, prev, replacement);
|
||||
});
|
||||
|
||||
// on messages filled in
|
||||
|
@ -1063,6 +1064,8 @@ void ChannelView::setChannel(const ChannelPtr &underlyingChannel)
|
|||
|
||||
this->underlyingChannel_ = underlyingChannel;
|
||||
|
||||
this->updateID();
|
||||
|
||||
this->performLayout();
|
||||
this->queueUpdate();
|
||||
|
||||
|
@ -1081,6 +1084,8 @@ void ChannelView::setChannel(const ChannelPtr &underlyingChannel)
|
|||
void ChannelView::setFilters(const QList<QUuid> &ids)
|
||||
{
|
||||
this->channelFilters_ = std::make_shared<FilterSet>(ids);
|
||||
|
||||
this->updateID();
|
||||
}
|
||||
|
||||
QList<QUuid> ChannelView::getFilterIds() const
|
||||
|
@ -1258,19 +1263,21 @@ void ChannelView::messageAddedAtStart(std::vector<MessagePtr> &messages)
|
|||
this->queueLayout();
|
||||
}
|
||||
|
||||
void ChannelView::messageReplaced(size_t index, MessagePtr &replacement)
|
||||
void ChannelView::messageReplaced(size_t hint, const MessagePtr &prev,
|
||||
const MessagePtr &replacement)
|
||||
{
|
||||
auto oMessage = this->messages_.get(index);
|
||||
if (!oMessage)
|
||||
auto optItem = this->messages_.find(hint, [&](const auto &it) {
|
||||
return it->getMessagePtr() == prev;
|
||||
});
|
||||
if (!optItem)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
auto message = *oMessage;
|
||||
const auto &[index, oldItem] = *optItem;
|
||||
|
||||
auto newItem = std::make_shared<MessageLayout>(replacement);
|
||||
|
||||
if (message->flags.has(MessageLayoutFlag::AlternateBackground))
|
||||
if (oldItem->flags.has(MessageLayoutFlag::AlternateBackground))
|
||||
{
|
||||
newItem->flags.set(MessageLayoutFlag::AlternateBackground);
|
||||
}
|
||||
|
@ -1278,7 +1285,7 @@ void ChannelView::messageReplaced(size_t index, MessagePtr &replacement)
|
|||
this->scrollBar_->replaceHighlight(index,
|
||||
replacement->getScrollBarHighlight());
|
||||
|
||||
this->messages_.replaceItem(message, newItem);
|
||||
this->messages_.replaceItem(index, newItem);
|
||||
this->queueLayout();
|
||||
}
|
||||
|
||||
|
@ -3240,4 +3247,27 @@ void ChannelView::pendingLinkInfoStateChanged()
|
|||
this->tooltipWidget_->applyLastBoundsCheck();
|
||||
}
|
||||
|
||||
void ChannelView::updateID()
|
||||
{
|
||||
if (!this->underlyingChannel_)
|
||||
{
|
||||
// cannot update
|
||||
return;
|
||||
}
|
||||
|
||||
std::size_t seed = 0;
|
||||
auto first = qHash(this->underlyingChannel_->getName());
|
||||
auto second = qHash(this->getFilterIds());
|
||||
|
||||
boost::hash_combine(seed, first);
|
||||
boost::hash_combine(seed, second);
|
||||
|
||||
this->id_ = seed;
|
||||
}
|
||||
|
||||
ChannelView::ChannelViewID ChannelView::getID() const
|
||||
{
|
||||
return this->id_;
|
||||
}
|
||||
|
||||
} // namespace chatterino
|
||||
|
|
|
@ -212,6 +212,14 @@ public:
|
|||
|
||||
Scrollbar *scrollbar();
|
||||
|
||||
using ChannelViewID = std::size_t;
|
||||
///
|
||||
/// \brief Get the ID of this ChannelView
|
||||
///
|
||||
/// The ID is made of the underlying channel's name
|
||||
/// combined with the filter set IDs
|
||||
ChannelViewID getID() const;
|
||||
|
||||
pajlada::Signals::Signal<QMouseEvent *> mouseDown;
|
||||
pajlada::Signals::NoArgSignal selectionChanged;
|
||||
pajlada::Signals::Signal<HighlightState> tabHighlightRequested;
|
||||
|
@ -268,7 +276,8 @@ private:
|
|||
std::optional<MessageFlags> overridingFlags);
|
||||
void messageAddedAtStart(std::vector<MessagePtr> &messages);
|
||||
void messageRemoveFromStart(MessagePtr &message);
|
||||
void messageReplaced(size_t index, MessagePtr &replacement);
|
||||
void messageReplaced(size_t hint, const MessagePtr &prev,
|
||||
const MessagePtr &replacement);
|
||||
void messagesUpdated();
|
||||
|
||||
void performLayout(bool causedByScrollbar = false,
|
||||
|
@ -314,6 +323,9 @@ private:
|
|||
void showReplyThreadPopup(const MessagePtr &message);
|
||||
bool canReplyToMessages() const;
|
||||
|
||||
void updateID();
|
||||
ChannelViewID id_{};
|
||||
|
||||
bool layoutQueued_ = false;
|
||||
bool bufferInvalidationQueued_ = false;
|
||||
|
||||
|
@ -375,7 +387,7 @@ private:
|
|||
FilterSetPtr channelFilters_;
|
||||
|
||||
// Returns true if message should be included
|
||||
bool shouldIncludeMessage(const MessagePtr &m) const;
|
||||
bool shouldIncludeMessage(const MessagePtr &message) const;
|
||||
|
||||
// Returns whether the scrollbar should have highlights
|
||||
bool showScrollbarHighlights() const;
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include "widgets/helper/NotebookTab.hpp"
|
||||
|
||||
#include "Application.hpp"
|
||||
#include "common/Channel.hpp"
|
||||
#include "common/Common.hpp"
|
||||
#include "controllers/hotkeys/HotkeyCategory.hpp"
|
||||
#include "controllers/hotkeys/HotkeyController.hpp"
|
||||
|
@ -12,9 +13,11 @@
|
|||
#include "widgets/dialogs/SettingsDialog.hpp"
|
||||
#include "widgets/Notebook.hpp"
|
||||
#include "widgets/splits/DraggedSplit.hpp"
|
||||
#include "widgets/splits/Split.hpp"
|
||||
#include "widgets/splits/SplitContainer.hpp"
|
||||
|
||||
#include <boost/bind/bind.hpp>
|
||||
#include <boost/container_hash/hash.hpp>
|
||||
#include <QAbstractAnimation>
|
||||
#include <QApplication>
|
||||
#include <QDebug>
|
||||
|
@ -302,10 +305,134 @@ bool NotebookTab::isSelected() const
|
|||
return this->selected_;
|
||||
}
|
||||
|
||||
void NotebookTab::removeHighlightStateChangeSources(
|
||||
const HighlightSources &toRemove)
|
||||
{
|
||||
for (const auto &[source, _] : toRemove)
|
||||
{
|
||||
this->removeHighlightSource(source);
|
||||
}
|
||||
}
|
||||
|
||||
void NotebookTab::removeHighlightSource(
|
||||
const ChannelView::ChannelViewID &source)
|
||||
{
|
||||
this->highlightSources_.erase(source);
|
||||
}
|
||||
|
||||
void NotebookTab::newHighlightSourceAdded(const ChannelView &channelViewSource)
|
||||
{
|
||||
auto channelViewId = channelViewSource.getID();
|
||||
this->removeHighlightSource(channelViewId);
|
||||
this->updateHighlightStateDueSourcesChange();
|
||||
|
||||
auto *splitNotebook = dynamic_cast<SplitNotebook *>(this->notebook_);
|
||||
if (splitNotebook)
|
||||
{
|
||||
for (int i = 0; i < splitNotebook->getPageCount(); ++i)
|
||||
{
|
||||
auto *splitContainer =
|
||||
dynamic_cast<SplitContainer *>(splitNotebook->getPageAt(i));
|
||||
if (splitContainer)
|
||||
{
|
||||
auto *tab = splitContainer->getTab();
|
||||
if (tab && tab != this)
|
||||
{
|
||||
tab->removeHighlightSource(channelViewId);
|
||||
tab->updateHighlightStateDueSourcesChange();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void NotebookTab::updateHighlightStateDueSourcesChange()
|
||||
{
|
||||
if (std::ranges::any_of(this->highlightSources_, [](const auto &keyval) {
|
||||
return keyval.second == HighlightState::Highlighted;
|
||||
}))
|
||||
{
|
||||
assert(this->highlightState_ == HighlightState::Highlighted);
|
||||
return;
|
||||
}
|
||||
|
||||
if (std::ranges::any_of(this->highlightSources_, [](const auto &keyval) {
|
||||
return keyval.second == HighlightState::NewMessage;
|
||||
}))
|
||||
{
|
||||
if (this->highlightState_ != HighlightState::NewMessage)
|
||||
{
|
||||
this->highlightState_ = HighlightState::NewMessage;
|
||||
this->update();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (this->highlightState_ != HighlightState::None)
|
||||
{
|
||||
this->highlightState_ = HighlightState::None;
|
||||
this->update();
|
||||
}
|
||||
}
|
||||
|
||||
assert(this->highlightState_ != HighlightState::Highlighted);
|
||||
}
|
||||
|
||||
void NotebookTab::copyHighlightStateAndSourcesFrom(const NotebookTab *sourceTab)
|
||||
{
|
||||
if (this->isSelected())
|
||||
{
|
||||
assert(this->highlightSources_.empty());
|
||||
assert(this->highlightState_ == HighlightState::None);
|
||||
return;
|
||||
}
|
||||
|
||||
this->highlightSources_ = sourceTab->highlightSources_;
|
||||
|
||||
if (!this->highlightEnabled_ &&
|
||||
sourceTab->highlightState_ == HighlightState::NewMessage)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (this->highlightState_ == sourceTab->highlightState_ ||
|
||||
this->highlightState_ == HighlightState::Highlighted)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
this->highlightState_ = sourceTab->highlightState_;
|
||||
this->update();
|
||||
}
|
||||
|
||||
void NotebookTab::setSelected(bool value)
|
||||
{
|
||||
this->selected_ = value;
|
||||
|
||||
if (value)
|
||||
{
|
||||
auto *splitNotebook = dynamic_cast<SplitNotebook *>(this->notebook_);
|
||||
if (splitNotebook)
|
||||
{
|
||||
for (int i = 0; i < splitNotebook->getPageCount(); ++i)
|
||||
{
|
||||
auto *splitContainer =
|
||||
dynamic_cast<SplitContainer *>(splitNotebook->getPageAt(i));
|
||||
if (splitContainer)
|
||||
{
|
||||
auto *tab = splitContainer->getTab();
|
||||
if (tab && tab != this)
|
||||
{
|
||||
tab->removeHighlightStateChangeSources(
|
||||
this->highlightSources_);
|
||||
tab->updateHighlightStateDueSourcesChange();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this->highlightSources_.clear();
|
||||
this->highlightState_ = HighlightState::None;
|
||||
|
||||
this->update();
|
||||
|
@ -358,13 +485,22 @@ bool NotebookTab::isLive() const
|
|||
return this->isLive_;
|
||||
}
|
||||
|
||||
HighlightState NotebookTab::highlightState() const
|
||||
{
|
||||
return this->highlightState_;
|
||||
}
|
||||
|
||||
void NotebookTab::setHighlightState(HighlightState newHighlightStyle)
|
||||
{
|
||||
if (this->isSelected())
|
||||
{
|
||||
assert(this->highlightSources_.empty());
|
||||
assert(this->highlightState_ == HighlightState::None);
|
||||
return;
|
||||
}
|
||||
|
||||
this->highlightSources_.clear();
|
||||
|
||||
if (!this->highlightEnabled_ &&
|
||||
newHighlightStyle == HighlightState::NewMessage)
|
||||
{
|
||||
|
@ -381,9 +517,79 @@ void NotebookTab::setHighlightState(HighlightState newHighlightStyle)
|
|||
this->update();
|
||||
}
|
||||
|
||||
HighlightState NotebookTab::highlightState() const
|
||||
void NotebookTab::updateHighlightState(HighlightState newHighlightStyle,
|
||||
const ChannelView &channelViewSource)
|
||||
{
|
||||
return this->highlightState_;
|
||||
if (this->isSelected())
|
||||
{
|
||||
assert(this->highlightSources_.empty());
|
||||
assert(this->highlightState_ == HighlightState::None);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this->shouldMessageHighlight(channelViewSource))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this->highlightEnabled_ &&
|
||||
newHighlightStyle == HighlightState::NewMessage)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// message is highlighting unvisible tab
|
||||
|
||||
auto channelViewId = channelViewSource.getID();
|
||||
|
||||
switch (newHighlightStyle)
|
||||
{
|
||||
case HighlightState::Highlighted:
|
||||
// override lower states
|
||||
this->highlightSources_.insert_or_assign(channelViewId,
|
||||
newHighlightStyle);
|
||||
case HighlightState::NewMessage: {
|
||||
// only insert if no state already there to avoid overriding
|
||||
if (!this->highlightSources_.contains(channelViewId))
|
||||
{
|
||||
this->highlightSources_.emplace(channelViewId,
|
||||
newHighlightStyle);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case HighlightState::None:
|
||||
break;
|
||||
}
|
||||
|
||||
if (this->highlightState_ == newHighlightStyle ||
|
||||
this->highlightState_ == HighlightState::Highlighted)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
this->highlightState_ = newHighlightStyle;
|
||||
this->update();
|
||||
}
|
||||
|
||||
bool NotebookTab::shouldMessageHighlight(
|
||||
const ChannelView &channelViewSource) const
|
||||
{
|
||||
auto *visibleSplitContainer =
|
||||
dynamic_cast<SplitContainer *>(this->notebook_->getSelectedPage());
|
||||
if (visibleSplitContainer != nullptr)
|
||||
{
|
||||
const auto &visibleSplits = visibleSplitContainer->getSplits();
|
||||
for (const auto &visibleSplit : visibleSplits)
|
||||
{
|
||||
if (channelViewSource.getID() ==
|
||||
visibleSplit->getChannelView().getID())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void NotebookTab::setHighlightsEnabled(const bool &newVal)
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include "common/Common.hpp"
|
||||
#include "widgets/helper/Button.hpp"
|
||||
#include "widgets/helper/ChannelView.hpp"
|
||||
#include "widgets/Notebook.hpp"
|
||||
|
||||
#include <pajlada/settings/setting.hpp>
|
||||
|
@ -59,11 +60,24 @@ public:
|
|||
**/
|
||||
bool isLive() const;
|
||||
|
||||
/**
|
||||
* @brief Sets the highlight state of this tab clearing highlight sources
|
||||
*
|
||||
* Obeys the HighlightsEnabled setting and highlight states hierarchy
|
||||
*/
|
||||
void setHighlightState(HighlightState style);
|
||||
HighlightState highlightState() const;
|
||||
|
||||
/**
|
||||
* @brief Updates the highlight state and highlight sources of this tab
|
||||
*
|
||||
* Obeys the HighlightsEnabled setting and the highlight state hierarchy and tracks the highlight state update sources
|
||||
*/
|
||||
void updateHighlightState(HighlightState style,
|
||||
const ChannelView &channelViewSource);
|
||||
void copyHighlightStateAndSourcesFrom(const NotebookTab *sourceTab);
|
||||
void setHighlightsEnabled(const bool &newVal);
|
||||
void newHighlightSourceAdded(const ChannelView &channelViewSource);
|
||||
bool hasHighlightsEnabled() const;
|
||||
HighlightState highlightState() const;
|
||||
|
||||
void moveAnimated(QPoint targetPos, bool animated = true);
|
||||
|
||||
|
@ -107,6 +121,16 @@ private:
|
|||
|
||||
int normalTabWidthForHeight(int height) const;
|
||||
|
||||
bool shouldMessageHighlight(const ChannelView &channelViewSource) const;
|
||||
|
||||
using HighlightSources =
|
||||
std::unordered_map<ChannelView::ChannelViewID, HighlightState>;
|
||||
HighlightSources highlightSources_;
|
||||
|
||||
void removeHighlightStateChangeSources(const HighlightSources &toRemove);
|
||||
void removeHighlightSource(const ChannelView::ChannelViewID &source);
|
||||
void updateHighlightStateDueSourcesChange();
|
||||
|
||||
QPropertyAnimation positionChangedAnimation_;
|
||||
QPoint positionAnimationDesiredPoint_;
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#include "util/IncognitoBrowser.hpp"
|
||||
#include "widgets/BaseWindow.hpp"
|
||||
#include "widgets/settingspages/GeneralPageView.hpp"
|
||||
#include "widgets/settingspages/SettingWidget.hpp"
|
||||
|
||||
#include <magic_enum/magic_enum.hpp>
|
||||
#include <QDesktopServices>
|
||||
|
@ -265,10 +266,13 @@ void GeneralPage::initLayout(GeneralPageView &layout)
|
|||
},
|
||||
false, "Choose which tabs are visible in the notebook");
|
||||
|
||||
layout.addCheckbox(
|
||||
"Show message reply context", s.hideReplyContext, true,
|
||||
"This setting will only affect how messages are shown. You can reply "
|
||||
"to a message regardless of this setting.");
|
||||
SettingWidget::inverseCheckbox("Show message reply context",
|
||||
s.hideReplyContext)
|
||||
->setTooltip(
|
||||
"This setting will only affect how messages are shown. You can "
|
||||
"reply to a message regardless of this setting.")
|
||||
->addTo(layout);
|
||||
|
||||
layout.addCheckbox("Show message reply button", s.showReplyButton, false,
|
||||
"Show a reply button next to every chat message");
|
||||
|
||||
|
@ -614,10 +618,19 @@ void GeneralPage::initLayout(GeneralPageView &layout)
|
|||
"Google",
|
||||
},
|
||||
s.emojiSet);
|
||||
layout.addCheckbox("Show BTTV global emotes", s.enableBTTVGlobalEmotes);
|
||||
layout.addCheckbox("Show BTTV channel emotes", s.enableBTTVChannelEmotes);
|
||||
layout.addCheckbox("Enable BTTV live emote updates (requires restart)",
|
||||
s.enableBTTVLiveUpdates);
|
||||
SettingWidget::checkbox("Show BetterTTV global emotes",
|
||||
s.enableBTTVGlobalEmotes)
|
||||
->addKeywords({"bttv"})
|
||||
->addTo(layout);
|
||||
SettingWidget::checkbox("Show BetterTTV channel emotes",
|
||||
s.enableBTTVChannelEmotes)
|
||||
->addKeywords({"bttv"})
|
||||
->addTo(layout);
|
||||
SettingWidget::checkbox(
|
||||
"Enable BetterTTV live emote updates (requires restart)",
|
||||
s.enableBTTVLiveUpdates)
|
||||
->addKeywords({"bttv"})
|
||||
->addTo(layout);
|
||||
layout.addCheckbox("Show FFZ global emotes", s.enableFFZGlobalEmotes);
|
||||
layout.addCheckbox("Show FFZ channel emotes", s.enableFFZChannelEmotes);
|
||||
layout.addCheckbox("Show 7TV global emotes", s.enableSevenTVGlobalEmotes);
|
||||
|
@ -1063,10 +1076,11 @@ void GeneralPage::initLayout(GeneralPageView &layout)
|
|||
false,
|
||||
"Make all clickable links lowercase to deter "
|
||||
"phishing attempts.");
|
||||
layout.addCheckbox(
|
||||
"Show user's pronouns in user card", s.showPronouns, false,
|
||||
"Shows users' pronouns in their user card. "
|
||||
"Pronouns are retrieved from alejo.io when the user card is opened.");
|
||||
SettingWidget::checkbox("Show user's pronouns in user card", s.showPronouns)
|
||||
->setDescription(
|
||||
R"(Pronouns are retrieved from <a href="https://pr.alejo.io">pr.alejo.io</a> when a user card is opened.)")
|
||||
->addTo(layout);
|
||||
|
||||
layout.addCheckbox("Bold @usernames", s.boldUsernames, false,
|
||||
"Bold @mentions to make them more noticable.");
|
||||
layout.addCheckbox("Color @usernames", s.colorUsernames, false,
|
||||
|
@ -1191,25 +1205,20 @@ void GeneralPage::initLayout(GeneralPageView &layout)
|
|||
"@mention for the related thread. If the reply context is hidden, "
|
||||
"these mentions will never be stripped.");
|
||||
|
||||
layout.addDropdownEnumClass<ChatSendProtocol>(
|
||||
"Chat send protocol", qmagicenum::enumNames<ChatSendProtocol>(),
|
||||
s.chatSendProtocol,
|
||||
"'Helix' will use Twitch's Helix API to send message. 'IRC' will use "
|
||||
"IRC to send messages.",
|
||||
{});
|
||||
SettingWidget::dropdown("Chat send protocol", s.chatSendProtocol)
|
||||
->setTooltip("'Helix' will use Twitch's Helix API to send message. "
|
||||
"'IRC' will use IRC to send messages.")
|
||||
->addTo(layout);
|
||||
|
||||
layout.addCheckbox(
|
||||
"Show send message button", s.showSendButton, false,
|
||||
"Show a Send button next to each split input that can be "
|
||||
"clicked to send the message");
|
||||
SettingWidget::checkbox("Show send message button", s.showSendButton)
|
||||
->setTooltip("Show a Send button next to each split input that can be "
|
||||
"clicked to send the message")
|
||||
->addTo(layout);
|
||||
|
||||
auto *soundBackend = layout.addDropdownEnumClass<SoundBackend>(
|
||||
"Sound backend (requires restart)",
|
||||
qmagicenum::enumNames<SoundBackend>(), s.soundBackend,
|
||||
"Change this only if you're noticing issues with sound playback on "
|
||||
"your system",
|
||||
{});
|
||||
soundBackend->setMinimumWidth(soundBackend->minimumSizeHint().width());
|
||||
SettingWidget::dropdown("Sound backend (requires restart)", s.soundBackend)
|
||||
->setTooltip("Change this only if you're noticing issues "
|
||||
"with sound playback on your system")
|
||||
->addTo(layout);
|
||||
|
||||
layout.addStretch();
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include "widgets/dialogs/ColorPickerDialog.hpp"
|
||||
#include "widgets/helper/color/ColorButton.hpp"
|
||||
#include "widgets/helper/Line.hpp"
|
||||
#include "widgets/settingspages/SettingWidget.hpp"
|
||||
|
||||
#include <QRegularExpression>
|
||||
#include <QScrollArea>
|
||||
|
@ -44,9 +45,16 @@ GeneralPageView::GeneralPageView(QWidget *parent)
|
|||
});
|
||||
}
|
||||
|
||||
void GeneralPageView::addWidget(QWidget *widget)
|
||||
void GeneralPageView::addWidget(QWidget *widget, QStringList keywords)
|
||||
{
|
||||
this->contentLayout_->addWidget(widget);
|
||||
if (!keywords.isEmpty())
|
||||
{
|
||||
this->groups_.back().widgets.push_back({
|
||||
.element = widget,
|
||||
.keywords = keywords,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void GeneralPageView::addLayout(QLayout *layout)
|
||||
|
@ -376,11 +384,10 @@ bool GeneralPageView::filterElements(const QString &query)
|
|||
currentSubtitleVisible = true;
|
||||
widget.element->show();
|
||||
groupAny = true;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
widget.element->hide();
|
||||
}
|
||||
|
||||
widget.element->hide();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@ class QScrollArea;
|
|||
namespace chatterino {
|
||||
|
||||
class ColorButton;
|
||||
class SettingWidget;
|
||||
|
||||
class Space : public QLabel
|
||||
{
|
||||
|
@ -95,7 +96,7 @@ class GeneralPageView : public QWidget
|
|||
public:
|
||||
GeneralPageView(QWidget *parent = nullptr);
|
||||
|
||||
void addWidget(QWidget *widget);
|
||||
void addWidget(QWidget *widget, QStringList keywords = {});
|
||||
void addLayout(QLayout *layout);
|
||||
void addStretch();
|
||||
|
||||
|
@ -274,50 +275,6 @@ public:
|
|||
return combo;
|
||||
}
|
||||
|
||||
template <typename T, std::size_t N>
|
||||
ComboBox *addDropdownEnumClass(const QString &text,
|
||||
const std::array<QStringView, N> &items,
|
||||
EnumStringSetting<T> &setting,
|
||||
QString toolTipText,
|
||||
const QString &defaultValueText)
|
||||
{
|
||||
auto *combo = this->addDropdown(text, {}, std::move(toolTipText));
|
||||
|
||||
for (const auto &item : items)
|
||||
{
|
||||
combo->addItem(item.toString());
|
||||
}
|
||||
|
||||
if (!defaultValueText.isEmpty())
|
||||
{
|
||||
combo->setCurrentText(defaultValueText);
|
||||
}
|
||||
|
||||
setting.connect(
|
||||
[&setting, combo](const QString &value) {
|
||||
auto enumValue =
|
||||
qmagicenum::enumCast<T>(value, qmagicenum::CASE_INSENSITIVE)
|
||||
.value_or(setting.defaultValue);
|
||||
|
||||
auto i = magic_enum::enum_integer(enumValue);
|
||||
|
||||
combo->setCurrentIndex(i);
|
||||
},
|
||||
this->managedConnections_);
|
||||
|
||||
QObject::connect(
|
||||
combo, &QComboBox::currentTextChanged,
|
||||
[&setting](const auto &newText) {
|
||||
// The setter for EnumStringSetting does not check that this value is valid
|
||||
// Instead, it's up to the getters to make sure that the setting is legic - see the enum_cast above
|
||||
// You could also use the settings `getEnum` function
|
||||
setting = newText;
|
||||
getApp()->getWindows()->forceLayoutChannelViews();
|
||||
});
|
||||
|
||||
return combo;
|
||||
}
|
||||
|
||||
void enableIf(QComboBox *widget, auto &setting, auto cb)
|
||||
{
|
||||
auto updateVisibility = [cb = std::move(cb), &setting, widget]() {
|
||||
|
|
144
src/widgets/settingspages/SettingWidget.cpp
Normal file
144
src/widgets/settingspages/SettingWidget.cpp
Normal file
|
@ -0,0 +1,144 @@
|
|||
#include "widgets/settingspages/SettingWidget.hpp"
|
||||
|
||||
#include "widgets/settingspages/GeneralPageView.hpp"
|
||||
|
||||
#include <QBoxLayout>
|
||||
#include <QCheckBox>
|
||||
#include <QLabel>
|
||||
|
||||
namespace {
|
||||
|
||||
constexpr int MAX_TOOLTIP_LINE_LENGTH = 50;
|
||||
const auto MAX_TOOLTIP_LINE_LENGTH_PATTERN =
|
||||
QStringLiteral(R"(.{%1}\S*\K(\s+))").arg(MAX_TOOLTIP_LINE_LENGTH);
|
||||
const QRegularExpression MAX_TOOLTIP_LINE_LENGTH_REGEX(
|
||||
MAX_TOOLTIP_LINE_LENGTH_PATTERN);
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
SettingWidget::SettingWidget(const QString &mainKeyword)
|
||||
: vLayout(new QVBoxLayout(this))
|
||||
, hLayout(new QHBoxLayout)
|
||||
{
|
||||
this->vLayout->setContentsMargins(0, 0, 0, 0);
|
||||
|
||||
this->hLayout->setContentsMargins(0, 0, 0, 0);
|
||||
this->vLayout->addLayout(hLayout);
|
||||
|
||||
this->keywords.append(mainKeyword);
|
||||
}
|
||||
|
||||
SettingWidget *SettingWidget::checkbox(const QString &label,
|
||||
BoolSetting &setting)
|
||||
{
|
||||
auto *widget = new SettingWidget(label);
|
||||
|
||||
auto *check = new QCheckBox(label);
|
||||
|
||||
widget->hLayout->addWidget(check);
|
||||
|
||||
// update when setting changes
|
||||
setting.connect(
|
||||
[check](const bool &value, auto) {
|
||||
check->setChecked(value);
|
||||
},
|
||||
widget->managedConnections);
|
||||
|
||||
// update setting on toggle
|
||||
QObject::connect(check, &QCheckBox::toggled, widget,
|
||||
[&setting](bool state) {
|
||||
setting = state;
|
||||
});
|
||||
|
||||
widget->actionWidget = check;
|
||||
widget->label = check;
|
||||
|
||||
return widget;
|
||||
}
|
||||
|
||||
SettingWidget *SettingWidget::inverseCheckbox(const QString &label,
|
||||
BoolSetting &setting)
|
||||
{
|
||||
auto *widget = new SettingWidget(label);
|
||||
|
||||
auto *check = new QCheckBox(label);
|
||||
|
||||
widget->hLayout->addWidget(check);
|
||||
|
||||
// update when setting changes
|
||||
setting.connect(
|
||||
[check](const bool &value, auto) {
|
||||
check->setChecked(!value);
|
||||
},
|
||||
widget->managedConnections);
|
||||
|
||||
// update setting on toggle
|
||||
QObject::connect(check, &QCheckBox::toggled, widget,
|
||||
[&setting](bool state) {
|
||||
setting = !state;
|
||||
});
|
||||
|
||||
widget->actionWidget = check;
|
||||
widget->label = check;
|
||||
|
||||
return widget;
|
||||
}
|
||||
|
||||
SettingWidget *SettingWidget::setTooltip(QString tooltip)
|
||||
{
|
||||
assert(!tooltip.isEmpty());
|
||||
|
||||
if (tooltip.length() > MAX_TOOLTIP_LINE_LENGTH)
|
||||
{
|
||||
// match MAX_TOOLTIP_LINE_LENGTH characters, any remaining
|
||||
// non-space, and then capture the following space for
|
||||
// replacement with newline
|
||||
tooltip.replace(MAX_TOOLTIP_LINE_LENGTH_REGEX, "\n");
|
||||
}
|
||||
|
||||
if (this->label != nullptr)
|
||||
{
|
||||
this->label->setToolTip(tooltip);
|
||||
}
|
||||
|
||||
if (this->actionWidget != nullptr)
|
||||
{
|
||||
this->actionWidget->setToolTip(tooltip);
|
||||
}
|
||||
|
||||
this->keywords.append(tooltip);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
SettingWidget *SettingWidget::setDescription(const QString &text)
|
||||
{
|
||||
auto *lbl = new QLabel(text);
|
||||
lbl->setTextInteractionFlags(Qt::TextBrowserInteraction |
|
||||
Qt::LinksAccessibleByKeyboard);
|
||||
lbl->setOpenExternalLinks(true);
|
||||
lbl->setWordWrap(true);
|
||||
lbl->setObjectName("description");
|
||||
|
||||
this->vLayout->insertWidget(0, lbl);
|
||||
|
||||
this->keywords.append(text);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
SettingWidget *SettingWidget::addKeywords(const QStringList &newKeywords)
|
||||
{
|
||||
this->keywords.append(newKeywords);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
void SettingWidget::addTo(GeneralPageView &view)
|
||||
{
|
||||
view.addWidget(this, this->keywords);
|
||||
}
|
||||
|
||||
} // namespace chatterino
|
106
src/widgets/settingspages/SettingWidget.hpp
Normal file
106
src/widgets/settingspages/SettingWidget.hpp
Normal file
|
@ -0,0 +1,106 @@
|
|||
#pragma once
|
||||
|
||||
#include "common/ChatterinoSetting.hpp"
|
||||
#include "util/QMagicEnum.hpp"
|
||||
#include "widgets/settingspages/GeneralPageView.hpp"
|
||||
|
||||
#include <pajlada/signals/signalholder.hpp>
|
||||
#include <QBoxLayout>
|
||||
#include <QComboBox>
|
||||
#include <QLabel>
|
||||
#include <QObject>
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
#include <QtContainerFwd>
|
||||
#include <QWidget>
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
class GeneralPageView;
|
||||
|
||||
class SettingWidget : QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
explicit SettingWidget(const QString &mainKeyword);
|
||||
|
||||
public:
|
||||
~SettingWidget() override = default;
|
||||
SettingWidget &operator=(const SettingWidget &) = delete;
|
||||
SettingWidget &operator=(SettingWidget &&) = delete;
|
||||
SettingWidget(const SettingWidget &other) = delete;
|
||||
SettingWidget(SettingWidget &&other) = delete;
|
||||
|
||||
static SettingWidget *checkbox(const QString &label, BoolSetting &setting);
|
||||
static SettingWidget *inverseCheckbox(const QString &label,
|
||||
BoolSetting &setting);
|
||||
template <typename T>
|
||||
static SettingWidget *dropdown(const QString &label,
|
||||
EnumStringSetting<T> &setting)
|
||||
{
|
||||
auto *widget = new SettingWidget(label);
|
||||
|
||||
auto *lbl = new QLabel(label % ":");
|
||||
auto *combo = new ComboBox;
|
||||
combo->setFocusPolicy(Qt::StrongFocus);
|
||||
for (const auto &item : qmagicenum::enumNames<T>())
|
||||
{
|
||||
combo->addItem(item.toString());
|
||||
}
|
||||
// TODO: this can probably use some other size hint/size strategy
|
||||
combo->setMinimumWidth(combo->minimumSizeHint().width());
|
||||
|
||||
widget->actionWidget = combo;
|
||||
widget->label = lbl;
|
||||
|
||||
widget->hLayout->addWidget(lbl);
|
||||
widget->hLayout->addStretch(1);
|
||||
widget->hLayout->addWidget(combo);
|
||||
|
||||
setting.connect(
|
||||
[&setting, combo](const QString &value) {
|
||||
auto enumValue =
|
||||
qmagicenum::enumCast<T>(value, qmagicenum::CASE_INSENSITIVE)
|
||||
.value_or(setting.defaultValue);
|
||||
|
||||
auto i = magic_enum::enum_integer(enumValue);
|
||||
|
||||
combo->setCurrentIndex(i);
|
||||
},
|
||||
widget->managedConnections);
|
||||
|
||||
QObject::connect(
|
||||
combo, &QComboBox::currentTextChanged,
|
||||
[&setting](const auto &newText) {
|
||||
// The setter for EnumStringSetting does not check that this value is valid
|
||||
// Instead, it's up to the getters to make sure that the setting is legic - see the enum_cast above
|
||||
// You could also use the settings `getEnum` function
|
||||
setting = newText;
|
||||
});
|
||||
|
||||
return widget;
|
||||
}
|
||||
|
||||
SettingWidget *setTooltip(QString tooltip);
|
||||
SettingWidget *setDescription(const QString &text);
|
||||
|
||||
/// Add extra keywords to the widget
|
||||
///
|
||||
/// All text from the tooltip, description, and label are already keywords
|
||||
SettingWidget *addKeywords(const QStringList &newKeywords);
|
||||
|
||||
void addTo(GeneralPageView &view);
|
||||
|
||||
private:
|
||||
QWidget *label = nullptr;
|
||||
QWidget *actionWidget = nullptr;
|
||||
|
||||
QVBoxLayout *vLayout;
|
||||
QHBoxLayout *hLayout;
|
||||
|
||||
pajlada::Signals::SignalHolder managedConnections;
|
||||
|
||||
QStringList keywords;
|
||||
};
|
||||
|
||||
} // namespace chatterino
|
|
@ -214,13 +214,21 @@ void SplitContainer::addSplit(Split *split)
|
|||
auto &&conns = this->connectionsPerSplit_[split];
|
||||
|
||||
conns.managedConnect(split->getChannelView().tabHighlightRequested,
|
||||
[this](HighlightState state) {
|
||||
[this, split](HighlightState state) {
|
||||
if (this->tab_ != nullptr)
|
||||
{
|
||||
this->tab_->setHighlightState(state);
|
||||
this->tab_->updateHighlightState(
|
||||
state, split->getChannelView());
|
||||
}
|
||||
});
|
||||
|
||||
conns.managedConnect(split->channelChanged, [this, split] {
|
||||
if (this->tab_ != nullptr)
|
||||
{
|
||||
this->tab_->newHighlightSourceAdded(split->getChannelView());
|
||||
}
|
||||
});
|
||||
|
||||
conns.managedConnect(split->getChannelView().liveStatusChanged, [this]() {
|
||||
this->refreshTabLiveStatus();
|
||||
});
|
||||
|
|
|
@ -180,6 +180,7 @@
|
|||
}
|
||||
],
|
||||
"flags": "Collapsed|Subscription",
|
||||
"highlightColor": "#64c466ff",
|
||||
"id": "8c26e1ab-b50c-4d9d-bc11-3fd57a941d90",
|
||||
"localizedName": "",
|
||||
"loginName": "supinic",
|
||||
|
|
|
@ -80,7 +80,7 @@
|
|||
"trailingSpace": true,
|
||||
"type": "SingleLineTextElement",
|
||||
"words": [
|
||||
"a"
|
||||
"b"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
@ -169,6 +169,7 @@
|
|||
"localizedName": "",
|
||||
"loginName": "nerixyz",
|
||||
"messageText": "c",
|
||||
"replyParent": "474f19ab-a1b0-410a-877a-5b0e2ae8be6d",
|
||||
"replyThread": {
|
||||
"replies": [
|
||||
"474f19ab-a1b0-410a-877a-5b0e2ae8be6d",
|
||||
|
|
|
@ -256,6 +256,7 @@
|
|||
}
|
||||
],
|
||||
"flags": "Collapsed|Subscription|SharedMessage",
|
||||
"highlightColor": "#64c466ff",
|
||||
"id": "01cd601f-bc3f-49d5-ab4b-136fa9d6ec22",
|
||||
"localizedName": "",
|
||||
"loginName": "lahoooo",
|
||||
|
|
|
@ -243,6 +243,7 @@
|
|||
}
|
||||
],
|
||||
"flags": "Collapsed|Subscription",
|
||||
"highlightColor": "#64c466ff",
|
||||
"id": "db25007f-7a18-43eb-9379-80131e44d633",
|
||||
"localizedName": "",
|
||||
"loginName": "ronni",
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
#include "singletons/Emotes.hpp"
|
||||
#include "Test.hpp"
|
||||
#include "util/IrcHelpers.hpp"
|
||||
#include "util/VectorMessageSink.hpp"
|
||||
|
||||
#include <IrcConnection>
|
||||
#include <QDebug>
|
||||
|
@ -572,19 +573,14 @@ TEST_P(TestIrcMessageHandlerP, Run)
|
|||
{
|
||||
auto channel = makeMockTwitchChannel(u"pajlada"_s, *snapshot);
|
||||
|
||||
std::vector<MessagePtr> prevMessages;
|
||||
VectorMessageSink sink;
|
||||
|
||||
for (auto prevInput : snapshot->param("prevMessages").toArray())
|
||||
{
|
||||
auto *ircMessage = Communi::IrcMessage::fromData(
|
||||
prevInput.toString().toUtf8(), nullptr);
|
||||
ASSERT_NE(ircMessage, nullptr);
|
||||
auto builtMessages = IrcMessageHandler::parseMessageWithReply(
|
||||
channel.get(), ircMessage, prevMessages);
|
||||
for (const auto &builtMessage : builtMessages)
|
||||
{
|
||||
prevMessages.emplace_back(builtMessage);
|
||||
}
|
||||
IrcMessageHandler::parseMessageInto(ircMessage, sink, channel.get());
|
||||
delete ircMessage;
|
||||
}
|
||||
|
||||
|
@ -592,13 +588,13 @@ TEST_P(TestIrcMessageHandlerP, Run)
|
|||
Communi::IrcMessage::fromData(snapshot->inputUtf8(), nullptr);
|
||||
ASSERT_NE(ircMessage, nullptr);
|
||||
|
||||
auto builtMessages = IrcMessageHandler::parseMessageWithReply(
|
||||
channel.get(), ircMessage, prevMessages);
|
||||
auto firstAddedMsg = sink.messages().size();
|
||||
IrcMessageHandler::parseMessageInto(ircMessage, sink, channel.get());
|
||||
|
||||
QJsonArray got;
|
||||
for (const auto &msg : builtMessages)
|
||||
for (auto i = firstAddedMsg; i < sink.messages().size(); i++)
|
||||
{
|
||||
got.append(msg->toJson());
|
||||
got.append(sink.messages()[i]->toJson());
|
||||
}
|
||||
|
||||
delete ircMessage;
|
||||
|
|
|
@ -114,20 +114,153 @@ TEST(LimitedQueue, PushFront)
|
|||
|
||||
TEST(LimitedQueue, ReplaceItem)
|
||||
{
|
||||
LimitedQueue<int> queue(5);
|
||||
LimitedQueue<int> queue(10);
|
||||
queue.pushBack(1);
|
||||
queue.pushBack(2);
|
||||
queue.pushBack(3);
|
||||
queue.pushBack(4);
|
||||
queue.pushBack(5);
|
||||
queue.pushBack(6);
|
||||
|
||||
int idex = queue.replaceItem(2, 10);
|
||||
EXPECT_EQ(idex, 1);
|
||||
idex = queue.replaceItem(5, 11);
|
||||
idex = queue.replaceItem(7, 11);
|
||||
EXPECT_EQ(idex, -1);
|
||||
|
||||
bool res = queue.replaceItem(std::size_t(0), 9);
|
||||
int prev = -1;
|
||||
bool res = queue.replaceItem(std::size_t(0), 9, &prev);
|
||||
EXPECT_TRUE(res);
|
||||
res = queue.replaceItem(std::size_t(5), 4);
|
||||
EXPECT_EQ(prev, 1);
|
||||
res = queue.replaceItem(std::size_t(6), 4);
|
||||
EXPECT_FALSE(res);
|
||||
|
||||
SNAPSHOT_EQUALS(queue.getSnapshot(), {9, 10, 3}, "first snapshot");
|
||||
// correct hint
|
||||
EXPECT_EQ(queue.replaceItem(3, 4, 11), 3);
|
||||
// incorrect hints
|
||||
EXPECT_EQ(queue.replaceItem(5, 11, 12), 3);
|
||||
EXPECT_EQ(queue.replaceItem(0, 12, 13), 3);
|
||||
// oob hint
|
||||
EXPECT_EQ(queue.replaceItem(42, 13, 14), 3);
|
||||
// bad needle
|
||||
EXPECT_EQ(queue.replaceItem(0, 15, 16), -1);
|
||||
|
||||
SNAPSHOT_EQUALS(queue.getSnapshot(), {9, 10, 3, 14, 5, 6},
|
||||
"first snapshot");
|
||||
}
|
||||
|
||||
TEST(LimitedQueue, Find)
|
||||
{
|
||||
LimitedQueue<int> queue(10);
|
||||
queue.pushBack(1);
|
||||
queue.pushBack(2);
|
||||
queue.pushBack(3);
|
||||
queue.pushBack(4);
|
||||
queue.pushBack(5);
|
||||
queue.pushBack(6);
|
||||
|
||||
// without hint
|
||||
EXPECT_FALSE(queue
|
||||
.find([](int i) {
|
||||
return i == 0;
|
||||
})
|
||||
.has_value());
|
||||
EXPECT_EQ(queue
|
||||
.find([](int i) {
|
||||
return i == 1;
|
||||
})
|
||||
.value(),
|
||||
1);
|
||||
EXPECT_EQ(queue
|
||||
.find([](int i) {
|
||||
return i == 2;
|
||||
})
|
||||
.value(),
|
||||
2);
|
||||
EXPECT_EQ(queue
|
||||
.find([](int i) {
|
||||
return i == 6;
|
||||
})
|
||||
.value(),
|
||||
6);
|
||||
EXPECT_FALSE(queue
|
||||
.find([](int i) {
|
||||
return i == 7;
|
||||
})
|
||||
.has_value());
|
||||
EXPECT_FALSE(queue
|
||||
.find([](int i) {
|
||||
return i > 6;
|
||||
})
|
||||
.has_value());
|
||||
EXPECT_FALSE(queue
|
||||
.find([](int i) {
|
||||
return i <= 0;
|
||||
})
|
||||
.has_value());
|
||||
|
||||
using Pair = std::pair<size_t, int>;
|
||||
// with hint
|
||||
EXPECT_FALSE(queue
|
||||
.find(0,
|
||||
[](int i) {
|
||||
return i == 0;
|
||||
})
|
||||
.has_value());
|
||||
// correct hint
|
||||
EXPECT_EQ(queue
|
||||
.find(0,
|
||||
[](int i) {
|
||||
return i == 1;
|
||||
})
|
||||
.value(),
|
||||
(Pair{0, 1}));
|
||||
EXPECT_EQ(queue
|
||||
.find(1,
|
||||
[](int i) {
|
||||
return i == 2;
|
||||
})
|
||||
.value(),
|
||||
(Pair{1, 2}));
|
||||
// incorrect hint
|
||||
EXPECT_EQ(queue
|
||||
.find(1,
|
||||
[](int i) {
|
||||
return i == 1;
|
||||
})
|
||||
.value(),
|
||||
(Pair{0, 1}));
|
||||
EXPECT_EQ(queue
|
||||
.find(5,
|
||||
[](int i) {
|
||||
return i == 6;
|
||||
})
|
||||
.value(),
|
||||
(Pair{5, 6}));
|
||||
// oob hint
|
||||
EXPECT_EQ(queue
|
||||
.find(6,
|
||||
[](int i) {
|
||||
return i == 3;
|
||||
})
|
||||
.value(),
|
||||
(Pair{2, 3}));
|
||||
// non-existent items
|
||||
EXPECT_FALSE(queue
|
||||
.find(42,
|
||||
[](int i) {
|
||||
return i == 7;
|
||||
})
|
||||
.has_value());
|
||||
EXPECT_FALSE(queue
|
||||
.find(0,
|
||||
[](int i) {
|
||||
return i > 6;
|
||||
})
|
||||
.has_value());
|
||||
EXPECT_FALSE(queue
|
||||
.find(0,
|
||||
[](int i) {
|
||||
return i <= 0;
|
||||
})
|
||||
.has_value());
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue