Compare commits

..

9 commits

Author SHA1 Message Date
iProdigy 01ab43e388
Merge 6d376b5416 into 2ec8fa8723 2024-10-21 22:27:27 +00:00
iProdigy 6d376b5416 chore: reformat emote initializer 2024-10-21 15:23:52 -07:00
iProdigy c7512dc734 chore: remove emote name for badge 2024-10-21 15:20:15 -07:00
iProdigy 0163474a93 refactor: utilize TwitchUsers::resolveID 2024-10-21 15:11:25 -07:00
iProdigy d2681a0b43 fix: capture channelId by value instead of ref 2024-10-21 13:27:30 -07:00
iProdigy e326ce428c chore: update snapshot tests 2024-10-21 13:19:26 -07:00
iProdigy 59bb2fe2e9 chore: remove userinfo link on badge 2024-10-21 12:19:59 -07:00
iProdigy d80dd6d8a2 Merge branch 'main' into feature/shared-chat-badge 2024-10-21 11:23:04 -07:00
iProdigy de40d42a60 chore: prevent mention on right click 2024-10-21 11:22:05 -07:00
12 changed files with 70 additions and 111 deletions

View file

@ -71,17 +71,6 @@ public:
}
}
void remove(const key_t &key)
{
auto it = _cache_items_map.find(key);
if (it == _cache_items_map.end())
{
throw std::range_error("There is no such key in cache");
}
_cache_items_list.erase(it->second);
_cache_items_map.erase(it);
}
const value_t &get(const key_t &key)
{
auto it = _cache_items_map.find(key);

View file

@ -3,6 +3,7 @@
#include "common/Args.hpp"
#include "mocks/DisabledStreamerMode.hpp"
#include "mocks/EmptyApplication.hpp"
#include "mocks/TwitchUsers.hpp"
#include "providers/bttv/BttvLiveUpdates.hpp"
#include "singletons/Fonts.hpp"
#include "singletons/Settings.hpp"
@ -55,6 +56,11 @@ public:
return &this->fonts;
}
ITwitchUsers *getTwitchUsers() override
{
return &this->twitchUsers;
}
BttvLiveUpdates *getBttvLiveUpdates() override
{
return nullptr;
@ -71,6 +77,7 @@ public:
DisabledStreamerMode streamerMode;
Theme theme;
Fonts fonts;
TwitchUsers twitchUsers;
};
} // namespace chatterino::mock

View file

@ -26,7 +26,6 @@ public:
, mentionsChannel(std::shared_ptr<Channel>(new MockChannel("forsen3")))
, liveChannel(std::shared_ptr<Channel>(new MockChannel("forsen")))
, automodChannel(std::shared_ptr<Channel>(new MockChannel("forsen2")))
, channelNamesById_(1)
{
}
@ -50,18 +49,6 @@ public:
return {};
}
std::optional<QString> getOrPopulateChannelCache(
const QString &channelId) override
{
if (channelId == "11148817")
return "pajlada";
if (channelId == "141981764")
return "twitchdev";
if (channelId == "1025594235")
return "shared_chat_test_01";
return {};
}
void addFakeMessage(const QString &data) override
{
}
@ -161,7 +148,6 @@ public:
ChannelPtr mentionsChannel;
ChannelPtr liveChannel;
ChannelPtr automodChannel;
UniqueAccess<cache::lru_cache<QString, QString>> channelNamesById_;
QString lastUserThatWhisperedMe{"forsen"};
std::unordered_map<QString, std::weak_ptr<Channel>> mockChannels;

View file

@ -0,0 +1,24 @@
#pragma once
#include "providers/twitch/TwitchUser.hpp"
#include "providers/twitch/TwitchUsers.hpp"
namespace chatterino::mock {
class TwitchUsers : public ITwitchUsers
{
public:
TwitchUsers() = default;
std::shared_ptr<TwitchUser> resolveID(const UserId &id)
{
TwitchUser u = {
.id = id.string,
.name = {},
.displayName = {},
};
return std::make_shared<TwitchUser>(u);
}
};
} // namespace chatterino::mock

