Skip to content

Commit

Permalink
Merge branch 'develop' into user-control-search-notes
Browse files Browse the repository at this point in the history
  • Loading branch information
poppingmoon committed Sep 9, 2023
2 parents ab2b2d7 + 1f52201 commit 45b29e5
Show file tree
Hide file tree
Showing 30 changed files with 850 additions and 205 deletions.
13 changes: 5 additions & 8 deletions lib/providers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,10 @@ final antennaTimelineProvider =
final mainStreamRepositoryProvider =
ChangeNotifierProvider.family<MainStreamRepository, Account>(
(ref, account) => MainStreamRepository(
ref.read(misskeyProvider(account)),
ref.read(emojiRepositoryProvider(account)),
account,
));
ref.read(misskeyProvider(account)),
ref.read(emojiRepositoryProvider(account)),
account,
ref.read(accountRepository)));

final favoriteProvider = ChangeNotifierProvider.autoDispose
.family<FavoriteRepository, Account>((ref, account) => FavoriteRepository(
Expand Down Expand Up @@ -161,10 +161,7 @@ final errorEventProvider =

final photoEditProvider =
StateNotifierProvider.autoDispose<PhotoEditStateNotifier, PhotoEdit>(
(ref) => PhotoEditStateNotifier(
const PhotoEdit(),
ref.read(dioProvider),
),
(ref) => PhotoEditStateNotifier(const PhotoEdit()),
);

final importExportRepository =
Expand Down
29 changes: 26 additions & 3 deletions lib/repository/account_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import 'package:miria/providers.dart';
import 'package:miria/repository/account_settings_repository.dart';
import 'package:miria/repository/tab_settings_repository.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:miria/view/common/constants.dart';
import 'package:miria/view/common/error_dialog_handler.dart';
import 'package:misskey_dart/misskey_dart.dart';
import 'package:url_launcher/url_launcher.dart';
Expand Down Expand Up @@ -59,12 +58,36 @@ class AccountRepository extends ChangeNotifier {
final index = _account.indexOf(account);
if (index == -1) return;
if (accountDataValidated.isNotEmpty && accountDataValidated[index]) return;
_account[index] = _account[index]
.copyWith(i: await reader(misskeyProvider(_account[index])).i.i());
final i = await reader(misskeyProvider(_account[index])).i.i();
_account[index] = _account[index].copyWith(i: i);
tabSettingsRepository.updateAccount(account, i);

accountDataValidated[index] = true;
notifyListeners();
}

Future<void> createUnreadAnnouncement(
Account account, AnnouncementsResponse announcement) async {
final i = _account[_account.indexOf(account)].i.copyWith(
unreadAnnouncements: [
..._account[_account.indexOf(account)].i.unreadAnnouncements,
announcement
]);
_account[_account.indexOf(account)] =
_account[_account.indexOf(account)].copyWith(i: i);
tabSettingsRepository.updateAccount(account, i);
notifyListeners();
}

Future<void> removeUnreadAnnouncement(Account account) async {
final i =
_account[_account.indexOf(account)].i.copyWith(unreadAnnouncements: []);
_account[_account.indexOf(account)] =
_account[_account.indexOf(account)].copyWith(i: i);
tabSettingsRepository.updateAccount(account, i);
notifyListeners();
}

Future<void> _addIfTabSettingNothing() async {
if (_account.length == 1) {
final account = _account.first;
Expand Down
15 changes: 14 additions & 1 deletion lib/repository/main_stream_repository.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
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';
Expand All @@ -11,9 +12,15 @@ class MainStreamRepository extends ChangeNotifier {
final Misskey misskey;
final EmojiRepository emojiRepository;
final Account account;
final AccountRepository accountRepository;
SocketController? socketController;

MainStreamRepository(this.misskey, this.emojiRepository, this.account);
MainStreamRepository(
this.misskey,
this.emojiRepository,
this.account,
this.accountRepository,
);

Future<void> latestMarkAs(String id) async {
final prefs = await SharedPreferences.getInstance();
Expand Down Expand Up @@ -60,12 +67,18 @@ class MainStreamRepository extends ChangeNotifier {
hasUnreadNotification = true;
notifyListeners();
},
onReadAllAnnouncements: () {
accountRepository.removeUnreadAnnouncement(account);
},
onEmojiAdded: (_) {
emojiRepository.loadFromSource();
},
onEmojiUpdated: (_) {
emojiRepository.loadFromSource();
},
onAnnouncementCreated: (announcement) {
accountRepository.createUnreadAnnouncement(account, announcement);
},
);
misskey.startStreaming();
Future(() async {
Expand Down
3 changes: 3 additions & 0 deletions lib/repository/note_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,12 @@ class NoteRepository extends ChangeNotifier {
}

void _registerNote(Note note) {
final registeredNote = _notes[note.id];
_notes[note.id] = note.copyWith(
renote: note.renote ?? _notes[note.renoteId],
reply: note.reply ?? _notes[note.replyId],
poll: note.poll ?? registeredNote?.poll,
myReaction: note.myReaction ?? registeredNote?.myReaction,
);
_noteStatuses[note.id] ??= const NoteStatus(
isCwOpened: false,
Expand Down
11 changes: 11 additions & 0 deletions lib/repository/tab_settings_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'dart:convert';
import 'package:flutter/foundation.dart';
import 'package:miria/model/account.dart';
import 'package:miria/model/tab_setting.dart';
import 'package:misskey_dart/misskey_dart.dart';
import 'package:shared_preferences/shared_preferences.dart';

class TabSettingsRepository extends ChangeNotifier {
Expand All @@ -28,6 +29,16 @@ class TabSettingsRepository extends ChangeNotifier {
}
}

void updateAccount(Account account, IResponse response) {
for (var i = 0; i < _tabSettings.length; i++) {
if (_tabSettings[i].account == account) {
_tabSettings[i] = _tabSettings[i]
.copyWith(account: _tabSettings[i].account.copyWith(i: response));
}
}
notifyListeners();
}

Future<void> save(List<TabSetting> tabSettings) async {
_tabSettings = tabSettings.toList();
final prefs = await SharedPreferences.getInstance();
Expand Down
2 changes: 2 additions & 0 deletions lib/router/app_router.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:miria/model/account.dart';
import 'package:miria/model/image_file.dart';
import 'package:miria/model/note_search_condition.dart';
import 'package:miria/model/tab_setting.dart';
import 'package:miria/view/announcements_page/announcements_page.dart';
import 'package:miria/view/antenna_page/antenna_page.dart';
import 'package:miria/view/channels_page/channels_page.dart';
import 'package:miria/view/clip_list_page/clip_detail_page.dart';
Expand Down Expand Up @@ -77,6 +78,7 @@ class AppRouter extends _$AppRouter {
AutoRoute(page: ExploreRoleUsersRoute.page),
AutoRoute(page: SearchRoute.page),
AutoRoute(page: FederationRoute.page),
AutoRoute(page: AnnouncementRoute.page),
AutoRoute(page: LoginRoute.page),
AutoRoute(page: SettingsRoute.page),
AutoRoute(page: GeneralSettingsRoute.page),
Expand Down
48 changes: 48 additions & 0 deletions lib/router/app_router.gr.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions lib/state_notifier/photo_edit_page/image_meta_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ class ImageMetaDialogState extends ConsumerState<ImageMetaDialog> {
late final TextEditingController captionController = TextEditingController()
..text = widget.initialMeta.caption;

@override
void dispose() {
fileNameController.dispose();
captionController.dispose();
super.dispose();
}

@override
Widget build(BuildContext context) {
return AlertDialog(
Expand Down
Loading

0 comments on commit 45b29e5

Please sign in to comment.