kopia lustrzana https://github.com/ryukoposting/Signal-Android
Add some extra preconditions to reaction processing.
rodzic
5a28cf616d
commit
1fad5e2c1e
|
@ -150,17 +150,17 @@ public class MmsSmsDatabase extends Database {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public @Nullable MessageRecord getMessageFor(long timestamp, RecipientId author) {
|
public @Nullable MessageRecord getMessageFor(long timestamp, RecipientId authorId) {
|
||||||
MmsSmsDatabase db = DatabaseFactory.getMmsSmsDatabase(context);
|
Recipient author = Recipient.resolved(authorId);
|
||||||
|
|
||||||
try (Cursor cursor = queryTables(PROJECTION, MmsSmsColumns.NORMALIZED_DATE_SENT + " = " + timestamp, null, null)) {
|
try (Cursor cursor = queryTables(PROJECTION, MmsSmsColumns.NORMALIZED_DATE_SENT + " = " + timestamp, null, null)) {
|
||||||
MmsSmsDatabase.Reader reader = db.readerFor(cursor);
|
MmsSmsDatabase.Reader reader = readerFor(cursor);
|
||||||
|
|
||||||
MessageRecord messageRecord;
|
MessageRecord messageRecord;
|
||||||
|
|
||||||
while ((messageRecord = reader.getNext()) != null) {
|
while ((messageRecord = reader.getNext()) != null) {
|
||||||
if ((Recipient.resolved(author).isSelf() && messageRecord.isOutgoing()) ||
|
if ((author.isSelf() && messageRecord.isOutgoing()) ||
|
||||||
(!Recipient.resolved(author).isSelf() && messageRecord.getIndividualRecipient().getId().equals(author)))
|
(!author.isSelf() && messageRecord.getIndividualRecipient().getId().equals(authorId)))
|
||||||
{
|
{
|
||||||
return messageRecord;
|
return messageRecord;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1318,7 +1318,7 @@ public class ThreadDatabase extends Database {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private @Nullable ThreadRecord getThreadRecord(@Nullable Long threadId) {
|
public @Nullable ThreadRecord getThreadRecord(@Nullable Long threadId) {
|
||||||
if (threadId == null) {
|
if (threadId == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,6 +44,7 @@ import org.thoughtcrime.securesms.database.model.MessageRecord;
|
||||||
import org.thoughtcrime.securesms.database.model.MmsMessageRecord;
|
import org.thoughtcrime.securesms.database.model.MmsMessageRecord;
|
||||||
import org.thoughtcrime.securesms.database.model.ReactionRecord;
|
import org.thoughtcrime.securesms.database.model.ReactionRecord;
|
||||||
import org.thoughtcrime.securesms.database.model.StickerRecord;
|
import org.thoughtcrime.securesms.database.model.StickerRecord;
|
||||||
|
import org.thoughtcrime.securesms.database.model.ThreadRecord;
|
||||||
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies;
|
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies;
|
||||||
import org.thoughtcrime.securesms.groups.BadGroupIdException;
|
import org.thoughtcrime.securesms.groups.BadGroupIdException;
|
||||||
import org.thoughtcrime.securesms.groups.GroupChangeBusyException;
|
import org.thoughtcrime.securesms.groups.GroupChangeBusyException;
|
||||||
|
@ -726,26 +727,49 @@ public final class MessageContentProcessor {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Recipient targetAuthor = Recipient.externalPush(context, reaction.getTargetAuthor());
|
Recipient reactionAuthor = Recipient.externalHighTrustPush(context, content.getSender());
|
||||||
MessageRecord targetMessage = DatabaseFactory.getMmsSmsDatabase(context).getMessageFor(reaction.getTargetSentTimestamp(), targetAuthor.getId());
|
Recipient targetAuthor = Recipient.externalPush(context, reaction.getTargetAuthor());
|
||||||
|
MessageRecord targetMessage = DatabaseFactory.getMmsSmsDatabase(context).getMessageFor(reaction.getTargetSentTimestamp(), targetAuthor.getId());
|
||||||
|
|
||||||
if (targetMessage != null && !targetMessage.isRemoteDelete()) {
|
if (targetMessage == null) {
|
||||||
Recipient reactionAuthor = Recipient.externalHighTrustPush(context, content.getSender());
|
warn(String.valueOf(content.getTimestamp()), "[handleReaction] Could not find matching message! Putting it in the early message cache. timestamp: " + reaction.getTargetSentTimestamp() + " author: " + targetAuthor.getId());
|
||||||
MessageDatabase db = targetMessage.isMms() ? DatabaseFactory.getMmsDatabase(context) : DatabaseFactory.getSmsDatabase(context);
|
|
||||||
|
|
||||||
if (reaction.isRemove()) {
|
|
||||||
db.deleteReaction(targetMessage.getId(), reactionAuthor.getId());
|
|
||||||
ApplicationDependencies.getMessageNotifier().updateNotification(context);
|
|
||||||
} else {
|
|
||||||
ReactionRecord reactionRecord = new ReactionRecord(reaction.getEmoji(), reactionAuthor.getId(), message.getTimestamp(), System.currentTimeMillis());
|
|
||||||
db.addReaction(targetMessage.getId(), reactionRecord);
|
|
||||||
ApplicationDependencies.getMessageNotifier().updateNotification(context, targetMessage.getThreadId(), false);
|
|
||||||
}
|
|
||||||
} else if (targetMessage != null) {
|
|
||||||
warn(String.valueOf(content.getTimestamp()), "[handleReaction] Found a matching message, but it's flagged as remotely deleted. timestamp: " + reaction.getTargetSentTimestamp() + " author: " + targetAuthor.getId());
|
|
||||||
} else {
|
|
||||||
warn(String.valueOf(content.getTimestamp()), "[handleReaction] Could not find matching message! timestamp: " + reaction.getTargetSentTimestamp() + " author: " + targetAuthor.getId());
|
|
||||||
ApplicationDependencies.getEarlyMessageCache().store(targetAuthor.getId(), reaction.getTargetSentTimestamp(), content);
|
ApplicationDependencies.getEarlyMessageCache().store(targetAuthor.getId(), reaction.getTargetSentTimestamp(), content);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (targetMessage.isRemoteDelete()) {
|
||||||
|
warn(String.valueOf(content.getTimestamp()), "[handleReaction] Found a matching message, but it's flagged as remotely deleted. timestamp: " + reaction.getTargetSentTimestamp() + " author: " + targetAuthor.getId());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ThreadRecord targetThread = DatabaseFactory.getThreadDatabase(context).getThreadRecord(targetMessage.getThreadId());
|
||||||
|
|
||||||
|
if (targetThread == null) {
|
||||||
|
warn(String.valueOf(content.getTimestamp()), "[handleReaction] Could not find a thread for the message! timestamp: " + reaction.getTargetSentTimestamp() + " author: " + targetAuthor.getId());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Recipient threadRecipient = targetThread.getRecipient().resolve();
|
||||||
|
|
||||||
|
if (threadRecipient.isGroup() && !threadRecipient.getParticipants().contains(reactionAuthor)) {
|
||||||
|
warn(String.valueOf(content.getTimestamp()), "[handleReaction] Reaction author is not in the group! timestamp: " + reaction.getTargetSentTimestamp() + " author: " + targetAuthor.getId());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!threadRecipient.isGroup() && !reactionAuthor.equals(threadRecipient) && !reactionAuthor.isSelf()) {
|
||||||
|
warn(String.valueOf(content.getTimestamp()), "[handleReaction] Reaction author is not a part of the 1:1 thread! timestamp: " + reaction.getTargetSentTimestamp() + " author: " + targetAuthor.getId());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
MessageDatabase db = targetMessage.isMms() ? DatabaseFactory.getMmsDatabase(context) : DatabaseFactory.getSmsDatabase(context);
|
||||||
|
|
||||||
|
if (reaction.isRemove()) {
|
||||||
|
db.deleteReaction(targetMessage.getId(), reactionAuthor.getId());
|
||||||
|
ApplicationDependencies.getMessageNotifier().updateNotification(context);
|
||||||
|
} else {
|
||||||
|
ReactionRecord reactionRecord = new ReactionRecord(reaction.getEmoji(), reactionAuthor.getId(), message.getTimestamp(), System.currentTimeMillis());
|
||||||
|
db.addReaction(targetMessage.getId(), reactionRecord);
|
||||||
|
ApplicationDependencies.getMessageNotifier().updateNotification(context, targetMessage.getThreadId(), false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue