treewide sweepfixes
This commit is contained in:
parent
8fda43ccf8
commit
012ecd9249
41 changed files with 270 additions and 386 deletions
|
|
@ -23,7 +23,7 @@ class AttachmentController(final String roomId)
|
|||
);
|
||||
|
||||
final content = await ref
|
||||
.watch(ClientController.provider.notifier)
|
||||
.read(ClientController.provider.notifier)
|
||||
.uploadMedia(.new(path: file.path, encrypt: isEncrypted));
|
||||
|
||||
state = (filename, content);
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ class AuthUrlController(final Uri homeserver)
|
|||
extends AsyncNotifier<OAuthAuthCodeResponse> {
|
||||
@override
|
||||
Future<OAuthAuthCodeResponse> build() async => ref
|
||||
.watch(ClientController.provider.notifier)
|
||||
.read(ClientController.provider.notifier)
|
||||
.getAuthUrl(
|
||||
.new(
|
||||
homeserverUrl: homeserver,
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import "package:nexus/controllers/client.dart";
|
|||
class ClientIdController(final Uri homeserver) extends AsyncNotifier<String> {
|
||||
@override
|
||||
Future<String> build() => ref
|
||||
.watch(ClientController.provider.notifier)
|
||||
.read(ClientController.provider.notifier)
|
||||
.registerClient(
|
||||
.new(
|
||||
clientName: "Nexus",
|
||||
|
|
|
|||
|
|
@ -19,13 +19,13 @@ class EventController(final GetEventRequest request)
|
|||
if (event != null) return event;
|
||||
|
||||
final fetchedEvent = await ref
|
||||
.watch(ClientController.provider.notifier)
|
||||
.read(ClientController.provider.notifier)
|
||||
.getEvent(request)
|
||||
.onError((_, _) => null);
|
||||
|
||||
if (fetchedEvent != null) {
|
||||
ref
|
||||
.watch(RoomsController.provider.notifier)
|
||||
.read(RoomsController.provider.notifier)
|
||||
.update(
|
||||
.new({
|
||||
request.roomId: .new(
|
||||
|
|
|
|||
|
|
@ -40,28 +40,23 @@ class GomuksListenerController extends AsyncNotifier<void> {
|
|||
switch (muksEventType) {
|
||||
case "client_state":
|
||||
ref
|
||||
.watch(ClientStateController.provider.notifier)
|
||||
.read(ClientStateController.provider.notifier)
|
||||
.set(.fromJson(decodedMuksEvent));
|
||||
break;
|
||||
case "sync_status":
|
||||
ref
|
||||
.watch(SyncStatusController.provider.notifier)
|
||||
.read(SyncStatusController.provider.notifier)
|
||||
.set(.fromJson(decodedMuksEvent));
|
||||
break;
|
||||
case "init_complete":
|
||||
ref.watch(InitCompleteController.provider.notifier).complete();
|
||||
break;
|
||||
ref.read(InitCompleteController.provider.notifier).complete();
|
||||
case "send_complete":
|
||||
final event = Event.fromJson(decodedMuksEvent["event"]);
|
||||
ref
|
||||
.watch(RoomsController.provider.notifier)
|
||||
.read(RoomsController.provider.notifier)
|
||||
.update(
|
||||
.new({
|
||||
event.roomId: .new(events: .new({event.rowId: event})),
|
||||
}),
|
||||
);
|
||||
|
||||
break;
|
||||
case "sync_complete":
|
||||
final syncData = SyncData.fromJson(decodedMuksEvent);
|
||||
final roomProvider = RoomsController.provider;
|
||||
|
|
@ -73,28 +68,27 @@ class GomuksListenerController extends AsyncNotifier<void> {
|
|||
}
|
||||
|
||||
ref
|
||||
.watch(roomProvider.notifier)
|
||||
.read(roomProvider.notifier)
|
||||
.update(syncData.rooms, syncData.leftRooms);
|
||||
ref
|
||||
.watch(accountDataProvider.notifier)
|
||||
.read(accountDataProvider.notifier)
|
||||
.update(syncData.accountData);
|
||||
|
||||
if (syncData.topLevelSpaces != null) {
|
||||
if (syncData.topLevelSpaces case final topLevelSpaces?) {
|
||||
ref
|
||||
.watch(TopLevelSpacesController.provider.notifier)
|
||||
.set(syncData.topLevelSpaces!);
|
||||
.read(TopLevelSpacesController.provider.notifier)
|
||||
.set(topLevelSpaces);
|
||||
}
|
||||
|
||||
if (syncData.spaceEdges != null) {
|
||||
if (syncData.spaceEdges case final spaceEdges?) {
|
||||
ref
|
||||
.watch(SpaceEdgesController.provider.notifier)
|
||||
.set(syncData.spaceEdges!);
|
||||
.read(SpaceEdgesController.provider.notifier)
|
||||
.set(spaceEdges);
|
||||
}
|
||||
|
||||
// ref
|
||||
// .watch(SyncStatusController.provider.notifier)
|
||||
// .set(SyncStatus.fromJson(decodedMuksEvent));
|
||||
break;
|
||||
// ref
|
||||
// .read(SyncStatusController.provider.notifier)
|
||||
// .set(SyncStatus.fromJson(decodedMuksEvent));
|
||||
default:
|
||||
debugPrint("Unhandled event: $muksEventType");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ class KeyController(final String key) extends AsyncNotifier<String?> {
|
|||
ref.watch(SharedPrefsController.provider).getString(key);
|
||||
|
||||
Future<void> set(String? value) async {
|
||||
final prefs = ref.watch(SharedPrefsController.provider);
|
||||
final prefs = ref.read(SharedPrefsController.provider);
|
||||
state = .data(value);
|
||||
|
||||
if (value == null) {
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ class MemberListOpenedController extends AsyncNotifier<bool> {
|
|||
|
||||
Future<void> set(bool value) async {
|
||||
state = .data(value);
|
||||
await ref.watch(SharedPrefsController.provider).setBool(key, value);
|
||||
await ref.read(SharedPrefsController.provider).setBool(key, value);
|
||||
}
|
||||
|
||||
static final provider =
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ class MembersController(final String roomId)
|
|||
|
||||
if (!room.hasFetchedMembers) {
|
||||
final fetchedState = await ref
|
||||
.watch(ClientController.provider.notifier)
|
||||
.read(ClientController.provider.notifier)
|
||||
.getRoomState(
|
||||
GetRoomStateRequest(
|
||||
roomId: roomId,
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ class NotificationsController(final NotificationsRequest request)
|
|||
final lastNotification = currentNotifications.lastOrNull;
|
||||
final lastTs = lastNotification == null
|
||||
? null
|
||||
: ref.watch(
|
||||
: ref.read(
|
||||
RoomsController.provider.select(
|
||||
(rooms) => rooms[lastNotification.$2]
|
||||
?.events[lastNotification.$1]
|
||||
|
|
|
|||
|
|
@ -13,8 +13,8 @@ class PushKeyController(final String instance) extends AsyncNotifier<String?> {
|
|||
|
||||
Future<void> set(String? value) async {
|
||||
final provider = KeyController.provider(KeyController.pushKeyKey);
|
||||
final notifier = ref.watch(provider.notifier);
|
||||
final prefs = IMap(json.decode(await ref.watch(provider.future) ?? "{}"));
|
||||
final notifier = ref.read(provider.notifier);
|
||||
final prefs = IMap(json.decode(await ref.read(provider.future) ?? "{}"));
|
||||
|
||||
state = .data(value);
|
||||
notifier.set(
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ class ReactionsController(final ReactionsConfig config)
|
|||
|
||||
final reactionEvents = eventInfo?.$2.isNotEmpty == true
|
||||
? await ref
|
||||
.watch(ClientController.provider.notifier)
|
||||
.read(ClientController.provider.notifier)
|
||||
.getRelatedEvents(
|
||||
.new(
|
||||
roomId: config.roomId,
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ class RecentEmojiController extends Notifier<IList<RecentEmoji>> {
|
|||
}
|
||||
|
||||
Future<void> add(String emoji) => ref
|
||||
.watch(ClientController.provider.notifier)
|
||||
.read(ClientController.provider.notifier)
|
||||
.setAccountData(
|
||||
.new(
|
||||
type: AccountData.recentEmojiKey,
|
||||
|
|
|
|||
|
|
@ -88,7 +88,7 @@ class RoomChatController(final ChatParams info)
|
|||
}
|
||||
|
||||
Future<void> deleteMessage(Event event, {String? reason}) => ref
|
||||
.watch(ClientController.provider.notifier)
|
||||
.read(ClientController.provider.notifier)
|
||||
.redactEvent(
|
||||
RedactEventRequest(
|
||||
eventId: event.eventId,
|
||||
|
|
@ -146,7 +146,7 @@ class RoomChatController(final ChatParams info)
|
|||
);
|
||||
|
||||
if (response.events.isEmpty) {
|
||||
state = .data(state.value);
|
||||
state = .data(chat);
|
||||
}
|
||||
|
||||
ref
|
||||
|
|
@ -234,7 +234,7 @@ class RoomChatController(final ChatParams info)
|
|||
Content? baseContent;
|
||||
final relatedEvent = relatedEventRowId == null
|
||||
? null
|
||||
: ref.watch(
|
||||
: ref.read(
|
||||
RoomsController.provider.select(
|
||||
(rooms) => rooms[info.roomId]?.events[relatedEventRowId],
|
||||
),
|
||||
|
|
@ -267,9 +267,7 @@ class RoomChatController(final ChatParams info)
|
|||
baseContent: baseContent,
|
||||
mentions: Mentions(
|
||||
userIds: [
|
||||
if (shouldMention == true &&
|
||||
relatedEvent != null &&
|
||||
relationType == RelationType.reply)
|
||||
if (shouldMention && relatedEvent != null && relationType == .reply)
|
||||
relatedEvent.sender,
|
||||
].toIList(),
|
||||
room: taggedMessage.contains("@room"),
|
||||
|
|
@ -307,24 +305,20 @@ class RoomChatController(final ChatParams info)
|
|||
),
|
||||
);
|
||||
|
||||
final reactionEvents = allReactionEvents
|
||||
?.where((event) => event.redactedBy == null)
|
||||
.toIList();
|
||||
|
||||
final reactionEvent = reactionEvents?.firstWhereOrNull(
|
||||
(event) => switch (event.content) {
|
||||
ReactionContent(:final key) =>
|
||||
key == reaction && event.sender == userId,
|
||||
_ => false,
|
||||
},
|
||||
final reactionEvent = allReactionEvents?.firstWhereOrNull(
|
||||
(event) =>
|
||||
event.redactedBy == null &&
|
||||
switch (event.content) {
|
||||
ReactionContent(:final key) =>
|
||||
key == reaction && event.sender == userId,
|
||||
_ => false,
|
||||
},
|
||||
);
|
||||
|
||||
if (reactionEvent != null) {
|
||||
await ref
|
||||
.watch(ClientController.provider.notifier)
|
||||
.redactEvent(
|
||||
.new(eventId: reactionEvent.eventId, roomId: info.roomId),
|
||||
);
|
||||
await client.redactEvent(
|
||||
.new(eventId: reactionEvent.eventId, roomId: info.roomId),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ class RoomsController extends Notifier<IMap<String, Room>> {
|
|||
hasMore: incoming.hasMore,
|
||||
clientSticky: incoming.resetClientSticky
|
||||
? incoming.clientSticky
|
||||
: (incoming.clientSticky.isEmpty == true
|
||||
: (incoming.clientSticky.isEmpty
|
||||
? existing.clientSticky
|
||||
: existing.clientSticky.addAll(
|
||||
incoming.clientSticky,
|
||||
|
|
@ -73,9 +73,9 @@ class RoomsController extends Notifier<IMap<String, Room>> {
|
|||
incoming.hasFetchedMembers || existing.hasFetchedMembers,
|
||||
hasFetchedState:
|
||||
incoming.hasFetchedState || existing.hasFetchedState,
|
||||
timeline: (incoming.reset
|
||||
timeline: incoming.reset
|
||||
? incoming.timeline
|
||||
: existing.timeline.addAll(incoming.timeline)),
|
||||
: existing.timeline.addAll(incoming.timeline),
|
||||
receipts: incoming.receipts.entries.fold(
|
||||
existing.receipts,
|
||||
(receiptAcc, event) => receiptAcc.add(
|
||||
|
|
@ -88,12 +88,7 @@ class RoomsController extends Notifier<IMap<String, Room>> {
|
|||
);
|
||||
});
|
||||
|
||||
final prunedList = leftRooms.fold(
|
||||
merged,
|
||||
(acc, roomId) => acc.remove(roomId),
|
||||
);
|
||||
|
||||
state = prunedList;
|
||||
state = leftRooms.fold(merged, (acc, roomId) => acc.remove(roomId));
|
||||
}
|
||||
|
||||
static final provider = NotifierProvider<RoomsController, IMap<String, Room>>(
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import "dart:convert";
|
||||
|
||||
import "package:flutter_riverpod/flutter_riverpod.dart";
|
||||
import "package:nexus/controllers/settings_file.dart";
|
||||
import "package:nexus/models/settings.dart";
|
||||
|
|
@ -17,7 +18,7 @@ class SettingsController extends AsyncNotifier<Settings> {
|
|||
|
||||
Future<void> set(Settings settings) async {
|
||||
state = .data(settings);
|
||||
final file = await ref.watch(SettingsFileController.provider.future);
|
||||
final file = await ref.read(SettingsFileController.provider.future);
|
||||
await file.writeAsString(json.encode(settings.toJson()));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import "dart:io";
|
||||
|
||||
import "package:flutter_riverpod/flutter_riverpod.dart";
|
||||
import "package:path/path.dart";
|
||||
import "package:path_provider/path_provider.dart";
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ class SettingsSectionsController
|
|||
options: ThemeMode.values,
|
||||
getName: (option) => toBeginningOfSentenceCase(option.name),
|
||||
onChanged: (value) => ref
|
||||
.watch(SettingsController.provider.notifier)
|
||||
.read(SettingsController.provider.notifier)
|
||||
.set(settings.copyWith(theme: value))
|
||||
.onError(showError),
|
||||
),
|
||||
|
|
@ -67,7 +67,7 @@ class SettingsSectionsController
|
|||
Platform.isMacOS ||
|
||||
Platform.isWindows)
|
||||
? (value) => ref
|
||||
.watch(SettingsController.provider.notifier)
|
||||
.read(SettingsController.provider.notifier)
|
||||
.set(settings.copyWith(useDynamicTheming: value))
|
||||
.onError(showError)
|
||||
: null,
|
||||
|
|
@ -89,7 +89,7 @@ class SettingsSectionsController
|
|||
secondary: Icon(icon),
|
||||
value: settings.showAllInHome,
|
||||
onChanged: (value) => ref
|
||||
.watch(SettingsController.provider.notifier)
|
||||
.read(SettingsController.provider.notifier)
|
||||
.set(settings.copyWith(showAllInHome: value))
|
||||
.onError(showError),
|
||||
),
|
||||
|
|
@ -106,7 +106,7 @@ class SettingsSectionsController
|
|||
secondary: Icon(icon),
|
||||
value: settings.showMinimizeButton,
|
||||
onChanged: (value) => ref
|
||||
.watch(SettingsController.provider.notifier)
|
||||
.read(SettingsController.provider.notifier)
|
||||
.set(settings.copyWith(showMinimizeButton: value))
|
||||
.onError(showError),
|
||||
),
|
||||
|
|
@ -122,7 +122,7 @@ class SettingsSectionsController
|
|||
value: settings.linuxMobileMode,
|
||||
onChanged: Platform.isLinux
|
||||
? (value) => ref
|
||||
.watch(SettingsController.provider.notifier)
|
||||
.read(SettingsController.provider.notifier)
|
||||
.set(settings.copyWith(linuxMobileMode: value))
|
||||
.onError(showError)
|
||||
: null,
|
||||
|
|
@ -190,14 +190,14 @@ class SettingsSectionsController
|
|||
loading.value = true;
|
||||
if (value != null) {
|
||||
if (await ref
|
||||
.watch(
|
||||
.read(
|
||||
NotificationController
|
||||
.provider
|
||||
.notifier,
|
||||
)
|
||||
.requestPermissions()) {
|
||||
await ref
|
||||
.watch(
|
||||
.read(
|
||||
UnifiedPushController
|
||||
.provider
|
||||
.notifier,
|
||||
|
|
@ -208,7 +208,7 @@ class SettingsSectionsController
|
|||
}
|
||||
} else {
|
||||
await ref
|
||||
.watch(
|
||||
.read(
|
||||
UnifiedPushController
|
||||
.provider
|
||||
.notifier,
|
||||
|
|
@ -268,7 +268,7 @@ class SettingsSectionsController
|
|||
onChanged: specVersionsResponse.maybeWhen(
|
||||
data: (_) =>
|
||||
(value) => ref
|
||||
.watch(ClientController.provider.notifier)
|
||||
.read(ClientController.provider.notifier)
|
||||
.setAccountData(
|
||||
.new(
|
||||
type: AccountData.invitePermissionConfigKey,
|
||||
|
|
|
|||
|
|
@ -19,10 +19,10 @@ class SpacesController extends AsyncNotifier<IList<Space>> {
|
|||
final spaceEdges = ref.watch(SpaceEdgesController.provider);
|
||||
final accountData = ref.watch(AccountDataController.provider);
|
||||
|
||||
final childrenById = {
|
||||
for (final entry in spaceEdges.entries)
|
||||
entry.key: entry.value.map((e) => e.childId).toList(),
|
||||
};
|
||||
final childrenById = spaceEdges.map(
|
||||
(spaceId, edges) =>
|
||||
MapEntry(spaceId, edges.map((edge) => edge.childId).toList()),
|
||||
);
|
||||
|
||||
Set<String> collectDescendants(String startId) {
|
||||
final visited = <String>{};
|
||||
|
|
@ -78,21 +78,22 @@ class SpacesController extends AsyncNotifier<IList<Space>> {
|
|||
|
||||
final spaces = topLevelSpaceIds.map(buildSpace).toIList();
|
||||
|
||||
final usedRooms = {
|
||||
for (final space in spaces) ...[
|
||||
...space.children,
|
||||
...space.subSpaces.expand((s) => s.children),
|
||||
],
|
||||
}.nonNulls.toISet();
|
||||
final usedRooms = spaces
|
||||
.expand(
|
||||
(space) => [
|
||||
...space.children,
|
||||
...space.subSpaces.expand((s) => s.children),
|
||||
],
|
||||
)
|
||||
.toISet();
|
||||
final usedRoomIds = usedRooms.map((room) => room.metadata?.id).toSet();
|
||||
|
||||
final directMessages = accountData.directMessages.values.flattened;
|
||||
final directMessages = accountData.directMessages.values.flattened.toSet();
|
||||
|
||||
final otherRooms = rooms.entries
|
||||
.where(
|
||||
(e) =>
|
||||
!usedRooms
|
||||
.map((element) => element.metadata?.id)
|
||||
.contains(e.key) &&
|
||||
!usedRoomIds.contains(e.key) &&
|
||||
!topLevelSpaceIds.contains(e.key) &&
|
||||
!childrenById.containsKey(e.key),
|
||||
)
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ class UnifiedPushAllowedController extends AsyncNotifier<String?> {
|
|||
}
|
||||
|
||||
final capabilities = await ref
|
||||
.watch(ClientController.provider.notifier)
|
||||
.read(ClientController.provider.notifier)
|
||||
.getCapabilities();
|
||||
|
||||
if (capabilities.webpush?.vapid == null) {
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ class UrlPreviewController(final Uri url)
|
|||
|
||||
try {
|
||||
return await ref
|
||||
.watch(ClientController.provider.notifier)
|
||||
.read(ClientController.provider.notifier)
|
||||
.getUrlPreview(url);
|
||||
} catch (error, stackTrace) {
|
||||
debugPrintStack(label: error.toString(), stackTrace: stackTrace);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import "dart:async";
|
||||
|
||||
import "package:collection/collection.dart";
|
||||
import "package:flutter_riverpod/flutter_riverpod.dart";
|
||||
import "package:nexus/controllers/members.dart";
|
||||
|
|
|
|||
Loading…
Reference in a new issue