Skip to content

Commit

Permalink
fix(helix-chat): show better error messages (Chatterino#5276)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nerixyz authored Mar 30, 2024
1 parent b6d75fd commit 9583a10
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
- Dev: Added signal to invalidate paint buffers of channel views without forcing a relayout. (#5123)
- Dev: Specialize `Atomic<std::shared_ptr<T>>` if underlying standard library supports it. (#5133)
- Dev: Added the `developer_name` field to the Linux AppData specification. (#5138)
- Dev: Twitch messages can be sent using Twitch's Helix API instead of IRC (disabled by default). (#5200)
- Dev: Twitch messages can be sent using Twitch's Helix API instead of IRC (disabled by default). (#5200, #5276)
- Dev: Added estimation for image sizes to avoid layout shifts. (#5192)
- Dev: Added the `launachable` entry to Linux AppData. (#5210)
- Dev: Cleaned up and optimized resources. (#5222)
Expand Down
17 changes: 15 additions & 2 deletions src/providers/twitch/TwitchIrcServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,17 @@ const QString SEVENTV_EVENTAPI_URL = "wss://events.7tv.io/v3";
void sendHelixMessage(const std::shared_ptr<TwitchChannel> &channel,
const QString &message, const QString &replyParentId = {})
{
auto broadcasterID = channel->roomId();
if (broadcasterID.isEmpty())
{
channel->addMessage(makeSystemMessage(
"Sending messages in this channel isn't possible."));
return;
}

getHelix()->sendChatMessage(
{
.broadcasterID = channel->roomId(),
.broadcasterID = broadcasterID,
.senderID =
getIApp()->getAccounts()->twitch.getCurrent()->getUserId(),
.message = message,
Expand All @@ -68,13 +76,18 @@ void sendHelixMessage(const std::shared_ptr<TwitchChannel> &channel,
}();
chan->addMessage(errorMessage);
},
[weak = std::weak_ptr(channel)](auto error, const auto &message) {
[weak = std::weak_ptr(channel)](auto error, auto message) {
auto chan = weak.lock();
if (!chan)
{
return;
}

if (message.isEmpty())
{
message = "(empty message)";
}

using Error = decltype(error);

auto errorMessage = [&]() -> QString {
Expand Down

0 comments on commit 9583a10

Please sign in to comment.