fix(helix-chat): show better error messages (#5276)

This commit is contained in:
nerix 2024-03-30 11:24:09 +01:00 committed by GitHub
parent b6d75fd867
commit 9583a10b88
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 16 additions and 3 deletions

View file

@ -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)

View file

@ -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,
@ -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 {