mirror of
https://github.com/krille-chan/fluffychat
synced 2024-09-10 13:05:11 +00:00
fix: Archive does not update its state
This commit is contained in:
parent
9d29f9dcd2
commit
b42a565a9a
5 changed files with 32 additions and 34 deletions
|
@ -16,17 +16,29 @@ class Archive extends StatefulWidget {
|
|||
}
|
||||
|
||||
class ArchiveController extends State<Archive> {
|
||||
List<Room>? archive;
|
||||
List<Room> archive = [];
|
||||
|
||||
Future<List<Room>> getArchive(BuildContext context) async {
|
||||
final archive = this.archive;
|
||||
if (archive != null) return archive;
|
||||
return this.archive = await Matrix.of(context).client.loadArchive();
|
||||
if (archive.isNotEmpty) return archive;
|
||||
return archive = await Matrix.of(context).client.loadArchive();
|
||||
}
|
||||
|
||||
void forgetRoomAction(int i) async {
|
||||
await showFutureLoadingDialog(
|
||||
context: context,
|
||||
future: () async {
|
||||
Logs().v('Forget room ${archive.last.getLocalizedDisplayname()}');
|
||||
await archive[i].forget();
|
||||
archive.removeAt(i);
|
||||
},
|
||||
);
|
||||
setState(() {});
|
||||
}
|
||||
|
||||
void forgetAllAction() async {
|
||||
final archive = this.archive;
|
||||
if (archive == null) return;
|
||||
final client = Matrix.of(context).client;
|
||||
if (archive.isEmpty) return;
|
||||
if (await showOkCancelAlertDialog(
|
||||
useRootNavigator: false,
|
||||
context: context,
|
||||
|
@ -48,6 +60,7 @@ class ArchiveController extends State<Archive> {
|
|||
}
|
||||
},
|
||||
);
|
||||
client.clearArchivesFromCache();
|
||||
setState(() {});
|
||||
}
|
||||
|
||||
|
|
|
@ -14,7 +14,6 @@ class ArchiveView extends StatelessWidget {
|
|||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var archive = controller.archive;
|
||||
return FutureBuilder<List<Room>>(
|
||||
future: controller.getArchive(context),
|
||||
builder: (BuildContext context, snapshot) => Scaffold(
|
||||
|
@ -50,16 +49,16 @@ class ArchiveView extends StatelessWidget {
|
|||
child: CircularProgressIndicator.adaptive(strokeWidth: 2),
|
||||
);
|
||||
} else {
|
||||
archive = snapshot.data;
|
||||
if (archive == null || archive!.isEmpty) {
|
||||
if (controller.archive.isEmpty) {
|
||||
return const Center(
|
||||
child: Icon(Icons.archive_outlined, size: 80),
|
||||
);
|
||||
}
|
||||
return ListView.builder(
|
||||
itemCount: archive!.length,
|
||||
itemCount: controller.archive.length,
|
||||
itemBuilder: (BuildContext context, int i) => ChatListItem(
|
||||
archive![i],
|
||||
controller.archive[i],
|
||||
onForget: () => controller.forgetRoomAction(i),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
|
|
@ -949,15 +949,6 @@ class ChatController extends State<ChatPageWithRoom> {
|
|||
return sendEmojiAction(emoji.emoji);
|
||||
}
|
||||
|
||||
void forgetRoom() async {
|
||||
final result = await showFutureLoadingDialog(
|
||||
context: context,
|
||||
future: room.forget,
|
||||
);
|
||||
if (result.error != null) return;
|
||||
context.go('/rooms/archive');
|
||||
}
|
||||
|
||||
void typeEmoji(Emoji? emoji) {
|
||||
if (emoji == null) return;
|
||||
final text = sendController.text;
|
||||
|
|
|
@ -108,21 +108,7 @@ class ChatView extends StatelessWidget {
|
|||
],
|
||||
),
|
||||
];
|
||||
} else if (controller.isArchived) {
|
||||
return [
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: TextButton.icon(
|
||||
onPressed: controller.forgetRoom,
|
||||
style: TextButton.styleFrom(
|
||||
foregroundColor: Theme.of(context).colorScheme.error,
|
||||
),
|
||||
icon: const Icon(Icons.delete_forever_outlined),
|
||||
label: Text(L10n.of(context)!.delete),
|
||||
),
|
||||
),
|
||||
];
|
||||
} else {
|
||||
} else if (!controller.room.isArchived) {
|
||||
return [
|
||||
if (Matrix.of(context).voipPlugin != null &&
|
||||
controller.room.isDirectChat)
|
||||
|
@ -135,6 +121,7 @@ class ChatView extends StatelessWidget {
|
|||
ChatSettingsPopupMenu(controller.room, true),
|
||||
];
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
@override
|
||||
|
|
|
@ -23,6 +23,7 @@ class ChatListItem extends StatelessWidget {
|
|||
final bool selected;
|
||||
final void Function()? onTap;
|
||||
final void Function()? onLongPress;
|
||||
final void Function()? onForget;
|
||||
|
||||
const ChatListItem(
|
||||
this.room, {
|
||||
|
@ -30,6 +31,7 @@ class ChatListItem extends StatelessWidget {
|
|||
this.selected = false,
|
||||
this.onTap,
|
||||
this.onLongPress,
|
||||
this.onForget,
|
||||
super.key,
|
||||
});
|
||||
|
||||
|
@ -362,6 +364,12 @@ class ChatListItem extends StatelessWidget {
|
|||
],
|
||||
),
|
||||
onTap: () => clickAction(context),
|
||||
trailing: onForget == null
|
||||
? null
|
||||
: IconButton(
|
||||
icon: const Icon(Icons.delete_outlined),
|
||||
onPressed: onForget,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
|
Loading…
Reference in a new issue