Skip to content
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

Enable system-wide object autosubscribe #2612

Merged
merged 10 commits into from
Feb 18, 2025
Merged
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 @@
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 @@
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 @@
return;
}

widget.onSave(htmlBodyDescription, plainDescription);
widget.onSave(ref, htmlBodyDescription, plainDescription);

Check warning on line 110 in app/lib/common/widgets/edit_html_description_sheet.dart

View check run for this annotation

Codecov / codecov/patch

app/lib/common/widgets/edit_html_description_sheet.dart#L110

Added line #L110 was not covered by tests
},
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 @@
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 @@
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 @@
}

// Need to update change of tile
widget.onSave(_titleController.text.trim());
widget.onSave(ref, _titleController.text.trim());

Check warning on line 94 in app/lib/common/widgets/edit_title_sheet.dart

View check run for this annotation

Codecov / codecov/patch

app/lib/common/widgets/edit_title_sheet.dart#L94

Added line #L94 was not covered by tests
},
child: Text(lang.save),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

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 @@
final res = await draft.send();
_log.info('attachment sent: $res');
}

await autosubscribe(

Check warning on line 117 in app/lib/features/attachments/actions/handle_selected_attachments.dart

View check run for this annotation

Codecov / codecov/patch

app/lib/features/attachments/actions/handle_selected_attachments.dart#L117

Added line #L117 was not covered by tests
ref: ref,
objectId: manager.objectIdStr(),

Check warning on line 119 in app/lib/features/attachments/actions/handle_selected_attachments.dart

View check run for this annotation

Codecov / codecov/patch

app/lib/features/attachments/actions/handle_selected_attachments.dart#L119

Added line #L119 was not covered by tests
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 @@
context: context,
bottomSheetTitle: L10n.of(context).editName,
titleValue: roomAvatarInfo.displayName ?? '',
onSave: (newName) => _saveName(newName),
onSave: (ref, newName) => _saveName(newName),

Check warning on line 214 in app/lib/features/chat/pages/room_profile_page.dart

View check run for this annotation

Codecov / codecov/patch

app/lib/features/chat/pages/room_profile_page.dart#L214

Added line #L214 was not covered by tests
);
}

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 @@

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

Future<bool> submitComment(
Future<String?> submitComment(

Check warning on line 9 in app/lib/features/comments/actions/submit_comment.dart

View check run for this annotation

Codecov / codecov/patch

app/lib/features/comments/actions/submit_comment.dart#L9

Added line #L9 was not covered by tests
L10n lang,
String plainDescription,
String htmlBodyDescription,
Expand All @@ -15,22 +15,22 @@
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();

Check warning on line 24 in app/lib/features/comments/actions/submit_comment.dart

View check run for this annotation

Codecov / codecov/patch

app/lib/features/comments/actions/submit_comment.dart#L24

Added line #L24 was not covered by tests
FocusManager.instance.primaryFocus?.unfocus();
EasyLoading.showToast(lang.commentSubmitted);
return true;
return id.toString();

Check warning on line 27 in app/lib/features/comments/actions/submit_comment.dart

View check run for this annotation

Codecov / codecov/patch

app/lib/features/comments/actions/submit_comment.dart#L27

Added line #L27 was not covered by tests
} 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 @@
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 @@
context: context,
bottomSheetTitle: L10n.of(context).addComment,
descriptionHtmlValue: _commentController.text,
onSave: (htmlBodyDescription, plainDescription) async {
onSave: (ref, htmlBodyDescription, plainDescription) async {

Check warning on line 65 in app/lib/features/comments/widgets/add_comment_widget.dart

View check run for this annotation

Codecov / codecov/patch

app/lib/features/comments/widgets/add_comment_widget.dart#L65

Added line #L65 was not covered by tests
final success = await addComment(
ref: ref,
plainDescription: plainDescription,
htmlBodyDescription: htmlBodyDescription,
);
Expand Down Expand Up @@ -91,8 +93,10 @@
),
child: IconButton(
key: AddCommentWidget.addCommentButton,
onPressed: () =>
addComment(plainDescription: _commentController.text),
onPressed: () => addComment(
ref: ref,
plainDescription: _commentController.text,

Check warning on line 98 in app/lib/features/comments/widgets/add_comment_widget.dart

View check run for this annotation

Codecov / codecov/patch

app/lib/features/comments/widgets/add_comment_widget.dart#L96-L98

Added lines #L96 - L98 were not covered by tests
),
icon: Icon(PhosphorIcons.paperPlaneTilt()),
),
)
Expand All @@ -102,23 +106,27 @@
}

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(

Check warning on line 114 in app/lib/features/comments/widgets/add_comment_widget.dart

View check run for this annotation

Codecov / codecov/patch

app/lib/features/comments/widgets/add_comment_widget.dart#L113-L114

Added lines #L113 - L114 were not covered by tests
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(

Check warning on line 123 in app/lib/features/comments/widgets/add_comment_widget.dart

View check run for this annotation

Codecov / codecov/patch

app/lib/features/comments/widgets/add_comment_widget.dart#L123

Added line #L123 was not covered by tests
ref: ref,
objectId: widget.manager.objectIdStr(),

Check warning on line 125 in app/lib/features/comments/widgets/add_comment_widget.dart

View check run for this annotation

Codecov / codecov/patch

app/lib/features/comments/widgets/add_comment_widget.dart#L125

Added line #L125 was not covered by tests
lang: lang,
subType: widget.autoSubscribeSection,

Check warning on line 127 in app/lib/features/comments/widgets/add_comment_widget.dart

View check run for this annotation

Codecov / codecov/patch

app/lib/features/comments/widgets/add_comment_widget.dart#L127

Added line #L127 was not covered by tests
);
}
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/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 @@
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 @@
commentListUI(commentManager),
AddCommentWidget(
manager: commentManager,
postCreateComment: postCreateComment,
autoSubscribeSection: autoSubscribeSection,

Check warning on line 75 in app/lib/features/comments/widgets/comments_section_widget.dart

View check run for this annotation

Codecov / codecov/patch

app/lib/features/comments/widgets/comments_section_widget.dart#L75

Added line #L75 was not covered by tests
),
],
);
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/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 @@
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);

Check warning on line 466 in app/lib/features/events/pages/create_event_page.dart

View check run for this annotation

Codecov / codecov/patch

app/lib/features/events/pages/create_event_page.dart#L466

Added line #L466 was not covered by tests

/// 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/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 @@
BookmarkAction(
bookmarker: BookmarkType.forEvent(widget.calendarId),
),
ObjectNotificationStatus(objectId: widget.calendarId),
_buildActionMenu(calendarEvent),
]
: [],
Expand Down Expand Up @@ -354,9 +357,10 @@
showEditTitleBottomSheet(
context: context,
titleValue: calendarEvent.title(),
onSave: (newName) {
onSave: (ref, newName) {

Check warning on line 360 in app/lib/features/events/pages/event_details_page.dart

View check run for this annotation

Codecov / codecov/patch

app/lib/features/events/pages/event_details_page.dart#L360

Added line #L360 was not covered by tests
saveEventTitle(
context: context,
ref: ref,
calendarEvent: calendarEvent,
newName: newName,
);
Expand All @@ -380,6 +384,12 @@
draft.status(statusStr);
final rsvpId = await draft.send();
_log.info('new rsvp id: $rsvpId');

await autosubscribe(

Check warning on line 388 in app/lib/features/events/pages/event_details_page.dart

View check run for this annotation

Codecov / codecov/patch

app/lib/features/events/pages/event_details_page.dart#L388

Added line #L388 was not covered by tests
ref: ref,
objectId: widget.calendarId,

Check warning on line 390 in app/lib/features/events/pages/event_details_page.dart

View check run for this annotation

Codecov / codecov/patch

app/lib/features/events/pages/event_details_page.dart#L390

Added line #L390 was not covered by tests
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 @@
context: context,
descriptionHtmlValue: content?.formatted(),
descriptionMarkdownValue: content?.body(),
onSave: (htmlBodyDescription, plainDescription) {
onSave: (ref, htmlBodyDescription, plainDescription) {

Check warning on line 697 in app/lib/features/events/pages/event_details_page.dart

View check run for this annotation

Codecov / codecov/patch

app/lib/features/events/pages/event_details_page.dart#L697

Added line #L697 was not covered by tests
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 @@
updateBuilder.title(newName);
final eventId = await updateBuilder.send();
_log.info('Calendar Event Title Updated $eventId');
await autosubscribe(

Check warning on line 26 in app/lib/features/events/utils/events_utils.dart

View check run for this annotation

Codecov / codecov/patch

app/lib/features/events/utils/events_utils.dart#L26

Added line #L26 was not covered by tests
ref: ref,
objectId: calendarEvent.eventId().toString(),

Check warning on line 28 in app/lib/features/events/utils/events_utils.dart

View check run for this annotation

Codecov / codecov/patch

app/lib/features/events/utils/events_utils.dart#L28

Added line #L28 was not covered by tests
lang: lang,
);

EasyLoading.dismiss();
if (context.mounted) Navigator.pop(context);
Expand All @@ -38,6 +46,7 @@

Future<void> saveEventDescription({
required BuildContext context,
required WidgetRef ref,
required CalendarEvent calendarEvent,
required String htmlBodyDescription,
required String plainDescription,
Expand All @@ -48,6 +57,11 @@
final updateBuilder = calendarEvent.updateBuilder();
updateBuilder.descriptionHtml(plainDescription, htmlBodyDescription);
await updateBuilder.send();
await autosubscribe(

Check warning on line 60 in app/lib/features/events/utils/events_utils.dart

View check run for this annotation

Codecov / codecov/patch

app/lib/features/events/utils/events_utils.dart#L60

Added line #L60 was not covered by tests
ref: ref,
objectId: calendarEvent.eventId().toString(),

Check warning on line 62 in app/lib/features/events/utils/events_utils.dart

View check run for this annotation

Codecov / codecov/patch

app/lib/features/events/utils/events_utils.dart#L62

Added line #L62 was not covered by tests
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/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 @@
final eventId = await updateBuilder.send();
_log.info('Calendar Event updated $eventId');

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

Check warning on line 334 in app/lib/features/events/widgets/change_date_sheet.dart

View check run for this annotation

Codecov / codecov/patch

app/lib/features/events/widgets/change_date_sheet.dart#L332-L334

Added lines #L332 - L334 were not covered by tests
lang: lang,
);

EasyLoading.dismiss();

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