Skip to content

Commit

Permalink
[nfc]: handle unknown users everywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
mofirojean committed Oct 23, 2024
1 parent 03dfdf1 commit cc5c85c
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 7 deletions.
4 changes: 3 additions & 1 deletion lib/widgets/emoji_reaction.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/zulip_localizations.dart';

import '../api/model/model.dart';
import '../api/route/messages.dart';
Expand Down Expand Up @@ -143,6 +144,7 @@ class ReactionChip extends StatelessWidget {
@override
Widget build(BuildContext context) {
final store = PerAccountStoreWidget.of(context);
final zulipLocalizations = ZulipLocalizations.of(context);

final reactionType = reactionWithVotes.reactionType;
final emojiCode = reactionWithVotes.emojiCode;
Expand All @@ -157,7 +159,7 @@ class ReactionChip extends StatelessWidget {
? userIds.map((id) {
return id == store.selfUserId
? 'You'
: store.users[id]?.fullName ?? '(unknown user)'; // TODO(i18n)
: store.users[id]?.fullName ?? zulipLocalizations.unknownUserName;
}).join(', ')
: userIds.length.toString();

Expand Down
8 changes: 6 additions & 2 deletions lib/widgets/inbox.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/zulip_localizations.dart';

import '../api/model/model.dart';
import '../model/narrow.dart';
Expand Down Expand Up @@ -368,18 +369,21 @@ class _DmItem extends StatelessWidget {
@override
Widget build(BuildContext context) {
final store = PerAccountStoreWidget.of(context);
final zulipLocalizations = ZulipLocalizations.of(context);
final selfUser = store.users[store.selfUserId]!;

final designVariables = DesignVariables.of(context);

final title = switch (narrow.otherRecipientIds) { // TODO dedupe with [RecentDmConversationsItem]
[] => selfUser.fullName,
[var otherUserId] => store.users[otherUserId]?.fullName ?? '(unknown user)',
[var otherUserId] => store.users[otherUserId]?.fullName ?? zulipLocalizations.unknownUserName,

// TODO(i18n): List formatting, like you can do in JavaScript:
// new Intl.ListFormat('ja').format(['Chris', 'Greg', 'Alya', 'Shu'])
// // 'Chris、Greg、Alya、Shu'
_ => narrow.otherRecipientIds.map((id) => store.users[id]?.fullName ?? '(unknown user)').join(', '),
_ => narrow.otherRecipientIds.map((id) =>
store.users[id]?.fullName ?? zulipLocalizations.unknownUserName
).join(', '),
};

return Material(
Expand Down
4 changes: 3 additions & 1 deletion lib/widgets/message_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,8 @@ class MessageListAppBarTitle extends StatelessWidget {
Widget build(BuildContext context) {
final zulipLocalizations = ZulipLocalizations.of(context);

// TODO(i18n): provide tranlations just as 'zulipLocalizations.unknownUserName'
// for 'unknown channel'
switch (narrow) {
case CombinedFeedNarrow():
return Text(zulipLocalizations.combinedFeedPageTitle);
Expand Down Expand Up @@ -349,7 +351,7 @@ class MessageListAppBarTitle extends StatelessWidget {
if (otherRecipientIds.isEmpty) {
return const Text("DMs with yourself");
} else {
final names = otherRecipientIds.map((id) => store.users[id]?.fullName ?? '(unknown user)');
final names = otherRecipientIds.map((id) => store.users[id]?.fullName ?? zulipLocalizations.unknownUserName);
return Text("DMs with ${names.join(", ")}"); // TODO show avatars
}
}
Expand Down
3 changes: 2 additions & 1 deletion lib/widgets/profile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,9 @@ class _UserWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
final store = PerAccountStoreWidget.of(context);
final zulipLocalizations = ZulipLocalizations.of(context);
final user = store.users[userId];
final fullName = user?.fullName ?? '(unknown user)';
final fullName = user?.fullName ?? zulipLocalizations.unknownUserName;
return InkWell(
onTap: () => Navigator.push(context,
ProfilePage.buildRoute(context: context,
Expand Down
5 changes: 3 additions & 2 deletions lib/widgets/recent_dm_conversations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ class RecentDmConversationsItem extends StatelessWidget {
Widget build(BuildContext context) {
final store = PerAccountStoreWidget.of(context);
final selfUser = store.users[store.selfUserId]!;
final zulipLocalizations = ZulipLocalizations.of(context);

final designVariables = DesignVariables.of(context);

Expand All @@ -107,13 +108,13 @@ class RecentDmConversationsItem extends StatelessWidget {
// (should we offer a "spam folder" style summary screen of recent
// 1:1 DM conversations from muted users?)
final otherUser = store.users[otherUserId];
title = otherUser?.fullName ?? '(unknown user)';
title = otherUser?.fullName ?? zulipLocalizations.unknownUserName;
avatar = AvatarImage(userId: otherUserId, size: _avatarSize);
default:
// TODO(i18n): List formatting, like you can do in JavaScript:
// new Intl.ListFormat('ja').format(['Chris', 'Greg', 'Alya'])
// // 'Chris、Greg、Alya'
title = narrow.otherRecipientIds.map((id) => store.users[id]?.fullName ?? '(unknown user)').join(', ');
title = narrow.otherRecipientIds.map((id) => store.users[id]?.fullName ?? zulipLocalizations.unknownUserName).join(', ');
avatar = ColoredBox(color: designVariables.groupDmConversationIconBg,
child: Center(
child: Icon(color: designVariables.groupDmConversationIcon,
Expand Down

0 comments on commit cc5c85c

Please sign in to comment.