Minor comment additions and fixes
Removed the redundant request for Twitch global and channel emotes in getAssets(). Since these emotes will be processed anyways when generating the span, there's no point in wasting bandwidth to fetch and store them.
This commit is contained in:
parent
fc315ece27
commit
05df4e8d2f
3 changed files with 17 additions and 12 deletions
|
|
@ -3,7 +3,7 @@ import 'package:flutter/widgets.dart';
|
|||
import 'package:frosty/models/irc.dart';
|
||||
|
||||
class IRC {
|
||||
// Applies the given CLEARCHAT message to a list and returns the result.
|
||||
/// Applies the given CLEARCHAT message to the given list of messages.
|
||||
static void clearChat({required List<IRCMessage> messages, required IRCMessage ircMessage}) {
|
||||
// If there is no message, it means that entire chat was cleared.
|
||||
if (ircMessage.message == null) {
|
||||
|
|
@ -20,10 +20,13 @@ class IRC {
|
|||
final bannedUser = ircMessage.message;
|
||||
final banDuration = ircMessage.tags['ban-duration'];
|
||||
|
||||
// Search the messages for the banned/timed-out user.
|
||||
messages.asMap().forEach((i, message) {
|
||||
if (message.user == bannedUser) {
|
||||
// Mark the message for removal.
|
||||
messages[i].command = Command.clearChat;
|
||||
|
||||
// If timed-out, indicate the duration.
|
||||
if (banDuration != null) {
|
||||
messages[i].tags['ban-duration'] = banDuration;
|
||||
}
|
||||
|
|
@ -31,7 +34,7 @@ class IRC {
|
|||
});
|
||||
}
|
||||
|
||||
// Applies the given CLEARMSG message to a list and returns the result.
|
||||
/// Applies the given CLEARMSG message to the given list of messages.
|
||||
static void clearMessage({required List<IRCMessage> messages, required IRCMessage ircMessage}) {
|
||||
// final targetUser = ircMessage.tags['login'];
|
||||
final targetId = ircMessage.tags['target-msg-id'];
|
||||
|
|
@ -45,13 +48,15 @@ class IRC {
|
|||
}
|
||||
}
|
||||
|
||||
/// Returns an [InlineSpan] list that corresponds to the badges, username, words, and emotes of the given [IRCMessage].
|
||||
static List<InlineSpan> generateSpan({required IRCMessage ircMessage, required assetToUrl}) {
|
||||
// Initialize the span list that will be used to render the chat message
|
||||
// The span list that will be used to render the chat message
|
||||
final span = <InlineSpan>[];
|
||||
|
||||
final localAssetToUrl = <String, String>{};
|
||||
// The map containing emotes from the user's tags to their URL.
|
||||
// This may include sub emotes that they can access but other users cannot.
|
||||
final localEmoteToUrl = <String, String>{};
|
||||
|
||||
// Parse the message's 'emotes' tag if they exist and store them for later use.
|
||||
final emoteTags = ircMessage.tags['emotes'];
|
||||
if (emoteTags != null) {
|
||||
// Emotes and their indices are separated by '/' so split them there.
|
||||
|
|
@ -79,7 +84,7 @@ class IRC {
|
|||
final emoteWord = ircMessage.message!.substring(startIndex, endIndex + 1);
|
||||
|
||||
// Store the emote word and its associated URL for later use.
|
||||
localAssetToUrl[emoteWord] = 'https://static-cdn.jtvnw.net/emoticons/v2/$emoteId/default/dark/3.0';
|
||||
localEmoteToUrl[emoteWord] = 'https://static-cdn.jtvnw.net/emoticons/v2/$emoteId/default/dark/3.0';
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -128,7 +133,7 @@ class IRC {
|
|||
for (final word in words) {
|
||||
span.add(const TextSpan(text: ' '));
|
||||
|
||||
final emoteUrl = assetToUrl[word] ?? localAssetToUrl[word];
|
||||
final emoteUrl = assetToUrl[word] ?? localEmoteToUrl[word];
|
||||
if (emoteUrl != null) {
|
||||
span.add(
|
||||
WidgetSpan(
|
||||
|
|
@ -151,6 +156,7 @@ class IRC {
|
|||
}
|
||||
}
|
||||
|
||||
/// The possible types of Twitch IRC commands.
|
||||
enum Command {
|
||||
privateMessage,
|
||||
clearChat,
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import 'package:flutter/foundation.dart';
|
||||
import 'package:frosty/api/irc_api.dart';
|
||||
|
||||
/// The object representation of a Twitch IRC message.
|
||||
class IRCMessage {
|
||||
final Map<String, String> tags;
|
||||
final String? user;
|
||||
|
|
@ -56,9 +57,8 @@ class IRCMessage {
|
|||
// If there is an associated message, set it.
|
||||
final String? message = splitMessage.length > 3 ? splitMessage.sublist(3).join(' ').substring(1) : null;
|
||||
|
||||
// Parse the command.
|
||||
// Check and parse the command.
|
||||
// The majority of messages will be PRIVMSG, so check that first.
|
||||
// Else, loop each possible command and match the correct one.
|
||||
final Command messageCommand;
|
||||
switch (splitMessage[1]) {
|
||||
case 'PRIVMSG':
|
||||
|
|
@ -96,6 +96,7 @@ class IRCMessage {
|
|||
}
|
||||
}
|
||||
|
||||
/// The object representation of the IRC ROOMSTATE message.
|
||||
class ROOMSTATE {
|
||||
final String emoteOnly;
|
||||
final String followersOnly;
|
||||
|
|
@ -111,7 +112,7 @@ class ROOMSTATE {
|
|||
this.subMode = "0",
|
||||
});
|
||||
|
||||
// Create a new copy with the paremeters from the provided [IRCMessage]
|
||||
/// Create a new copy with the paremeters from the provided [IRCMessage]
|
||||
ROOMSTATE copyWith(IRCMessage ircMessage) {
|
||||
return ROOMSTATE(
|
||||
emoteOnly: ircMessage.tags['emote-only'] ?? emoteOnly,
|
||||
|
|
|
|||
|
|
@ -209,8 +209,6 @@ abstract class _ChatStoreBase with Store {
|
|||
await FFZ.getEmotesChannel(id: channelInfo.id),
|
||||
await BTTV.getEmotesGlobal(),
|
||||
await BTTV.getEmotesChannel(id: channelInfo.id),
|
||||
await Twitch.getEmotesGlobal(headers: auth.headersTwitch),
|
||||
await Twitch.getEmotesChannel(id: channelInfo.id, headers: auth.headersTwitch),
|
||||
await Twitch.getBadgesGlobal(headers: auth.headersTwitch),
|
||||
await Twitch.getBadgesChannel(id: channelInfo.id, headers: auth.headersTwitch),
|
||||
await SevenTV.getEmotesGlobal(),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue