Skip to content

Commit

Permalink
Merge branch 'develop' into fix-pushable-listview
Browse files Browse the repository at this point in the history
  • Loading branch information
poppingmoon committed Sep 12, 2023
2 parents 8e39496 + 9a4c173 commit 084b701
Show file tree
Hide file tree
Showing 46 changed files with 1,116 additions and 275 deletions.
2 changes: 1 addition & 1 deletion ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 1430;
LastUpgradeCheck = 1300;
LastUpgradeCheck = 1430;
ORGANIZATIONNAME = "";
TargetAttributes = {
97C146ED1CF9000F007C117D = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1300"
LastUpgradeVersion = "1430"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
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
4 changes: 4 additions & 0 deletions lib/repository/note_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,13 @@ 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 ??
(note.reactions.isNotEmpty ? registeredNote?.myReaction : null),
);
_noteStatuses[note.id] ??= const NoteStatus(
isCwOpened: false,
Expand Down
11 changes: 10 additions & 1 deletion lib/repository/socket_timeline_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,16 @@ abstract class SocketTimelineRepository extends TimelineRepository {
@override
void reconnect() {
super.reconnect();
socketController?.reconnect();
try {
socketController!.reconnect();
} catch (e) {
socketController = null;
Future(() async {
await misskey.streamingService.restart();
startTimeLine();
});
return;
}
mainStreamRepository.reconnect();
reloadLatestNotes();
}
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 @@ -5,6 +5,7 @@ import 'package:flutter/material.dart';
import 'package:miria/model/account.dart';
import 'package:miria/model/image_file.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 @@ -76,6 +77,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 084b701

Please sign in to comment.