|
|
@ -34,7 +34,7 @@ Future<Conversation> createConversation(String title, List<Friend> friends, bool |
|
|
|
status: ConversationStatus.pending, |
|
|
|
isRead: true, |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
await db.insert( |
|
|
|
'conversations', |
|
|
|
conversation.toMap(), |
|
|
@ -65,12 +65,32 @@ Future<Conversation> createConversation(String title, List<Friend> friends, bool |
|
|
|
username: friend.username, |
|
|
|
associationKey: uuid.v4(), |
|
|
|
publicKey: friend.publicKey, |
|
|
|
admin: false, |
|
|
|
admin: twoUser ? true : false, |
|
|
|
).toMap(), |
|
|
|
conflictAlgorithm: ConflictAlgorithm.replace, |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
if (twoUser) { |
|
|
|
List<Map<String, dynamic>> maps = await db.query( |
|
|
|
'conversation_users', |
|
|
|
where: 'conversation_id = ? AND user_id != ?', |
|
|
|
whereArgs: [ conversation.id, profile.id ], |
|
|
|
); |
|
|
|
|
|
|
|
if (maps.length != 1) { |
|
|
|
throw ArgumentError('Invalid user id'); |
|
|
|
} |
|
|
|
|
|
|
|
conversation.name = maps[0]['username']; |
|
|
|
|
|
|
|
await db.insert( |
|
|
|
'conversations', |
|
|
|
conversation.toMap(), |
|
|
|
conflictAlgorithm: ConflictAlgorithm.replace, |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
return conversation; |
|
|
|
} |
|
|
|
|
|
|
@ -138,7 +158,10 @@ Future<Conversation> getConversationById(String id) async { |
|
|
|
Future<List<Conversation>> getConversations() async { |
|
|
|
final db = await getDatabaseConnection(); |
|
|
|
|
|
|
|
final List<Map<String, dynamic>> maps = await db.query('conversations'); |
|
|
|
final List<Map<String, dynamic>> maps = await db.query( |
|
|
|
'conversations', |
|
|
|
orderBy: 'name', |
|
|
|
); |
|
|
|
|
|
|
|
return List.generate(maps.length, (i) { |
|
|
|
return Conversation( |
|
|
@ -159,9 +182,6 @@ Future<Conversation?> getTwoUserConversation(String userId) async { |
|
|
|
|
|
|
|
MyProfile profile = await MyProfile.getProfile(); |
|
|
|
|
|
|
|
print(userId); |
|
|
|
print(profile.id); |
|
|
|
|
|
|
|
final List<Map<String, dynamic>> maps = await db.rawQuery( |
|
|
|
''' |
|
|
|
SELECT conversations.* FROM conversations |
|
|
@ -281,6 +301,7 @@ class Conversation { |
|
|
|
'id': id, |
|
|
|
'name': AesHelper.aesEncrypt(symKey, Uint8List.fromList(name.codeUnits)), |
|
|
|
'users': await getEncryptedConversationUsers(this, symKey), |
|
|
|
'two_user': AesHelper.aesEncrypt(symKey, Uint8List.fromList((twoUser ? 'true' : 'false').codeUnits)), |
|
|
|
'user_conversations': userConversations, |
|
|
|
}; |
|
|
|
} |
|
|
@ -320,7 +341,7 @@ class Conversation { |
|
|
|
ORDER BY created_at DESC |
|
|
|
LIMIT 1; |
|
|
|
''', |
|
|
|
[id], |
|
|
|
[ id ], |
|
|
|
); |
|
|
|
|
|
|
|
if (maps.isEmpty) { |
|
|
@ -339,28 +360,6 @@ class Conversation { |
|
|
|
failedToSend: maps[0]['failed_to_send'] == 1, |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
Future<String> getName() async { |
|
|
|
if (!twoUser) { |
|
|
|
return name; |
|
|
|
} |
|
|
|
|
|
|
|
MyProfile profile = await MyProfile.getProfile(); |
|
|
|
|
|
|
|
final db = await getDatabaseConnection(); |
|
|
|
|
|
|
|
List<Map<String, dynamic>> maps = await db.query( |
|
|
|
'conversation_users', |
|
|
|
where: 'conversation_id = ? AND user_id != ?', |
|
|
|
whereArgs: [ id, profile.id ], |
|
|
|
); |
|
|
|
|
|
|
|
if (maps.length != 1) { |
|
|
|
throw ArgumentError('Invalid user id'); |
|
|
|
} |
|
|
|
|
|
|
|
return maps[0]['username']; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|