Skip to content

Commit 5c8d81d

Browse files
committed
narrow [nfc]: Move DmNarrow.withUser{,s} factories near plain constructor
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.
1 parent cd49fcf commit 5c8d81d

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

lib/model/narrow.dart

+9-9
Original file line numberDiff line numberDiff line change
@@ -131,31 +131,31 @@ class DmNarrow extends Narrow implements SendableNarrow {
131131
assert(allRecipientIds.contains(selfUserId)),
132132
_selfUserId = selfUserId;
133133

134-
factory DmNarrow.ofMessage(DmMessage message, {required int selfUserId}) {
134+
factory DmNarrow.withUser(int userId, {required int selfUserId}) {
135135
return DmNarrow(
136-
allRecipientIds: List.unmodifiable(message.allRecipientIds),
136+
allRecipientIds: {userId, selfUserId}.toList()..sort(),
137137
selfUserId: selfUserId,
138138
);
139139
}
140140

141-
/// A [DmNarrow] from an item in [InitialSnapshot.recentPrivateConversations].
142-
factory DmNarrow.ofRecentDmConversation(RecentDmConversation conversation, {required int selfUserId}) {
141+
factory DmNarrow.withUsers(List<int> userIds, {required int selfUserId}) {
143142
return DmNarrow(
144-
allRecipientIds: [...conversation.userIds, selfUserId]..sort(),
143+
allRecipientIds: {...userIds, selfUserId}.toList()..sort(),
145144
selfUserId: selfUserId,
146145
);
147146
}
148147

149-
factory DmNarrow.withUser(int userId, {required int selfUserId}) {
148+
factory DmNarrow.ofMessage(DmMessage message, {required int selfUserId}) {
150149
return DmNarrow(
151-
allRecipientIds: {userId, selfUserId}.toList()..sort(),
150+
allRecipientIds: List.unmodifiable(message.allRecipientIds),
152151
selfUserId: selfUserId,
153152
);
154153
}
155154

156-
factory DmNarrow.withUsers(List<int> userIds, {required int selfUserId}) {
155+
/// A [DmNarrow] from an item in [InitialSnapshot.recentPrivateConversations].
156+
factory DmNarrow.ofRecentDmConversation(RecentDmConversation conversation, {required int selfUserId}) {
157157
return DmNarrow(
158-
allRecipientIds: {...userIds, selfUserId}.toList()..sort(),
158+
allRecipientIds: [...conversation.userIds, selfUserId]..sort(),
159159
selfUserId: selfUserId,
160160
);
161161
}

0 commit comments

Comments
 (0)