fix(service): Fix loading the wrong quote from the database
This commit is contained in:
parent
9b16bf6e6f
commit
09ba2122e7
@ -110,7 +110,7 @@ class DatabaseService {
|
||||
final rawQuote = (await _db.query(
|
||||
'Messages',
|
||||
where: 'conversationJid = ? AND id = ?',
|
||||
whereArgs: [jid, m['id']! as int],
|
||||
whereArgs: [jid, m['quote_id']! as int],
|
||||
)).first;
|
||||
quotes = Message.fromDatabaseJson(rawQuote, null);
|
||||
}
|
||||
@ -268,7 +268,7 @@ class DatabaseService {
|
||||
int? mediaSize,
|
||||
}
|
||||
) async {
|
||||
final m = Message(
|
||||
var m = Message(
|
||||
sender,
|
||||
body,
|
||||
timestamp,
|
||||
@ -301,17 +301,17 @@ class DatabaseService {
|
||||
mediaSize: mediaSize,
|
||||
);
|
||||
|
||||
Message? quotes;
|
||||
if (quoteId != null) {
|
||||
quotes = await getMessageByXmppId(quoteId, conversationJid);
|
||||
final quotes = await getMessageByXmppId(quoteId, conversationJid);
|
||||
if (quotes == null) {
|
||||
_log.warning('Failed to add quote for message with id $quoteId');
|
||||
} else {
|
||||
m = m.copyWith(quotes: quotes);
|
||||
}
|
||||
}
|
||||
|
||||
return m.copyWith(
|
||||
id: await _db.insert('Messages', m.toDatabaseJson(quotes?.id)),
|
||||
quotes: quotes,
|
||||
id: await _db.insert('Messages', m.toDatabaseJson()),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -83,7 +83,7 @@ class Message with _$Message {
|
||||
}).copyWith(quotes: quotes);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toDatabaseJson(int? quoteId) {
|
||||
Map<String, dynamic> toDatabaseJson() {
|
||||
final map = toJson()
|
||||
..remove('id')
|
||||
..remove('quotes');
|
||||
@ -96,7 +96,8 @@ class Message with _$Message {
|
||||
'displayed': boolToInt(displayed),
|
||||
'acked': boolToInt(acked),
|
||||
'encrypted': boolToInt(encrypted),
|
||||
'quote_id': quoteId,
|
||||
// NOTE: Message.quote_id is a foreign-key
|
||||
'quote_id': quotes?.id,
|
||||
'plaintextHashes': _optionalJsonEncode(plaintextHashes),
|
||||
'ciphertextHashes': _optionalJsonEncode(ciphertextHashes),
|
||||
'isDownloading': boolToInt(isDownloading),
|
||||
|
Loading…
Reference in New Issue
Block a user