Skip to content

Commit

Permalink
Merge pull request #2612 from acterglobal/ben-auto-subscribe-for-objects
Browse files Browse the repository at this point in the history
Enable system-wide object autosubscribe
  • Loading branch information
gnunicorn authored Feb 18, 2025
2 parents 55eb5fb + ff6de28 commit e3eee03
Show file tree
Hide file tree
Showing 39 changed files with 426 additions and 182 deletions.
1 change: 1 addition & 0 deletions .changes/2612-autosubscribe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Automatically subscribe to all objects you created or interact with to receive push notifications on updates about it. You can disable that in the notification settings if you want to.
6 changes: 3 additions & 3 deletions app/lib/common/widgets/edit_html_description_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ void showEditHtmlDescriptionBottomSheet({
String? bottomSheetTitle,
String? descriptionHtmlValue,
String? descriptionMarkdownValue,
required Function(String, String) onSave,
required Function(WidgetRef, String, String) onSave,
}) {
showModalBottomSheet(
showDragHandle: true,
Expand All @@ -34,7 +34,7 @@ class EditHtmlDescriptionSheet extends ConsumerStatefulWidget {
final String? bottomSheetTitle;
final String? descriptionHtmlValue;
final String? descriptionMarkdownValue;
final Function(String, String) onSave;
final Function(WidgetRef, String, String) onSave;

const EditHtmlDescriptionSheet({
super.key,
Expand Down Expand Up @@ -107,7 +107,7 @@ class _EditHtmlDescriptionSheetState
return;
}

widget.onSave(htmlBodyDescription, plainDescription);
widget.onSave(ref, htmlBodyDescription, plainDescription);
},
child: Text(lang.save),
),
Expand Down
6 changes: 3 additions & 3 deletions app/lib/common/widgets/edit_title_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ void showEditTitleBottomSheet({
required BuildContext context,
String? bottomSheetTitle,
required String titleValue,
required Function(String) onSave,
required Function(WidgetRef, String) onSave,
}) {
showModalBottomSheet(
showDragHandle: true,
Expand All @@ -27,7 +27,7 @@ void showEditTitleBottomSheet({
class EditTitleSheet extends ConsumerStatefulWidget {
final String? bottomSheetTitle;
final String titleValue;
final Function(String) onSave;
final Function(WidgetRef, String) onSave;

const EditTitleSheet({
super.key,
Expand Down Expand Up @@ -91,7 +91,7 @@ class _EditTitleSheetState extends ConsumerState<EditTitleSheet> {
}

// Need to update change of tile
widget.onSave(_titleController.text.trim());
widget.onSave(ref, _titleController.text.trim());
},
child: Text(lang.save),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'dart:typed_data';

import 'package:acter/common/models/types.dart';
import 'package:acter/features/home/providers/client_providers.dart';
import 'package:acter/features/notifications/actions/autosubscribe.dart';
import 'package:acter_flutter_sdk/acter_flutter_sdk_ffi.dart'
show AttachmentDraft, AttachmentsManager, RefDetails;
import 'package:flutter/material.dart';
Expand Down Expand Up @@ -112,6 +113,12 @@ Future<void> addRefDetailAttachment({
final res = await draft.send();
_log.info('attachment sent: $res');
}

await autosubscribe(
ref: ref,
objectId: manager.objectIdStr(),
lang: lang,
);
EasyLoading.dismiss();
} catch (e, s) {
_log.severe('Failed to create attachments', e, s);
Expand Down
2 changes: 1 addition & 1 deletion app/lib/features/chat/pages/room_profile_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ class _RoomProfilePageState extends ConsumerState<RoomProfilePage> {
context: context,
bottomSheetTitle: L10n.of(context).editName,
titleValue: roomAvatarInfo.displayName ?? '',
onSave: (newName) => _saveName(newName),
onSave: (ref, newName) => _saveName(newName),
);
}

Expand Down
10 changes: 5 additions & 5 deletions app/lib/features/comments/actions/submit_comment.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import 'package:logging/logging.dart';

final _log = Logger('a3::submit::comment');

Future<bool> submitComment(
Future<String?> submitComment(
L10n lang,
String plainDescription,
String htmlBodyDescription,
Expand All @@ -15,22 +15,22 @@ Future<bool> submitComment(
final trimmedPlainText = plainDescription.trim();
if (trimmedPlainText.isEmpty) {
EasyLoading.showToast(lang.youNeedToEnterAComment);
return false;
return null;
}
EasyLoading.show(status: lang.submittingComment);
try {
final draft = manager.commentDraft();
draft.contentFormatted(trimmedPlainText, htmlBodyDescription);
await draft.send();
final id = await draft.send();
FocusManager.instance.primaryFocus?.unfocus();
EasyLoading.showToast(lang.commentSubmitted);
return true;
return id.toString();
} catch (e, s) {
_log.severe('Failed to submit comment', e, s);
EasyLoading.showError(
lang.errorSubmittingComment(e),
duration: const Duration(seconds: 3),
);
return false;
return null;
}
}
2 changes: 0 additions & 2 deletions app/lib/features/comments/types.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import 'package:acter_flutter_sdk/acter_flutter_sdk_ffi.dart'
show ActerPin, CalendarEvent, CommentsManager, NewsEntry, Task, TaskList;

typedef PostCreateComment = Function();

/// This is the actual input type for the providers and widget of this feature
/// the way to get this is through implementing a "wrapper" type for the getter
/// and make sure that the manager hash-id and equal is bound to the inner
Expand Down
36 changes: 22 additions & 14 deletions app/lib/features/comments/widgets/add_comment_widget.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import 'package:acter/common/providers/common_providers.dart';
import 'package:acter/common/widgets/edit_html_description_sheet.dart';
import 'package:acter/features/comments/actions/submit_comment.dart';
import 'package:acter/features/comments/types.dart';
import 'package:acter/features/notifications/actions/autosubscribe.dart';
import 'package:acter/features/notifications/types.dart';
import 'package:acter_avatar/acter_avatar.dart';
import 'package:acter_flutter_sdk/acter_flutter_sdk_ffi.dart';
import 'package:atlas_icons/atlas_icons.dart';
Expand All @@ -14,12 +15,12 @@ class AddCommentWidget extends ConsumerStatefulWidget {
static const addCommentButton = Key('add-comment-button');

final CommentsManager manager;
final PostCreateComment? postCreateComment;
final SubscriptionSubType? autoSubscribeSection;

const AddCommentWidget({
super.key,
required this.manager,
this.postCreateComment,
this.autoSubscribeSection,
});

@override
Expand Down Expand Up @@ -61,8 +62,9 @@ class _AddCommentWidgetState extends ConsumerState<AddCommentWidget> {
context: context,
bottomSheetTitle: L10n.of(context).addComment,
descriptionHtmlValue: _commentController.text,
onSave: (htmlBodyDescription, plainDescription) async {
onSave: (ref, htmlBodyDescription, plainDescription) async {
final success = await addComment(
ref: ref,
plainDescription: plainDescription,
htmlBodyDescription: htmlBodyDescription,
);
Expand Down Expand Up @@ -91,8 +93,10 @@ class _AddCommentWidgetState extends ConsumerState<AddCommentWidget> {
),
child: IconButton(
key: AddCommentWidget.addCommentButton,
onPressed: () =>
addComment(plainDescription: _commentController.text),
onPressed: () => addComment(
ref: ref,
plainDescription: _commentController.text,
),
icon: Icon(PhosphorIcons.paperPlaneTilt()),
),
)
Expand All @@ -102,23 +106,27 @@ class _AddCommentWidgetState extends ConsumerState<AddCommentWidget> {
}

Future<bool> addComment({
required WidgetRef ref,
required String plainDescription,
String? htmlBodyDescription,
}) async {
final success = await submitComment(
L10n.of(context),
final lang = L10n.of(context);
final objectId = await submitComment(
lang,
plainDescription,
htmlBodyDescription ?? plainDescription,
widget.manager,
);
if (success) {
if (objectId != null) {
_commentController.clear();
showSendButton.value = false;
final postCommentFn = widget.postCreateComment;
if (postCommentFn != null) {
postCommentFn();
}
await autosubscribe(
ref: ref,
objectId: widget.manager.objectIdStr(),
lang: lang,
subType: widget.autoSubscribeSection,
);
}
return success;
return objectId != null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:acter/features/comments/types.dart';
import 'package:acter/features/comments/widgets/add_comment_widget.dart';
import 'package:acter/features/comments/widgets/skeletons/comment_list_skeleton_widget.dart';
import 'package:acter/features/comments/widgets/comment_list_widget.dart';
import 'package:acter/features/notifications/types.dart';
import 'package:acter_flutter_sdk/acter_flutter_sdk_ffi.dart';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
Expand All @@ -19,15 +20,15 @@ class CommentsSectionWidget extends ConsumerWidget {
final bool centerTitle;
final bool useCompactEmptyState;
final List<Widget>? actions;
final PostCreateComment? postCreateComment;
final SubscriptionSubType? autoSubscribeSection;

const CommentsSectionWidget({
super.key,
this.shrinkWrap = true,
this.centerTitle = false,
this.useCompactEmptyState = true,
required this.managerProvider,
this.postCreateComment,
this.autoSubscribeSection, // null means all
this.actions,
});

Expand Down Expand Up @@ -71,7 +72,7 @@ class CommentsSectionWidget extends ConsumerWidget {
commentListUI(commentManager),
AddCommentWidget(
manager: commentManager,
postCreateComment: postCreateComment,
autoSubscribeSection: autoSubscribeSection,
),
],
);
Expand Down
2 changes: 2 additions & 0 deletions app/lib/features/events/pages/create_event_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import 'package:acter/common/widgets/spaces/select_space_form_field.dart';
import 'package:acter/features/events/model/keys.dart';
import 'package:acter/features/events/utils/events_utils.dart';
import 'package:acter/features/home/providers/client_providers.dart';
import 'package:acter/features/notifications/actions/autosubscribe.dart';
import 'package:acter_flutter_sdk/acter_flutter_sdk.dart';
import 'package:acter_flutter_sdk/acter_flutter_sdk_ffi.dart';
import 'package:appflowy_editor/appflowy_editor.dart';
Expand Down Expand Up @@ -462,6 +463,7 @@ class CreateEventPageConsumerState extends ConsumerState<CreateEventPage> {
final eventId = (await draft.send()).toString();
final client = await ref.read(alwaysClientProvider.future);
final calendarEvent = await client.waitForCalendarEvent(eventId, null);
await autosubscribe(ref: ref, objectId: eventId, lang: lang);

/// Event is created, set RSVP status to `Yes` by default for host.
final rsvpManager = await calendarEvent.rsvps();
Expand Down
15 changes: 13 additions & 2 deletions app/lib/features/events/pages/event_details_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import 'package:acter/features/events/widgets/participants_list.dart';
import 'package:acter/features/events/widgets/skeletons/event_details_skeleton_widget.dart';
import 'package:acter/features/home/providers/client_providers.dart';
import 'package:acter/features/home/widgets/space_chip.dart';
import 'package:acter/features/notifications/actions/autosubscribe.dart';
import 'package:acter/features/notifications/widgets/object_notification_status.dart';
import 'package:acter/features/share/action/share_space_object_action.dart';
import 'package:acter/features/space/widgets/member_avatar.dart';
import 'package:acter_avatar/acter_avatar.dart';
Expand Down Expand Up @@ -103,6 +105,7 @@ class _EventDetailPageConsumerState extends ConsumerState<EventDetailPage> {
BookmarkAction(
bookmarker: BookmarkType.forEvent(widget.calendarId),
),
ObjectNotificationStatus(objectId: widget.calendarId),
_buildActionMenu(calendarEvent),
]
: [],
Expand Down Expand Up @@ -354,9 +357,10 @@ class _EventDetailPageConsumerState extends ConsumerState<EventDetailPage> {
showEditTitleBottomSheet(
context: context,
titleValue: calendarEvent.title(),
onSave: (newName) {
onSave: (ref, newName) {
saveEventTitle(
context: context,
ref: ref,
calendarEvent: calendarEvent,
newName: newName,
);
Expand All @@ -380,6 +384,12 @@ class _EventDetailPageConsumerState extends ConsumerState<EventDetailPage> {
draft.status(statusStr);
final rsvpId = await draft.send();
_log.info('new rsvp id: $rsvpId');

await autosubscribe(
ref: ref,
objectId: widget.calendarId,
lang: lang,
);
// refresh cache
final client = await ref.read(alwaysClientProvider.future);
await client.waitForRsvp(rsvpId.toString(), null);
Expand Down Expand Up @@ -684,10 +694,11 @@ class _EventDetailPageConsumerState extends ConsumerState<EventDetailPage> {
context: context,
descriptionHtmlValue: content?.formatted(),
descriptionMarkdownValue: content?.body(),
onSave: (htmlBodyDescription, plainDescription) {
onSave: (ref, htmlBodyDescription, plainDescription) {
saveEventDescription(
context: context,
calendarEvent: ev,
ref: ref,
htmlBodyDescription: htmlBodyDescription,
plainDescription: plainDescription,
);
Expand Down
14 changes: 14 additions & 0 deletions app/lib/features/events/utils/events_utils.dart
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import 'package:acter/features/notifications/actions/autosubscribe.dart';
import 'package:acter_flutter_sdk/acter_flutter_sdk.dart';
import 'package:acter_flutter_sdk/acter_flutter_sdk_ffi.dart';
import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:intl/intl.dart';
import 'package:logging/logging.dart';

final _log = Logger('a3::cal_event::utils');

Future<void> saveEventTitle({
required BuildContext context,
required WidgetRef ref,
required CalendarEvent calendarEvent,
required String newName,
}) async {
Expand All @@ -20,6 +23,11 @@ Future<void> saveEventTitle({
updateBuilder.title(newName);
final eventId = await updateBuilder.send();
_log.info('Calendar Event Title Updated $eventId');
await autosubscribe(
ref: ref,
objectId: calendarEvent.eventId().toString(),
lang: lang,
);

EasyLoading.dismiss();
if (context.mounted) Navigator.pop(context);
Expand All @@ -38,6 +46,7 @@ Future<void> saveEventTitle({

Future<void> saveEventDescription({
required BuildContext context,
required WidgetRef ref,
required CalendarEvent calendarEvent,
required String htmlBodyDescription,
required String plainDescription,
Expand All @@ -48,6 +57,11 @@ Future<void> saveEventDescription({
final updateBuilder = calendarEvent.updateBuilder();
updateBuilder.descriptionHtml(plainDescription, htmlBodyDescription);
await updateBuilder.send();
await autosubscribe(
ref: ref,
objectId: calendarEvent.eventId().toString(),
lang: lang,
);
EasyLoading.dismiss();
if (context.mounted) Navigator.pop(context);
} catch (e, s) {
Expand Down
7 changes: 7 additions & 0 deletions app/lib/features/events/widgets/change_date_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:acter/common/toolkit/buttons/primary_action_button.dart';
import 'package:acter/common/utils/utils.dart';
import 'package:acter/features/events/providers/event_providers.dart';
import 'package:acter/features/events/utils/events_utils.dart';
import 'package:acter/features/notifications/actions/autosubscribe.dart';
import 'package:acter_flutter_sdk/acter_flutter_sdk.dart';
import 'package:dart_date/dart_date.dart';
import 'package:flutter/material.dart';
Expand Down Expand Up @@ -328,6 +329,12 @@ class _ChangeDateSheetState extends ConsumerState<ChangeDateSheet> {
final eventId = await updateBuilder.send();
_log.info('Calendar Event updated $eventId');

await autosubscribe(
ref: ref,
objectId: eventId.toString(),
lang: lang,
);

EasyLoading.dismiss();

if (mounted) Navigator.pop(context);
Expand Down
Loading

0 comments on commit e3eee03

Please sign in to comment.