View file

@ -32,6 +32,7 @@
#include "providers/twitch/TwitchChannel.hpp"
#include "providers/twitch/TwitchIrc.hpp"
#include "providers/twitch/TwitchIrcServer.hpp"
#include "providers/twitch/TwitchUsers.hpp"
#include "singletons/Emotes.hpp"
#include "singletons/Resources.hpp"
#include "singletons/Settings.hpp"
@ -382,13 +383,14 @@ EmotePtr makeAutoModBadge()
EmotePtr makeSharedChatBadge(const QString &sourceName)
{
return std::make_shared<Emote>(
Emote{"SharedChat_" + sourceName,
ImageSet{Image::fromResourcePixmap(
return std::make_shared<Emote>(Emote{
.name = EmoteName{},
.images = ImageSet{Image::fromResourcePixmap(
getResources().twitch.sharedChat, 0.25)},
Tooltip{"Shared Message" +
.tooltip = Tooltip{"Shared Message" +
(sourceName.isEmpty() ? "" : " from " + sourceName)},
Url{"https://link.twitch.tv/SharedChatViewer"}});
.homePage = Url{"https://link.twitch.tv/SharedChatViewer"},
});
}
std::tuple<std::optional<EmotePtr>, MessageElementFlags, bool> parseEmote(
@ -2765,28 +2767,23 @@ void MessageBuilder::appendTwitchBadges(const QVariantMap &tags,
if (this->message().flags.has(MessageFlag::SharedMessage))
{
const QString sourceId = tags["source-room-id"].toString();
std::optional<QString> sourceName;
if (twitchChannel->roomId() == sourceId)
QString sourceName;
if (sourceId.isEmpty())
{
sourceName = "";
}
else if (twitchChannel->roomId() == sourceId)
{
sourceName = twitchChannel->getName();
}
else
{
sourceName =
getApp()->getTwitch()->getOrPopulateChannelCache(sourceId);
getApp()->getTwitchUsers()->resolveID({sourceId})->displayName;
}
if (sourceName.has_value())
{
const auto &name = sourceName.value();
auto *badge = this->emplace<BadgeElement>(
makeSharedChatBadge(name),
this->emplace<BadgeElement>(makeSharedChatBadge(sourceName),
MessageElementFlag::BadgeSharedChannel);
if (!name.isEmpty())
{
badge->setLink({Link::UserInfo, name});
}
}
}
auto badgeInfos = parseBadgeInfoTag(tags);

View file

@ -153,7 +153,6 @@ TwitchIrcServer::TwitchIrcServer()
, liveChannel(new Channel("/live", Channel::Type::TwitchLive))
, automodChannel(new Channel("/automod", Channel::Type::TwitchAutomod))
, watchingChannel(Channel::getEmpty(), Channel::Type::TwitchWatching)
, channelNamesById_(512)
{
// Initialize the connections
// XXX: don't create write connection if there is no separate write connection.
@ -1129,38 +1128,6 @@ std::shared_ptr<Channel> TwitchIrcServer::getChannelOrEmptyByID(
return Channel::getEmpty();
}
std::optional<QString> TwitchIrcServer::getOrPopulateChannelCache(
const QString &channelId)
{
{
const auto cache = this->channelNamesById_.access();
if (cache->exists(channelId))
{
return cache->get(channelId);
}
// prevent multiple helix requests for single user
cache->put(channelId, "");
}
getHelix()->getUserById(
channelId,
[this](const HelixUser &user) {
const auto cache = this->channelNamesById_.access();
cache->put(user.id, user.login);
},
[this, &channelId] {
const auto cache = this->channelNamesById_.access();
if (cache->exists(channelId) && cache->get(channelId).isEmpty())
{
// invalidate cache so another helix request can be attempted
cache->remove(channelId);
}
});
return {};
}
QString TwitchIrcServer::cleanChannelName(const QString &dirtyChannelName)
{
if (dirtyChannelName.startsWith('#'))

View file

@ -3,12 +3,10 @@
#include "common/Atomic.hpp"
#include "common/Channel.hpp"
#include "common/Common.hpp"
#include "common/UniqueAccess.hpp"
#include "providers/irc/IrcConnection2.hpp"
#include "util/RatelimitBucket.hpp"
#include <IrcMessage>
#include <lrucache/lrucache.hpp>
#include <pajlada/signals/signal.hpp>
#include <pajlada/signals/signalholder.hpp>
@ -45,9 +43,6 @@ public:
virtual ChannelPtr getOrAddChannel(const QString &dirtyChannelName) = 0;
virtual ChannelPtr getChannelOrEmpty(const QString &dirtyChannelName) = 0;
virtual std::optional<QString> getOrPopulateChannelCache(
const QString &channelId) = 0;
virtual void addFakeMessage(const QString &data) = 0;
virtual void addGlobalSystemMessage(const QString &messageText) = 0;
@ -100,14 +95,6 @@ public:
std::shared_ptr<Channel> getChannelOrEmptyByID(
const QString &channelID) override;
/**
* Obtains the channel login name associated with the passed ID,
* so that Shared Chat messages can provide source channel context.
* Can yield an empty string if a helix request is already in-flight.
*/
std::optional<QString> getOrPopulateChannelCache(
const QString &channelId) override;
void reloadAllBTTVChannelEmotes();
void reloadAllFFZChannelEmotes();
void reloadAllSevenTVChannelEmotes();
@ -203,9 +190,6 @@ private:
// https://dev.twitch.tv/docs/irc/guide#rate-limits
QObjectPtr<RatelimitBucket> joinBucket_;
// cached channel id => name for resolving Shared Chat members
UniqueAccess<cache::lru_cache<QString, QString>> channelNamesById_;
QTimer reconnectTimer_;
int falloffCounter_ = 1;

View file

@ -2408,6 +2408,11 @@ void ChannelView::handleMouseClick(QMouseEvent *event,
return;
}
if (link.value.startsWith("id:"))
{
return;
}
// Insert @username into split input
const bool commaMention =
getSettings()->mentionUsersWithComma;

View file

@ -70,15 +70,15 @@
"images": {
"1x": ""
},
"name": "SharedChat_shared_chat_test_01",
"tooltip": "Shared Message from shared_chat_test_01"
"name": "",
"tooltip": "Shared Message"
},
"flags": "BadgeSharedChannel",
"link": {
"type": "UserInfo",
"value": "shared_chat_test_01"
"type": "None",
"value": ""
},
"tooltip": "Shared Message from shared_chat_test_01",
"tooltip": "Shared Message",
"trailingSpace": true,
"type": "BadgeElement"
},

View file

@ -70,13 +70,13 @@
"images": {
"1x": ""
},
"name": "SharedChat_twitchdev",
"name": "",
"tooltip": "Shared Message from twitchdev"
},
"flags": "BadgeSharedChannel",
"link": {
"type": "UserInfo",
"value": "twitchdev"
"type": "None",
"value": ""
},
"tooltip": "Shared Message from twitchdev",
"trailingSpace": true,

View file

@ -70,13 +70,13 @@
"images": {
"1x": ""
},
"name": "SharedChat_twitchdev",
"name": "",
"tooltip": "Shared Message from twitchdev"
},
"flags": "BadgeSharedChannel",
"link": {
"type": "UserInfo",
"value": "twitchdev"
"type": "None",
"value": ""
},
"tooltip": "Shared Message from twitchdev",
"trailingSpace": true,

View file

@ -70,15 +70,15 @@
"images": {
"1x": ""
},
"name": "SharedChat_shared_chat_test_01",
"tooltip": "Shared Message from shared_chat_test_01"
"name": "",
"tooltip": "Shared Message"
},
"flags": "BadgeSharedChannel",
"link": {
"type": "UserInfo",
"value": "shared_chat_test_01"
"type": "None",
"value": ""
},
"tooltip": "Shared Message from shared_chat_test_01",
"tooltip": "Shared Message",
"trailingSpace": true,
"type": "BadgeElement"
},