-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a notification page to display individual messages (#1069)
* Add a notification page to display individual messages * Use MultiBlocListener * Move notifications navigation method * Fix notifications page padding
- Loading branch information
Showing
9 changed files
with
242 additions
and
54 deletions.
There are no files selected for viewing
This file contains 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 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 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
39 changes: 39 additions & 0 deletions
39
lib/thunder/cubits/notifications_cubit/notifications_cubit.dart
This file contains 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,39 @@ | ||
import 'dart:async'; | ||
|
||
import 'package:bloc/bloc.dart'; | ||
import 'package:equatable/equatable.dart'; | ||
import 'package:flutter_local_notifications/flutter_local_notifications.dart'; | ||
import 'package:thunder/utils/notifications.dart'; | ||
|
||
part 'notifications_state.dart'; | ||
|
||
/// A cubit for handling notifications | ||
class NotificationsCubit extends Cubit<NotificationsState> { | ||
final Stream<NotificationResponse> notificationsStream; | ||
StreamSubscription<NotificationResponse>? _notificationsStreamSubscription; | ||
|
||
NotificationsCubit({required this.notificationsStream}) : super(const NotificationsState()); | ||
|
||
void handleNotifications() { | ||
_notificationsStreamSubscription = notificationsStream.listen((notificationResponse) async { | ||
// Check if this is a reply notification | ||
if (notificationResponse.payload?.contains(repliesGroupKey) == true) { | ||
// Check if this is a specific notification for a specific reply | ||
int? replyId; | ||
final List<String> parts = notificationResponse.payload!.split('-'); | ||
if (parts.length == 2) { | ||
replyId = int.tryParse(parts[1]); | ||
} | ||
|
||
emit(state.copyWith(status: NotificationsStatus.reply, replyId: replyId)); | ||
} | ||
|
||
// Reset the state | ||
emit(state.copyWith(status: NotificationsStatus.none, replyId: null)); | ||
}); | ||
} | ||
|
||
void dispose() { | ||
_notificationsStreamSubscription?.cancel(); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
lib/thunder/cubits/notifications_cubit/notifications_state.dart
This file contains 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,29 @@ | ||
part of 'notifications_cubit.dart'; | ||
|
||
enum NotificationsStatus { none, reply } | ||
|
||
class NotificationsState extends Equatable { | ||
final NotificationsStatus status; | ||
final int? replyId; | ||
|
||
const NotificationsState({ | ||
this.status = NotificationsStatus.none, | ||
this.replyId, | ||
}); | ||
|
||
NotificationsState copyWith({ | ||
required NotificationsStatus status, | ||
required int? replyId, | ||
}) { | ||
return NotificationsState( | ||
status: status, | ||
replyId: replyId, | ||
); | ||
} | ||
|
||
@override | ||
List<dynamic> get props => [ | ||
status, | ||
replyId, | ||
]; | ||
} |
This file contains 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,54 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_bloc/flutter_bloc.dart'; | ||
import 'package:lemmy_api_client/v3.dart'; | ||
import 'package:flutter_gen/gen_l10n/app_localizations.dart'; | ||
|
||
import 'package:thunder/inbox/bloc/inbox_bloc.dart'; | ||
import 'package:thunder/inbox/widgets/inbox_replies_view.dart'; | ||
import 'package:thunder/post/bloc/post_bloc.dart'; | ||
|
||
/// A page for displaying the result of reply notifications | ||
class NotificationsReplyPage extends StatelessWidget { | ||
final List<CommentReplyView> replies; | ||
|
||
const NotificationsReplyPage({super.key, required this.replies}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
final ThemeData theme = Theme.of(context); | ||
final AppLocalizations l10n = AppLocalizations.of(context)!; | ||
|
||
return MultiBlocProvider( | ||
providers: [ | ||
BlocProvider.value(value: InboxBloc()), | ||
BlocProvider.value(value: PostBloc()), | ||
], | ||
child: Container( | ||
color: theme.colorScheme.background, | ||
child: SafeArea( | ||
top: false, | ||
child: CustomScrollView( | ||
slivers: <Widget>[ | ||
SliverAppBar( | ||
flexibleSpace: const FlexibleSpaceBar(titlePadding: EdgeInsets.zero), | ||
pinned: true, | ||
title: ListTile( | ||
title: Text(l10n.inbox, style: theme.textTheme.titleLarge), | ||
subtitle: Text(l10n.reply(replies.length)), | ||
), | ||
), | ||
SliverToBoxAdapter( | ||
child: Material( | ||
child: InboxRepliesView( | ||
replies: replies, | ||
showAll: true, | ||
), | ||
), | ||
), | ||
], | ||
), | ||
), | ||
), | ||
); | ||
} | ||
} |
This file contains 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 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
Oops, something went wrong.