Revert 05df4e8, comment additions & fixes

The previously removed requests in 05df4e8 were actually required for
rendering emotes whenever the user themself sends a message.
This commit is contained in:
tommyxchow 2021-11-02 03:51:34 -04:00
parent d4c3714561
commit 2df2326f73
3 changed files with 18 additions and 15 deletions

View file

@ -13,9 +13,9 @@ class IRCMessage {
/// Parses an IRC string and returns its corresponding [IRCMessage] object.
factory IRCMessage.fromString(String whole) {
// We have three parts:
// 1. The tags of the IRC message
// 2. The metadata (user, command, and channel)
// 3. The message itself
// 1. The tags of the IRC message.
// 2. The metadata (user, command, and channel).
// 3. The message itself.
// First, slice the message tags (1) and set aside the rest for later.
// Each part is separated by a space, so we'll start off by breaking off the tags and parsing them.
@ -104,7 +104,7 @@ class ROOMSTATE {
final String slowMode;
final String subMode;
ROOMSTATE({
const ROOMSTATE({
this.emoteOnly = "0",
this.followersOnly = "0",
this.r9k = "0",
@ -112,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 parameters from the provided [IRCMessage]
ROOMSTATE copyWith(IRCMessage ircMessage) {
return ROOMSTATE(
emoteOnly: ircMessage.tags['emote-only'] ?? emoteOnly,

View file

@ -24,7 +24,7 @@ abstract class _ChatStoreBase with Store {
/// The list of chat messages to render and display.
final messages = ObservableList<IRCMessage>();
/// The map of badges and emote words to their image/gif URL.
/// The map of badges and emote words to their image or GIF URL.
final _assetToUrl = <String, String>{};
/// The scroll controller that controls auto-scroll and resume-scroll behavior.
@ -50,7 +50,7 @@ abstract class _ChatStoreBase with Store {
/// The rules and modes being used in the chat.
@readonly
var _roomState = ROOMSTATE();
var _roomState = const ROOMSTATE();
_ChatStoreBase({required this.auth, required this.channelName}) {
// Listen for new messages and forward them to the handler.
@ -75,7 +75,7 @@ abstract class _ChatStoreBase with Store {
'JOIN #$channelName',
];
// Send each command in-order.
// Send each command in order.
for (final command in commands) {
_channel.sink.add(command);
}
@ -99,9 +99,8 @@ abstract class _ChatStoreBase with Store {
@action
void _handleIRCData(String data) {
// The IRC data can contain more than one message separated by CRLF.
// To account for this, split by CRLF. Then loop and process each message.
for (final message in data.substring(0, data.length - 2).split('\r\n')) {
// debugPrint(message);
// To account for this, split by CRLF, then loop and process each message.
for (final message in data.trimRight().split('\r\n')) {
if (message.startsWith('@')) {
final parsedIRCMessage = IRCMessage.fromString(message);
@ -131,7 +130,6 @@ abstract class _ChatStoreBase with Store {
case Command.globalUserState:
// Updates the current global user state data (it includes user-id),
// Don't really see a use for it when USERSTATE exists, so leaving it unimplemented for now.
// _globalUserState = message;
break;
default:
debugPrint('Unknown command: ${parsedIRCMessage.command}');
@ -209,6 +207,8 @@ 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(),
@ -230,6 +230,7 @@ abstract class _ChatStoreBase with Store {
final span = IRC.generateSpan(ircMessage: ircMessage, assetToUrl: _assetToUrl);
if (ircMessage.command == Command.clearChat || ircMessage.command == Command.clearMessage) {
// Render timeouts and bans
final banDuration = ircMessage.tags['ban-duration'];
return Padding(
padding: const EdgeInsets.symmetric(vertical: 10.0),
@ -256,15 +257,14 @@ abstract class _ChatStoreBase with Store {
),
);
} else if (ircMessage.command == Command.userNotice) {
// Render sub alerts
return Container(
color: Colors.purple.withOpacity(0.3),
padding: const EdgeInsets.all(5.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
ircMessage.tags['system-msg']!,
),
Text(ircMessage.tags['system-msg']!),
const SizedBox(height: 5),
if (ircMessage.message != null)
ChatMessage(
@ -275,6 +275,7 @@ abstract class _ChatStoreBase with Store {
),
);
} else {
// Render normal chat message (PRIVMSG).
return Padding(
padding: const EdgeInsets.symmetric(vertical: 5.0),
child: ChatMessage(

View file

@ -31,6 +31,8 @@ class _ChatState extends State<Chat> {
Observer(
builder: (_) {
return ListView.builder(
addAutomaticKeepAlives: false,
addRepaintBoundaries: false,
itemCount: widget.chatStore.messages.length,
controller: widget.chatStore.scrollController,
padding: const EdgeInsets.all(5.0),