Add clickable usernames in host offline messages (#2922)

Co-authored-by: pajlada <rasmus.karlsson@pajlada.com>
This commit is contained in:
Tal Neoran 2021-06-27 16:50:12 +03:00 committed by GitHub
parent e1895de7f3
commit db09a88c8d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 35 additions and 13 deletions

View file

@ -2,6 +2,7 @@
## Unversioned
- Minor: Channel name in `<channel> has gone offline. Exiting host mode.` messages is now clickable. (#2922)
- Minor: Added `/openurl` command. Usage: `/openurl <URL>`. Opens the provided URL in the browser. (#2461, #2926)
- Bugfix: Fixed large timeout durations in moderation buttons overlapping with usernames or other buttons. (#2865, #2921)

View file

@ -819,21 +819,26 @@ void IrcMessageHandler::handleNoticeMessage(Communi::IrcNoticeMessage *message)
"Usage: \"/delete <msg-id>\" - can't take more "
"than one argument"));
}
else if (tags == "host_on")
else if (tags == "host_on" || tags == "host_target_went_offline")
{
bool hostOn = (tags == "host_on");
QStringList parts = msg->messageText.split(QLatin1Char(' '));
if (parts.size() != 3)
if ((hostOn && parts.size() != 3) || (!hostOn && parts.size() != 7))
{
return;
}
auto &channelName = parts[2];
auto &channelName = hostOn ? parts[2] : parts[0];
if (channelName.size() < 2)
{
return;
}
channelName.chop(1);
if (hostOn)
{
channelName.chop(1);
}
MessageBuilder builder;
TwitchMessageBuilder::hostingSystemMessage(channelName, &builder);
TwitchMessageBuilder::hostingSystemMessage(channelName, &builder,
hostOn);
channel->addMessage(builder.release());
}
else

View file

@ -1337,17 +1337,33 @@ void TwitchMessageBuilder::offlineSystemMessage(const QString &channelName,
}
void TwitchMessageBuilder::hostingSystemMessage(const QString &channelName,
MessageBuilder *builder)
MessageBuilder *builder,
bool hostOn)
{
builder->emplace<TimestampElement>();
builder->message().flags.set(MessageFlag::System);
builder->message().flags.set(MessageFlag::DoNotTriggerNotification);
builder->emplace<TextElement>("Now hosting", MessageElementFlag::Text,
MessageColor::System);
builder
->emplace<TextElement>(channelName + ".", MessageElementFlag::Username,
MessageColor::System, FontStyle::ChatMediumBold)
->setLink({Link::UserInfo, channelName});
if (hostOn)
{
builder->emplace<TextElement>("Now hosting", MessageElementFlag::Text,
MessageColor::System);
builder
->emplace<TextElement>(
channelName + ".", MessageElementFlag::Username,
MessageColor::System, FontStyle::ChatMediumBold)
->setLink({Link::UserInfo, channelName});
}
else
{
builder
->emplace<TextElement>(channelName, MessageElementFlag::Username,
MessageColor::System,
FontStyle::ChatMediumBold)
->setLink({Link::UserInfo, channelName});
builder->emplace<TextElement>("has gone offline. Exiting host mode.",
MessageElementFlag::Text,
MessageColor::System);
}
}
// irc variant

View file

@ -58,7 +58,7 @@ public:
static void offlineSystemMessage(const QString &channelName,
MessageBuilder *builder);
static void hostingSystemMessage(const QString &channelName,
MessageBuilder *builder);
MessageBuilder *builder, bool hostOn);
static void deletionMessage(const MessagePtr originalMessage,
MessageBuilder *builder);
static void deletionMessage(const DeleteAction &action,