Pinned chat room

This commit is contained in:
2025-12-22 00:04:23 +08:00
parent 2df31e4244
commit a481b1b82f
11 changed files with 1074 additions and 472 deletions

View File

@@ -47,6 +47,7 @@ class ChatRoomJoinedNotifier extends _$ChatRoomJoinedNotifier {
try {
final localRoomsData = await db.select(db.chatRooms).get();
final localRealmsData = await db.select(db.realms).get();
if (localRoomsData.isNotEmpty) {
final localRooms = await Future.wait(
localRoomsData.map((row) async {
@@ -87,11 +88,15 @@ class ChatRoomJoinedNotifier extends _$ChatRoomJoinedNotifier {
: null,
realmId: row.realmId,
accountId: row.accountId,
realm: null,
realm: localRealmsData
.where((e) => e.id == row.realmId)
.map((e) => _buildRealmFromTableEntry(e))
.firstOrNull,
createdAt: row.createdAt,
updatedAt: row.updatedAt,
deletedAt: row.deletedAt,
members: members,
isPinned: row.isPinned ?? false,
);
}),
);
@@ -126,6 +131,29 @@ class ChatRoomJoinedNotifier extends _$ChatRoomJoinedNotifier {
return rooms;
}
SnRealm _buildRealmFromTableEntry(Realm localRealm) {
return SnRealm(
id: localRealm.id,
slug: localRealm.slug,
name: localRealm.name ?? localRealm.slug,
description: localRealm.description ?? '',
verifiedAs: localRealm.verifiedAs,
verifiedAt: localRealm.verifiedAt,
isCommunity: localRealm.isCommunity,
isPublic: localRealm.isPublic,
picture: localRealm.picture != null
? SnCloudFile.fromJson(localRealm.picture!)
: null,
background: localRealm.background != null
? SnCloudFile.fromJson(localRealm.background!)
: null,
accountId: localRealm.accountId ?? '',
createdAt: localRealm.createdAt,
updatedAt: localRealm.updatedAt,
deletedAt: localRealm.deletedAt,
);
}
Future<List<SnChatRoom>> _buildRoomsFromDb(AppDatabase db) async {
final localRoomsData = await db.select(db.chatRooms).get();
return Future.wait(
@@ -207,6 +235,7 @@ class ChatRoomJoinedNotifier extends _$ChatRoomJoinedNotifier {
updatedAt: row.updatedAt,
deletedAt: row.deletedAt,
members: members,
isPinned: row.isPinned ?? false,
);
}),
);

View File

@@ -34,7 +34,7 @@ final class ChatRoomJoinedNotifierProvider
}
String _$chatRoomJoinedNotifierHash() =>
r'65961aac28b5188900c4b25308f6fd080a14d5ab';
r'805b38e477df574c92b1ef3cd54527cfd03a55cb';
abstract class _$ChatRoomJoinedNotifier
extends $AsyncNotifier<List<SnChatRoom>> {