Skip to content

Commit f94982f

Browse files
authored
feat(samples): add support for handling push notifications (#32)
1 parent ff3eaa8 commit f94982f

File tree

124 files changed

+2607
-244
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

124 files changed

+2607
-244
lines changed

.github/workflows/stream_feeds_flutter_workflow.yml

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,10 @@ jobs:
4545
run: melos bootstrap --verbose
4646

4747
- name: Dart Analyze
48-
run: |
49-
melos run analyze
48+
run: melos run analyze
5049

5150
- name: Check formatting
52-
run: |
53-
melos run format:verify
51+
run: melos run format:verify
5452

5553
## Test and coverage reporting
5654
- name: "Flutter Test"
@@ -72,18 +70,18 @@ jobs:
7270
with:
7371
fetch-depth: 0
7472

75-
- name: ⚙️ Set up Java
76-
uses: actions/setup-java@v3
77-
with:
78-
distribution: "zulu"
79-
java-version: "17"
80-
8173
- name: Install Flutter
8274
uses: subosito/flutter-action@v2
8375
with:
8476
cache: true
77+
cache-key: flutter-:os:-:channel:-:version:-:arch:-:hash:-${{ hashFiles('**/pubspec.lock') }}
8578
channel: ${{ env.FLUTTER_CHANNEL }}
86-
flutter-version: ${{ env.FLUTTER_VERSION }}
79+
80+
- name: Install Tools
81+
run: flutter pub global activate melos
82+
83+
- name: Bootstrap Workspace
84+
run: melos bootstrap --verbose
8785

8886
- name: Build APK
8987
working-directory: sample_app

all_lint_rules.yaml

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ linter:
33
- always_declare_return_types
44
- always_put_control_body_on_new_line
55
- always_put_required_named_parameters_first
6-
- always_require_non_null_named_parameters
76
- always_specify_types
87
- always_use_package_imports
98
- annotate_overrides
9+
- annotate_redeclares
1010
- avoid_annotating_with_dynamic
1111
- avoid_bool_literals_in_conditional_expressions
1212
- avoid_catches_without_on_clauses
@@ -20,6 +20,7 @@ linter:
2020
- avoid_field_initializers_in_const_classes
2121
- avoid_final_parameters
2222
- avoid_function_literals_in_foreach_calls
23+
- avoid_futureor_void
2324
- avoid_implementing_value_types
2425
- avoid_init_to_null
2526
- avoid_js_rounded_ints
@@ -32,8 +33,6 @@ linter:
3233
- avoid_relative_lib_imports
3334
- avoid_renaming_method_parameters
3435
- avoid_return_types_on_setters
35-
- avoid_returning_null
36-
- avoid_returning_null_for_future
3736
- avoid_returning_null_for_void
3837
- avoid_returning_this
3938
- avoid_setters_without_getters
@@ -61,12 +60,15 @@ linter:
6160
- constant_identifier_names
6261
- control_flow_in_finally
6362
- curly_braces_in_flow_control_structures
63+
- dangling_library_doc_comments
6464
- depend_on_referenced_packages
6565
- deprecated_consistency
66+
- deprecated_member_use_from_same_package
6667
- diagnostic_describe_all_properties
6768
- directives_ordering
6869
- discarded_futures
6970
- do_not_use_environment
71+
- document_ignores
7072
- empty_catches
7173
- empty_constructor_bodies
7274
- empty_statements
@@ -76,32 +78,41 @@ linter:
7678
- flutter_style_todos
7779
- hash_and_equals
7880
- implementation_imports
79-
- iterable_contains_unrelated_type
81+
- implicit_call_tearoffs
82+
- implicit_reopen
83+
- invalid_case_patterns
84+
- invalid_runtime_check_with_js_interop_types
8085
- join_return_with_assignment
8186
- leading_newlines_in_multiline_strings
87+
- library_annotations
8288
- library_names
8389
- library_prefixes
8490
- library_private_types_in_public_api
8591
- lines_longer_than_80_chars
86-
- list_remove_unrelated_type
8792
- literal_only_boolean_expressions
93+
- matching_super_parameters
94+
- missing_code_block_language_in_doc_comment
8895
- missing_whitespace_between_adjacent_strings
8996
- no_adjacent_strings_in_list
9097
- no_default_cases
9198
- no_duplicate_case_values
9299
- no_leading_underscores_for_library_prefixes
93100
- no_leading_underscores_for_local_identifiers
101+
- no_literal_bool_comparisons
94102
- no_logic_in_create_state
95103
- no_runtimeType_toString
104+
- no_self_assignments
105+
- no_wildcard_variable_uses
96106
- non_constant_identifier_names
97107
- noop_primitive_operations
98108
- null_check_on_nullable_type_parameter
99109
- null_closures
100110
- omit_local_variable_types
111+
- omit_obvious_local_variable_types
112+
- omit_obvious_property_types
101113
- one_member_abstracts
102114
- only_throw_errors
103115
- overridden_fields
104-
- package_api_docs
105116
- package_names
106117
- package_prefixed_library_names
107118
- parameter_assignments
@@ -117,7 +128,6 @@ linter:
117128
- prefer_constructors_over_static_methods
118129
- prefer_contains
119130
- prefer_double_quotes
120-
- prefer_equal_for_default_values
121131
- prefer_expression_function_bodies
122132
- prefer_final_fields
123133
- prefer_final_in_for_each
@@ -157,20 +167,31 @@ linter:
157167
- sort_constructors_first
158168
- sort_pub_dependencies
159169
- sort_unnamed_constructors_first
170+
- specify_nonobvious_local_variable_types
171+
- specify_nonobvious_property_types
172+
- strict_top_level_inference
173+
- switch_on_type
160174
- test_types_in_equals
161175
- throw_in_finally
162176
- tighten_type_of_initializing_formals
163177
- type_annotate_public_apis
164178
- type_init_formals
179+
- type_literal_in_constant_pattern
165180
- unawaited_futures
181+
- unintended_html_in_doc_comment
182+
- unnecessary_async
166183
- unnecessary_await_in_return
167184
- unnecessary_brace_in_string_interps
185+
- unnecessary_breaks
168186
- unnecessary_const
169187
- unnecessary_constructor_name
170188
- unnecessary_final
171189
- unnecessary_getters_setters
190+
- unnecessary_ignore
172191
- unnecessary_lambdas
173192
- unnecessary_late
193+
- unnecessary_library_directive
194+
- unnecessary_library_name
174195
- unnecessary_new
175196
- unnecessary_null_aware_assignments
176197
- unnecessary_null_aware_operator_on_extension_on_nullable
@@ -185,9 +206,11 @@ linter:
185206
- unnecessary_string_interpolations
186207
- unnecessary_this
187208
- unnecessary_to_list_in_spreads
209+
- unnecessary_unawaited
210+
- unnecessary_underscores
188211
- unreachable_from_main
189212
- unrelated_type_equality_checks
190-
- unsafe_html
213+
- unsafe_variance
191214
- use_build_context_synchronously
192215
- use_colored_box
193216
- use_decorated_box
@@ -199,6 +222,7 @@ linter:
199222
- use_key_in_widget_constructors
200223
- use_late_for_private_fields_and_variables
201224
- use_named_constants
225+
- use_null_aware_elements
202226
- use_raw_strings
203227
- use_rethrow_when_possible
204228
- use_setters_to_change_properties
@@ -207,5 +231,6 @@ linter:
207231
- use_super_parameters
208232
- use_test_throws_matchers
209233
- use_to_and_as_if_applicable
234+
- use_truncating_division
210235
- valid_regexps
211-
- void_checks
236+
- void_checks

analysis_options.yaml

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,10 @@ analyzer:
1010
# We explicitly enabled even conflicting rules and are fixing the conflict
1111
# in this file.
1212
included_file_warning: ignore
13-
14-
todo: ignore
1513
exclude:
1614
# exclude all the generated files
17-
- packages/*/lib/**/*.g.dart
15+
- packages/*/lib/**/*.*.dart
16+
- packages/stream_feeds/lib/src/generated/**
1817

1918
linter:
2019
rules:
@@ -93,6 +92,18 @@ linter:
9392
# There are situations where we use default in enums on purpose
9493
no_default_cases: false
9594

96-
# Temporarily disabled to find more important issues
95+
# Redundant and not required
96+
document_ignores: false
97+
98+
# Conflicts with `omit_local_variable_types`
99+
specify_nonobvious_local_variable_types: false
100+
specify_nonobvious_property_types: false
101+
102+
# False positives
103+
unsafe_variance: false
104+
105+
# TODO: Remove once we remove support for flutter 3.27.4
106+
omit_obvious_property_types: false
107+
108+
# TODO: Temporarily disabled to find more important issues
97109
public_member_api_docs: false
98-
avoid_print: false

docs/analysis_options.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ analyzer:
77
linter:
88
rules:
99
file_names: false
10+
avoid_print: false
1011
avoid_redundant_argument_values: false

melos.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ command:
2020
# List of all the dependencies used in the project.
2121
dependencies:
2222
auto_route: ^10.0.0
23-
cached_network_image: ^3.4.1
2423
collection: ^1.18.0
2524
chewie: ^1.11.3
2625
dio: ^5.9.0
@@ -31,7 +30,10 @@ command:
3130
get_it: ^8.0.3
3231
google_fonts: ^6.3.0
3332
file_picker: ^8.1.4
33+
firebase_core: ^3.0.0
34+
firebase_messaging: ^15.0.0
3435
flex_grid_view: ^0.1.0
36+
flutter_local_notifications: ^18.0.1
3537
injectable: ^2.5.1
3638
http: ^1.1.0
3739
intl: ">=0.18.1 <=0.21.0"
@@ -51,6 +53,7 @@ command:
5153
dev_dependencies:
5254
auto_route_generator: ^10.0.0
5355
build_runner: ^2.4.15
56+
flutter_launcher_icons: ^0.14.4
5457
freezed: ^3.0.0
5558
injectable_generator: ^2.7.0
5659
json_serializable: ^6.9.5

packages/stream_feeds/lib/src/client/feeds_client_impl.dart

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -448,16 +448,20 @@ class StreamFeedsClientImpl implements StreamFeedsClient {
448448
}
449449

450450
@override
451-
Future<Result<void>> createDevice(
452-
String id,
453-
PushNotificationsProvider pushProvider,
454-
String pushProviderName,
455-
) {
456-
return _devicesRepository.createDevice(id, pushProvider, pushProviderName);
451+
Future<Result<void>> createDevice({
452+
required String id,
453+
required PushNotificationsProvider pushProvider,
454+
required String pushProviderName,
455+
}) {
456+
return _devicesRepository.createDevice(
457+
id,
458+
pushProvider,
459+
pushProviderName,
460+
);
457461
}
458462

459463
@override
460-
Future<Result<void>> deleteDevice(String id) {
464+
Future<Result<void>> deleteDevice({required String id}) {
461465
return _devicesRepository.deleteDevice(id);
462466
}
463467

packages/stream_feeds/lib/src/feeds_client.dart

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -653,9 +653,9 @@ abstract interface class StreamFeedsClient {
653653
/// Example:
654654
/// ```dart
655655
/// final result = await client.createDevice(
656-
/// 'firebase-token-123',
657-
/// PushNotificationsProvider.firebase,
658-
/// 'MyApp Firebase Config',
656+
/// id: 'firebase-token-123',
657+
/// pushProvider: PushNotificationsProvider.firebase,
658+
/// pushProviderName: 'MyApp Firebase Config',
659659
/// );
660660
///
661661
/// switch (result) {
@@ -667,11 +667,11 @@ abstract interface class StreamFeedsClient {
667667
/// ```
668668
///
669669
/// Returns a [Result] indicating success or failure of the device creation operation.
670-
Future<Result<void>> createDevice(
671-
String id,
672-
PushNotificationsProvider pushProvider,
673-
String pushProviderName,
674-
);
670+
Future<Result<void>> createDevice({
671+
required String id,
672+
required PushNotificationsProvider pushProvider,
673+
required String pushProviderName,
674+
});
675675

676676
/// Deletes a device by its unique identifier.
677677
///
@@ -680,7 +680,7 @@ abstract interface class StreamFeedsClient {
680680
///
681681
/// Example:
682682
/// ```dart
683-
/// final result = await client.deleteDevice('firebase-token-123');
683+
/// final result = await client.deleteDevice(id: 'firebase-token-123');
684684
///
685685
/// switch (result) {
686686
/// case Success():
@@ -691,7 +691,7 @@ abstract interface class StreamFeedsClient {
691691
/// ```
692692
///
693693
/// Returns a [Result] indicating success or failure of the deletion operation.
694-
Future<Result<void>> deleteDevice(String id);
694+
Future<Result<void>> deleteDevice({required String id});
695695

696696
/// Deletes a previously uploaded file from the CDN.
697697
///

packages/stream_feeds/lib/src/models.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export 'models/feed_member_request_data.dart';
88
export 'models/feeds_config.dart';
99
export 'models/follow_data.dart';
1010
export 'models/poll_data.dart';
11+
export 'models/push_notifications_config.dart';
1112
export 'models/request/activity_add_comment_request.dart'
1213
show ActivityAddCommentRequest;
1314
export 'models/request/activity_update_comment_request.dart'

packages/stream_feeds/lib/src/repository/devices_repository.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class DevicesRepository {
3535
String id,
3636
PushNotificationsProvider pushProvider,
3737
String pushProviderName,
38-
) async {
38+
) {
3939
final request = api.CreateDeviceRequest(
4040
id: id,
4141
pushProvider: pushProvider.toRequest(),

packages/stream_feeds/lib/src/state/event/feed_event_handler.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import 'package:stream_core/stream_core.dart';
33
import '../../generated/api/models.dart' as api;
44
import '../../models/activity_data.dart';
55
import '../../models/activity_pin_data.dart';
6+
import '../../models/aggregated_activity_data.dart';
67
import '../../models/bookmark_data.dart';
78
import '../../models/comment_data.dart';
89
import '../../models/feed_data.dart';
@@ -65,6 +66,14 @@ class FeedEventHandler implements StateEventHandler {
6566
return state.onActivityMarked(event.toModel());
6667
}
6768

69+
if (event is api.NotificationFeedUpdatedEvent) {
70+
if (event.fid != fid.rawValue) return;
71+
return state.onNotificationFeedUpdated(
72+
event.aggregatedActivities?.map((it) => it.toModel()).toList(),
73+
event.notificationStatus,
74+
);
75+
}
76+
6877
if (event is api.BookmarkAddedEvent) {
6978
if (!event.bookmark.activity.feeds.contains(fid.rawValue)) return;
7079
return state.onBookmarkAdded(event.bookmark.toModel());

0 commit comments

Comments
 (0)