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> {
|
class ArchiveController extends State<Archive> {
|
||||||
List<Room>? archive;
|
List<Room> archive = [];
|
||||||
|
|
||||||
Future<List<Room>> getArchive(BuildContext context) async {
|
Future<List<Room>> getArchive(BuildContext context) async {
|
||||||
final archive = this.archive;
|
if (archive.isNotEmpty) return archive;
|
||||||
if (archive != null) return archive;
|
return archive = await Matrix.of(context).client.loadArchive();
|
||||||
return this.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 {
|
void forgetAllAction() async {
|
||||||
final archive = this.archive;
|
final archive = this.archive;
|
||||||
if (archive == null) return;
|
final client = Matrix.of(context).client;
|
||||||
|
if (archive.isEmpty) return;
|
||||||
if (await showOkCancelAlertDialog(
|
if (await showOkCancelAlertDialog(
|
||||||
useRootNavigator: false,
|
useRootNavigator: false,
|
||||||
context: context,
|
context: context,
|
||||||
|
@ -48,6 +60,7 @@ class ArchiveController extends State<Archive> {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
client.clearArchivesFromCache();
|
||||||
setState(() {});
|
setState(() {});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,6 @@ class ArchiveView extends StatelessWidget {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
var archive = controller.archive;
|
|
||||||
return FutureBuilder<List<Room>>(
|
return FutureBuilder<List<Room>>(
|
||||||
future: controller.getArchive(context),
|
future: controller.getArchive(context),
|
||||||
builder: (BuildContext context, snapshot) => Scaffold(
|
builder: (BuildContext context, snapshot) => Scaffold(
|
||||||
|
@ -50,16 +49,16 @@ class ArchiveView extends StatelessWidget {
|
||||||
child: CircularProgressIndicator.adaptive(strokeWidth: 2),
|
child: CircularProgressIndicator.adaptive(strokeWidth: 2),
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
archive = snapshot.data;
|
if (controller.archive.isEmpty) {
|
||||||
if (archive == null || archive!.isEmpty) {
|
|
||||||
return const Center(
|
return const Center(
|
||||||
child: Icon(Icons.archive_outlined, size: 80),
|
child: Icon(Icons.archive_outlined, size: 80),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return ListView.builder(
|
return ListView.builder(
|
||||||
itemCount: archive!.length,
|
itemCount: controller.archive.length,
|
||||||
itemBuilder: (BuildContext context, int i) => ChatListItem(
|
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);
|
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) {
|
void typeEmoji(Emoji? emoji) {
|
||||||
if (emoji == null) return;
|
if (emoji == null) return;
|
||||||
final text = sendController.text;
|
final text = sendController.text;
|
||||||
|
|
|
@ -108,21 +108,7 @@ class ChatView extends StatelessWidget {
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
];
|
];
|
||||||
} else if (controller.isArchived) {
|
} else if (!controller.room.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 {
|
|
||||||
return [
|
return [
|
||||||
if (Matrix.of(context).voipPlugin != null &&
|
if (Matrix.of(context).voipPlugin != null &&
|
||||||
controller.room.isDirectChat)
|
controller.room.isDirectChat)
|
||||||
|
@ -135,6 +121,7 @@ class ChatView extends StatelessWidget {
|
||||||
ChatSettingsPopupMenu(controller.room, true),
|
ChatSettingsPopupMenu(controller.room, true),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|
|
@ -23,6 +23,7 @@ class ChatListItem extends StatelessWidget {
|
||||||
final bool selected;
|
final bool selected;
|
||||||
final void Function()? onTap;
|
final void Function()? onTap;
|
||||||
final void Function()? onLongPress;
|
final void Function()? onLongPress;
|
||||||
|
final void Function()? onForget;
|
||||||
|
|
||||||
const ChatListItem(
|
const ChatListItem(
|
||||||
this.room, {
|
this.room, {
|
||||||
|
@ -30,6 +31,7 @@ class ChatListItem extends StatelessWidget {
|
||||||
this.selected = false,
|
this.selected = false,
|
||||||
this.onTap,
|
this.onTap,
|
||||||
this.onLongPress,
|
this.onLongPress,
|
||||||
|
this.onForget,
|
||||||
super.key,
|
super.key,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -362,6 +364,12 @@ class ChatListItem extends StatelessWidget {
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
onTap: () => clickAction(context),
|
onTap: () => clickAction(context),
|
||||||
|
trailing: onForget == null
|
||||||
|
? null
|
||||||
|
: IconButton(
|
||||||
|
icon: const Icon(Icons.delete_outlined),
|
||||||
|
onPressed: onForget,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in a new issue