-
Notifications
You must be signed in to change notification settings - Fork 1.3k
announcements #4314
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
Open
mdmohsin7
wants to merge
2
commits into
main
Choose a base branch
from
whats-new
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+2,868
−16
Open
announcements #4314
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| import 'dart:convert'; | ||
|
|
||
| import 'package:omi/backend/http/shared.dart'; | ||
| import 'package:omi/env/env.dart'; | ||
| import 'package:omi/models/announcement.dart'; | ||
|
|
||
| Future<List<Announcement>> getAppChangelogs({ | ||
| String? fromVersion, | ||
| String? toVersion, | ||
| int limit = 5, | ||
| }) async { | ||
| String url; | ||
| if (fromVersion != null && toVersion != null) { | ||
| final encodedFromVersion = Uri.encodeComponent(fromVersion); | ||
| final encodedToVersion = Uri.encodeComponent(toVersion); | ||
| url = "${Env.apiBaseUrl}v1/announcements/changelogs?from_version=$encodedFromVersion&to_version=$encodedToVersion"; | ||
| } else { | ||
| url = "${Env.apiBaseUrl}v1/announcements/changelogs?limit=$limit"; | ||
| } | ||
|
|
||
| var res = await makeApiCall( | ||
| url: url, | ||
| headers: {}, | ||
| body: '', | ||
| method: 'GET', | ||
| ); | ||
|
|
||
| if (res == null || res.statusCode != 200) { | ||
| return []; | ||
| } | ||
|
|
||
| final List<dynamic> data = jsonDecode(res.body); | ||
| return data.map((json) => Announcement.fromJson(json)).toList(); | ||
| } | ||
|
|
||
| /// Get feature announcements for a specific version. | ||
| /// For firmware updates: returns features explaining new device behavior. | ||
| /// For app updates: returns features explaining major new app functionality. | ||
| Future<List<Announcement>> getFeatureAnnouncements({ | ||
| required String version, | ||
| required String versionType, // 'app' or 'firmware' | ||
| String? deviceModel, | ||
| }) async { | ||
| var url = "${Env.apiBaseUrl}v1/announcements/features?version=$version&version_type=$versionType"; | ||
| if (deviceModel != null) { | ||
| url += "&device_model=$deviceModel"; | ||
| } | ||
|
|
||
| var res = await makeApiCall( | ||
| url: url, | ||
| headers: {}, | ||
| body: '', | ||
| method: 'GET', | ||
| ); | ||
|
|
||
| if (res == null || res.statusCode != 200) { | ||
| return []; | ||
| } | ||
|
|
||
| final List<dynamic> data = jsonDecode(res.body); | ||
| return data.map((json) => Announcement.fromJson(json)).toList(); | ||
| } | ||
|
|
||
| /// Get active, non-expired general announcements. | ||
| /// If lastCheckedAt is provided, only returns announcements created after that time. | ||
| Future<List<Announcement>> getGeneralAnnouncements({ | ||
| DateTime? lastCheckedAt, | ||
| }) async { | ||
| var url = "${Env.apiBaseUrl}v1/announcements/general"; | ||
| if (lastCheckedAt != null) { | ||
| url += "?last_checked_at=${Uri.encodeComponent(lastCheckedAt.toUtc().toIso8601String())}"; | ||
| } | ||
|
|
||
| var res = await makeApiCall( | ||
| url: url, | ||
| headers: {}, | ||
| body: '', | ||
| method: 'GET', | ||
| ); | ||
|
|
||
| if (res == null || res.statusCode != 200) { | ||
| return []; | ||
| } | ||
|
|
||
| final List<dynamic> data = jsonDecode(res.body); | ||
| return data.map((json) => Announcement.fromJson(json)).toList(); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,150 @@ | ||
| import 'package:json_annotation/json_annotation.dart'; | ||
|
|
||
| part 'announcement.g.dart'; | ||
|
|
||
| enum AnnouncementType { | ||
| changelog, | ||
| feature, | ||
| announcement, | ||
| } | ||
|
|
||
| // Changelog content models | ||
| @JsonSerializable(fieldRename: FieldRename.snake) | ||
| class ChangelogItem { | ||
| final String title; | ||
| final String description; | ||
| final String? icon; | ||
|
|
||
| ChangelogItem({ | ||
| required this.title, | ||
| required this.description, | ||
| this.icon, | ||
| }); | ||
|
|
||
| factory ChangelogItem.fromJson(Map<String, dynamic> json) => _$ChangelogItemFromJson(json); | ||
| Map<String, dynamic> toJson() => _$ChangelogItemToJson(this); | ||
| } | ||
|
|
||
| @JsonSerializable(fieldRename: FieldRename.snake) | ||
| class ChangelogContent { | ||
| final String title; | ||
| final List<ChangelogItem> changes; | ||
|
|
||
| ChangelogContent({ | ||
| required this.title, | ||
| required this.changes, | ||
| }); | ||
|
|
||
| factory ChangelogContent.fromJson(Map<String, dynamic> json) => _$ChangelogContentFromJson(json); | ||
| Map<String, dynamic> toJson() => _$ChangelogContentToJson(this); | ||
| } | ||
|
|
||
| // Feature content models | ||
| @JsonSerializable(fieldRename: FieldRename.snake) | ||
| class FeatureStep { | ||
| final String title; | ||
| final String description; | ||
| final String? imageUrl; | ||
| final String? videoUrl; | ||
| final String? highlightText; | ||
|
|
||
| FeatureStep({ | ||
| required this.title, | ||
| required this.description, | ||
| this.imageUrl, | ||
| this.videoUrl, | ||
| this.highlightText, | ||
| }); | ||
|
|
||
| factory FeatureStep.fromJson(Map<String, dynamic> json) => _$FeatureStepFromJson(json); | ||
| Map<String, dynamic> toJson() => _$FeatureStepToJson(this); | ||
| } | ||
|
|
||
| @JsonSerializable(fieldRename: FieldRename.snake) | ||
| class FeatureContent { | ||
| final String title; | ||
| final List<FeatureStep> steps; | ||
|
|
||
| FeatureContent({ | ||
| required this.title, | ||
| required this.steps, | ||
| }); | ||
|
|
||
| factory FeatureContent.fromJson(Map<String, dynamic> json) => _$FeatureContentFromJson(json); | ||
| Map<String, dynamic> toJson() => _$FeatureContentToJson(this); | ||
| } | ||
|
|
||
| // Announcement content models | ||
| @JsonSerializable(fieldRename: FieldRename.snake) | ||
| class AnnouncementCTA { | ||
| final String text; | ||
| final String action; | ||
|
|
||
| AnnouncementCTA({ | ||
| required this.text, | ||
| required this.action, | ||
| }); | ||
|
|
||
| factory AnnouncementCTA.fromJson(Map<String, dynamic> json) => _$AnnouncementCTAFromJson(json); | ||
| Map<String, dynamic> toJson() => _$AnnouncementCTAToJson(this); | ||
| } | ||
|
|
||
| @JsonSerializable(fieldRename: FieldRename.snake) | ||
| class AnnouncementContent { | ||
| final String title; | ||
| final String body; | ||
| final String? imageUrl; | ||
| final AnnouncementCTA? cta; | ||
|
|
||
| AnnouncementContent({ | ||
| required this.title, | ||
| required this.body, | ||
| this.imageUrl, | ||
| this.cta, | ||
| }); | ||
|
|
||
| factory AnnouncementContent.fromJson(Map<String, dynamic> json) => _$AnnouncementContentFromJson(json); | ||
| Map<String, dynamic> toJson() => _$AnnouncementContentToJson(this); | ||
| } | ||
|
|
||
| // Main announcement model | ||
| @JsonSerializable(fieldRename: FieldRename.snake) | ||
| class Announcement { | ||
| final String id; | ||
| final AnnouncementType type; | ||
| final DateTime createdAt; | ||
| @JsonKey(defaultValue: true) | ||
| final bool active; | ||
|
|
||
| // Version triggers | ||
| final String? appVersion; | ||
| final String? firmwareVersion; | ||
| @JsonKey(defaultValue: []) | ||
| final List<String>? deviceModels; | ||
|
|
||
| // For general announcements | ||
| final DateTime? expiresAt; | ||
|
|
||
| // Raw content - parsed based on type | ||
| final Map<String, dynamic> content; | ||
|
|
||
| Announcement({ | ||
| required this.id, | ||
| required this.type, | ||
| required this.createdAt, | ||
| this.active = true, | ||
| this.appVersion, | ||
| this.firmwareVersion, | ||
| this.deviceModels, | ||
| this.expiresAt, | ||
| required this.content, | ||
| }); | ||
|
|
||
| factory Announcement.fromJson(Map<String, dynamic> json) => _$AnnouncementFromJson(json); | ||
| Map<String, dynamic> toJson() => _$AnnouncementToJson(this); | ||
|
|
||
| // Type-specific content getters | ||
| ChangelogContent get changelogContent => ChangelogContent.fromJson(content); | ||
| FeatureContent get featureContent => FeatureContent.fromJson(content); | ||
| AnnouncementContent get announcementContent => AnnouncementContent.fromJson(content); | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
The query parameters
versionanddeviceModelare not URL-encoded. This can lead to issues if they contain special characters (e.g., a+in a version string like1.0.0+123would be misinterpreted as a space). It's safer to useUri.encodeComponentfor all query parameter values, or construct the URI using its constructor with aqueryParametersmap to handle encoding automatically and robustly.