Fix unnecessary observables in chat message widget
This commit is contained in:
parent
9933f329e7
commit
7fe5764dd3
1 changed files with 112 additions and 108 deletions
|
|
@ -21,116 +21,120 @@ class ChatMessage extends StatelessWidget {
|
|||
const highlightPadding = EdgeInsets.symmetric(vertical: 5.0, horizontal: 10.0);
|
||||
const messagePadding = EdgeInsets.symmetric(horizontal: 10.0);
|
||||
|
||||
return Observer(
|
||||
builder: (context) {
|
||||
switch (ircMessage.command) {
|
||||
case Command.privateMessage:
|
||||
case Command.userState:
|
||||
// Render normal chat message (PRIVMSG).
|
||||
final span = Text.rich(
|
||||
TextSpan(
|
||||
children: ircMessage.generateSpan(
|
||||
style: DefaultTextStyle.of(context).style,
|
||||
assetsStore: assetsStore,
|
||||
useZeroWidth: settingsStore.showZeroWidth,
|
||||
useReadableColors: settingsStore.useReadableColors,
|
||||
isLightTheme: Theme.of(context).brightness == Brightness.light,
|
||||
timestamp: settingsStore.timestampType,
|
||||
),
|
||||
switch (ircMessage.command) {
|
||||
case Command.privateMessage:
|
||||
case Command.userState:
|
||||
// Render normal chat message (PRIVMSG).
|
||||
final child = Observer(
|
||||
builder: (context) => Text.rich(
|
||||
TextSpan(
|
||||
children: ircMessage.generateSpan(
|
||||
style: DefaultTextStyle.of(context).style,
|
||||
assetsStore: assetsStore,
|
||||
useZeroWidth: settingsStore.showZeroWidth,
|
||||
useReadableColors: settingsStore.useReadableColors,
|
||||
isLightTheme: Theme.of(context).brightness == Brightness.light,
|
||||
timestamp: settingsStore.timestampType,
|
||||
),
|
||||
);
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
if (ircMessage.mention) {
|
||||
return Container(
|
||||
padding: highlightPadding,
|
||||
color: const Color(0x4DFF0000),
|
||||
child: span,
|
||||
);
|
||||
}
|
||||
return Padding(
|
||||
padding: messagePadding,
|
||||
child: span,
|
||||
);
|
||||
case Command.clearChat:
|
||||
case Command.clearMessage:
|
||||
// Render timeouts and bans
|
||||
final banDuration = ircMessage.tags['ban-duration'];
|
||||
return Padding(
|
||||
padding: highlightPadding,
|
||||
child: Opacity(
|
||||
opacity: 0.50,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text.rich(
|
||||
TextSpan(
|
||||
children: ircMessage.generateSpan(
|
||||
style: DefaultTextStyle.of(context).style,
|
||||
assetsStore: assetsStore,
|
||||
showMessage: settingsStore.showDeletedMessages,
|
||||
useZeroWidth: settingsStore.showZeroWidth,
|
||||
useReadableColors: settingsStore.useReadableColors,
|
||||
isLightTheme: Theme.of(context).brightness == Brightness.light,
|
||||
timestamp: settingsStore.timestampType,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 5.0),
|
||||
if (banDuration == null)
|
||||
if (ircMessage.command == Command.clearMessage)
|
||||
const Text('Message Deleted', style: TextStyle(fontWeight: FontWeight.bold))
|
||||
else
|
||||
const Text('User Permanently Banned', style: TextStyle(fontWeight: FontWeight.bold))
|
||||
else
|
||||
Text(
|
||||
int.parse(banDuration) > 1 ? 'Timed out for $banDuration seconds' : 'Timed out for $banDuration second',
|
||||
style: const TextStyle(fontWeight: FontWeight.bold),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
case Command.notice:
|
||||
return Padding(
|
||||
padding: messagePadding,
|
||||
child: Text.rich(
|
||||
TextSpan(
|
||||
text: ircMessage.message,
|
||||
),
|
||||
style: TextStyle(
|
||||
color: Theme.of(context).textTheme.bodyText2?.color?.withOpacity(0.5),
|
||||
),
|
||||
),
|
||||
);
|
||||
case Command.userNotice:
|
||||
return Container(
|
||||
padding: highlightPadding,
|
||||
color: const Color(0x339146FF),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(ircMessage.tags['system-msg']!),
|
||||
const SizedBox(height: 5.0),
|
||||
if (ircMessage.message != null)
|
||||
Text.rich(
|
||||
TextSpan(
|
||||
children: ircMessage.generateSpan(
|
||||
style: DefaultTextStyle.of(context).style,
|
||||
assetsStore: assetsStore,
|
||||
useZeroWidth: settingsStore.showZeroWidth,
|
||||
useReadableColors: settingsStore.useReadableColors,
|
||||
isLightTheme: Theme.of(context).brightness == Brightness.light,
|
||||
timestamp: settingsStore.timestampType,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
default:
|
||||
return const SizedBox();
|
||||
if (ircMessage.mention) {
|
||||
return Container(
|
||||
padding: highlightPadding,
|
||||
color: const Color(0x4DFF0000),
|
||||
child: child,
|
||||
);
|
||||
}
|
||||
},
|
||||
);
|
||||
return Padding(
|
||||
padding: messagePadding,
|
||||
child: child,
|
||||
);
|
||||
case Command.clearChat:
|
||||
case Command.clearMessage:
|
||||
// Render timeouts and bans
|
||||
final banDuration = ircMessage.tags['ban-duration'];
|
||||
return Padding(
|
||||
padding: highlightPadding,
|
||||
child: Opacity(
|
||||
opacity: 0.50,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Observer(
|
||||
builder: (context) => Text.rich(
|
||||
TextSpan(
|
||||
children: ircMessage.generateSpan(
|
||||
style: DefaultTextStyle.of(context).style,
|
||||
assetsStore: assetsStore,
|
||||
showMessage: settingsStore.showDeletedMessages,
|
||||
useZeroWidth: settingsStore.showZeroWidth,
|
||||
useReadableColors: settingsStore.useReadableColors,
|
||||
isLightTheme: Theme.of(context).brightness == Brightness.light,
|
||||
timestamp: settingsStore.timestampType,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 5.0),
|
||||
if (banDuration == null)
|
||||
if (ircMessage.command == Command.clearMessage)
|
||||
const Text(
|
||||
'Message Deleted',
|
||||
style: TextStyle(fontWeight: FontWeight.bold),
|
||||
)
|
||||
else
|
||||
const Text(
|
||||
'User Permanently Banned',
|
||||
style: TextStyle(fontWeight: FontWeight.bold),
|
||||
)
|
||||
else
|
||||
Text(
|
||||
'Timed out for $banDuration ${int.parse(banDuration) > 1 ? 'seconds' : 'second'}',
|
||||
style: const TextStyle(fontWeight: FontWeight.bold),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
case Command.notice:
|
||||
return Padding(
|
||||
padding: messagePadding,
|
||||
child: Text.rich(
|
||||
TextSpan(text: ircMessage.message),
|
||||
style: TextStyle(color: Theme.of(context).textTheme.bodyText2?.color?.withOpacity(0.5)),
|
||||
),
|
||||
);
|
||||
case Command.userNotice:
|
||||
return Container(
|
||||
padding: highlightPadding,
|
||||
color: const Color(0x339146FF),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(ircMessage.tags['system-msg']!),
|
||||
const SizedBox(height: 5.0),
|
||||
if (ircMessage.message != null)
|
||||
Observer(
|
||||
builder: (context) => Text.rich(
|
||||
TextSpan(
|
||||
children: ircMessage.generateSpan(
|
||||
style: DefaultTextStyle.of(context).style,
|
||||
assetsStore: assetsStore,
|
||||
useZeroWidth: settingsStore.showZeroWidth,
|
||||
useReadableColors: settingsStore.useReadableColors,
|
||||
isLightTheme: Theme.of(context).brightness == Brightness.light,
|
||||
timestamp: settingsStore.timestampType,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
default:
|
||||
return const SizedBox();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue