Skip to content

Commit

Permalink
Merge pull request #2073 from bitfriend/issue198_cleanup-periodically
Browse files Browse the repository at this point in the history
Add severe log to missed parts
  • Loading branch information
gnunicorn authored Aug 22, 2024
2 parents 7a5ef06 + 7453641 commit bea1581
Show file tree
Hide file tree
Showing 91 changed files with 1,694 additions and 1,642 deletions.
5 changes: 3 additions & 2 deletions app/lib/common/actions/show_limited_space_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ class LimitedSpaceList extends ConsumerWidget {
_log.severe('Failed to load pin', e, s);
return Text(L10n.of(context).errorLoadingSpaces(e));
},
loading: () =>
const Skeletonizer(child: SizedBox(height: 100, width: 100)),
loading: () => const Skeletonizer(
child: SizedBox(height: 100, width: 100),
),
);
}

Expand Down
5 changes: 2 additions & 3 deletions app/lib/common/providers/common_providers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,8 @@ final notificationSettingsProvider = AsyncNotifierProvider<

final appContentNotificationSetting =
FutureProvider.family<bool, String>((ref, appKey) async {
final notificationsSettings =
await ref.watch(notificationSettingsProvider.future);
return await notificationsSettings.globalContentSetting(appKey);
final settings = await ref.watch(notificationSettingsProvider.future);
return await settings.globalContentSetting(appKey);
});

