import '/utils/storage/database.dart'; import '/models/conversations.dart'; class ConversationUser{ String id; String conversationId; String username; String associationKey; String admin; ConversationUser({ required this.id, required this.conversationId, required this.username, required this.associationKey, required this.admin, }); factory ConversationUser.fromJson(Map json, String conversationId) { return ConversationUser( id: json['id'], conversationId: conversationId, username: json['username'], associationKey: json['association_key'], admin: json['admin'], ); } Map toMap() { return { 'id': id, 'conversation_id': conversationId, 'username': username, 'association_key': associationKey, 'admin': admin, }; } } // A method that retrieves all the dogs from the dogs table. Future> getConversationUsers(Conversation conversation) async { final db = await getDatabaseConnection(); final List> maps = await db.query( 'conversation_users', where: 'conversation_id = ?', whereArgs: [conversation.id], ); return List.generate(maps.length, (i) { return ConversationUser( id: maps[i]['id'], conversationId: maps[i]['conversation_id'], username: maps[i]['username'], associationKey: maps[i]['association_key'], admin: maps[i]['admin'], ); }); } Future getConversationUserById(Conversation conversation, String id) async { final db = await getDatabaseConnection(); final List> maps = await db.query( 'conversation_users', where: 'conversation_id = ? AND id = ?', whereArgs: [conversation.id, id], ); if (maps.length != 1) { throw ArgumentError('Invalid conversation_id or id'); } return ConversationUser( id: maps[0]['id'], conversationId: maps[0]['conversation_id'], username: maps[0]['username'], associationKey: maps[0]['association_key'], admin: maps[0]['admin'], ); } Future getConversationUserByUsername(Conversation conversation, String username) async { final db = await getDatabaseConnection(); final List> maps = await db.query( 'conversation_users', where: 'conversation_id = ? AND username = ?', whereArgs: [conversation.id, username], ); if (maps.length != 1) { throw ArgumentError('Invalid conversation_id or username'); } return ConversationUser( id: maps[0]['id'], conversationId: maps[0]['conversation_id'], username: maps[0]['username'], associationKey: maps[0]['association_key'], admin: maps[0]['admin'], ); }