Skip to content

Commit

Permalink
test [nfc]: Reorder example data and group a bit more finely
Browse files Browse the repository at this point in the history
  • Loading branch information
gnprice committed Oct 23, 2023
1 parent 92b4d3f commit d866621
Showing 1 changed file with 81 additions and 78 deletions.
159 changes: 81 additions & 78 deletions test/example_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -107,29 +107,32 @@ ZulipStream stream({
canRemoveSubscribersGroupId: canRemoveSubscribersGroupId ?? 123,
);
}
const _stream = stream;

////////////////////////////////////////////////////////////////
// Messages.
// Messages, and pieces of messages.
//

UnreadMessagesSnapshot unreadMsgs({
int? count,
List<UnreadDmSnapshot>? dms,
List<UnreadStreamSnapshot>? streams,
List<UnreadHuddleSnapshot>? huddles,
List<int>? mentions,
bool? oldUnreadsMissing,
}) {
return UnreadMessagesSnapshot(
count: count ?? 0,
dms: dms ?? [],
streams: streams ?? [],
huddles: huddles ?? [],
mentions: mentions ?? [],
oldUnreadsMissing: oldUnreadsMissing ?? false,
);
}
const _unreadMsgs = unreadMsgs;
Reaction unicodeEmojiReaction = Reaction(
emojiName: 'thumbs_up',
emojiCode: '1f44d',
reactionType: ReactionType.unicodeEmoji,
userId: selfUser.userId,
);

Reaction realmEmojiReaction = Reaction(
emojiName: 'twocents',
emojiCode: '181',
reactionType: ReactionType.realmEmoji,
userId: selfUser.userId,
);

Reaction zulipExtraEmojiReaction = Reaction(
emojiName: 'zulip',
emojiCode: 'zulip',
reactionType: ReactionType.zulipExtraEmoji,
userId: selfUser.userId,
);

final _messagePropertiesBase = {
'is_me_message': false,
Expand Down Expand Up @@ -161,8 +164,6 @@ Map<String, dynamic> _messagePropertiesFromContent(String? content, String? cont
}
}

const _stream = stream;

StreamMessage streamMessage({
int? id,
User? sender,
Expand Down Expand Up @@ -229,26 +230,67 @@ DmMessage dmMessage({
}) as Map<String, dynamic>);
}

Reaction unicodeEmojiReaction = Reaction(
emojiName: 'thumbs_up',
emojiCode: '1f44d',
reactionType: ReactionType.unicodeEmoji,
userId: selfUser.userId,
);
////////////////////////////////////////////////////////////////
// Aggregate data structures.
//

Reaction realmEmojiReaction = Reaction(
emojiName: 'twocents',
emojiCode: '181',
reactionType: ReactionType.realmEmoji,
userId: selfUser.userId,
);
UnreadMessagesSnapshot unreadMsgs({
int? count,
List<UnreadDmSnapshot>? dms,
List<UnreadStreamSnapshot>? streams,
List<UnreadHuddleSnapshot>? huddles,
List<int>? mentions,
bool? oldUnreadsMissing,
}) {
return UnreadMessagesSnapshot(
count: count ?? 0,
dms: dms ?? [],
streams: streams ?? [],
huddles: huddles ?? [],
mentions: mentions ?? [],
oldUnreadsMissing: oldUnreadsMissing ?? false,
);
}
const _unreadMsgs = unreadMsgs;

Reaction zulipExtraEmojiReaction = Reaction(
emojiName: 'zulip',
emojiCode: 'zulip',
reactionType: ReactionType.zulipExtraEmoji,
userId: selfUser.userId,
);
////////////////////////////////////////////////////////////////
// Events.
//

UpdateMessageFlagsRemoveEvent updateMessageFlagsRemoveEvent(
MessageFlag flag,
Iterable<Message> messages, {
int? selfUserId,
}) {
return UpdateMessageFlagsRemoveEvent(
id: 0,
flag: flag,
messages: messages.map((m) => m.id).toList(),
messageDetails: Map.fromEntries(messages.map((message) {
final mentioned = message.flags.contains(MessageFlag.mentioned)
|| message.flags.contains(MessageFlag.wildcardMentioned);
return MapEntry(
message.id,
switch (message) {
StreamMessage() => UpdateMessageFlagsMessageDetail(
type: MessageType.stream,
mentioned: mentioned,
streamId: message.streamId,
topic: message.subject,
userIds: null,
),
DmMessage() => UpdateMessageFlagsMessageDetail(
type: MessageType.private,
mentioned: mentioned,
streamId: null,
topic: null,
userIds: DmNarrow.ofMessage(message, selfUserId: selfUserId ?? selfUser.userId)
.otherRecipientIds,
),
},
);
})));
}

////////////////////////////////////////////////////////////////
// The entire per-account state.
Expand Down Expand Up @@ -302,42 +344,3 @@ PerAccountStore store({Account? account, InitialSnapshot? initialSnapshot}) {
initialSnapshot: initialSnapshot ?? _initialSnapshot(),
);
}

////////////////////////////////////////////////////////////////
// Events.
//

UpdateMessageFlagsRemoveEvent updateMessageFlagsRemoveEvent(
MessageFlag flag,
Iterable<Message> messages, {
int? selfUserId,
}) {
return UpdateMessageFlagsRemoveEvent(
id: 0,
flag: flag,
messages: messages.map((m) => m.id).toList(),
messageDetails: Map.fromEntries(messages.map((message) {
final mentioned = message.flags.contains(MessageFlag.mentioned)
|| message.flags.contains(MessageFlag.wildcardMentioned);
return MapEntry(
message.id,
switch (message) {
StreamMessage() => UpdateMessageFlagsMessageDetail(
type: MessageType.stream,
mentioned: mentioned,
streamId: message.streamId,
topic: message.subject,
userIds: null,
),
DmMessage() => UpdateMessageFlagsMessageDetail(
type: MessageType.private,
mentioned: mentioned,
streamId: null,
topic: null,
userIds: DmNarrow.ofMessage(message, selfUserId: selfUserId ?? selfUser.userId)
.otherRecipientIds,
),
},
);
})));
}

0 comments on commit d866621

Please sign in to comment.