Skip to content

Commit

Permalink
fix: #253
Browse files Browse the repository at this point in the history
  • Loading branch information
shiosyakeyakini-info committed Dec 16, 2023
1 parent 75c036b commit 74c0d3f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 40 deletions.
33 changes: 2 additions & 31 deletions lib/repository/main_stream_repository.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import 'package:collection/collection.dart';
import 'package:flutter/widgets.dart';
import 'package:miria/model/account.dart';
import 'package:miria/repository/account_repository.dart';
import 'package:miria/repository/emoji_repository.dart';
import 'package:misskey_dart/misskey_dart.dart';
import 'package:shared_preferences/shared_preferences.dart';

class MainStreamRepository extends ChangeNotifier {
var hasUnreadNotification = false;
Expand All @@ -23,29 +21,9 @@ class MainStreamRepository extends ChangeNotifier {
this.accountRepository,
);

Future<void> latestMarkAs(String id) async {
final prefs = await SharedPreferences.getInstance();
prefs.setString(
"latestReadNotification@${account.userId}@${account.host}", id);
hasUnreadNotification = false;
notifyListeners();
}

Future<void> confirmNotification() async {
final notifications = await misskey.i.notifications(
const INotificationsRequest(markAsRead: false, limit: 1));
final prefs = await SharedPreferences.getInstance();

if (notifications.isEmpty) return;

// 最後に読んだものと違うものがプッシュ通知にあれば通知をオン
if (prefs.getString(
"latestReadNotification@${account.userId}@${account.host}") ==
notifications.firstOrNull?.id) {
hasUnreadNotification = false;
} else {
hasUnreadNotification = true;
}
final i = await misskey.i.i();
hasUnreadNotification = i.hasUnreadNotification;

notifyListeners();
}
Expand All @@ -54,13 +32,6 @@ class MainStreamRepository extends ChangeNotifier {
socketController = misskey.mainStream(
onReadAllNotifications: () {
hasUnreadNotification = false;
Future(() async {
final notifications = await misskey.i.notifications(
const INotificationsRequest(markAsRead: false, limit: 1));

// 最後に読んだものとして記憶しておく
latestMarkAs(notifications.firstOrNull?.id ?? "");
});

notifyListeners();
},
Expand Down
10 changes: 1 addition & 9 deletions lib/view/notification_page/notification_page.dart
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
import 'package:auto_route/auto_route.dart';
import 'package:collection/collection.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:miria/extensions/date_time_extension.dart';
import 'package:miria/model/account.dart';
import 'package:miria/model/misskey_emoji_data.dart';
import 'package:miria/providers.dart';
import 'package:miria/router/app_router.dart';
import 'package:miria/view/notification_page/notification_page_data.dart';
import 'package:miria/view/common/account_scope.dart';
import 'package:miria/view/common/avatar_icon.dart';
import 'package:miria/view/common/error_dialog_handler.dart';
import 'package:miria/view/common/misskey_notes/custom_emoji.dart';
import 'package:miria/view/common/misskey_notes/mfm_text.dart' as mfm_text;
import 'package:miria/view/common/misskey_notes/mfm_text.dart';
import 'package:miria/view/common/misskey_notes/misskey_note.dart'
as misskey_note;
Expand Down Expand Up @@ -56,15 +52,11 @@ class NotificationPageState extends ConsumerState<NotificationPage> {
final result = await misskey.i
.notifications(const INotificationsRequest(
limit: 50,
markAsRead: true,
));
ref
.read(notesProvider(widget.account))
.registerAll(result.map((e) => e.note).whereNotNull());
if (result.isNotEmpty) {
ref
.read(mainStreamRepositoryProvider(widget.account))
.latestMarkAs(result.first.id);
}
return result.toNotificationData();
},
nextFuture: (lastElement, _) async {
Expand Down

0 comments on commit 74c0d3f

Please sign in to comment.