Skip to content

Commit

Permalink
narrow [nfc]: Strength-reduce implementation of DmNarrow.withUser
Browse files Browse the repository at this point in the history
No need to allocate a `Set` for this, as it's always either
just one or two elements.  This version should be a bit more
efficient if we find ourselves constructing many of these.
  • Loading branch information
gnprice authored and chrisbobbe committed Oct 24, 2023
1 parent fb0ee80 commit d9ae8ca
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/model/narrow.dart
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,10 @@ class DmNarrow extends Narrow implements SendableNarrow {

/// A [DmNarrow] for a 1:1 DM conversation, either with self or otherwise.
factory DmNarrow.withUser(int userId, {required int selfUserId}) {
return DmNarrow(
allRecipientIds: {userId, selfUserId}.toList()..sort(),
selfUserId: selfUserId,
);
return DmNarrow(selfUserId: selfUserId,
allRecipientIds: (userId == selfUserId) ? [selfUserId]
: (userId < selfUserId) ? [userId, selfUserId]
: [selfUserId, userId]);
}

/// A [DmNarrow] from a list of users which may or may not include self
Expand Down

0 comments on commit d9ae8ca

Please sign in to comment.