Skip to content

Commit

Permalink
narrow [nfc]: Move DmNarrow.withUser{,s} factories near plain constru…
Browse files Browse the repository at this point in the history
…ctor

As Greg points out (before withUsers was added, but it should apply
to that too):
  zulip#304 (comment)

> [withUser] and `ofMessage` and the plain one are the really
> general-purpose constructors; as the number of special-purpose
> constructors grows, it starts getting pushed down where it's
> harder to spot.
  • Loading branch information
chrisbobbe committed Oct 19, 2023
1 parent cd49fcf commit 5c8d81d
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions lib/model/narrow.dart
Original file line number Diff line number Diff line change
Expand Up @@ -131,31 +131,31 @@ class DmNarrow extends Narrow implements SendableNarrow {
assert(allRecipientIds.contains(selfUserId)),
_selfUserId = selfUserId;

factory DmNarrow.ofMessage(DmMessage message, {required int selfUserId}) {
factory DmNarrow.withUser(int userId, {required int selfUserId}) {
return DmNarrow(
allRecipientIds: List.unmodifiable(message.allRecipientIds),
allRecipientIds: {userId, selfUserId}.toList()..sort(),
selfUserId: selfUserId,
);
}

/// A [DmNarrow] from an item in [InitialSnapshot.recentPrivateConversations].
factory DmNarrow.ofRecentDmConversation(RecentDmConversation conversation, {required int selfUserId}) {
factory DmNarrow.withUsers(List<int> userIds, {required int selfUserId}) {
return DmNarrow(
allRecipientIds: [...conversation.userIds, selfUserId]..sort(),
allRecipientIds: {...userIds, selfUserId}.toList()..sort(),
selfUserId: selfUserId,
);
}

factory DmNarrow.withUser(int userId, {required int selfUserId}) {
factory DmNarrow.ofMessage(DmMessage message, {required int selfUserId}) {
return DmNarrow(
allRecipientIds: {userId, selfUserId}.toList()..sort(),
allRecipientIds: List.unmodifiable(message.allRecipientIds),
selfUserId: selfUserId,
);
}

factory DmNarrow.withUsers(List<int> userIds, {required int selfUserId}) {
/// A [DmNarrow] from an item in [InitialSnapshot.recentPrivateConversations].
factory DmNarrow.ofRecentDmConversation(RecentDmConversation conversation, {required int selfUserId}) {
return DmNarrow(
allRecipientIds: {...userIds, selfUserId}.toList()..sort(),
allRecipientIds: [...conversation.userIds, selfUserId]..sort(),
selfUserId: selfUserId,
);
}
Expand Down

0 comments on commit 5c8d81d

Please sign in to comment.