mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +01:00
Compare commits
4 commits
de87f22684
...
fae4e5cae0
Author | SHA1 | Date | |
---|---|---|---|
fae4e5cae0 | |||
101a45fd3a | |||
5f76f5b755 | |||
ecfb35c9b7 |
|
@ -64,6 +64,7 @@
|
||||||
- Bugfix: Fixed double-click selection not working when clicking outside a message. (#5617)
|
- Bugfix: Fixed double-click selection not working when clicking outside a message. (#5617)
|
||||||
- Bugfix: Fixed emotes starting with ":" not tab-completing. (#5603)
|
- Bugfix: Fixed emotes starting with ":" not tab-completing. (#5603)
|
||||||
- Bugfix: Fixed 7TV emotes messing with Qt's HTML. (#5677)
|
- 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 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: 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)
|
- Dev: Unsingletonize `ISoundController`. (#5462)
|
||||||
|
@ -76,7 +77,7 @@
|
||||||
- Dev: Removed unused timegate settings. (#5361)
|
- Dev: Removed unused timegate settings. (#5361)
|
||||||
- Dev: Add `Channel::addSystemMessage` helper function, allowing us to avoid the common `channel->addMessage(makeSystemMessage(...));` pattern. (#5500)
|
- Dev: Add `Channel::addSystemMessage` helper function, allowing us to avoid the common `channel->addMessage(makeSystemMessage(...));` pattern. (#5500)
|
||||||
- Dev: Unsingletonize `Resources2`. (#5460)
|
- 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: Images are now loaded in worker threads. (#5431)
|
||||||
- Dev: Fixed broken `SignalVector::operator[]` implementation. (#5556)
|
- Dev: Fixed broken `SignalVector::operator[]` implementation. (#5556)
|
||||||
- Dev: Qt Creator now auto-configures Conan when loading the project and skips vcpkg. (#5305)
|
- Dev: Qt Creator now auto-configures Conan when loading the project and skips vcpkg. (#5305)
|
||||||
|
@ -111,11 +112,12 @@
|
||||||
- Dev: Twitch messages are now sent using Twitch's Helix API instead of IRC by default. (#5607)
|
- 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: `GIFTimer` is no longer initialized in tests. (#5608)
|
||||||
- Dev: Emojis now use flags instead of a set of strings for capabilities. (#5616)
|
- 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: Refactored static `MessageBuilder` helpers to standalone functions. (#5652)
|
||||||
- Dev: Decoupled reply parsing from `MessageBuilder`. (#5660, #5668)
|
- Dev: Decoupled reply parsing from `MessageBuilder`. (#5660, #5668)
|
||||||
- Dev: Refactored IRC message building. (#5663)
|
- Dev: Refactored IRC message building. (#5663)
|
||||||
- Dev: Fixed some compiler warnings. (#5672)
|
- Dev: Fixed some compiler warnings. (#5672)
|
||||||
|
- Dev: Unified parsing of historic and live IRC messages. (#5678)
|
||||||
|
|
||||||
## 2.5.1
|
## 2.5.1
|
||||||
|
|
||||||
|
|
|
@ -5,20 +5,20 @@
|
||||||
-- Add the folder this file is in to "Lua.workspace.library".
|
-- Add the folder this file is in to "Lua.workspace.library".
|
||||||
|
|
||||||
c2 = {}
|
c2 = {}
|
||||||
---@alias c2.LogLevel.Debug "c2.LogLevel.Debug"
|
---@enum c2.LogLevel
|
||||||
---@alias c2.LogLevel.Info "c2.LogLevel.Info"
|
c2.LogLevel = {
|
||||||
---@alias c2.LogLevel.Warning "c2.LogLevel.Warning"
|
Debug = {}, ---@type c2.LogLevel.Debug
|
||||||
---@alias c2.LogLevel.Critical "c2.LogLevel.Critical"
|
Info = {}, ---@type c2.LogLevel.Info
|
||||||
---@alias c2.LogLevel c2.LogLevel.Debug|c2.LogLevel.Info|c2.LogLevel.Warning|c2.LogLevel.Critical
|
Warning = {}, ---@type c2.LogLevel.Warning
|
||||||
---@type { Debug: c2.LogLevel.Debug, Info: c2.LogLevel.Info, Warning: c2.LogLevel.Warning, Critical: c2.LogLevel.Critical }
|
Critical = {}, ---@type c2.LogLevel.Critical
|
||||||
c2.LogLevel = {}
|
}
|
||||||
|
|
||||||
-- Begin src/controllers/plugins/api/EventType.hpp
|
-- Begin src/controllers/plugins/api/EventType.hpp
|
||||||
|
|
||||||
---@alias c2.EventType.CompletionRequested "c2.EventType.CompletionRequested"
|
---@enum c2.EventType
|
||||||
---@alias c2.EventType c2.EventType.CompletionRequested
|
c2.EventType = {
|
||||||
---@type { CompletionRequested: c2.EventType.CompletionRequested }
|
CompletionRequested = {}, ---@type c2.EventType.CompletionRequested
|
||||||
c2.EventType = {}
|
}
|
||||||
|
|
||||||
-- End src/controllers/plugins/api/EventType.hpp
|
-- End src/controllers/plugins/api/EventType.hpp
|
||||||
|
|
||||||
|
@ -38,19 +38,19 @@ c2.EventType = {}
|
||||||
|
|
||||||
-- Begin src/common/Channel.hpp
|
-- Begin src/common/Channel.hpp
|
||||||
|
|
||||||
---@alias c2.ChannelType.None "c2.ChannelType.None"
|
---@enum c2.ChannelType
|
||||||
---@alias c2.ChannelType.Direct "c2.ChannelType.Direct"
|
c2.ChannelType = {
|
||||||
---@alias c2.ChannelType.Twitch "c2.ChannelType.Twitch"
|
None = {}, ---@type c2.ChannelType.None
|
||||||
---@alias c2.ChannelType.TwitchWhispers "c2.ChannelType.TwitchWhispers"
|
Direct = {}, ---@type c2.ChannelType.Direct
|
||||||
---@alias c2.ChannelType.TwitchWatching "c2.ChannelType.TwitchWatching"
|
Twitch = {}, ---@type c2.ChannelType.Twitch
|
||||||
---@alias c2.ChannelType.TwitchMentions "c2.ChannelType.TwitchMentions"
|
TwitchWhispers = {}, ---@type c2.ChannelType.TwitchWhispers
|
||||||
---@alias c2.ChannelType.TwitchLive "c2.ChannelType.TwitchLive"
|
TwitchWatching = {}, ---@type c2.ChannelType.TwitchWatching
|
||||||
---@alias c2.ChannelType.TwitchAutomod "c2.ChannelType.TwitchAutomod"
|
TwitchMentions = {}, ---@type c2.ChannelType.TwitchMentions
|
||||||
---@alias c2.ChannelType.TwitchEnd "c2.ChannelType.TwitchEnd"
|
TwitchLive = {}, ---@type c2.ChannelType.TwitchLive
|
||||||
---@alias c2.ChannelType.Misc "c2.ChannelType.Misc"
|
TwitchAutomod = {}, ---@type c2.ChannelType.TwitchAutomod
|
||||||
---@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
|
TwitchEnd = {}, ---@type c2.ChannelType.TwitchEnd
|
||||||
---@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 }
|
Misc = {}, ---@type c2.ChannelType.Misc
|
||||||
c2.ChannelType = {}
|
}
|
||||||
|
|
||||||
-- End src/common/Channel.hpp
|
-- End src/common/Channel.hpp
|
||||||
|
|
||||||
|
@ -174,90 +174,97 @@ function c2.Channel.by_twitch_id(id) end
|
||||||
|
|
||||||
-- Begin src/controllers/plugins/api/HTTPResponse.hpp
|
-- Begin src/controllers/plugins/api/HTTPResponse.hpp
|
||||||
|
|
||||||
---@class HTTPResponse
|
---@class c2.HTTPResponse
|
||||||
HTTPResponse = {}
|
c2.HTTPResponse = {}
|
||||||
|
|
||||||
--- Returns the data. This is not guaranteed to be encoded using any
|
--- Returns the data. This is not guaranteed to be encoded using any
|
||||||
--- particular encoding scheme. It's just the bytes the server returned.
|
--- 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.
|
--- 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
|
--- 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
|
---@return string
|
||||||
function HTTPResponse:__tostring() end
|
---@nodiscard
|
||||||
|
function c2.HTTPResponse:__tostring() end
|
||||||
|
|
||||||
-- End src/controllers/plugins/api/HTTPResponse.hpp
|
-- End src/controllers/plugins/api/HTTPResponse.hpp
|
||||||
|
|
||||||
-- Begin src/controllers/plugins/api/HTTPRequest.hpp
|
-- Begin src/controllers/plugins/api/HTTPRequest.hpp
|
||||||
|
|
||||||
---@alias HTTPCallback fun(result: HTTPResponse): nil
|
---@alias c2.HTTPCallback fun(result: c2.HTTPResponse): nil
|
||||||
---@class HTTPRequest
|
---@class c2.HTTPRequest
|
||||||
HTTPRequest = {}
|
c2.HTTPRequest = {}
|
||||||
|
|
||||||
--- Sets the success callback
|
--- Sets the success callback
|
||||||
---
|
---
|
||||||
---@param callback HTTPCallback Function to call when the HTTP request succeeds
|
---@param callback c2.HTTPCallback Function to call when the HTTP request succeeds
|
||||||
function HTTPRequest:on_success(callback) end
|
function c2.HTTPRequest:on_success(callback) end
|
||||||
|
|
||||||
--- Sets the failure callback
|
--- Sets the failure callback
|
||||||
---
|
---
|
||||||
---@param callback HTTPCallback Function to call when the HTTP request fails or returns a non-ok status
|
---@param callback c2.HTTPCallback Function to call when the HTTP request fails or returns a non-ok status
|
||||||
function HTTPRequest:on_error(callback) end
|
function c2.HTTPRequest:on_error(callback) end
|
||||||
|
|
||||||
--- Sets the finally callback
|
--- Sets the finally callback
|
||||||
---
|
---
|
||||||
---@param callback fun(): nil Function to call when the HTTP request finishes
|
---@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
|
--- Sets the timeout
|
||||||
---
|
---
|
||||||
---@param timeout integer How long in milliseconds until the times out
|
---@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
|
--- Sets the request payload
|
||||||
---
|
---
|
||||||
---@param data string
|
---@param data string
|
||||||
function HTTPRequest:set_payload(data) end
|
function c2.HTTPRequest:set_payload(data) end
|
||||||
|
|
||||||
--- Sets a header in the request
|
--- Sets a header in the request
|
||||||
---
|
---
|
||||||
---@param name string
|
---@param name string
|
||||||
---@param value string
|
---@param value string
|
||||||
function HTTPRequest:set_header(name, value) end
|
function c2.HTTPRequest:set_header(name, value) end
|
||||||
|
|
||||||
--- Executes the HTTP request
|
--- Executes the HTTP request
|
||||||
---
|
---
|
||||||
function HTTPRequest:execute() end
|
function c2.HTTPRequest:execute() end
|
||||||
|
|
||||||
---@return string
|
---@return string
|
||||||
function HTTPRequest:__tostring() end
|
function c2.HTTPRequest:__tostring() end
|
||||||
|
|
||||||
--- Creates a new HTTPRequest
|
--- 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
|
---@param url string Where to send the request to
|
||||||
---@return HTTPRequest
|
---@return c2.HTTPRequest
|
||||||
function HTTPRequest.create(method, url) end
|
function c2.HTTPRequest.create(method, url) end
|
||||||
|
|
||||||
-- End src/controllers/plugins/api/HTTPRequest.hpp
|
-- End src/controllers/plugins/api/HTTPRequest.hpp
|
||||||
|
|
||||||
-- Begin src/common/network/NetworkCommon.hpp
|
-- Begin src/common/network/NetworkCommon.hpp
|
||||||
|
|
||||||
---@alias HTTPMethod.Get "HTTPMethod.Get"
|
---@enum c2.HTTPMethod
|
||||||
---@alias HTTPMethod.Post "HTTPMethod.Post"
|
c2.HTTPMethod = {
|
||||||
---@alias HTTPMethod.Put "HTTPMethod.Put"
|
Get = {}, ---@type c2.HTTPMethod.Get
|
||||||
---@alias HTTPMethod.Delete "HTTPMethod.Delete"
|
Post = {}, ---@type c2.HTTPMethod.Post
|
||||||
---@alias HTTPMethod.Patch "HTTPMethod.Patch"
|
Put = {}, ---@type c2.HTTPMethod.Put
|
||||||
---@alias HTTPMethod HTTPMethod.Get|HTTPMethod.Post|HTTPMethod.Put|HTTPMethod.Delete|HTTPMethod.Patch
|
Delete = {}, ---@type c2.HTTPMethod.Delete
|
||||||
---@type { Get: HTTPMethod.Get, Post: HTTPMethod.Post, Put: HTTPMethod.Put, Delete: HTTPMethod.Delete, Patch: HTTPMethod.Patch }
|
Patch = {}, ---@type c2.HTTPMethod.Patch
|
||||||
HTTPMethod = {}
|
}
|
||||||
|
|
||||||
-- End src/common/network/NetworkCommon.hpp
|
-- End src/common/network/NetworkCommon.hpp
|
||||||
|
|
||||||
|
|
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
|
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]
|
name = header[0].split(" ", 1)[1]
|
||||||
printmsg(path, reader.line_no(), f"enum {name}")
|
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:
|
if header_comment:
|
||||||
out.write(f"--- {header_comment}\n")
|
out.write(f"--- {header_comment}\n")
|
||||||
out.write("---@type { ")
|
out.write(f"---@enum {name}\n")
|
||||||
|
out.write(f"{name} = {{\n")
|
||||||
out.write(
|
out.write(
|
||||||
", ".join(
|
"\n".join(
|
||||||
[f"{variant}: {typ}" for variant, typ in zip(variants,vtypes)]
|
[
|
||||||
|
f" {variant} = {{}}, ---@type {name}.{variant}"
|
||||||
|
for variant in reader.read_enum_variants()
|
||||||
|
]
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
out.write(" }\n")
|
out.write("\n}\n\n")
|
||||||
out.write(f"{name} = {{}}\n\n")
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# class
|
# class
|
||||||
|
|
|
@ -40,6 +40,7 @@ set(SOURCE_FILES
|
||||||
common/WindowDescriptors.cpp
|
common/WindowDescriptors.cpp
|
||||||
common/WindowDescriptors.hpp
|
common/WindowDescriptors.hpp
|
||||||
|
|
||||||
|
common/enums/MessageContext.hpp
|
||||||
common/enums/MessageOverflow.hpp
|
common/enums/MessageOverflow.hpp
|
||||||
|
|
||||||
common/network/NetworkCommon.cpp
|
common/network/NetworkCommon.cpp
|
||||||
|
@ -282,6 +283,9 @@ set(SOURCE_FILES
|
||||||
messages/MessageElement.cpp
|
messages/MessageElement.cpp
|
||||||
messages/MessageElement.hpp
|
messages/MessageElement.hpp
|
||||||
messages/MessageFlag.hpp
|
messages/MessageFlag.hpp
|
||||||
|
messages/MessageSimilarity.cpp
|
||||||
|
messages/MessageSimilarity.hpp
|
||||||
|
messages/MessageSink.hpp
|
||||||
messages/MessageThread.cpp
|
messages/MessageThread.cpp
|
||||||
messages/MessageThread.hpp
|
messages/MessageThread.hpp
|
||||||
|
|
||||||
|
@ -527,6 +531,8 @@ set(SOURCE_FILES
|
||||||
util/Twitch.hpp
|
util/Twitch.hpp
|
||||||
util/TypeName.hpp
|
util/TypeName.hpp
|
||||||
util/Variant.hpp
|
util/Variant.hpp
|
||||||
|
util/VectorMessageSink.cpp
|
||||||
|
util/VectorMessageSink.hpp
|
||||||
util/WidgetHelpers.cpp
|
util/WidgetHelpers.cpp
|
||||||
util/WidgetHelpers.hpp
|
util/WidgetHelpers.hpp
|
||||||
util/WindowsHelper.cpp
|
util/WindowsHelper.cpp
|
||||||
|
|
|
@ -3,7 +3,9 @@
|
||||||
#include "Application.hpp"
|
#include "Application.hpp"
|
||||||
#include "messages/Message.hpp"
|
#include "messages/Message.hpp"
|
||||||
#include "messages/MessageBuilder.hpp"
|
#include "messages/MessageBuilder.hpp"
|
||||||
|
#include "messages/MessageSimilarity.hpp"
|
||||||
#include "providers/twitch/IrcMessageHandler.hpp"
|
#include "providers/twitch/IrcMessageHandler.hpp"
|
||||||
|
#include "providers/twitch/TwitchIrcServer.hpp"
|
||||||
#include "singletons/Emotes.hpp"
|
#include "singletons/Emotes.hpp"
|
||||||
#include "singletons/Logging.hpp"
|
#include "singletons/Logging.hpp"
|
||||||
#include "singletons/Settings.hpp"
|
#include "singletons/Settings.hpp"
|
||||||
|
@ -121,10 +123,10 @@ void Channel::addSystemMessage(const QString &contents)
|
||||||
this->addMessage(msg, MessageContext::Original);
|
this->addMessage(msg, MessageContext::Original);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Channel::addOrReplaceTimeout(MessagePtr message)
|
void Channel::addOrReplaceTimeout(MessagePtr message, QTime now)
|
||||||
{
|
{
|
||||||
addOrReplaceChannelTimeout(
|
addOrReplaceChannelTimeout(
|
||||||
this->getMessageSnapshot(), std::move(message), QTime::currentTime(),
|
this->getMessageSnapshot(), std::move(message), now,
|
||||||
[this](auto /*idx*/, auto msg, auto replacement) {
|
[this](auto /*idx*/, auto msg, auto replacement) {
|
||||||
this->replaceMessage(msg, 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);
|
int index = this->messages_.replaceItem(message, replacement);
|
||||||
|
|
||||||
if (index >= 0)
|
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)
|
MessagePtr Channel::findMessage(QString messageID)
|
||||||
|
{
|
||||||
|
return this->findMessageByID(messageID);
|
||||||
|
}
|
||||||
|
|
||||||
|
MessagePtr Channel::findMessageByID(QStringView messageID)
|
||||||
{
|
{
|
||||||
MessagePtr res;
|
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;
|
return msg->id == messageID;
|
||||||
});
|
});
|
||||||
msg)
|
msg)
|
||||||
|
@ -301,6 +320,19 @@ MessagePtr Channel::findMessage(QString messageID)
|
||||||
return res;
|
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
|
bool Channel::canSendMessage() const
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "common/enums/MessageContext.hpp"
|
||||||
#include "controllers/completion/TabCompletionModel.hpp"
|
#include "controllers/completion/TabCompletionModel.hpp"
|
||||||
#include "messages/LimitedQueue.hpp"
|
#include "messages/LimitedQueue.hpp"
|
||||||
#include "messages/MessageFlag.hpp"
|
#include "messages/MessageFlag.hpp"
|
||||||
|
#include "messages/MessageSink.hpp"
|
||||||
|
|
||||||
#include <magic_enum/magic_enum.hpp>
|
#include <magic_enum/magic_enum.hpp>
|
||||||
#include <pajlada/signals/signal.hpp>
|
#include <pajlada/signals/signal.hpp>
|
||||||
|
@ -26,15 +28,7 @@ enum class TimeoutStackStyle : int {
|
||||||
Default = DontStackBeyondUserMessage,
|
Default = DontStackBeyondUserMessage,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Context of the message being added to a channel
|
class Channel : public std::enable_shared_from_this<Channel>, public MessageSink
|
||||||
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>
|
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
// This is for Lua. See scripts/make_luals_meta.py
|
// This is for Lua. See scripts/make_luals_meta.py
|
||||||
|
@ -55,7 +49,7 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
explicit Channel(const QString &name, Type type);
|
explicit Channel(const QString &name, Type type);
|
||||||
virtual ~Channel();
|
~Channel() override;
|
||||||
|
|
||||||
// SIGNALS
|
// SIGNALS
|
||||||
pajlada::Signals::Signal<const QString &, const QString &, bool &>
|
pajlada::Signals::Signal<const QString &, const QString &, bool &>
|
||||||
|
@ -66,7 +60,9 @@ public:
|
||||||
pajlada::Signals::Signal<MessagePtr &, std::optional<MessageFlags>>
|
pajlada::Signals::Signal<MessagePtr &, std::optional<MessageFlags>>
|
||||||
messageAppended;
|
messageAppended;
|
||||||
pajlada::Signals::Signal<std::vector<MessagePtr> &> messagesAddedAtStart;
|
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
|
/// Invoked when some number of messages were filled in using time received
|
||||||
pajlada::Signals::Signal<const std::vector<MessagePtr> &> filledInMessages;
|
pajlada::Signals::Signal<const std::vector<MessagePtr> &> filledInMessages;
|
||||||
pajlada::Signals::NoArgSignal destroyed;
|
pajlada::Signals::NoArgSignal destroyed;
|
||||||
|
@ -85,8 +81,9 @@ public:
|
||||||
// overridingFlags can be filled in with flags that should be used instead
|
// 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
|
// of the message's flags. This is useful in case a flag is specific to a
|
||||||
// type of split
|
// type of split
|
||||||
void addMessage(MessagePtr message, MessageContext context,
|
void addMessage(
|
||||||
std::optional<MessageFlags> overridingFlags = std::nullopt);
|
MessagePtr message, MessageContext context,
|
||||||
|
std::optional<MessageFlags> overridingFlags = std::nullopt) final;
|
||||||
void addMessagesAtStart(const std::vector<MessagePtr> &messages_);
|
void addMessagesAtStart(const std::vector<MessagePtr> &messages_);
|
||||||
|
|
||||||
void addSystemMessage(const QString &contents);
|
void addSystemMessage(const QString &contents);
|
||||||
|
@ -94,19 +91,28 @@ public:
|
||||||
/// Inserts the given messages in order by Message::serverReceivedTime.
|
/// Inserts the given messages in order by Message::serverReceivedTime.
|
||||||
void fillInMissingMessages(const std::vector<MessagePtr> &messages);
|
void fillInMissingMessages(const std::vector<MessagePtr> &messages);
|
||||||
|
|
||||||
void addOrReplaceTimeout(MessagePtr message);
|
void addOrReplaceTimeout(MessagePtr message, QTime now) final;
|
||||||
void disableAllMessages();
|
void disableAllMessages() final;
|
||||||
void replaceMessage(MessagePtr message, MessagePtr replacement);
|
void replaceMessage(const MessagePtr &message,
|
||||||
void replaceMessage(size_t index, MessagePtr replacement);
|
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);
|
void deleteMessage(QString messageID);
|
||||||
|
|
||||||
/// Removes all messages from this channel and invokes #messagesCleared
|
/// Removes all messages from this channel and invokes #messagesCleared
|
||||||
void clearMessages();
|
void clearMessages();
|
||||||
|
|
||||||
MessagePtr findMessage(QString messageID);
|
[[deprecated("Use findMessageByID instead")]] MessagePtr findMessage(
|
||||||
|
QString messageID);
|
||||||
|
MessagePtr findMessageByID(QStringView messageID) final;
|
||||||
|
|
||||||
bool hasMessages() const;
|
bool hasMessages() const;
|
||||||
|
|
||||||
|
void applySimilarityFilters(const MessagePtr &message) const final;
|
||||||
|
|
||||||
|
MessageSinkTraits sinkTraits() const final;
|
||||||
|
|
||||||
// CHANNEL INFO
|
// CHANNEL INFO
|
||||||
virtual bool canSendMessage() const;
|
virtual bool canSendMessage() const;
|
||||||
virtual bool isWritable() const; // whether split input will be usable
|
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()>;
|
using NetworkFinallyCallback = std::function<void()>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @exposeenum HTTPMethod
|
* @exposeenum c2.HTTPMethod
|
||||||
*/
|
*/
|
||||||
enum class NetworkRequestType {
|
enum class NetworkRequestType {
|
||||||
Get,
|
Get,
|
||||||
|
|
|
@ -16,11 +16,11 @@ namespace chatterino::lua::api {
|
||||||
// NOLINTBEGIN(readability-identifier-naming)
|
// 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>
|
class HTTPRequest : public std::enable_shared_from_this<HTTPRequest>
|
||||||
{
|
{
|
||||||
|
@ -61,16 +61,16 @@ public:
|
||||||
/**
|
/**
|
||||||
* Sets the success callback
|
* Sets the success callback
|
||||||
*
|
*
|
||||||
* @lua@param callback HTTPCallback Function to call when the HTTP request succeeds
|
* @lua@param callback c2.HTTPCallback Function to call when the HTTP request succeeds
|
||||||
* @exposed HTTPRequest:on_success
|
* @exposed c2.HTTPRequest:on_success
|
||||||
*/
|
*/
|
||||||
void on_success(sol::protected_function func);
|
void on_success(sol::protected_function func);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the failure callback
|
* Sets the failure callback
|
||||||
*
|
*
|
||||||
* @lua@param callback HTTPCallback Function to call when the HTTP request fails or returns a non-ok status
|
* @lua@param callback c2.HTTPCallback Function to call when the HTTP request fails or returns a non-ok status
|
||||||
* @exposed HTTPRequest:on_error
|
* @exposed c2.HTTPRequest:on_error
|
||||||
*/
|
*/
|
||||||
void on_error(sol::protected_function func);
|
void on_error(sol::protected_function func);
|
||||||
|
|
||||||
|
@ -78,7 +78,7 @@ public:
|
||||||
* Sets the finally callback
|
* Sets the finally callback
|
||||||
*
|
*
|
||||||
* @lua@param callback fun(): nil Function to call when the HTTP request finishes
|
* @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);
|
void finally(sol::protected_function func);
|
||||||
|
|
||||||
|
@ -86,7 +86,7 @@ public:
|
||||||
* Sets the timeout
|
* Sets the timeout
|
||||||
*
|
*
|
||||||
* @lua@param timeout integer How long in milliseconds until the times out
|
* @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);
|
void set_timeout(int timeout);
|
||||||
|
|
||||||
|
@ -94,7 +94,7 @@ public:
|
||||||
* Sets the request payload
|
* Sets the request payload
|
||||||
*
|
*
|
||||||
* @lua@param data string
|
* @lua@param data string
|
||||||
* @exposed HTTPRequest:set_payload
|
* @exposed c2.HTTPRequest:set_payload
|
||||||
*/
|
*/
|
||||||
void set_payload(QByteArray payload);
|
void set_payload(QByteArray payload);
|
||||||
|
|
||||||
|
@ -103,19 +103,19 @@ public:
|
||||||
*
|
*
|
||||||
* @lua@param name string
|
* @lua@param name string
|
||||||
* @lua@param value string
|
* @lua@param value string
|
||||||
* @exposed HTTPRequest:set_header
|
* @exposed c2.HTTPRequest:set_header
|
||||||
*/
|
*/
|
||||||
void set_header(QByteArray name, QByteArray value);
|
void set_header(QByteArray name, QByteArray value);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Executes the HTTP request
|
* Executes the HTTP request
|
||||||
*
|
*
|
||||||
* @exposed HTTPRequest:execute
|
* @exposed c2.HTTPRequest:execute
|
||||||
*/
|
*/
|
||||||
void execute(sol::this_state L);
|
void execute(sol::this_state L);
|
||||||
/**
|
/**
|
||||||
* @lua@return string
|
* @lua@return string
|
||||||
* @exposed HTTPRequest:__tostring
|
* @exposed c2.HTTPRequest:__tostring
|
||||||
*/
|
*/
|
||||||
QString to_string();
|
QString to_string();
|
||||||
|
|
||||||
|
@ -126,11 +126,11 @@ public:
|
||||||
/**
|
/**
|
||||||
* Creates a new HTTPRequest
|
* 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@param url string Where to send the request to
|
||||||
*
|
*
|
||||||
* @lua@return HTTPRequest
|
* @lua@return c2.HTTPRequest
|
||||||
* @exposed HTTPRequest.create
|
* @exposed c2.HTTPRequest.create
|
||||||
*/
|
*/
|
||||||
static std::shared_ptr<HTTPRequest> create(sol::this_state L,
|
static std::shared_ptr<HTTPRequest> create(sol::this_state L,
|
||||||
NetworkRequestType method,
|
NetworkRequestType method,
|
||||||
|
|
|
@ -15,7 +15,7 @@ namespace chatterino::lua::api {
|
||||||
// NOLINTBEGIN(readability-identifier-naming)
|
// NOLINTBEGIN(readability-identifier-naming)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @lua@class HTTPResponse
|
* @lua@class c2.HTTPResponse
|
||||||
*/
|
*/
|
||||||
class HTTPResponse
|
class HTTPResponse
|
||||||
{
|
{
|
||||||
|
@ -38,26 +38,34 @@ public:
|
||||||
* Returns the data. This is not guaranteed to be encoded using any
|
* Returns the data. This is not guaranteed to be encoded using any
|
||||||
* particular encoding scheme. It's just the bytes the server returned.
|
* 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();
|
QByteArray data();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the status code.
|
* Returns the status code.
|
||||||
*
|
*
|
||||||
* @exposed HTTPResponse:status
|
* @lua@return number|nil
|
||||||
|
* @lua@nodiscard
|
||||||
|
* @exposed c2.HTTPResponse:status
|
||||||
*/
|
*/
|
||||||
std::optional<int> status();
|
std::optional<int> status();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A somewhat human readable description of an error if such happened
|
* 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();
|
QString error();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @lua@return string
|
* @lua@return string
|
||||||
* @exposed HTTPResponse:__tostring
|
* @lua@nodiscard
|
||||||
|
* @exposed c2.HTTPResponse:__tostring
|
||||||
*/
|
*/
|
||||||
QString to_string();
|
QString to_string();
|
||||||
};
|
};
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
#include <shared_mutex>
|
#include <shared_mutex>
|
||||||
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
namespace chatterino {
|
namespace chatterino {
|
||||||
|
@ -212,9 +213,10 @@ public:
|
||||||
*
|
*
|
||||||
* @param[in] index the index of the item to replace
|
* @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[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
|
* @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_);
|
std::unique_lock lock(this->mutex_);
|
||||||
|
|
||||||
|
@ -223,10 +225,46 @@ public:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (prev)
|
||||||
|
{
|
||||||
|
*prev = std::exchange(this->buffer_[index], replacement);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
this->buffer_[index] = replacement;
|
this->buffer_[index] = replacement;
|
||||||
|
}
|
||||||
return true;
|
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
|
* @brief Inserts the given item before another item
|
||||||
*
|
*
|
||||||
|
@ -315,6 +353,32 @@ public:
|
||||||
return std::nullopt;
|
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
|
* @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 "common/Env.hpp"
|
||||||
#include "messages/MessageBuilder.hpp"
|
#include "messages/MessageBuilder.hpp"
|
||||||
#include "providers/twitch/IrcMessageHandler.hpp"
|
#include "providers/twitch/IrcMessageHandler.hpp"
|
||||||
|
#include "providers/twitch/TwitchChannel.hpp"
|
||||||
#include "util/Helpers.hpp"
|
#include "util/Helpers.hpp"
|
||||||
|
#include "util/VectorMessageSink.hpp"
|
||||||
|
|
||||||
#include <QJsonArray>
|
#include <QJsonArray>
|
||||||
#include <QUrlQuery>
|
#include <QUrlQuery>
|
||||||
|
@ -40,7 +42,13 @@ std::vector<Communi::IrcMessage *> parseRecentMessages(
|
||||||
std::vector<MessagePtr> buildRecentMessages(
|
std::vector<MessagePtr> buildRecentMessages(
|
||||||
std::vector<Communi::IrcMessage *> &messages, Channel *channel)
|
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)
|
for (auto *message : messages)
|
||||||
{
|
{
|
||||||
|
@ -58,24 +66,16 @@ std::vector<MessagePtr> buildRecentMessages(
|
||||||
auto msg = makeSystemMessage(
|
auto msg = makeSystemMessage(
|
||||||
QLocale().toString(msgDate, QLocale::LongFormat),
|
QLocale().toString(msgDate, QLocale::LongFormat),
|
||||||
QTime(0, 0));
|
QTime(0, 0));
|
||||||
msg->flags.set(MessageFlag::RecentMessage);
|
sink.addMessage(msg, MessageContext::Original);
|
||||||
allBuiltMessages.emplace_back(msg);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto builtMessages = IrcMessageHandler::parseMessageWithReply(
|
IrcMessageHandler::parseMessageInto(message, sink, twitchChannel);
|
||||||
channel, message, allBuiltMessages);
|
|
||||||
|
|
||||||
for (const auto &builtMessage : builtMessages)
|
|
||||||
{
|
|
||||||
builtMessage->flags.set(MessageFlag::RecentMessage);
|
|
||||||
allBuiltMessages.emplace_back(builtMessage);
|
|
||||||
}
|
|
||||||
|
|
||||||
message->deleteLater();
|
message->deleteLater();
|
||||||
}
|
}
|
||||||
|
|
||||||
return allBuiltMessages;
|
return std::move(sink).takeMessages();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns the URL to be used for querying the Recent Messages API for the
|
// Returns the URL to be used for querying the Recent Messages API for the
|
||||||
|
|
|
@ -7,24 +7,21 @@
|
||||||
#include "common/QLogging.hpp"
|
#include "common/QLogging.hpp"
|
||||||
#include "controllers/accounts/AccountController.hpp"
|
#include "controllers/accounts/AccountController.hpp"
|
||||||
#include "controllers/ignores/IgnoreController.hpp"
|
#include "controllers/ignores/IgnoreController.hpp"
|
||||||
#include "messages/LimitedQueue.hpp"
|
|
||||||
#include "messages/Link.hpp"
|
#include "messages/Link.hpp"
|
||||||
#include "messages/Message.hpp"
|
#include "messages/Message.hpp"
|
||||||
#include "messages/MessageBuilder.hpp"
|
#include "messages/MessageBuilder.hpp"
|
||||||
#include "messages/MessageColor.hpp"
|
#include "messages/MessageColor.hpp"
|
||||||
#include "messages/MessageElement.hpp"
|
#include "messages/MessageElement.hpp"
|
||||||
|
#include "messages/MessageSink.hpp"
|
||||||
#include "messages/MessageThread.hpp"
|
#include "messages/MessageThread.hpp"
|
||||||
#include "providers/twitch/ChannelPointReward.hpp"
|
|
||||||
#include "providers/twitch/TwitchAccount.hpp"
|
#include "providers/twitch/TwitchAccount.hpp"
|
||||||
#include "providers/twitch/TwitchAccountManager.hpp"
|
#include "providers/twitch/TwitchAccountManager.hpp"
|
||||||
#include "providers/twitch/TwitchChannel.hpp"
|
#include "providers/twitch/TwitchChannel.hpp"
|
||||||
#include "providers/twitch/TwitchHelpers.hpp"
|
#include "providers/twitch/TwitchHelpers.hpp"
|
||||||
#include "providers/twitch/TwitchIrcServer.hpp"
|
#include "providers/twitch/TwitchIrcServer.hpp"
|
||||||
#include "singletons/Resources.hpp"
|
|
||||||
#include "singletons/Settings.hpp"
|
#include "singletons/Settings.hpp"
|
||||||
#include "singletons/StreamerMode.hpp"
|
#include "singletons/StreamerMode.hpp"
|
||||||
#include "singletons/WindowManager.hpp"
|
#include "singletons/WindowManager.hpp"
|
||||||
#include "util/ChannelHelpers.hpp"
|
|
||||||
#include "util/FormatTime.hpp"
|
#include "util/FormatTime.hpp"
|
||||||
#include "util/Helpers.hpp"
|
#include "util/Helpers.hpp"
|
||||||
#include "util/IrcHelpers.hpp"
|
#include "util/IrcHelpers.hpp"
|
||||||
|
@ -34,7 +31,6 @@
|
||||||
#include <QStringBuilder>
|
#include <QStringBuilder>
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <unordered_set>
|
|
||||||
|
|
||||||
using namespace chatterino::literals;
|
using namespace chatterino::literals;
|
||||||
|
|
||||||
|
@ -165,50 +161,6 @@ ChannelPtr channelOrEmptyByTarget(const QString &target,
|
||||||
return server.getChannelOrEmpty(channelName);
|
return server.getChannelOrEmpty(channelName);
|
||||||
}
|
}
|
||||||
|
|
||||||
float relativeSimilarity(const QString &str1, const QString &str2)
|
|
||||||
{
|
|
||||||
// Longest Common Substring Problem
|
|
||||||
std::vector<std::vector<int>> tree(str1.size(),
|
|
||||||
std::vector<int>(str2.size(), 0));
|
|
||||||
int z = 0;
|
|
||||||
|
|
||||||
for (int i = 0; i < str1.size(); ++i)
|
|
||||||
{
|
|
||||||
for (int 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;
|
|
||||||
}
|
|
||||||
if (tree[i][j] > z)
|
|
||||||
{
|
|
||||||
z = tree[i][j];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
tree[i][j] = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ensure that no div by 0
|
|
||||||
if (z == 0)
|
|
||||||
{
|
|
||||||
return 0.F;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto div = std::max<int>(1, std::max(str1.size(), str2.size()));
|
|
||||||
|
|
||||||
return float(z) / float(div);
|
|
||||||
}
|
|
||||||
|
|
||||||
QMap<QString, QString> parseBadges(const QString &badgesString)
|
QMap<QString, QString> parseBadges(const QString &badgesString)
|
||||||
{
|
{
|
||||||
QMap<QString, QString> badges;
|
QMap<QString, QString> badges;
|
||||||
|
@ -232,106 +184,6 @@ struct ReplyContext {
|
||||||
MessagePtr parent;
|
MessagePtr parent;
|
||||||
};
|
};
|
||||||
|
|
||||||
[[nodiscard]] ReplyContext getReplyContext(
|
|
||||||
TwitchChannel *channel, Communi::IrcMessage *message,
|
|
||||||
const std::vector<MessagePtr> &otherLoaded)
|
|
||||||
{
|
|
||||||
ReplyContext ctx;
|
|
||||||
|
|
||||||
const auto &tags = message->tags();
|
|
||||||
if (const auto it = tags.find("reply-thread-parent-msg-id");
|
|
||||||
it != tags.end())
|
|
||||||
{
|
|
||||||
const QString replyID = it.value().toString();
|
|
||||||
auto threadIt = channel->threads().find(replyID);
|
|
||||||
std::shared_ptr<MessageThread> rootThread;
|
|
||||||
if (threadIt != channel->threads().end())
|
|
||||||
{
|
|
||||||
auto owned = threadIt->second.lock();
|
|
||||||
if (owned)
|
|
||||||
{
|
|
||||||
// Thread already exists (has a reply)
|
|
||||||
checkThreadSubscription(tags, message->nick(), owned);
|
|
||||||
ctx.thread = owned;
|
|
||||||
rootThread = owned;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!rootThread)
|
|
||||||
{
|
|
||||||
MessagePtr foundMessage;
|
|
||||||
|
|
||||||
// Thread does not yet exist, find root reply and create thread.
|
|
||||||
// Linear search is justified by the infrequent use of replies
|
|
||||||
for (const auto &otherMsg : otherLoaded)
|
|
||||||
{
|
|
||||||
if (otherMsg->id == replyID)
|
|
||||||
{
|
|
||||||
// Found root reply message
|
|
||||||
foundMessage = otherMsg;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!foundMessage)
|
|
||||||
{
|
|
||||||
// We didn't find the reply root message in the otherLoaded messages
|
|
||||||
// which are typically the already-parsed recent messages from the
|
|
||||||
// Recent Messages API. We could have a really old message that
|
|
||||||
// still exists being replied to, so check for that here.
|
|
||||||
foundMessage = channel->findMessage(replyID);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (foundMessage)
|
|
||||||
{
|
|
||||||
std::shared_ptr<MessageThread> newThread =
|
|
||||||
std::make_shared<MessageThread>(foundMessage);
|
|
||||||
checkThreadSubscription(tags, message->nick(), newThread);
|
|
||||||
|
|
||||||
ctx.thread = newThread;
|
|
||||||
rootThread = newThread;
|
|
||||||
// Store weak reference to thread in channel
|
|
||||||
channel->addReplyThread(newThread);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (const auto parentIt = tags.find("reply-parent-msg-id");
|
|
||||||
parentIt != tags.end())
|
|
||||||
{
|
|
||||||
const QString parentID = parentIt.value().toString();
|
|
||||||
if (replyID == parentID)
|
|
||||||
{
|
|
||||||
if (rootThread)
|
|
||||||
{
|
|
||||||
ctx.parent = rootThread->root();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
auto parentThreadIt = channel->threads().find(parentID);
|
|
||||||
if (parentThreadIt != channel->threads().end())
|
|
||||||
{
|
|
||||||
auto thread = parentThreadIt->second.lock();
|
|
||||||
if (thread)
|
|
||||||
{
|
|
||||||
ctx.parent = thread->root();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
auto parent = channel->findMessage(parentID);
|
|
||||||
if (parent)
|
|
||||||
{
|
|
||||||
ctx.parent = parent;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return ctx;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::optional<ClearChatMessage> parseClearChatMessage(
|
std::optional<ClearChatMessage> parseClearChatMessage(
|
||||||
Communi::IrcMessage *message)
|
Communi::IrcMessage *message)
|
||||||
{
|
{
|
||||||
|
@ -370,9 +222,9 @@ std::optional<ClearChatMessage> parseClearChatMessage(
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse a single IRC NOTICE message into 0 or more Chatterino messages
|
* Parse a single IRC NOTICE message into a Chatterino message
|
||||||
**/
|
**/
|
||||||
std::vector<MessagePtr> parseNoticeMessage(Communi::IrcNoticeMessage *message)
|
MessagePtr parseNoticeMessage(Communi::IrcNoticeMessage *message)
|
||||||
{
|
{
|
||||||
assert(message != nullptr);
|
assert(message != nullptr);
|
||||||
|
|
||||||
|
@ -400,7 +252,7 @@ std::vector<MessagePtr> parseNoticeMessage(Communi::IrcNoticeMessage *message)
|
||||||
linkColor)
|
linkColor)
|
||||||
->setLink(accountsLink);
|
->setLink(accountsLink);
|
||||||
|
|
||||||
return {builder.release()};
|
return builder.release();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (message->content().startsWith("You are permanently banned "))
|
if (message->content().startsWith("You are permanently banned "))
|
||||||
|
@ -410,256 +262,19 @@ std::vector<MessagePtr> parseNoticeMessage(Communi::IrcNoticeMessage *message)
|
||||||
|
|
||||||
if (message->tags().value("msg-id") == "msg_timedout")
|
if (message->tags().value("msg-id") == "msg_timedout")
|
||||||
{
|
{
|
||||||
std::vector<MessagePtr> builtMessage;
|
|
||||||
|
|
||||||
QString remainingTime =
|
QString remainingTime =
|
||||||
formatTime(message->content().split(" ").value(5));
|
formatTime(message->content().split(" ").value(5));
|
||||||
QString formattedMessage =
|
QString formattedMessage =
|
||||||
QString("You are timed out for %1.")
|
QString("You are timed out for %1.")
|
||||||
.arg(remainingTime.isEmpty() ? "0s" : remainingTime);
|
.arg(remainingTime.isEmpty() ? "0s" : remainingTime);
|
||||||
|
|
||||||
builtMessage.emplace_back(makeSystemMessage(
|
return makeSystemMessage(formattedMessage,
|
||||||
formattedMessage, calculateMessageTime(message).time()));
|
calculateMessageTime(message).time());
|
||||||
|
|
||||||
return builtMessage;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// default case
|
// default case
|
||||||
std::vector<MessagePtr> builtMessages;
|
return makeSystemMessage(message->content(),
|
||||||
|
|
||||||
builtMessages.emplace_back(makeSystemMessage(
|
|
||||||
message->content(), calculateMessageTime(message).time()));
|
|
||||||
|
|
||||||
return builtMessages;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Parse a single IRC USERNOTICE message into 0 or more Chatterino messages
|
|
||||||
**/
|
|
||||||
std::vector<MessagePtr> parseUserNoticeMessage(Channel *channel,
|
|
||||||
Communi::IrcMessage *message)
|
|
||||||
{
|
|
||||||
assert(channel != nullptr);
|
|
||||||
assert(message != nullptr);
|
|
||||||
|
|
||||||
std::vector<MessagePtr> builtMessages;
|
|
||||||
|
|
||||||
auto tags = message->tags();
|
|
||||||
auto parameters = message->parameters();
|
|
||||||
|
|
||||||
QString msgType = tags.value("msg-id").toString();
|
|
||||||
bool mirrored = msgType == "sharedchatnotice";
|
|
||||||
if (mirrored)
|
|
||||||
{
|
|
||||||
msgType = tags.value("source-msg-id").toString();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
auto rIt = tags.find("room-id");
|
|
||||||
auto sIt = tags.find("source-room-id");
|
|
||||||
if (rIt != tags.end() && sIt != tags.end())
|
|
||||||
{
|
|
||||||
mirrored = rIt.value().toString() != sIt.value().toString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mirrored && msgType != "announcement")
|
|
||||||
{
|
|
||||||
// avoid confusing broadcasters with user payments to other channels
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
QString content;
|
|
||||||
if (parameters.size() >= 2)
|
|
||||||
{
|
|
||||||
content = parameters[1];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isIgnoredMessage({
|
|
||||||
.message = content,
|
|
||||||
.twitchUserID = tags.value("user-id").toString(),
|
|
||||||
.isMod = channel->isMod(),
|
|
||||||
.isBroadcaster = channel->isBroadcaster(),
|
|
||||||
}))
|
|
||||||
{
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
if (SPECIAL_MESSAGE_TYPES.contains(msgType))
|
|
||||||
{
|
|
||||||
// Messages are not required, so they might be empty
|
|
||||||
if (!content.isEmpty())
|
|
||||||
{
|
|
||||||
MessageParseArgs args;
|
|
||||||
args.trimSubscriberUsername = true;
|
|
||||||
args.allowIgnore = false;
|
|
||||||
|
|
||||||
auto [built, highlight] = MessageBuilder::makeIrcMessage(
|
|
||||||
channel, message, args, content, 0);
|
|
||||||
if (built)
|
|
||||||
{
|
|
||||||
built->flags.set(MessageFlag::Subscription);
|
|
||||||
built->flags.unset(MessageFlag::Highlighted);
|
|
||||||
if (mirrored)
|
|
||||||
{
|
|
||||||
built->flags.set(MessageFlag::SharedMessage);
|
|
||||||
}
|
|
||||||
builtMessages.emplace_back(std::move(built));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
auto it = tags.find("system-msg");
|
|
||||||
|
|
||||||
if (it != tags.end())
|
|
||||||
{
|
|
||||||
// By default, we return value of system-msg tag
|
|
||||||
QString messageText = it.value().toString();
|
|
||||||
|
|
||||||
if (msgType == "bitsbadgetier")
|
|
||||||
{
|
|
||||||
messageText =
|
|
||||||
QString("%1 just earned a new %2 Bits badge!")
|
|
||||||
.arg(tags.value("display-name").toString(),
|
|
||||||
kFormatNumbers(
|
|
||||||
tags.value("msg-param-threshold").toInt()));
|
|
||||||
}
|
|
||||||
else if (msgType == "announcement")
|
|
||||||
{
|
|
||||||
messageText = "Announcement";
|
|
||||||
}
|
|
||||||
else if (msgType == "raid")
|
|
||||||
{
|
|
||||||
auto login = tags.value("login").toString();
|
|
||||||
auto displayName = tags.value("msg-param-displayName").toString();
|
|
||||||
|
|
||||||
if (!login.isEmpty() && !displayName.isEmpty())
|
|
||||||
{
|
|
||||||
MessageColor color = MessageColor::System;
|
|
||||||
if (auto colorTag = tags.value("color").value<QColor>();
|
|
||||||
colorTag.isValid())
|
|
||||||
{
|
|
||||||
color = MessageColor(colorTag);
|
|
||||||
}
|
|
||||||
|
|
||||||
auto b = MessageBuilder(
|
|
||||||
raidEntryMessage, parseTagString(messageText), login,
|
|
||||||
displayName, color, calculateMessageTime(message).time());
|
|
||||||
|
|
||||||
b->flags.set(MessageFlag::Subscription);
|
|
||||||
if (mirrored)
|
|
||||||
{
|
|
||||||
b->flags.set(MessageFlag::SharedMessage);
|
|
||||||
}
|
|
||||||
|
|
||||||
auto newMessage = b.release();
|
|
||||||
builtMessages.emplace_back(newMessage);
|
|
||||||
return builtMessages;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (msgType == "subgift")
|
|
||||||
{
|
|
||||||
if (auto monthsIt = tags.find("msg-param-gift-months");
|
|
||||||
monthsIt != tags.end())
|
|
||||||
{
|
|
||||||
int months = monthsIt.value().toInt();
|
|
||||||
if (months > 1)
|
|
||||||
{
|
|
||||||
auto plan = tags.value("msg-param-sub-plan").toString();
|
|
||||||
QString name =
|
|
||||||
ANONYMOUS_GIFTER_ID == tags.value("user-id").toString()
|
|
||||||
? "An anonymous user"
|
|
||||||
: tags.value("display-name").toString();
|
|
||||||
messageText =
|
|
||||||
QString("%1 gifted %2 months of a Tier %3 sub to %4!")
|
|
||||||
.arg(name, QString::number(months),
|
|
||||||
plan.isEmpty() ? '1' : plan.at(0),
|
|
||||||
tags.value("msg-param-recipient-display-name")
|
|
||||||
.toString());
|
|
||||||
|
|
||||||
if (auto countIt = tags.find("msg-param-sender-count");
|
|
||||||
countIt != tags.end())
|
|
||||||
{
|
|
||||||
int count = countIt.value().toInt();
|
|
||||||
if (count > months)
|
|
||||||
{
|
|
||||||
messageText +=
|
|
||||||
QString(
|
|
||||||
" They've gifted %1 months in the channel.")
|
|
||||||
.arg(QString::number(count));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (msgType == "sub" || msgType == "resub")
|
|
||||||
{
|
|
||||||
if (auto tenure = tags.find("msg-param-multimonth-tenure");
|
|
||||||
tenure != tags.end() && tenure.value().toInt() == 0)
|
|
||||||
{
|
|
||||||
int months =
|
|
||||||
tags.value("msg-param-multimonth-duration").toInt();
|
|
||||||
if (months > 1)
|
|
||||||
{
|
|
||||||
int tier = tags.value("msg-param-sub-plan").toInt() / 1000;
|
|
||||||
messageText =
|
|
||||||
QString(
|
|
||||||
"%1 subscribed at Tier %2 for %3 months in advance")
|
|
||||||
.arg(tags.value("display-name").toString(),
|
|
||||||
QString::number(tier),
|
|
||||||
QString::number(months));
|
|
||||||
if (msgType == "resub")
|
|
||||||
{
|
|
||||||
int cumulative =
|
|
||||||
tags.value("msg-param-cumulative-months").toInt();
|
|
||||||
messageText +=
|
|
||||||
QString(", reaching %1 months cumulatively so far!")
|
|
||||||
.arg(QString::number(cumulative));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
messageText += "!";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
auto b = MessageBuilder(systemMessage, parseTagString(messageText),
|
|
||||||
calculateMessageTime(message).time());
|
calculateMessageTime(message).time());
|
||||||
b->flags.set(MessageFlag::Subscription);
|
|
||||||
if (mirrored)
|
|
||||||
{
|
|
||||||
b->flags.set(MessageFlag::SharedMessage);
|
|
||||||
}
|
|
||||||
|
|
||||||
auto newMessage = b.release();
|
|
||||||
builtMessages.emplace_back(newMessage);
|
|
||||||
}
|
|
||||||
|
|
||||||
return builtMessages;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Parse a single IRC PRIVMSG into 0-1 Chatterino messages
|
|
||||||
*/
|
|
||||||
std::vector<MessagePtr> parsePrivMessage(Channel *channel,
|
|
||||||
Communi::IrcPrivateMessage *message)
|
|
||||||
{
|
|
||||||
assert(channel != nullptr);
|
|
||||||
assert(message != nullptr);
|
|
||||||
|
|
||||||
std::vector<MessagePtr> builtMessages;
|
|
||||||
MessageParseArgs args;
|
|
||||||
args.isAction = message->isAction();
|
|
||||||
auto [built, alert] = MessageBuilder::makeIrcMessage(channel, message, args,
|
|
||||||
message->content(), 0);
|
|
||||||
if (built)
|
|
||||||
{
|
|
||||||
builtMessages.emplace_back(std::move(built));
|
|
||||||
MessageBuilder::triggerHighlights(channel, alert);
|
|
||||||
}
|
|
||||||
|
|
||||||
return builtMessages;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
@ -674,65 +289,27 @@ IrcMessageHandler &IrcMessageHandler::instance()
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<MessagePtr> IrcMessageHandler::parseMessageWithReply(
|
void IrcMessageHandler::parseMessageInto(Communi::IrcMessage *message,
|
||||||
Channel *channel, Communi::IrcMessage *message,
|
MessageSink &sink,
|
||||||
std::vector<MessagePtr> &otherLoaded)
|
TwitchChannel *channel)
|
||||||
{
|
{
|
||||||
std::vector<MessagePtr> builtMessages;
|
|
||||||
|
|
||||||
auto command = message->command();
|
auto command = message->command();
|
||||||
|
|
||||||
if (command == u"PRIVMSG"_s)
|
if (command == u"PRIVMSG"_s)
|
||||||
{
|
{
|
||||||
auto *privMsg = dynamic_cast<Communi::IrcPrivateMessage *>(message);
|
parsePrivMessageInto(
|
||||||
auto *tc = dynamic_cast<TwitchChannel *>(channel);
|
dynamic_cast<Communi::IrcPrivateMessage *>(message), sink, channel);
|
||||||
if (!tc)
|
|
||||||
{
|
|
||||||
return parsePrivMessage(channel, privMsg);
|
|
||||||
}
|
}
|
||||||
|
else if (command == u"USERNOTICE"_s)
|
||||||
QString content = privMsg->content();
|
|
||||||
int messageOffset = stripLeadingReplyMention(privMsg->tags(), content);
|
|
||||||
MessageParseArgs args;
|
|
||||||
auto tags = privMsg->tags();
|
|
||||||
if (const auto it = tags.find("custom-reward-id"); it != tags.end())
|
|
||||||
{
|
{
|
||||||
args.channelPointRewardId = it.value().toString();
|
parseUserNoticeMessageInto(message, sink, channel);
|
||||||
}
|
|
||||||
args.isAction = privMsg->isAction();
|
|
||||||
|
|
||||||
auto replyCtx = getReplyContext(tc, message, otherLoaded);
|
|
||||||
auto [built, alert] = MessageBuilder::makeIrcMessage(
|
|
||||||
channel, message, args, content, messageOffset, replyCtx.thread,
|
|
||||||
replyCtx.parent);
|
|
||||||
|
|
||||||
if (built)
|
|
||||||
{
|
|
||||||
builtMessages.emplace_back(built);
|
|
||||||
MessageBuilder::triggerHighlights(channel, alert);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (message->tags().contains(u"pinned-chat-paid-amount"_s))
|
|
||||||
{
|
|
||||||
auto ptr = MessageBuilder::buildHypeChatMessage(privMsg);
|
|
||||||
if (ptr)
|
|
||||||
{
|
|
||||||
builtMessages.emplace_back(std::move(ptr));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return builtMessages;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (command == u"USERNOTICE"_s)
|
|
||||||
{
|
|
||||||
return parseUserNoticeMessage(channel, message);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (command == u"NOTICE"_s)
|
if (command == u"NOTICE"_s)
|
||||||
{
|
{
|
||||||
return parseNoticeMessage(
|
sink.addMessage(parseNoticeMessage(
|
||||||
dynamic_cast<Communi::IrcNoticeMessage *>(message));
|
dynamic_cast<Communi::IrcNoticeMessage *>(message)),
|
||||||
|
MessageContext::Original);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (command == u"CLEARCHAT"_s)
|
if (command == u"CLEARCHAT"_s)
|
||||||
|
@ -740,32 +317,20 @@ std::vector<MessagePtr> IrcMessageHandler::parseMessageWithReply(
|
||||||
auto cc = parseClearChatMessage(message);
|
auto cc = parseClearChatMessage(message);
|
||||||
if (!cc)
|
if (!cc)
|
||||||
{
|
{
|
||||||
return builtMessages;
|
return;
|
||||||
}
|
}
|
||||||
auto &clearChat = *cc;
|
auto &clearChat = *cc;
|
||||||
if (clearChat.disableAllMessages)
|
if (clearChat.disableAllMessages)
|
||||||
{
|
{
|
||||||
builtMessages.emplace_back(std::move(clearChat.message));
|
sink.addMessage(std::move(clearChat.message),
|
||||||
|
MessageContext::Original);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
addOrReplaceChannelTimeout(
|
sink.addOrReplaceTimeout(std::move(clearChat.message),
|
||||||
otherLoaded, std::move(clearChat.message),
|
calculateMessageTime(message).time());
|
||||||
calculateMessageTime(message).time(),
|
|
||||||
[&](auto idx, auto /*msg*/, auto &&replacement) {
|
|
||||||
replacement->flags.set(MessageFlag::RecentMessage);
|
|
||||||
otherLoaded[idx] = replacement;
|
|
||||||
},
|
|
||||||
[&](auto &&msg) {
|
|
||||||
builtMessages.emplace_back(msg);
|
|
||||||
},
|
|
||||||
false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return builtMessages;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return builtMessages;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void IrcMessageHandler::handlePrivMessage(Communi::IrcPrivateMessage *message,
|
void IrcMessageHandler::handlePrivMessage(Communi::IrcPrivateMessage *message,
|
||||||
|
@ -778,8 +343,17 @@ void IrcMessageHandler::handlePrivMessage(Communi::IrcPrivateMessage *message,
|
||||||
}
|
}
|
||||||
|
|
||||||
auto *twitchChannel = dynamic_cast<TwitchChannel *>(chan.get());
|
auto *twitchChannel = dynamic_cast<TwitchChannel *>(chan.get());
|
||||||
|
if (!twitchChannel)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (twitchChannel != nullptr)
|
parsePrivMessageInto(message, *twitchChannel, twitchChannel);
|
||||||
|
}
|
||||||
|
|
||||||
|
void IrcMessageHandler::parsePrivMessageInto(
|
||||||
|
Communi::IrcPrivateMessage *message, MessageSink &sink,
|
||||||
|
TwitchChannel *channel)
|
||||||
{
|
{
|
||||||
auto currentUser = getApp()->getAccounts()->twitch.getCurrent();
|
auto currentUser = getApp()->getAccounts()->twitch.getCurrent();
|
||||||
if (message->tag("user-id") == currentUser->getUserId())
|
if (message->tag("user-id") == currentUser->getUserId())
|
||||||
|
@ -788,22 +362,22 @@ void IrcMessageHandler::handlePrivMessage(Communi::IrcPrivateMessage *message,
|
||||||
if (badgesTag.isValid())
|
if (badgesTag.isValid())
|
||||||
{
|
{
|
||||||
auto parsedBadges = parseBadges(badgesTag.toString());
|
auto parsedBadges = parseBadges(badgesTag.toString());
|
||||||
twitchChannel->setMod(parsedBadges.contains("moderator"));
|
channel->setMod(parsedBadges.contains("moderator"));
|
||||||
twitchChannel->setVIP(parsedBadges.contains("vip"));
|
channel->setVIP(parsedBadges.contains("vip"));
|
||||||
twitchChannel->setStaff(parsedBadges.contains("staff"));
|
channel->setStaff(parsedBadges.contains("staff"));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this->addMessage(message, chan, unescapeZeroWidthJoiner(message->content()),
|
IrcMessageHandler::addMessage(
|
||||||
twitchServer, false, message->isAction());
|
message, sink, channel, unescapeZeroWidthJoiner(message->content()),
|
||||||
|
*getApp()->getTwitch(), false, message->isAction());
|
||||||
|
|
||||||
if (message->tags().contains(u"pinned-chat-paid-amount"_s))
|
if (message->tags().contains(u"pinned-chat-paid-amount"_s))
|
||||||
{
|
{
|
||||||
auto ptr = MessageBuilder::buildHypeChatMessage(message);
|
auto ptr = MessageBuilder::buildHypeChatMessage(message);
|
||||||
if (ptr)
|
if (ptr)
|
||||||
{
|
{
|
||||||
chan->addMessage(ptr, MessageContext::Original);
|
sink.addMessage(ptr, MessageContext::Original);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -900,7 +474,8 @@ void IrcMessageHandler::handleClearChatMessage(Communi::IrcMessage *message)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
chan->addOrReplaceTimeout(std::move(clearChat.message));
|
chan->addOrReplaceTimeout(std::move(clearChat.message),
|
||||||
|
calculateMessageTime(message).time());
|
||||||
|
|
||||||
// refresh all
|
// refresh all
|
||||||
getApp()->getWindows()->repaintVisibleChatWidgets(chan.get());
|
getApp()->getWindows()->repaintVisibleChatWidgets(chan.get());
|
||||||
|
@ -1039,11 +614,24 @@ void IrcMessageHandler::handleWhisperMessage(Communi::IrcMessage *ircMessage)
|
||||||
|
|
||||||
void IrcMessageHandler::handleUserNoticeMessage(Communi::IrcMessage *message,
|
void IrcMessageHandler::handleUserNoticeMessage(Communi::IrcMessage *message,
|
||||||
ITwitchIrcServer &twitchServer)
|
ITwitchIrcServer &twitchServer)
|
||||||
|
{
|
||||||
|
auto target = message->parameter(0);
|
||||||
|
auto *channel = dynamic_cast<TwitchChannel *>(
|
||||||
|
twitchServer.getChannelOrEmpty(target).get());
|
||||||
|
if (!channel)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
parseUserNoticeMessageInto(message, *channel, channel);
|
||||||
|
}
|
||||||
|
|
||||||
|
void IrcMessageHandler::parseUserNoticeMessageInto(Communi::IrcMessage *message,
|
||||||
|
MessageSink &sink,
|
||||||
|
TwitchChannel *channel)
|
||||||
{
|
{
|
||||||
auto tags = message->tags();
|
auto tags = message->tags();
|
||||||
auto parameters = message->parameters();
|
auto parameters = message->parameters();
|
||||||
|
|
||||||
auto target = parameters[0];
|
|
||||||
QString msgType = tags.value("msg-id").toString();
|
QString msgType = tags.value("msg-id").toString();
|
||||||
bool mirrored = msgType == "sharedchatnotice";
|
bool mirrored = msgType == "sharedchatnotice";
|
||||||
if (mirrored)
|
if (mirrored)
|
||||||
|
@ -1072,12 +660,11 @@ void IrcMessageHandler::handleUserNoticeMessage(Communi::IrcMessage *message,
|
||||||
content = parameters[1];
|
content = parameters[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
auto chn = twitchServer.getChannelOrEmpty(target);
|
|
||||||
if (isIgnoredMessage({
|
if (isIgnoredMessage({
|
||||||
.message = content,
|
.message = content,
|
||||||
.twitchUserID = tags.value("user-id").toString(),
|
.twitchUserID = tags.value("user-id").toString(),
|
||||||
.isMod = chn->isMod(),
|
.isMod = channel->isMod(),
|
||||||
.isBroadcaster = chn->isBroadcaster(),
|
.isBroadcaster = channel->isBroadcaster(),
|
||||||
}))
|
}))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
|
@ -1088,7 +675,8 @@ void IrcMessageHandler::handleUserNoticeMessage(Communi::IrcMessage *message,
|
||||||
// Messages are not required, so they might be empty
|
// Messages are not required, so they might be empty
|
||||||
if (!content.isEmpty())
|
if (!content.isEmpty())
|
||||||
{
|
{
|
||||||
this->addMessage(message, chn, content, twitchServer, true, false);
|
addMessage(message, sink, channel, content, *getApp()->getTwitch(),
|
||||||
|
true, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1136,25 +724,7 @@ void IrcMessageHandler::handleUserNoticeMessage(Communi::IrcMessage *message,
|
||||||
}
|
}
|
||||||
auto newMessage = b.release();
|
auto newMessage = b.release();
|
||||||
|
|
||||||
QString channelName;
|
sink.addMessage(newMessage, MessageContext::Original);
|
||||||
|
|
||||||
if (message->parameters().size() < 1)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!trimChannelName(message->parameter(0), channelName))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto chan = twitchServer.getChannelOrEmpty(channelName);
|
|
||||||
|
|
||||||
if (!chan->isEmpty())
|
|
||||||
{
|
|
||||||
chan->addMessage(newMessage, MessageContext::Original);
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1235,33 +805,14 @@ void IrcMessageHandler::handleUserNoticeMessage(Communi::IrcMessage *message,
|
||||||
}
|
}
|
||||||
auto newMessage = b.release();
|
auto newMessage = b.release();
|
||||||
|
|
||||||
QString channelName;
|
sink.addMessage(newMessage, MessageContext::Original);
|
||||||
|
|
||||||
if (message->parameters().size() < 1)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!trimChannelName(message->parameter(0), channelName))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto chan = twitchServer.getChannelOrEmpty(channelName);
|
|
||||||
|
|
||||||
if (!chan->isEmpty())
|
|
||||||
{
|
|
||||||
chan->addMessage(newMessage, MessageContext::Original);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void IrcMessageHandler::handleNoticeMessage(Communi::IrcNoticeMessage *message)
|
void IrcMessageHandler::handleNoticeMessage(Communi::IrcNoticeMessage *message)
|
||||||
{
|
{
|
||||||
auto builtMessages = parseNoticeMessage(message);
|
auto msg = parseNoticeMessage(message);
|
||||||
|
|
||||||
for (const auto &msg : builtMessages)
|
|
||||||
{
|
|
||||||
QString channelName;
|
QString channelName;
|
||||||
if (!trimChannelName(message->target(), channelName) ||
|
if (!trimChannelName(message->target(), channelName) ||
|
||||||
channelName == "jtv")
|
channelName == "jtv")
|
||||||
|
@ -1316,8 +867,8 @@ void IrcMessageHandler::handleNoticeMessage(Communi::IrcNoticeMessage *message)
|
||||||
{
|
{
|
||||||
hostedChannelName.chop(1);
|
hostedChannelName.chop(1);
|
||||||
}
|
}
|
||||||
channel->addMessage(MessageBuilder::makeHostingSystemMessage(
|
channel->addMessage(
|
||||||
hostedChannelName, hostOn),
|
MessageBuilder::makeHostingSystemMessage(hostedChannelName, hostOn),
|
||||||
MessageContext::Original);
|
MessageContext::Original);
|
||||||
}
|
}
|
||||||
else if (tags == "room_mods" || tags == "vips_success")
|
else if (tags == "room_mods" || tags == "vips_success")
|
||||||
|
@ -1345,8 +896,8 @@ void IrcMessageHandler::handleNoticeMessage(Communi::IrcNoticeMessage *message)
|
||||||
.mid(1) // there is a space before the first user
|
.mid(1) // there is a space before the first user
|
||||||
.split(", ");
|
.split(", ");
|
||||||
users.sort(Qt::CaseInsensitive);
|
users.sort(Qt::CaseInsensitive);
|
||||||
channel->addMessage(MessageBuilder::makeListOfUsersMessage(
|
channel->addMessage(
|
||||||
msgParts.at(0), users, tc),
|
MessageBuilder::makeListOfUsersMessage(msgParts.at(0), users, tc),
|
||||||
MessageContext::Original);
|
MessageContext::Original);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -1354,7 +905,6 @@ void IrcMessageHandler::handleNoticeMessage(Communi::IrcNoticeMessage *message)
|
||||||
channel->addMessage(msg, MessageContext::Original);
|
channel->addMessage(msg, MessageContext::Original);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void IrcMessageHandler::handleJoinMessage(Communi::IrcMessage *message)
|
void IrcMessageHandler::handleJoinMessage(Communi::IrcMessage *message)
|
||||||
{
|
{
|
||||||
|
@ -1405,76 +955,13 @@ void IrcMessageHandler::handlePartMessage(Communi::IrcMessage *message)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
float IrcMessageHandler::similarity(
|
|
||||||
const MessagePtr &msg, const LimitedQueueSnapshot<MessagePtr> &messages)
|
|
||||||
{
|
|
||||||
float similarityPercent = 0.0F;
|
|
||||||
int checked = 0;
|
|
||||||
|
|
||||||
for (size_t i = 1; i <= messages.size(); ++i)
|
|
||||||
{
|
|
||||||
if (checked >= getSettings()->hideSimilarMaxMessagesToCheck)
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
const auto &prevMsg = messages[messages.size() - i];
|
|
||||||
if (prevMsg->parseTime.secsTo(QTime::currentTime()) >=
|
|
||||||
getSettings()->hideSimilarMaxDelay)
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (getSettings()->hideSimilarBySameUser &&
|
|
||||||
msg->loginName != prevMsg->loginName)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
++checked;
|
|
||||||
similarityPercent = std::max(
|
|
||||||
similarityPercent,
|
|
||||||
relativeSimilarity(msg->messageText, prevMsg->messageText));
|
|
||||||
}
|
|
||||||
|
|
||||||
return similarityPercent;
|
|
||||||
}
|
|
||||||
|
|
||||||
void IrcMessageHandler::setSimilarityFlags(const MessagePtr &message,
|
|
||||||
const ChannelPtr &channel)
|
|
||||||
{
|
|
||||||
if (getSettings()->similarityEnabled)
|
|
||||||
{
|
|
||||||
bool isMyself =
|
|
||||||
message->loginName ==
|
|
||||||
getApp()->getAccounts()->twitch.getCurrent()->getUserName();
|
|
||||||
bool hideMyself = getSettings()->hideSimilarMyself;
|
|
||||||
|
|
||||||
if (isMyself && !hideMyself)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (IrcMessageHandler::similarity(message,
|
|
||||||
channel->getMessageSnapshot()) >
|
|
||||||
getSettings()->similarityPercentage)
|
|
||||||
{
|
|
||||||
message->flags.set(MessageFlag::Similar, true);
|
|
||||||
if (getSettings()->colorSimilarDisabled)
|
|
||||||
{
|
|
||||||
message->flags.set(MessageFlag::Disabled, true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void IrcMessageHandler::addMessage(Communi::IrcMessage *message,
|
void IrcMessageHandler::addMessage(Communi::IrcMessage *message,
|
||||||
const ChannelPtr &chan,
|
MessageSink &sink, TwitchChannel *chan,
|
||||||
const QString &originalContent,
|
const QString &originalContent,
|
||||||
ITwitchIrcServer &server, bool isSub,
|
ITwitchIrcServer &twitch, bool isSub,
|
||||||
bool isAction)
|
bool isAction)
|
||||||
{
|
{
|
||||||
if (chan->isEmpty())
|
assert(chan);
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
MessageParseArgs args;
|
MessageParseArgs args;
|
||||||
if (isSub)
|
if (isSub)
|
||||||
|
@ -1489,8 +976,6 @@ void IrcMessageHandler::addMessage(Communi::IrcMessage *message,
|
||||||
}
|
}
|
||||||
args.isAction = isAction;
|
args.isAction = isAction;
|
||||||
|
|
||||||
auto *channel = dynamic_cast<TwitchChannel *>(chan.get());
|
|
||||||
|
|
||||||
const auto &tags = message->tags();
|
const auto &tags = message->tags();
|
||||||
QString rewardId;
|
QString rewardId;
|
||||||
if (const auto it = tags.find("custom-reward-id"); it != tags.end())
|
if (const auto it = tags.find("custom-reward-id"); it != tags.end())
|
||||||
|
@ -1506,13 +991,16 @@ void IrcMessageHandler::addMessage(Communi::IrcMessage *message,
|
||||||
rewardId = msgId;
|
rewardId = msgId;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!rewardId.isEmpty() && !channel->isChannelPointRewardKnown(rewardId))
|
if (!rewardId.isEmpty() &&
|
||||||
|
sink.sinkTraits().has(
|
||||||
|
MessageSinkTrait::RequiresKnownChannelPointReward) &&
|
||||||
|
!chan->isChannelPointRewardKnown(rewardId))
|
||||||
{
|
{
|
||||||
// Need to wait for pubsub reward notification
|
// Need to wait for pubsub reward notification
|
||||||
qCDebug(chatterinoTwitch) << "TwitchChannel reward added ADD "
|
qCDebug(chatterinoTwitch) << "TwitchChannel reward added ADD "
|
||||||
"callback since reward is not known:"
|
"callback since reward is not known:"
|
||||||
<< rewardId;
|
<< rewardId;
|
||||||
channel->addQueuedRedemption(rewardId, originalContent, message);
|
chan->addQueuedRedemption(rewardId, originalContent, message);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
args.channelPointRewardId = rewardId;
|
args.channelPointRewardId = rewardId;
|
||||||
|
@ -1526,9 +1014,9 @@ void IrcMessageHandler::addMessage(Communi::IrcMessage *message,
|
||||||
it != tags.end())
|
it != tags.end())
|
||||||
{
|
{
|
||||||
const QString replyID = it.value().toString();
|
const QString replyID = it.value().toString();
|
||||||
auto threadIt = channel->threads().find(replyID);
|
auto threadIt = chan->threads().find(replyID);
|
||||||
std::shared_ptr<MessageThread> rootThread;
|
std::shared_ptr<MessageThread> rootThread;
|
||||||
if (threadIt != channel->threads().end() && !threadIt->second.expired())
|
if (threadIt != chan->threads().end() && !threadIt->second.expired())
|
||||||
{
|
{
|
||||||
// Thread already exists (has a reply)
|
// Thread already exists (has a reply)
|
||||||
auto thread = threadIt->second.lock();
|
auto thread = threadIt->second.lock();
|
||||||
|
@ -1539,7 +1027,7 @@ void IrcMessageHandler::addMessage(Communi::IrcMessage *message,
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Thread does not yet exist, find root reply and create thread.
|
// Thread does not yet exist, find root reply and create thread.
|
||||||
auto root = channel->findMessage(replyID);
|
auto root = sink.findMessageByID(replyID);
|
||||||
if (root)
|
if (root)
|
||||||
{
|
{
|
||||||
// Found root reply message
|
// Found root reply message
|
||||||
|
@ -1549,7 +1037,7 @@ void IrcMessageHandler::addMessage(Communi::IrcMessage *message,
|
||||||
replyCtx.thread = newThread;
|
replyCtx.thread = newThread;
|
||||||
rootThread = newThread;
|
rootThread = newThread;
|
||||||
// Store weak reference to thread in channel
|
// Store weak reference to thread in channel
|
||||||
channel->addReplyThread(newThread);
|
chan->addReplyThread(newThread);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1566,8 +1054,8 @@ void IrcMessageHandler::addMessage(Communi::IrcMessage *message,
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
auto parentThreadIt = channel->threads().find(parentID);
|
auto parentThreadIt = chan->threads().find(parentID);
|
||||||
if (parentThreadIt != channel->threads().end())
|
if (parentThreadIt != chan->threads().end())
|
||||||
{
|
{
|
||||||
auto thread = parentThreadIt->second.lock();
|
auto thread = parentThreadIt->second.lock();
|
||||||
if (thread)
|
if (thread)
|
||||||
|
@ -1577,7 +1065,7 @@ void IrcMessageHandler::addMessage(Communi::IrcMessage *message,
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
auto parent = channel->findMessage(parentID);
|
auto parent = sink.findMessageByID(parentID);
|
||||||
if (parent)
|
if (parent)
|
||||||
{
|
{
|
||||||
replyCtx.parent = parent;
|
replyCtx.parent = parent;
|
||||||
|
@ -1589,7 +1077,7 @@ void IrcMessageHandler::addMessage(Communi::IrcMessage *message,
|
||||||
|
|
||||||
args.allowIgnore = !isSub;
|
args.allowIgnore = !isSub;
|
||||||
auto [msg, alert] = MessageBuilder::makeIrcMessage(
|
auto [msg, alert] = MessageBuilder::makeIrcMessage(
|
||||||
channel, message, args, content, messageOffset, replyCtx.thread,
|
chan, message, args, content, messageOffset, replyCtx.thread,
|
||||||
replyCtx.parent);
|
replyCtx.parent);
|
||||||
|
|
||||||
if (msg)
|
if (msg)
|
||||||
|
@ -1600,29 +1088,27 @@ void IrcMessageHandler::addMessage(Communi::IrcMessage *message,
|
||||||
msg->flags.unset(MessageFlag::Highlighted);
|
msg->flags.unset(MessageFlag::Highlighted);
|
||||||
}
|
}
|
||||||
|
|
||||||
IrcMessageHandler::setSimilarityFlags(msg, chan);
|
sink.applySimilarityFilters(msg);
|
||||||
|
|
||||||
if (!msg->flags.has(MessageFlag::Similar) ||
|
if (!msg->flags.has(MessageFlag::Similar) ||
|
||||||
(!getSettings()->hideSimilar &&
|
(!getSettings()->hideSimilar &&
|
||||||
getSettings()->shownSimilarTriggerHighlights))
|
getSettings()->shownSimilarTriggerHighlights))
|
||||||
{
|
{
|
||||||
MessageBuilder::triggerHighlights(channel, alert);
|
MessageBuilder::triggerHighlights(chan, alert);
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto highlighted = msg->flags.has(MessageFlag::Highlighted);
|
const auto highlighted = msg->flags.has(MessageFlag::Highlighted);
|
||||||
const auto showInMentions = msg->flags.has(MessageFlag::ShowInMentions);
|
const auto showInMentions = msg->flags.has(MessageFlag::ShowInMentions);
|
||||||
|
|
||||||
if (highlighted && showInMentions)
|
if (highlighted && showInMentions &&
|
||||||
|
sink.sinkTraits().has(MessageSinkTrait::AddMentionsToGlobalChannel))
|
||||||
{
|
{
|
||||||
server.getMentionsChannel()->addMessage(msg,
|
twitch.getMentionsChannel()->addMessage(msg,
|
||||||
MessageContext::Original);
|
MessageContext::Original);
|
||||||
}
|
}
|
||||||
|
|
||||||
chan->addMessage(msg, MessageContext::Original);
|
sink.addMessage(msg, MessageContext::Original);
|
||||||
if (auto *chatters = dynamic_cast<ChannelChatters *>(chan.get()))
|
chan->addRecentChatter(msg->displayName);
|
||||||
{
|
|
||||||
chatters->addRecentChatter(msg->displayName);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,7 @@ struct Message;
|
||||||
using MessagePtr = std::shared_ptr<const Message>;
|
using MessagePtr = std::shared_ptr<const Message>;
|
||||||
class TwitchChannel;
|
class TwitchChannel;
|
||||||
class TwitchMessageBuilder;
|
class TwitchMessageBuilder;
|
||||||
|
class MessageSink;
|
||||||
|
|
||||||
struct ClearChatMessage {
|
struct ClearChatMessage {
|
||||||
MessagePtr message;
|
MessagePtr message;
|
||||||
|
@ -33,30 +34,34 @@ public:
|
||||||
* Parse an IRC message into 0 or more Chatterino messages
|
* Parse an IRC message into 0 or more Chatterino messages
|
||||||
* Takes previously loaded messages into consideration to add reply contexts
|
* Takes previously loaded messages into consideration to add reply contexts
|
||||||
**/
|
**/
|
||||||
static std::vector<MessagePtr> parseMessageWithReply(
|
static void parseMessageInto(Communi::IrcMessage *message,
|
||||||
Channel *channel, Communi::IrcMessage *message,
|
MessageSink &sink, TwitchChannel *channel);
|
||||||
std::vector<MessagePtr> &otherLoaded);
|
|
||||||
|
|
||||||
void handlePrivMessage(Communi::IrcPrivateMessage *message,
|
void handlePrivMessage(Communi::IrcPrivateMessage *message,
|
||||||
ITwitchIrcServer &twitchServer);
|
ITwitchIrcServer &twitchServer);
|
||||||
|
static void parsePrivMessageInto(Communi::IrcPrivateMessage *message,
|
||||||
|
MessageSink &sink, TwitchChannel *channel);
|
||||||
|
|
||||||
void handleRoomStateMessage(Communi::IrcMessage *message);
|
void handleRoomStateMessage(Communi::IrcMessage *message);
|
||||||
void handleClearChatMessage(Communi::IrcMessage *message);
|
void handleClearChatMessage(Communi::IrcMessage *message);
|
||||||
void handleClearMessageMessage(Communi::IrcMessage *message);
|
void handleClearMessageMessage(Communi::IrcMessage *message);
|
||||||
void handleUserStateMessage(Communi::IrcMessage *message);
|
void handleUserStateMessage(Communi::IrcMessage *message);
|
||||||
void handleWhisperMessage(Communi::IrcMessage *ircMessage);
|
|
||||||
|
|
||||||
|
void handleWhisperMessage(Communi::IrcMessage *ircMessage);
|
||||||
void handleUserNoticeMessage(Communi::IrcMessage *message,
|
void handleUserNoticeMessage(Communi::IrcMessage *message,
|
||||||
ITwitchIrcServer &twitchServer);
|
ITwitchIrcServer &twitchServer);
|
||||||
|
static void parseUserNoticeMessageInto(Communi::IrcMessage *message,
|
||||||
|
MessageSink &sink,
|
||||||
|
TwitchChannel *channel);
|
||||||
|
|
||||||
void handleNoticeMessage(Communi::IrcNoticeMessage *message);
|
void handleNoticeMessage(Communi::IrcNoticeMessage *message);
|
||||||
|
|
||||||
void handleJoinMessage(Communi::IrcMessage *message);
|
void handleJoinMessage(Communi::IrcMessage *message);
|
||||||
void handlePartMessage(Communi::IrcMessage *message);
|
void handlePartMessage(Communi::IrcMessage *message);
|
||||||
|
|
||||||
void addMessage(Communi::IrcMessage *message, const ChannelPtr &chan,
|
static void addMessage(Communi::IrcMessage *message, MessageSink &sink,
|
||||||
const QString &originalContent, ITwitchIrcServer &server,
|
TwitchChannel *chan, const QString &originalContent,
|
||||||
bool isSub, bool isAction);
|
ITwitchIrcServer &twitch, bool isSub, bool isAction);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static float similarity(const MessagePtr &msg,
|
static float similarity(const MessagePtr &msg,
|
||||||
|
|
|
@ -452,8 +452,8 @@ void TwitchChannel::addChannelPointReward(const ChannelPointReward &reward)
|
||||||
if (reward.id == msg.rewardID)
|
if (reward.id == msg.rewardID)
|
||||||
{
|
{
|
||||||
IrcMessageHandler::instance().addMessage(
|
IrcMessageHandler::instance().addMessage(
|
||||||
msg.message.get(), shared_from_this(),
|
msg.message.get(), *this, this, msg.originalContent,
|
||||||
msg.originalContent, *server, false, false);
|
*server, false, false);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -1356,8 +1356,6 @@ void TwitchChannel::loadRecentMessages()
|
||||||
{
|
{
|
||||||
msgs.push_back(msg);
|
msgs.push_back(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
tc->addRecentChatter(msg->displayName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getApp()->getTwitch()->getMentionsChannel()->fillInMissingMessages(
|
getApp()->getTwitch()->getMentionsChannel()->fillInMissingMessages(
|
||||||
|
|
|
@ -312,7 +312,7 @@ void TwitchIrcServer::initialize()
|
||||||
postToThread([chan, action] {
|
postToThread([chan, action] {
|
||||||
MessageBuilder msg(action);
|
MessageBuilder msg(action);
|
||||||
msg->flags.set(MessageFlag::PubSub);
|
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
|
|
@ -967,10 +967,10 @@ void ChannelView::setChannel(const ChannelPtr &underlyingChannel)
|
||||||
|
|
||||||
this->channelConnections_.managedConnect(
|
this->channelConnections_.managedConnect(
|
||||||
underlyingChannel->messageReplaced,
|
underlyingChannel->messageReplaced,
|
||||||
[this](auto index, const auto &replacement) {
|
[this](auto index, const auto &prev, const auto &replacement) {
|
||||||
if (this->shouldIncludeMessage(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
|
// on message replaced
|
||||||
this->channelConnections_.managedConnect(
|
this->channelConnections_.managedConnect(
|
||||||
this->channel_->messageReplaced,
|
this->channel_->messageReplaced,
|
||||||
[this](size_t index, MessagePtr replacement) {
|
[this](size_t index, const MessagePtr &prev,
|
||||||
this->messageReplaced(index, replacement);
|
const MessagePtr &replacement) {
|
||||||
|
this->messageReplaced(index, prev, replacement);
|
||||||
});
|
});
|
||||||
|
|
||||||
// on messages filled in
|
// on messages filled in
|
||||||
|
@ -1262,19 +1263,21 @@ void ChannelView::messageAddedAtStart(std::vector<MessagePtr> &messages)
|
||||||
this->queueLayout();
|
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);
|
auto optItem = this->messages_.find(hint, [&](const auto &it) {
|
||||||
if (!oMessage)
|
return it->getMessagePtr() == prev;
|
||||||
|
});
|
||||||
|
if (!optItem)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
const auto &[index, oldItem] = *optItem;
|
||||||
auto message = *oMessage;
|
|
||||||
|
|
||||||
auto newItem = std::make_shared<MessageLayout>(replacement);
|
auto newItem = std::make_shared<MessageLayout>(replacement);
|
||||||
|
|
||||||
if (message->flags.has(MessageLayoutFlag::AlternateBackground))
|
if (oldItem->flags.has(MessageLayoutFlag::AlternateBackground))
|
||||||
{
|
{
|
||||||
newItem->flags.set(MessageLayoutFlag::AlternateBackground);
|
newItem->flags.set(MessageLayoutFlag::AlternateBackground);
|
||||||
}
|
}
|
||||||
|
@ -1282,7 +1285,7 @@ void ChannelView::messageReplaced(size_t index, MessagePtr &replacement)
|
||||||
this->scrollBar_->replaceHighlight(index,
|
this->scrollBar_->replaceHighlight(index,
|
||||||
replacement->getScrollBarHighlight());
|
replacement->getScrollBarHighlight());
|
||||||
|
|
||||||
this->messages_.replaceItem(message, newItem);
|
this->messages_.replaceItem(index, newItem);
|
||||||
this->queueLayout();
|
this->queueLayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -276,7 +276,8 @@ private:
|
||||||
std::optional<MessageFlags> overridingFlags);
|
std::optional<MessageFlags> overridingFlags);
|
||||||
void messageAddedAtStart(std::vector<MessagePtr> &messages);
|
void messageAddedAtStart(std::vector<MessagePtr> &messages);
|
||||||
void messageRemoveFromStart(MessagePtr &message);
|
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 messagesUpdated();
|
||||||
|
|
||||||
void performLayout(bool causedByScrollbar = false,
|
void performLayout(bool causedByScrollbar = false,
|
||||||
|
|
|
@ -180,6 +180,7 @@
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"flags": "Collapsed|Subscription",
|
"flags": "Collapsed|Subscription",
|
||||||
|
"highlightColor": "#64c466ff",
|
||||||
"id": "8c26e1ab-b50c-4d9d-bc11-3fd57a941d90",
|
"id": "8c26e1ab-b50c-4d9d-bc11-3fd57a941d90",
|
||||||
"localizedName": "",
|
"localizedName": "",
|
||||||
"loginName": "supinic",
|
"loginName": "supinic",
|
||||||
|
|
|
@ -80,7 +80,7 @@
|
||||||
"trailingSpace": true,
|
"trailingSpace": true,
|
||||||
"type": "SingleLineTextElement",
|
"type": "SingleLineTextElement",
|
||||||
"words": [
|
"words": [
|
||||||
"a"
|
"b"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -169,6 +169,7 @@
|
||||||
"localizedName": "",
|
"localizedName": "",
|
||||||
"loginName": "nerixyz",
|
"loginName": "nerixyz",
|
||||||
"messageText": "c",
|
"messageText": "c",
|
||||||
|
"replyParent": "474f19ab-a1b0-410a-877a-5b0e2ae8be6d",
|
||||||
"replyThread": {
|
"replyThread": {
|
||||||
"replies": [
|
"replies": [
|
||||||
"474f19ab-a1b0-410a-877a-5b0e2ae8be6d",
|
"474f19ab-a1b0-410a-877a-5b0e2ae8be6d",
|
||||||
|
|
|
@ -256,6 +256,7 @@
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"flags": "Collapsed|Subscription|SharedMessage",
|
"flags": "Collapsed|Subscription|SharedMessage",
|
||||||
|
"highlightColor": "#64c466ff",
|
||||||
"id": "01cd601f-bc3f-49d5-ab4b-136fa9d6ec22",
|
"id": "01cd601f-bc3f-49d5-ab4b-136fa9d6ec22",
|
||||||
"localizedName": "",
|
"localizedName": "",
|
||||||
"loginName": "lahoooo",
|
"loginName": "lahoooo",
|
||||||
|
|
|
@ -243,6 +243,7 @@
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"flags": "Collapsed|Subscription",
|
"flags": "Collapsed|Subscription",
|
||||||
|
"highlightColor": "#64c466ff",
|
||||||
"id": "db25007f-7a18-43eb-9379-80131e44d633",
|
"id": "db25007f-7a18-43eb-9379-80131e44d633",
|
||||||
"localizedName": "",
|
"localizedName": "",
|
||||||
"loginName": "ronni",
|
"loginName": "ronni",
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
#include "singletons/Emotes.hpp"
|
#include "singletons/Emotes.hpp"
|
||||||
#include "Test.hpp"
|
#include "Test.hpp"
|
||||||
#include "util/IrcHelpers.hpp"
|
#include "util/IrcHelpers.hpp"
|
||||||
|
#include "util/VectorMessageSink.hpp"
|
||||||
|
|
||||||
#include <IrcConnection>
|
#include <IrcConnection>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
@ -572,19 +573,14 @@ TEST_P(TestIrcMessageHandlerP, Run)
|
||||||
{
|
{
|
||||||
auto channel = makeMockTwitchChannel(u"pajlada"_s, *snapshot);
|
auto channel = makeMockTwitchChannel(u"pajlada"_s, *snapshot);
|
||||||
|
|
||||||
std::vector<MessagePtr> prevMessages;
|
VectorMessageSink sink;
|
||||||
|
|
||||||
for (auto prevInput : snapshot->param("prevMessages").toArray())
|
for (auto prevInput : snapshot->param("prevMessages").toArray())
|
||||||
{
|
{
|
||||||
auto *ircMessage = Communi::IrcMessage::fromData(
|
auto *ircMessage = Communi::IrcMessage::fromData(
|
||||||
prevInput.toString().toUtf8(), nullptr);
|
prevInput.toString().toUtf8(), nullptr);
|
||||||
ASSERT_NE(ircMessage, nullptr);
|
ASSERT_NE(ircMessage, nullptr);
|
||||||
auto builtMessages = IrcMessageHandler::parseMessageWithReply(
|
IrcMessageHandler::parseMessageInto(ircMessage, sink, channel.get());
|
||||||
channel.get(), ircMessage, prevMessages);
|
|
||||||
for (const auto &builtMessage : builtMessages)
|
|
||||||
{
|
|
||||||
prevMessages.emplace_back(builtMessage);
|
|
||||||
}
|
|
||||||
delete ircMessage;
|
delete ircMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -592,13 +588,13 @@ TEST_P(TestIrcMessageHandlerP, Run)
|
||||||
Communi::IrcMessage::fromData(snapshot->inputUtf8(), nullptr);
|
Communi::IrcMessage::fromData(snapshot->inputUtf8(), nullptr);
|
||||||
ASSERT_NE(ircMessage, nullptr);
|
ASSERT_NE(ircMessage, nullptr);
|
||||||
|
|
||||||
auto builtMessages = IrcMessageHandler::parseMessageWithReply(
|
auto firstAddedMsg = sink.messages().size();
|
||||||
channel.get(), ircMessage, prevMessages);
|
IrcMessageHandler::parseMessageInto(ircMessage, sink, channel.get());
|
||||||
|
|
||||||
QJsonArray got;
|
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;
|
delete ircMessage;
|
||||||
|
|
|
@ -114,20 +114,153 @@ TEST(LimitedQueue, PushFront)
|
||||||
|
|
||||||
TEST(LimitedQueue, ReplaceItem)
|
TEST(LimitedQueue, ReplaceItem)
|
||||||
{
|
{
|
||||||
LimitedQueue<int> queue(5);
|
LimitedQueue<int> queue(10);
|
||||||
queue.pushBack(1);
|
queue.pushBack(1);
|
||||||
queue.pushBack(2);
|
queue.pushBack(2);
|
||||||
queue.pushBack(3);
|
queue.pushBack(3);
|
||||||
|
queue.pushBack(4);
|
||||||
|
queue.pushBack(5);
|
||||||
|
queue.pushBack(6);
|
||||||
|
|
||||||
int idex = queue.replaceItem(2, 10);
|
int idex = queue.replaceItem(2, 10);
|
||||||
EXPECT_EQ(idex, 1);
|
EXPECT_EQ(idex, 1);
|
||||||
idex = queue.replaceItem(5, 11);
|
idex = queue.replaceItem(7, 11);
|
||||||
EXPECT_EQ(idex, -1);
|
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);
|
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);
|
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