-
Notifications
You must be signed in to change notification settings - Fork 309
Add and handle live-updates to saved snippets data #1511
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import 'package:json_annotation/json_annotation.dart'; | ||
|
||
import '../core.dart'; | ||
|
||
part 'saved_snippets.g.dart'; | ||
|
||
/// https://zulip.com/api/create-saved-snippet | ||
Future<CreateSavedSnippetResult> createSavedSnippet(ApiConnection connection, { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This needs a simple smoke test in test/api/route/. |
||
required String title, | ||
required String content, | ||
}) { | ||
assert(connection.zulipFeatureLevel! >= 297); // TODO(server-10) | ||
return connection.post('createSavedSnippet', CreateSavedSnippetResult.fromJson, 'saved_snippets', { | ||
'title': RawParameter(title), | ||
'content': RawParameter(content), | ||
}); | ||
} | ||
|
||
@JsonSerializable(fieldRename: FieldRename.snake) | ||
class CreateSavedSnippetResult { | ||
final int savedSnippetId; | ||
|
||
CreateSavedSnippetResult({ | ||
required this.savedSnippetId, | ||
}); | ||
|
||
factory CreateSavedSnippetResult.fromJson(Map<String, dynamic> json) => | ||
_$CreateSavedSnippetResultFromJson(json); | ||
|
||
Map<String, dynamic> toJson() => _$CreateSavedSnippetResultToJson(this); | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import 'package:collection/collection.dart'; | ||
|
||
import '../api/model/events.dart'; | ||
import '../api/model/model.dart'; | ||
import 'store.dart'; | ||
|
||
mixin SavedSnippetStore { | ||
Map<int, SavedSnippet> get savedSnippets; | ||
} | ||
|
||
class SavedSnippetStoreImpl extends PerAccountStoreBase with SavedSnippetStore { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Commit-message nit: this commit does more than just handle live-updates to savedSnippets—it's what adds savedSnippets into the codebase in the first place :) Could be:
or similar. |
||
SavedSnippetStoreImpl({ | ||
required super.core, | ||
required Iterable<SavedSnippet> savedSnippets, | ||
}) : _savedSnippets = { | ||
for (final savedSnippet in savedSnippets) | ||
savedSnippet.id: savedSnippet, | ||
}; | ||
|
||
@override | ||
late Map<int, SavedSnippet> savedSnippets = UnmodifiableMapView(_savedSnippets); | ||
final Map<int, SavedSnippet> _savedSnippets; | ||
|
||
void handleSavedSnippetsEvent(SavedSnippetsEvent event) { | ||
switch (event) { | ||
case SavedSnippetsAddEvent(:final savedSnippet): | ||
_savedSnippets[savedSnippet.id] = savedSnippet; | ||
|
||
case SavedSnippetsUpdateEvent(:final savedSnippet): | ||
assert(_savedSnippets[savedSnippet.id]!.dateCreated | ||
== savedSnippet.dateCreated); // TODO(log) | ||
_savedSnippets[savedSnippet.id] = savedSnippet; | ||
|
||
case SavedSnippetsRemoveEvent(:final savedSnippetId): | ||
_savedSnippets.remove(savedSnippetId); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,7 @@ import 'message_list.dart'; | |
import 'recent_dm_conversations.dart'; | ||
import 'recent_senders.dart'; | ||
import 'channel.dart'; | ||
import 'saved_snippet.dart'; | ||
import 'settings.dart'; | ||
import 'typing_status.dart'; | ||
import 'unreads.dart'; | ||
|
@@ -431,7 +432,7 @@ Uri? tryResolveUrl(Uri baseUrl, String reference) { | |
/// This class does not attempt to poll an event queue | ||
/// to keep the data up to date. For that behavior, see | ||
/// [UpdateMachine]. | ||
class PerAccountStore extends PerAccountStoreBase with ChangeNotifier, EmojiStore, UserStore, ChannelStore, MessageStore { | ||
class PerAccountStore extends PerAccountStoreBase with ChangeNotifier, EmojiStore, SavedSnippetStore, UserStore, ChannelStore, MessageStore { | ||
/// Construct a store for the user's data, starting from the given snapshot. | ||
/// | ||
/// The global store must already have been updated with | ||
|
@@ -486,6 +487,8 @@ class PerAccountStore extends PerAccountStoreBase with ChangeNotifier, EmojiStor | |
emoji: EmojiStoreImpl( | ||
core: core, allRealmEmoji: initialSnapshot.realmEmoji), | ||
userSettings: initialSnapshot.userSettings, | ||
savedSnippets: SavedSnippetStoreImpl( | ||
core: core, savedSnippets: initialSnapshot.savedSnippets ?? []), | ||
typingNotifier: TypingNotifier( | ||
core: core, | ||
typingStoppedWaitPeriod: Duration( | ||
|
@@ -524,6 +527,7 @@ class PerAccountStore extends PerAccountStoreBase with ChangeNotifier, EmojiStor | |
required this.emailAddressVisibility, | ||
required EmojiStoreImpl emoji, | ||
required this.userSettings, | ||
required SavedSnippetStoreImpl savedSnippets, | ||
required this.typingNotifier, | ||
required UserStoreImpl users, | ||
required this.typingStatus, | ||
|
@@ -534,6 +538,7 @@ class PerAccountStore extends PerAccountStoreBase with ChangeNotifier, EmojiStor | |
required this.recentSenders, | ||
}) : _realmEmptyTopicDisplayName = realmEmptyTopicDisplayName, | ||
_emoji = emoji, | ||
_savedSnippets = savedSnippets, | ||
_users = users, | ||
_channels = channels, | ||
_messages = messages; | ||
|
@@ -621,6 +626,10 @@ class PerAccountStore extends PerAccountStoreBase with ChangeNotifier, EmojiStor | |
|
||
final UserSettings? userSettings; // TODO(server-5) | ||
|
||
@override | ||
Map<int, SavedSnippet> get savedSnippets => _savedSnippets.savedSnippets; | ||
final SavedSnippetStoreImpl _savedSnippets; | ||
|
||
final TypingNotifier typingNotifier; | ||
|
||
//////////////////////////////// | ||
|
@@ -868,6 +877,11 @@ class PerAccountStore extends PerAccountStoreBase with ChangeNotifier, EmojiStor | |
autocompleteViewManager.handleRealmUserUpdateEvent(event); | ||
notifyListeners(); | ||
|
||
case SavedSnippetsEvent(): | ||
assert(debugLog('server event: saved_snippets/${event.op}')); | ||
_savedSnippets.handleSavedSnippetsEvent(event); | ||
notifyListeners(); | ||
Comment on lines
+880
to
+883
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah I guess this case needs to be handled (as a no-op) in the earlier commit—
—to satisfy the analyzer there. |
||
|
||
case ChannelEvent(): | ||
assert(debugLog("server event: stream/${event.op}")); | ||
_channels.handleChannelEvent(event); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Commit-message nit:
saved_snippets
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also this is labeled as an "api:" commit, but it also adds to model code; how about separate
api:
andmodel:
commits?(Or perhaps just one
model:
commit with the API-binding additions lumped into that same commit—but if doing that, it would be logical to lump all the new API-binding code into that commit, including the initial-snapshot code.)