Skip to content

Commit

Permalink
sort chat rooms by created time
Browse files Browse the repository at this point in the history
  • Loading branch information
tangenta committed Aug 6, 2023
1 parent 2807b46 commit 419afcf
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/repository/chat_room.dart
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,6 @@ class ChatRoomRepository {
final String path = join(await getDatabasesPath(), 'moyubie.db');
_database = await openDatabase(path, version: 1,
onCreate: (Database db, int version) async {
print("on create!");
final batch = db.batch();

batch.execute('''
Expand Down Expand Up @@ -416,7 +415,7 @@ class ChatRoomRepository {
ask_ai: m[_columnAskAI] == 1);
messages[roomId] = msg;
}));
return List.generate(maps.length, (i) {
var ret = List.generate(maps.length, (i) {
final msg = messages[maps[i][_columnChatRoomUuid]];
var ct = maps[i][_columnChatRoomCreateTime];
return ChatRoom(
Expand All @@ -428,6 +427,8 @@ class ChatRoomRepository {
.firstWhere((e) => e.name == maps[i][_columnChatRoomRole]),
firstMessage: msg);
});
ret.sort((a, b) => b.createTime.compareTo(a.createTime));
return ret;
}

Future<List<ChatRoom>> getChatRoomsRemote() async {
Expand Down

0 comments on commit 419afcf

Please sign in to comment.