mirror of
https://codeberg.org/monocles/monocles_chat.git
synced 2025-01-27 15:34:14 +01:00
look up older messages in DB for reactions
(cherry picked from commit d84a4796e257db7679e4729680003e93ad75e960)
This commit is contained in:
parent
3684c83d90
commit
a5c4fb0cf3
2 changed files with 86 additions and 20 deletions
|
@ -1432,10 +1432,20 @@ public class MessageParser extends AbstractParser implements Consumer<im.convers
|
||||||
final var occupant =
|
final var occupant =
|
||||||
mucOptions.occupantId() ? packet.getExtension(OccupantId.class) : null;
|
mucOptions.occupantId() ? packet.getExtension(OccupantId.class) : null;
|
||||||
final var occupantId = occupant == null ? null : occupant.getId();
|
final var occupantId = occupant == null ? null : occupant.getId();
|
||||||
final var message = conversation.findMessageWithServerMsgId(reactingTo);
|
if (occupantId != null) {
|
||||||
// TODO use occupant id for isSelf assessment
|
// TODO use occupant id for isSelf assessment
|
||||||
final boolean isReceived = !mucOptions.isSelf(counterpart);
|
final boolean isReceived = !mucOptions.isSelf(counterpart);
|
||||||
if (occupantId != null && message != null) {
|
final Message message;
|
||||||
|
final var inMemoryMessage =
|
||||||
|
conversation.findMessageWithServerMsgId(reactingTo);
|
||||||
|
if (inMemoryMessage != null) {
|
||||||
|
message = inMemoryMessage;
|
||||||
|
} else {
|
||||||
|
message =
|
||||||
|
mXmppConnectionService.databaseBackend
|
||||||
|
.getMessageWithServerMsgId(conversation, reactingTo);
|
||||||
|
}
|
||||||
|
if (message != null) {
|
||||||
final var newReactions = new HashSet<>(reactions.getReactions());
|
final var newReactions = new HashSet<>(reactions.getReactions());
|
||||||
newReactions.removeAll(message.getReactions().stream().filter(r -> occupantId.equals(r.occupantId)).map(r -> r.reaction).collect(Collectors.toList()));
|
newReactions.removeAll(message.getReactions().stream().filter(r -> occupantId.equals(r.occupantId)).map(r -> r.reaction).collect(Collectors.toList()));
|
||||||
final var combinedReactions =
|
final var combinedReactions =
|
||||||
|
@ -1451,10 +1461,24 @@ public class MessageParser extends AbstractParser implements Consumer<im.convers
|
||||||
mXmppConnectionService.updateMessage(message, false);
|
mXmppConnectionService.updateMessage(message, false);
|
||||||
if (!isCarbon && !packet.fromAccount(account)) mXmppConnectionService.getNotificationService().push(message, counterpart, occupantId, newReactions);
|
if (!isCarbon && !packet.fromAccount(account)) mXmppConnectionService.getNotificationService().push(message, counterpart, occupantId, newReactions);
|
||||||
} else {
|
} else {
|
||||||
Log.d(Config.LOGTAG,"not found occupant or message");
|
Log.d(Config.LOGTAG, "message with id " + reactingTo + " not found");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Log.d(
|
||||||
|
Config.LOGTAG,
|
||||||
|
"received reaction in channel w/o occupant ids. ignoring");
|
||||||
}
|
}
|
||||||
} else if (conversation.getMode() == Conversational.MODE_SINGLE) {
|
} else if (conversation.getMode() == Conversational.MODE_SINGLE) {
|
||||||
final var message = conversation.findMessageWithUuidOrRemoteId(reactingTo);
|
final Message message;
|
||||||
|
final var inMemoryMessage =
|
||||||
|
conversation.findMessageWithUuidOrRemoteId(reactingTo);
|
||||||
|
if (inMemoryMessage != null) {
|
||||||
|
message = inMemoryMessage;
|
||||||
|
} else {
|
||||||
|
message =
|
||||||
|
mXmppConnectionService.databaseBackend.getMessageWithUuidOrRemoteId(
|
||||||
|
conversation, reactingTo);
|
||||||
|
}
|
||||||
final boolean isReceived;
|
final boolean isReceived;
|
||||||
final Jid reactionFrom;
|
final Jid reactionFrom;
|
||||||
if (packet.fromAccount(account)) {
|
if (packet.fromAccount(account)) {
|
||||||
|
@ -1478,6 +1502,8 @@ public class MessageParser extends AbstractParser implements Consumer<im.convers
|
||||||
message.setReactions(combinedReactions);
|
message.setReactions(combinedReactions);
|
||||||
mXmppConnectionService.updateMessage(message, false);
|
mXmppConnectionService.updateMessage(message, false);
|
||||||
if (!isCarbon && !packet.fromAccount(account)) mXmppConnectionService.getNotificationService().push(message, counterpart, null, newReactions);
|
if (!isCarbon && !packet.fromAccount(account)) mXmppConnectionService.getNotificationService().push(message, counterpart, null, newReactions);
|
||||||
|
} else {
|
||||||
|
Log.d(Config.LOGTAG, "message with id " + reactingTo + " not found");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1318,6 +1318,46 @@ public class DatabaseBackend extends SQLiteOpenHelper {
|
||||||
return filesPaths;
|
return filesPaths;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Message getMessageWithServerMsgId(
|
||||||
|
final Conversation conversation, final String messageId) {
|
||||||
|
final var db = this.getReadableDatabase();
|
||||||
|
final String sql =
|
||||||
|
"select * from messages where conversationUuid=? and serverMsgId=? LIMIT 1";
|
||||||
|
final String[] args = {conversation.getUuid(), messageId};
|
||||||
|
final Cursor cursor = db.rawQuery(sql, args);
|
||||||
|
if (cursor == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
Message message = null;
|
||||||
|
try {
|
||||||
|
if (cursor.moveToFirst()) {
|
||||||
|
message = Message.fromCursor(cursor, conversation);
|
||||||
|
}
|
||||||
|
} catch (final IOException e) { }
|
||||||
|
cursor.close();
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Message getMessageWithUuidOrRemoteId(
|
||||||
|
final Conversation conversation, final String messageId) {
|
||||||
|
final var db = this.getReadableDatabase();
|
||||||
|
final String sql =
|
||||||
|
"select * from messages where conversationUuid=? and (uuid=? OR remoteMsgId=?) LIMIT 1";
|
||||||
|
final String[] args = {conversation.getUuid(), messageId, messageId};
|
||||||
|
final Cursor cursor = db.rawQuery(sql, args);
|
||||||
|
if (cursor == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
Message message = null;
|
||||||
|
try {
|
||||||
|
if (cursor.moveToFirst()) {
|
||||||
|
message = Message.fromCursor(cursor, conversation);
|
||||||
|
}
|
||||||
|
} catch (final IOException e) { }
|
||||||
|
cursor.close();
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
public static class FilePath {
|
public static class FilePath {
|
||||||
public final UUID uuid;
|
public final UUID uuid;
|
||||||
public final String path;
|
public final String path;
|
||||||
|
|
Loading…
Add table
Reference in a new issue