Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into chatterino7
Browse files Browse the repository at this point in the history
  • Loading branch information
Nerixyz committed Mar 18, 2024
2 parents b55de17 + f21b9a2 commit 2629aa0
Show file tree
Hide file tree
Showing 28 changed files with 505 additions and 78 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
- Minor: 7TV emotes now have a 4x image rather than a 3x image. (#5209)
- Minor: Add wrappers for Lua `io` library for experimental plugins feature. (#5231)
- Minor: Add permissions to experimental plugins feature. (#5231)
- Minor: Added warning message if you have multiple commands with the same trigger. (#4322)
- Minor: Add support to send /announce[color] commands. (#5250)
- Bugfix: Fixed an issue where certain emojis did not send to Twitch chat correctly. (#4840)
- Bugfix: Fixed capitalized channel names in log inclusion list not being logged. (#4848)
- Bugfix: Trimmed custom streamlink paths on all platforms making sure you don't accidentally add spaces at the beginning or end of its path. (#4834)
Expand Down Expand Up @@ -80,6 +82,7 @@
- Bugfix: Fixed badge highlight changes not immediately being reflected. (#5110)
- Bugfix: Fixed emotes being reloaded when pressing "Cancel" in the settings dialog, causing a slowdown. (#5240)
- Bugfix: Fixed some emotes not appearing when using _Ignores_. (#4965, #5126)
- Bugfix: Fixed double-click selection not selecting words that were split onto multiple lines correctly. (#5243)
- Bugfix: Fixed lookahead/-behind not working in _Ignores_. (#4965, #5126)
- Bugfix: Fixed Image Uploader accidentally deleting images with some hosts when link resolver was enabled. (#4971)
- Bugfix: Fixed rare crash with Image Uploader when closing a split right after starting an upload. (#4971)
Expand Down Expand Up @@ -108,6 +111,7 @@
- Bugfix: Fixed the "Cancel" button in the settings dialog only working after opening the settings dialog twice. (#5229)
- Bugfix: Fixed split header tooltips showing in the wrong position on Windows. (#5230)
- Bugfix: Fixed split header tooltips appearing too tall. (#5232)
- Bugfix: Fixed past messages not showing in the search popup after adding a channel. (#5248)
- Dev: Run miniaudio in a separate thread, and simplify it to not manage the device ourselves. There's a chance the simplification is a bad idea. (#4978)
- Dev: Change clang-format from v14 to v16. (#4929)
- Dev: Fixed UTF16 encoding of `modes` file for the installer. (#4791)
Expand Down Expand Up @@ -162,6 +166,7 @@
- Dev: Load less message history upon reconnects. (#5001, #5018)
- Dev: Removed the `NullablePtr` class. (#5091)
- Dev: BREAKING: Replace custom `import()` with normal Lua `require()`. (#5014, #5108)
- Dev: Compile Lua as a C library. (#5251)
- Dev: Fixed most compiler warnings. (#5028, #5137)
- Dev: Added the ability to show `ChannelView`s without a `Split`. (#4747)
- Dev: Refactor Args to be less of a singleton. (#5041)
Expand Down
2 changes: 1 addition & 1 deletion lib/lua/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@ target_include_directories(lua
PUBLIC
${LUA_INCLUDE_DIRS}
)
set_source_files_properties(${LUA_SRC} PROPERTIES LANGUAGE CXX)
set_source_files_properties(${LUA_SRC} PROPERTIES LANGUAGE C)
10 changes: 10 additions & 0 deletions src/common/SignalVectorModel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,22 @@ class SignalVectorModel : public QAbstractTableModel,
else
{
int vecRow = this->getVectorIndexFromModelIndex(row);
// TODO: This is only a safety-thing for when we modify data that's being modified right now.
// It should not be necessary, but it would require some rethinking about this surrounding logic
if (vecRow >= this->vector_->readOnly()->size())
{
return false;
}
this->vector_->removeAt(vecRow, this);

assert(this->rows_[row].original);
TVectorItem item = this->getItemFromRow(
this->rows_[row].items, this->rows_[row].original.value());
this->vector_->insert(item, vecRow, this);

QVector<int> roles = QVector<int>();
roles.append(role);
emit dataChanged(index, index, roles);
}

return true;
Expand Down
4 changes: 4 additions & 0 deletions src/controllers/commands/CommandController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,10 @@ void CommandController::initialize(Settings &, const Paths &paths)
this->registerCommand("/unmod", &commands::removeModerator);

this->registerCommand("/announce", &commands::sendAnnouncement);
this->registerCommand("/announceblue", &commands::sendAnnouncementBlue);
this->registerCommand("/announcegreen", &commands::sendAnnouncementGreen);
this->registerCommand("/announceorange", &commands::sendAnnouncementOrange);
this->registerCommand("/announcepurple", &commands::sendAnnouncementPurple);

this->registerCommand("/vip", &commands::addVIP);

Expand Down
67 changes: 60 additions & 7 deletions src/controllers/commands/builtin/twitch/Announce.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
#include "providers/twitch/TwitchAccount.hpp"
#include "providers/twitch/TwitchChannel.hpp"

namespace chatterino::commands {
namespace {
using namespace chatterino;

QString sendAnnouncement(const CommandContext &ctx)
QString sendAnnouncementColor(const CommandContext &ctx,
const HelixAnnouncementColor color)
{
if (ctx.channel == nullptr)
{
Expand All @@ -25,25 +27,47 @@ QString sendAnnouncement(const CommandContext &ctx)
return "";
}

QString colorStr = "";
if (color != HelixAnnouncementColor::Primary)
{
colorStr =
QString::fromStdString(
std::string{
magic_enum::enum_name<HelixAnnouncementColor>(color)})
.toLower();
}

if (ctx.words.size() < 2)
{
ctx.channel->addMessage(makeSystemMessage(
"Usage: /announce <message> - Call attention to your "
"message with a highlight."));
QString usageMsg;
if (color == HelixAnnouncementColor::Primary)
{
usageMsg = "Usage: /announce <message> - Call attention to your "
"message with a highlight.";
}
else
{
usageMsg =
QString("Usage: /announce%1 <message> - Call attention to your "
"message with a %1 highlight.")
.arg(colorStr);
}
ctx.channel->addMessage(makeSystemMessage(usageMsg));
return "";
}

auto user = getIApp()->getAccounts()->twitch.getCurrent();
if (user->isAnon())
{
ctx.channel->addMessage(makeSystemMessage(
"You must be logged in to use the /announce command."));
QString("You must be logged in to use the /announce%1 command.")
.arg(colorStr)));
return "";
}

getHelix()->sendChatAnnouncement(
ctx.twitchChannel->roomId(), user->getUserId(),
ctx.words.mid(1).join(" "), HelixAnnouncementColor::Primary,
ctx.words.mid(1).join(" "), color,
[]() {
// do nothing.
},
Expand Down Expand Up @@ -78,4 +102,33 @@ QString sendAnnouncement(const CommandContext &ctx)
return "";
}

} // namespace

namespace chatterino::commands {

QString sendAnnouncement(const CommandContext &ctx)
{
return sendAnnouncementColor(ctx, HelixAnnouncementColor::Primary);
}

QString sendAnnouncementBlue(const CommandContext &ctx)
{
return sendAnnouncementColor(ctx, HelixAnnouncementColor::Blue);
}

QString sendAnnouncementGreen(const CommandContext &ctx)
{
return sendAnnouncementColor(ctx, HelixAnnouncementColor::Green);
}

QString sendAnnouncementOrange(const CommandContext &ctx)
{
return sendAnnouncementColor(ctx, HelixAnnouncementColor::Orange);
}

QString sendAnnouncementPurple(const CommandContext &ctx)
{
return sendAnnouncementColor(ctx, HelixAnnouncementColor::Purple);
}

} // namespace chatterino::commands
12 changes: 12 additions & 0 deletions src/controllers/commands/builtin/twitch/Announce.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,16 @@ namespace chatterino::commands {
/// /announce
QString sendAnnouncement(const CommandContext &ctx);

/// /announceblue
QString sendAnnouncementBlue(const CommandContext &ctx);

/// /announcegreen
QString sendAnnouncementGreen(const CommandContext &ctx);

/// /announceorange
QString sendAnnouncementOrange(const CommandContext &ctx);

/// /announcepurple
QString sendAnnouncementPurple(const CommandContext &ctx);

} // namespace chatterino::commands
2 changes: 2 additions & 0 deletions src/controllers/plugins/LuaAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
# include "messages/MessageBuilder.hpp"
# include "providers/twitch/TwitchIrcServer.hpp"

extern "C" {
# include <lauxlib.h>
# include <lua.h>
# include <lualib.h>
}
# include <QFileInfo>
# include <QLoggingCategory>
# include <QTextCodec>
Expand Down
2 changes: 2 additions & 0 deletions src/controllers/plugins/LuaAPI.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

#ifdef CHATTERINO_HAVE_PLUGINS

extern "C" {
# include <lua.h>
}
# include <QString>

# include <cassert>
Expand Down
2 changes: 2 additions & 0 deletions src/controllers/plugins/LuaUtilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
# include "controllers/plugins/api/ChannelRef.hpp"
# include "controllers/plugins/LuaAPI.hpp"

extern "C" {
# include <lauxlib.h>
# include <lua.h>
}

# include <climits>
# include <cstdlib>
Expand Down
2 changes: 2 additions & 0 deletions src/controllers/plugins/LuaUtilities.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@

# include "common/QLogging.hpp"

extern "C" {
# include <lua.h>
# include <lualib.h>
}
# include <magic_enum/magic_enum.hpp>
# include <QList>

Expand Down
2 changes: 2 additions & 0 deletions src/controllers/plugins/Plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
# include "common/QLogging.hpp"
# include "controllers/commands/CommandController.hpp"

extern "C" {
# include <lua.h>
}
# include <magic_enum/magic_enum.hpp>
# include <QJsonArray>
# include <QJsonObject>
Expand Down
2 changes: 2 additions & 0 deletions src/controllers/plugins/PluginController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@
# include "singletons/Paths.hpp"
# include "singletons/Settings.hpp"

extern "C" {
# include <lauxlib.h>
# include <lua.h>
# include <lualib.h>
}
# include <QJsonDocument>

# include <memory>
Expand Down
2 changes: 2 additions & 0 deletions src/controllers/plugins/api/ChannelRef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
# include "providers/twitch/TwitchChannel.hpp"
# include "providers/twitch/TwitchIrcServer.hpp"

extern "C" {
# include <lauxlib.h>
# include <lua.h>
}

# include <cassert>
# include <memory>
Expand Down
7 changes: 5 additions & 2 deletions src/controllers/plugins/api/IOWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
# include "Application.hpp"
# include "controllers/plugins/LuaUtilities.hpp"
# include "controllers/plugins/PluginController.hpp"
# include "lauxlib.h"
# include "lua.h"

extern "C" {
# include <lauxlib.h>
# include <lua.h>
}

# include <cerrno>

Expand Down
5 changes: 4 additions & 1 deletion src/messages/MessageElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ QStringList TextElement::words() const
void TextElement::addToContainer(MessageLayoutContainer &container,
MessageElementFlags flags)
{
auto *app = getApp();
auto *app = getIApp();

if (flags.hasAny(this->getFlags()))
{
Expand All @@ -563,6 +563,8 @@ void TextElement::addToContainer(MessageLayoutContainer &container,

for (const auto &word : this->words_)
{
auto wordId = container.nextWordId();

auto getTextLayoutElement = [&](QString text, int width,
bool hasTrailingSpace) {
auto color = this->color_.getColor(*app->getThemes());
Expand All @@ -573,6 +575,7 @@ void TextElement::addToContainer(MessageLayoutContainer &container,
this->style_, container.getScale());
e->setTrailingSpace(hasTrailingSpace);
e->setText(text);
e->setWordId(wordId);

return e;
};
Expand Down
21 changes: 20 additions & 1 deletion src/messages/layouts/MessageLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -443,12 +443,31 @@ void MessageLayout::deleteCache()
// returns nullptr if none was found

// fourtf: this should return a MessageLayoutItem
const MessageLayoutElement *MessageLayout::getElementAt(QPoint point)
const MessageLayoutElement *MessageLayout::getElementAt(QPoint point) const
{
// go through all words and return the first one that contains the point.
return this->container_.getElementAt(point);
}

std::pair<int, int> MessageLayout::getWordBounds(
const MessageLayoutElement *hoveredElement, QPoint relativePos) const
{
// An element with wordId != -1 can be multiline, so we need to check all
// elements in the container
if (hoveredElement->getWordId() != -1)
{
return this->container_.getWordBounds(hoveredElement);
}

const auto wordStart = this->getSelectionIndex(relativePos) -
hoveredElement->getMouseOverIndex(relativePos);
const auto selectionLength = hoveredElement->getSelectionIndexCount();
const auto length = hoveredElement->hasTrailingSpace() ? selectionLength - 1
: selectionLength;

return {wordStart, wordStart + length};
}

size_t MessageLayout::getLastCharacterIndex() const
{
return this->container_.getLastCharacterIndex();
Expand Down
16 changes: 15 additions & 1 deletion src/messages/layouts/MessageLayout.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,21 @@ class MessageLayout
*
* If no element is found at the given point, this returns a null pointer
*/
const MessageLayoutElement *getElementAt(QPoint point);
const MessageLayoutElement *getElementAt(QPoint point) const;

/**
* @brief Returns the word bounds of the given element
*
* The first value is the index of the first character in the word,
* the second value is the index of the character after the last character in the word.
*
* Given the word "abc" by itself, we would return (0, 3)
*
* V V
* "abc "
*/
std::pair<int, int> getWordBounds(
const MessageLayoutElement *hoveredElement, QPoint relativePos) const;

/**
* Get the index of the last character in this message's container
Expand Down
Loading

0 comments on commit 2629aa0

Please sign in to comment.