diff --git a/lib/components/chat_history/twitch/follow_event.dart b/lib/components/chat_history/twitch/follow_event.dart index 3fc282a66..ffa113f8c 100644 --- a/lib/components/chat_history/twitch/follow_event.dart +++ b/lib/components/chat_history/twitch/follow_event.dart @@ -2,9 +2,11 @@ import 'dart:math'; import 'package:flutter/material.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; +import 'package:provider/provider.dart'; import 'package:rtchat/components/chat_history/decorated_event.dart'; import 'package:rtchat/components/image/resilient_network_image.dart'; import 'package:rtchat/models/messages/twitch/event.dart'; +import 'package:rtchat/models/style.dart'; import 'package:styled_text/styled_text.dart'; class TwitchFollowEventWidget extends StatelessWidget { @@ -18,12 +20,12 @@ class TwitchFollowEventWidget extends StatelessWidget { avatars: model.followers .sublist(0, min(3, model.followers.length)) .map((follower) => ResilientNetworkImage(follower.profilePictureUrl)), - child: Builder(builder: ((context) { + child: Consumer(builder: (context, styleModel, child) { switch (model.followers.length) { case 1: return StyledText( - text: AppLocalizations.of(context)! - .followingEvent(model.followers.first.display), + text: AppLocalizations.of(context)!.followingEvent( + styleModel.getTwitchDisplayName(model.followers.first)), tags: { 'bold': StyledTextTag( style: Theme.of(context).textTheme.titleSmall), @@ -32,8 +34,8 @@ class TwitchFollowEventWidget extends StatelessWidget { // return x and y are following you. return StyledText( text: AppLocalizations.of(context)!.followingEvent2( - model.followers.first.display, - model.followers.last.display), + styleModel.getTwitchDisplayName(model.followers.first), + styleModel.getTwitchDisplayName(model.followers.last)), tags: { 'bold': StyledTextTag( style: Theme.of(context).textTheme.titleSmall), @@ -42,15 +44,15 @@ class TwitchFollowEventWidget extends StatelessWidget { // return x, y, and n others are following you. return StyledText( text: AppLocalizations.of(context)!.followingEvent3( - model.followers.first.display, - model.followers.last.display, + styleModel.getTwitchDisplayName(model.followers.first), + styleModel.getTwitchDisplayName(model.followers.last), model.followers.length - 2), tags: { 'bold': StyledTextTag( style: Theme.of(context).textTheme.titleSmall), }); } - })), + }), ); } } diff --git a/lib/components/chat_history/twitch/message.dart b/lib/components/chat_history/twitch/message.dart index 6de864fb6..505805d14 100644 --- a/lib/components/chat_history/twitch/message.dart +++ b/lib/components/chat_history/twitch/message.dart @@ -159,8 +159,9 @@ class TwitchMessageWidget extends StatelessWidget { final orientation = snapshot.data; if (orientation == null) { return RichText( - text: - TextSpan(text: model.author.display, style: authorStyle)); + text: TextSpan( + text: styleModel.getTwitchDisplayName(model.author), + style: authorStyle)); } final hslColor = HSLColor.fromColor( styleModel.applyLightnessBoost(context, color)); @@ -172,7 +173,7 @@ class TwitchMessageWidget extends StatelessWidget { hslColor.withHue((hslColor.hue - deg) % 360).toColor(); return RichText( text: TextSpan( - text: model.author.display, + text: styleModel.getTwitchDisplayName(model.author), style: authorStyle.copyWith(color: shimmer))); }); } @@ -184,7 +185,9 @@ class TwitchMessageWidget extends StatelessWidget { if (contributors.contains(model.author.userId)) { return WidgetSpan(child: authorWidget(author, styleModel, authorStyle)); } - return TextSpan(text: model.author.display, style: authorStyle); + return TextSpan( + text: styleModel.getTwitchDisplayName(model.author), + style: authorStyle); } @override diff --git a/lib/models/messages/twitch/user.dart b/lib/models/messages/twitch/user.dart index a68962f25..296852b67 100644 --- a/lib/models/messages/twitch/user.dart +++ b/lib/models/messages/twitch/user.dart @@ -56,17 +56,8 @@ class TwitchUserModel { bool get isBot => botList.contains(login.toLowerCase()); - String get display { - final author = displayName ?? login; - if (author.toLowerCase() != login) { - // this is an internationalized name. - return "$displayName ($login)"; - } - return author; - } - Color get color { - final n = display.codeUnits.first + display.codeUnits.last; + final n = login.codeUnits.first + login.codeUnits.last; return colors[n % colors.length]; } diff --git a/lib/models/style.dart b/lib/models/style.dart index 33e0728b3..c174ac9a3 100644 --- a/lib/models/style.dart +++ b/lib/models/style.dart @@ -1,6 +1,7 @@ import 'dart:core'; import 'package:flutter/material.dart'; +import 'package:rtchat/models/messages/twitch/user.dart'; Color darken(Color color, [double amount = .1]) { assert(amount >= 0 && amount <= 1); @@ -54,6 +55,7 @@ class StyleModel extends ChangeNotifier { bool _isDeletedMessagesVisible = true; CompactMessages _compactMessages = CompactMessages.none; bool _isDiscoModeAvailable = false; + bool _isLoginShown = true; double get fontSize { return _fontSize; @@ -99,6 +101,22 @@ class StyleModel extends ChangeNotifier { notifyListeners(); } + bool get isLoginShown => _isLoginShown; + + set isLoginShown(bool isLoginShown) { + _isLoginShown = isLoginShown; + notifyListeners(); + } + + String getTwitchDisplayName(TwitchUserModel user) { + final author = user.displayName ?? user.login; + if (author.toLowerCase() != user.login && isLoginShown) { + // this is an internationalized name. + return "${user.displayName} (${user.login})"; + } + return author; + } + bool get isDiscoModeAvailable => _isDiscoModeAvailable; StyleModel.fromJson(Map json) { @@ -117,6 +135,9 @@ class StyleModel extends ChangeNotifier { if (json['isDiscoModeEnabled'] != null) { _isDiscoModeAvailable = json['isDiscoModeEnabled']; } + if (json['isLoginShown'] != null) { + _isLoginShown = json['isLoginShown']; + } } Map toJson() => { @@ -125,5 +146,6 @@ class StyleModel extends ChangeNotifier { "isDeletedMessagesVisible": _isDeletedMessagesVisible, "compactMessages": _compactMessages.toJson(), "isDiscoModeEnabled": _isDiscoModeAvailable, + "isLoginShown": _isLoginShown, }; } diff --git a/lib/screens/settings/chat_history.dart b/lib/screens/settings/chat_history.dart index e26e4334d..5b60b0867 100644 --- a/lib/screens/settings/chat_history.dart +++ b/lib/screens/settings/chat_history.dart @@ -39,7 +39,8 @@ final message2 = TwitchMessageModel( channelId: 'placeholder'); final message3 = TwitchMessageModel( messageId: "placeholder3", - author: const TwitchUserModel(userId: 'muxfd', login: 'muxfd'), + author: const TwitchUserModel( + userId: 'muxfd', login: 'muxfd', displayName: 'マックス'), tags: { "color": "#00FF7F", "badges-raw": "broadcaster/1,moderator/1", @@ -141,6 +142,17 @@ class ChatHistoryScreen extends StatelessWidget { styleModel.isDeletedMessagesVisible = value; }, ), + SwitchListTile.adaptive( + title: const Text('Show login names'), + subtitle: styleModel.isLoginShown + ? const Text( + "Login names will be shown if they are different from the display name") + : const Text("Login names will be hidden"), + value: styleModel.isLoginShown, + onChanged: (value) { + styleModel.isLoginShown = value; + }, + ), Padding( padding: const EdgeInsets.all(16), child: Text("Compact messages",