// Email addresses that registered by user
Expand Down
34 changes: 20 additions & 14 deletions app/lib/common/providers/notifiers/chat_notifiers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,20 @@ class AsyncConvoNotifier extends FamilyAsyncNotifier<Convo?, String> {
final client = ref.watch(alwaysClientProvider);
_listener = client.subscribeStream(convoId); // keep it resident in memory
_poller = _listener.listen(
(e) async {
(data) async {
final newConvo = await client.convo(convoId);
state = AsyncValue.data(newConvo);
},
onError: (e, stack) {
state = AsyncValue.error(e, stack);
_log.severe('stream errored.', e, stack);
onError: (e, s) {
_log.severe('convo stream errored', e, s);
state = AsyncValue.error(e, s);
},
onDone: () {
_log.info('stream ended');
_log.info('convo stream ended');
},
);
ref.onDispose(() => _poller.cancel());
return await client.convoWithRetry(
convoId,
120,
);
return await client.convoWithRetry(convoId, 120);
}
}

Expand All @@ -50,17 +47,18 @@ class AsyncLatestMsgNotifier extends FamilyAsyncNotifier<RoomMessage?, String> {
final client = ref.watch(alwaysClientProvider);
_listener = client.subscribeStream('$roomId::latest_message');
_poller = _listener.listen(
(e) {
(data) {
_log.info('received new latest message call for $roomId');
state = ref
.watch(chatProvider(roomId))
.whenData((cb) => cb?.latestMessage());
},
onError: (e, stack) {
_log.severe('stream errored', e, stack);
onError: (e, s) {
_log.severe('latest msg stream errored', e, s);
state = AsyncValue.error(e, s);
},
onDone: () {
_log.info('stream ended');
_log.info('latest msg stream ended');
},
);
ref.onDispose(() => _poller.cancel());
Expand All @@ -82,7 +80,15 @@ class ChatRoomsListNotifier extends StateNotifier<List<Convo>> {

void _init(Ref ref) {
_listener = client.convosStream(); // keep it resident in memory
_poller = _listener.listen(_handleDiff);
_poller = _listener.listen(
_handleDiff,
onError: (e, s) {
_log.severe('convo list stream errored', e, s);
},
onDone: () {
_log.info('convo list stream ended');
},
);
ref.onDispose(() => _poller.cancel());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ class AsyncNotificationSettingsNotifier
final settings = await client.notificationSettings();
_listener = settings.changesStream();
_poller = _listener.listen(
(e) {
(data) {
// reset the state of this to trigger the notification
// cascade
state = AsyncValue.data(settings);
},
onError: (e, stack) {
_log.severe('stream errored', e, stack);
onError: (e, s) {
_log.severe('stream errored', e, s);
},
onDone: () {
_log.info('stream ended');
Expand Down
6 changes: 3 additions & 3 deletions app/lib/common/providers/notifiers/reactions_notifiers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ class ReactionManagerNotifier
ReactionManager build(ReactionManager arg) {
_listener = arg.subscribeStream(); // keep it resident in memory
_poller = _listener.listen(
(e) async {
(data) async {
_log.info('attempting to reload');
final newManager = await arg.reload();
_log.info('manager updated. likes: ${newManager.likesCount()}');
state = newManager;
},
onError: (e, stack) {
_log.severe('stream errored.', e, stack);
onError: (e, s) {
_log.severe('stream errored', e, s);
},
onDone: () {
_log.info('stream ended');
Expand Down
8 changes: 4 additions & 4 deletions app/lib/common/providers/notifiers/room_notifiers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ class AsyncMaybeRoomNotifier extends FamilyAsyncNotifier<Room?, String> {
final client = ref.watch(alwaysClientProvider);
_listener = client.subscribeStream(arg); // keep it resident in memory
_poller = _listener.listen(
(e) async {
(data) async {
_log.info('seen update for room $arg');
state = await AsyncValue.guard(_getRoom);
},
onError: (e, stack) {
_log.severe('stream errored', e, stack);
onError: (e, s) {
_log.severe('room stream errored', e, s);
},
onDone: () {
_log.info('stream ended');
_log.info('room stream ended');
},
);
ref.onDispose(() => _poller.cancel());
Expand Down
18 changes: 13 additions & 5 deletions app/lib/common/providers/notifiers/space_notifiers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ class AsyncMaybeSpaceNotifier extends FamilyAsyncNotifier<Space?, String> {
final client = ref.watch(alwaysClientProvider);
_listener = client.subscribeStream(arg); // keep it resident in memory
_poller = _listener.listen(
(e) async {
(data) async {
_log.info('seen update $arg');
state = await AsyncValue.guard(_getSpace);
},
onError: (e, stack) {
_log.severe('stream errored', e, stack);
onError: (e, s) {
_log.severe('space stream errored', e, s);
},
onDone: () {
_log.info('stream ended');
_log.info('space stream ended');
},
);
ref.onDispose(() => _poller.cancel());
Expand All @@ -52,7 +52,15 @@ class SpaceListNotifier extends StateNotifier<List<Space>> {

void _init() async {
_listener = client.spacesStream(); // keep it resident in memory
_poller = _listener.listen(_handleDiff);
_poller = _listener.listen(
_handleDiff,
onError: (e, s) {
_log.severe('space list stream errored', e, s);
},
onDone: () {
_log.info('space list stream ended');
},
);
ref.onDispose(() => _poller.cancel());
}

Expand Down
6 changes: 2 additions & 4 deletions app/lib/common/widgets/add_button_with_can_permission.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@ class AddButtonWithCanPermission extends ConsumerWidget {
@override
Widget build(BuildContext context, WidgetRef ref) {
if (canString == null) return _buildIconButton(context);
final canAdd =
ref.watch(hasSpaceWithPermissionProvider(canString!)).valueOrNull ??
false;

final canDoLoader = ref.watch(hasSpaceWithPermissionProvider(canString!));
final canAdd = canDoLoader.valueOrNull ?? false;
return canAdd ? _buildIconButton(context) : const SizedBox.shrink();
}

Expand Down
96 changes: 47 additions & 49 deletions app/lib/common/widgets/event/event_selector_drawer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,58 +24,56 @@ Future<String?> selectEventDrawer({
isDismissible: true,
builder: (context) => Consumer(
builder: (context, ref, child) {
final events = ref.watch(allEventListProvider(spaceId));
return events.when(
data: (eventsList) {
return Column(
key: key,
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Padding(
padding: const EdgeInsets.symmetric(horizontal: 20.0),
child: Row(
children: [
Expanded(
child: title ?? const Text('Select event'),
),
OutlinedButton.icon(
icon: const Icon(Atlas.minus_circle_thin),
onPressed: () {
Navigator.pop(context, null);
},
label: const Text('Clear'),
),
],
),
final calEventsLoader = ref.watch(allEventListProvider(spaceId));
return calEventsLoader.when(
data: (calEvents) => Column(
key: key,
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Padding(
padding: const EdgeInsets.symmetric(horizontal: 20.0),
child: Row(
children: [
Expanded(
child: title ?? const Text('Select event'),
),
OutlinedButton.icon(
icon: const Icon(Atlas.minus_circle_thin),
onPressed: () {
Navigator.pop(context, null);
},
label: const Text('Clear'),
),
],
),
Flexible(
child: eventsList.isEmpty
? Container(
height: 200,
alignment: Alignment.center,
child: const Text('No events found'),
)
: ListView.builder(
padding: const EdgeInsets.all(8),
itemCount: eventsList.length,
itemBuilder: (context, index) => EventItem(
event: eventsList[index],
isShowRsvp: false,
onTapEventItem: (event) {
Navigator.pop(context, event);
},
),
),
Flexible(
child: calEvents.isEmpty
? Container(
height: 200,
alignment: Alignment.center,
child: const Text('No events found'),
)
: ListView.builder(
padding: const EdgeInsets.all(8),
itemCount: calEvents.length,
itemBuilder: (context, index) => EventItem(
event: calEvents[index],
isShowRsvp: false,
onTapEventItem: (event) {
Navigator.pop(context, event);
},
),
),
],
);
},
error: (error, stack) {
_log.severe('Failed to load all cal events', error, stack);
),
),
],
),
error: (e, s) {
_log.severe('Failed to load all cal events', e, s);
return Center(
child: Text(L10n.of(context).failedToLoadEventsDueTo(error)),
child: Text(L10n.of(context).failedToLoadEventsDueTo(e)),
);
},
loading: () => const SizedBox(
Expand Down
20 changes: 16 additions & 4 deletions app/lib/common/widgets/html_editor.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import 'dart:async';

import 'package:acter/common/toolkit/buttons/primary_action_button.dart';
import 'package:acter/common/utils/constants.dart';
import 'package:acter_flutter_sdk/acter_flutter_sdk_ffi.dart';
import 'package:flutter/material.dart';
import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:flutter/material.dart';
import 'package:logging/logging.dart';

final _log = Logger('a3::common::html_editor');

AppFlowyEditorHTMLCodec defaultHtmlCodec = const AppFlowyEditorHTMLCodec(
encodeParsers: [
Expand Down Expand Up @@ -140,9 +144,17 @@ class HtmlEditorState extends State<HtmlEditor> {

_changeListener?.cancel();
if (widget.onChanged != null) {
_changeListener = editorState.transactionStream.listen((event) {
_triggerExport(widget.onChanged!);
});
_changeListener = editorState.transactionStream.listen(
(data) {
_triggerExport(widget.onChanged!);
},
onError: (e, s) {
_log.severe('tx stream errored', e, s);
},
onDone: () {
_log.info('tx stream ended');
},
);
}
});
}
Expand Down
Loading

0 comments on commit bea1581

Please sign in to comment.