Skip to content

Commit

Permalink
Do not notify for reactions if not the group story sender.
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-signal authored and greyson-signal committed Jul 5, 2022
1 parent 6d24c34 commit bd5907e
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 3 deletions.
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
}
@@ -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
Expand All @@ -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(
Expand All @@ -34,8 +37,8 @@ object MmsHelper {
viewOnce,
distributionType,
storyType,
null,
false,
parentStoryId,
isStoryReaction,
null,
emptyList(),
emptyList(),
Expand Down
Expand Up @@ -885,7 +885,9 @@ public boolean hasSelfReplyInStory(long parentStoryId) {
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)) {
Expand Down

0 comments on commit bd5907e

Please sign in to comment.