From bd5907ea04cb438265366a275ceb1af7be99995d Mon Sep 17 00:00:00 2001 From: Alex Hart Date: Fri, 1 Jul 2022 13:17:27 -0300 Subject: [PATCH] Do not notify for reactions if not the group story sender. --- .../database/MmsDatabaseTest_stories.kt | 95 +++++++++++++++++++ .../securesms/database/MmsHelper.kt | 7 +- .../securesms/database/MmsDatabase.java | 4 +- 3 files changed, 103 insertions(+), 3 deletions(-) diff --git a/app/src/androidTest/java/org/thoughtcrime/securesms/database/MmsDatabaseTest_stories.kt b/app/src/androidTest/java/org/thoughtcrime/securesms/database/MmsDatabaseTest_stories.kt index 774ede0ca..f56328ba7 100644 --- a/app/src/androidTest/java/org/thoughtcrime/securesms/database/MmsDatabaseTest_stories.kt +++ b/app/src/androidTest/java/org/thoughtcrime/securesms/database/MmsDatabaseTest_stories.kt @@ -8,6 +8,7 @@ import org.junit.Before import org.junit.Test import org.junit.runner.RunWith import org.thoughtcrime.securesms.database.model.DistributionListId +import org.thoughtcrime.securesms.database.model.ParentStoryId import org.thoughtcrime.securesms.database.model.StoryType import org.thoughtcrime.securesms.keyvalue.SignalStore import org.thoughtcrime.securesms.mms.IncomingMediaMessage @@ -238,4 +239,98 @@ class MmsDatabaseTest_stories { // THEN assertTrue(result) } + + @Test + fun givenAGroupStoryWithNoReplies_whenICheckHasSelfReplyInGroupStory_thenIExpectFalse() { + // GIVEN + val groupStoryId = MmsHelper.insert( + recipient = myStory, + sentTimeMillis = 200, + storyType = StoryType.STORY_WITH_REPLIES, + threadId = -1L + ) + + // WHEN + val result = mms.hasSelfReplyInGroupStory(groupStoryId) + + // THEN + assertFalse(result) + } + + @Test + fun givenAGroupStoryWithAReplyFromSelf_whenICheckHasSelfReplyInGroupStory_thenIExpectTrue() { + // GIVEN + val groupStoryId = MmsHelper.insert( + recipient = myStory, + sentTimeMillis = 200, + storyType = StoryType.STORY_WITH_REPLIES, + threadId = -1L + ) + + MmsHelper.insert( + recipient = myStory, + sentTimeMillis = 201, + storyType = StoryType.NONE, + parentStoryId = ParentStoryId.GroupReply(groupStoryId) + ) + + // WHEN + val result = mms.hasSelfReplyInGroupStory(groupStoryId) + + // THEN + assertTrue(result) + } + + @Test + fun givenAGroupStoryWithAReactionFromSelf_whenICheckHasSelfReplyInGroupStory_thenIExpectFalse() { + // GIVEN + val groupStoryId = MmsHelper.insert( + recipient = myStory, + sentTimeMillis = 200, + storyType = StoryType.STORY_WITH_REPLIES, + threadId = -1L + ) + + MmsHelper.insert( + recipient = myStory, + sentTimeMillis = 201, + storyType = StoryType.NONE, + parentStoryId = ParentStoryId.GroupReply(groupStoryId), + isStoryReaction = true + ) + + // WHEN + val result = mms.hasSelfReplyInGroupStory(groupStoryId) + + // THEN + assertFalse(result) + } + + @Test + fun givenAGroupStoryWithAReplyFromSomeoneElse_whenICheckHasSelfReplyInGroupStory_thenIExpectFalse() { + // GIVEN + val groupStoryId = MmsHelper.insert( + recipient = myStory, + sentTimeMillis = 200, + storyType = StoryType.STORY_WITH_REPLIES, + threadId = -1L + ) + + MmsHelper.insert( + IncomingMediaMessage( + from = myStory.id, + sentTimeMillis = 201, + serverTimeMillis = 201, + receivedTimeMillis = 202, + parentStoryId = ParentStoryId.GroupReply(groupStoryId) + ), + -1 + ) + + // WHEN + val result = mms.hasSelfReplyInGroupStory(groupStoryId) + + // THEN + assertFalse(result) + } } diff --git a/app/src/androidTest/java/org/thoughtcrime/securesms/database/MmsHelper.kt b/app/src/androidTest/java/org/thoughtcrime/securesms/database/MmsHelper.kt index 00ee18dd9..8c43d0bfc 100644 --- a/app/src/androidTest/java/org/thoughtcrime/securesms/database/MmsHelper.kt +++ b/app/src/androidTest/java/org/thoughtcrime/securesms/database/MmsHelper.kt @@ -1,5 +1,6 @@ package org.thoughtcrime.securesms.database +import org.thoughtcrime.securesms.database.model.ParentStoryId import org.thoughtcrime.securesms.database.model.StoryType import org.thoughtcrime.securesms.database.model.databaseprotos.GiftBadge import org.thoughtcrime.securesms.mms.IncomingMediaMessage @@ -22,6 +23,8 @@ object MmsHelper { distributionType: Int = ThreadDatabase.DistributionTypes.DEFAULT, threadId: Long = 1, storyType: StoryType = StoryType.NONE, + parentStoryId: ParentStoryId? = null, + isStoryReaction: Boolean = false, giftBadge: GiftBadge? = null ): Long { val message = OutgoingMediaMessage( @@ -34,8 +37,8 @@ object MmsHelper { viewOnce, distributionType, storyType, - null, - false, + parentStoryId, + isStoryReaction, null, emptyList(), emptyList(), diff --git a/app/src/main/java/org/thoughtcrime/securesms/database/MmsDatabase.java b/app/src/main/java/org/thoughtcrime/securesms/database/MmsDatabase.java index 199897d8f..4f1278209 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/database/MmsDatabase.java +++ b/app/src/main/java/org/thoughtcrime/securesms/database/MmsDatabase.java @@ -885,7 +885,9 @@ public class MmsDatabase extends MessageDatabase { public boolean hasSelfReplyInGroupStory(long parentStoryId) { SQLiteDatabase db = databaseHelper.getSignalReadableDatabase(); String[] columns = new String[]{"COUNT(*)"}; - String where = PARENT_STORY_ID + " = ? AND (" + getOutgoingTypeClause() + ")"; + String where = PARENT_STORY_ID + " = ? AND (" + + getOutgoingTypeClause() + ") AND (" + + MESSAGE_BOX + " & " + Types.SPECIAL_TYPES_MASK + " != " + Types.SPECIAL_TYPE_STORY_REACTION + ")"; String[] whereArgs = SqlUtil.buildArgs(parentStoryId); try (Cursor cursor = db.query(TABLE_NAME, columns, where, whereArgs, null, null, null, null)) {