Skip to content

Commit 2063975

Browse files
committed
user [nfc]: Add a selfUser getter
1 parent 8dc1e7a commit 2063975

File tree

4 files changed

+12
-6
lines changed

4 files changed

+12
-6
lines changed

lib/model/user.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ mixin UserStore {
99
/// i.e. the account the person using this app is logged into.
1010
///
1111
/// This always equals the [Account.userId] on [PerAccountStore.account].
12+
///
13+
/// For the corresponding [User] object, see [selfUser].
1214
int get selfUserId;
1315

1416
/// All known users in the realm, by [User.userId].
@@ -31,6 +33,12 @@ mixin UserStore {
3133
/// Consider using [userDisplayName].
3234
Map<int, User> get users;
3335

36+
/// The [User] object for the "self-user",
37+
/// i.e. the account the person using this app is logged into.
38+
///
39+
/// When only the user ID is needed, see [selfUserId].
40+
User get selfUser => users[selfUserId]!;
41+
3442
/// The name to show the given user as in the UI, even for unknown users.
3543
///
3644
/// This is the user's [User.fullName] if the user is known,

lib/widgets/compose_box.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1408,9 +1408,8 @@ class _ComposeBoxState extends State<ComposeBox> with PerAccountStoreAwareStateM
14081408
case ChannelNarrow(:final streamId):
14091409
case TopicNarrow(:final streamId):
14101410
final channel = store.streams[streamId];
1411-
final selfUser = store.users[store.selfUserId]!;
14121411
if (channel == null || !store.hasPostingPermission(inChannel: channel,
1413-
user: selfUser, byDate: DateTime.now())) {
1412+
user: store.selfUser, byDate: DateTime.now())) {
14141413
return _ErrorBanner(label:
14151414
ZulipLocalizations.of(context).errorBannerCannotPostInChannelLabel);
14161415
}

lib/widgets/inbox.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ class _DmItem extends StatelessWidget {
385385
final designVariables = DesignVariables.of(context);
386386

387387
final title = switch (narrow.otherRecipientIds) { // TODO dedupe with [RecentDmConversationsItem]
388-
[] => store.users[store.selfUserId]!.fullName,
388+
[] => store.selfUser.fullName,
389389
[var otherUserId] => store.userDisplayName(otherUserId),
390390

391391
// TODO(i18n): List formatting, like you can do in JavaScript:

lib/widgets/recent_dm_conversations.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,8 @@ class RecentDmConversationsItem extends StatelessWidget {
8585
final Widget avatar;
8686
switch (narrow.otherRecipientIds) { // TODO dedupe with DM items in [InboxPage]
8787
case []:
88-
final selfUser = store.users[store.selfUserId]!;
89-
title = selfUser.fullName;
90-
avatar = AvatarImage(userId: selfUser.userId, size: _avatarSize);
88+
title = store.selfUser.fullName;
89+
avatar = AvatarImage(userId: store.selfUserId, size: _avatarSize);
9190
case [var otherUserId]:
9291
// TODO(#296) actually don't show this row if the user is muted?
9392
// (should we offer a "spam folder" style summary screen of recent

0 commit comments

Comments
 (0)