mirror of
https://github.com/krille-chan/fluffychat
synced 2024-09-10 13:05:11 +00:00
refactor: update iOS badge on every notification
This commit is contained in:
parent
0c233c2d57
commit
1775552cd4
4 changed files with 14 additions and 24 deletions
|
@ -26,7 +26,6 @@ import 'package:fluffychat/pages/chat/recording_dialog.dart';
|
|||
import 'package:fluffychat/utils/adaptive_bottom_sheet.dart';
|
||||
import 'package:fluffychat/utils/error_reporter.dart';
|
||||
import 'package:fluffychat/utils/matrix_sdk_extensions/event_extension.dart';
|
||||
import 'package:fluffychat/utils/matrix_sdk_extensions/ios_badge_client_extension.dart';
|
||||
import 'package:fluffychat/utils/matrix_sdk_extensions/matrix_locals.dart';
|
||||
import 'package:fluffychat/utils/platform_infos.dart';
|
||||
import 'package:fluffychat/widgets/matrix.dart';
|
||||
|
@ -360,7 +359,6 @@ class ChatController extends State<ChatPageWithRoom> {
|
|||
_setReadMarkerFuture = timeline.setReadMarker(eventId: eventId).then((_) {
|
||||
_setReadMarkerFuture = null;
|
||||
});
|
||||
room.client.updateIosBadge();
|
||||
}
|
||||
|
||||
@override
|
||||
|
|
|
@ -17,7 +17,6 @@ import 'package:fluffychat/utils/adaptive_bottom_sheet.dart';
|
|||
import 'package:fluffychat/utils/date_time_extension.dart';
|
||||
import 'package:fluffychat/utils/localized_exception_extension.dart';
|
||||
import 'package:fluffychat/utils/matrix_sdk_extensions/client_stories_extension.dart';
|
||||
import 'package:fluffychat/utils/matrix_sdk_extensions/ios_badge_client_extension.dart';
|
||||
import 'package:fluffychat/utils/platform_infos.dart';
|
||||
import 'package:fluffychat/utils/room_status_extension.dart';
|
||||
import 'package:fluffychat/utils/story_theme_data.dart';
|
||||
|
@ -474,8 +473,6 @@ class StoryPageController extends State<StoryPage> {
|
|||
void maybeSetReadMarker() {
|
||||
final currentEvent = this.currentEvent;
|
||||
if (currentEvent == null) return;
|
||||
final room = currentEvent.room;
|
||||
room.client.updateIosBadge();
|
||||
if (index == events.length - 1) {
|
||||
timeline!.setReadMarker();
|
||||
return;
|
||||
|
|
|
@ -1,19 +0,0 @@
|
|||
import 'package:flutter_app_badger/flutter_app_badger.dart';
|
||||
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
|
||||
import 'package:matrix/matrix.dart';
|
||||
|
||||
import 'package:fluffychat/utils/platform_infos.dart';
|
||||
|
||||
extension IosBadgeClientExtension on Client {
|
||||
void updateIosBadge() {
|
||||
if (!PlatformInfos.isIOS) return;
|
||||
final unreadCount = rooms.where((room) => room.isUnreadOrInvited).length;
|
||||
if (unreadCount == 0) {
|
||||
FlutterAppBadger.removeBadge();
|
||||
FlutterLocalNotificationsPlugin()
|
||||
.cancelAll(); // Workaround for iOS not clearing notifications with fcm_shared_isolate
|
||||
} else {
|
||||
FlutterAppBadger.updateBadgeCount(unreadCount);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -4,6 +4,7 @@ import 'package:flutter/foundation.dart';
|
|||
|
||||
import 'package:desktop_lifecycle/desktop_lifecycle.dart';
|
||||
import 'package:desktop_notifications/desktop_notifications.dart';
|
||||
import 'package:flutter_app_badger/flutter_app_badger.dart';
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:matrix/matrix.dart';
|
||||
|
@ -31,6 +32,19 @@ extension LocalNotificationsExtension on MatrixState {
|
|||
return;
|
||||
}
|
||||
if (room.notificationCount == 0) return;
|
||||
|
||||
// Workaround for app icon badge not updating
|
||||
if (Platform.isIOS) {
|
||||
final unreadCount =
|
||||
client.rooms.where((room) => room.isUnreadOrInvited).length;
|
||||
if (unreadCount == 0) {
|
||||
FlutterAppBadger.removeBadge();
|
||||
} else {
|
||||
FlutterAppBadger.updateBadgeCount(unreadCount);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
final event = Event.fromJson(eventUpdate.content, room);
|
||||
final title =
|
||||
room.getLocalizedDisplayname(MatrixLocals(L10n.of(widget.context)!));
|
||||
|
|
Loading…
Reference in a new issue