Skip to content

Commit

Permalink
Ensure release note simple updates are in release notes chat.
Browse files Browse the repository at this point in the history
Co-authored-by: Greyson Parrelli <[email protected]>
  • Loading branch information
trevor-signal and greyson-signal authored Nov 16, 2024
1 parent d271842 commit c23600b
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 9 deletions.
8 changes: 8 additions & 0 deletions src/main/kotlin/StandardFrames.kt
Original file line number Diff line number Diff line change
Expand Up @@ -282,4 +282,12 @@ object StandardFrames {
expireTimerVersion = 1
)
)

val chatReleaseNotes = Frame(
chat = Chat(
id = 4,
recipientId = recipientReleaseNotes.recipient!!.id,
expireTimerVersion = 1
)
)
}
29 changes: 21 additions & 8 deletions src/main/kotlin/tests/ChatItemSimpleUpdatesTestCase.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,36 +29,42 @@ object ChatItemSimpleUpdatesTestCase : TestCase("chat_item_simple_updates") {
val selfRecipientId = StandardFrames.recipientSelf.recipient!!.id
val aliceRecipientId = StandardFrames.recipientAlice.recipient!!.id
val releaseNotesRecipientId = StandardFrames.recipientReleaseNotes.recipient!!.id
val aliceChatId = StandardFrames.chatAlice.chat!!.id
val releaseNotesChatId = StandardFrames.chatReleaseNotes.chat!!.id

// Some simple chat updates can originate from the local user or a remote
// user, while some are necessarily from one or the other.
val authorIds: List<Long> = when (simpleChatUpdate) {
val authorData: AuthorData = when (simpleChatUpdate) {
// ...and release note donation requests should come from the release
// notes recipient.
SimpleChatUpdate.Type.RELEASE_CHANNEL_DONATION_REQUEST -> listOf(releaseNotesRecipientId)
SimpleChatUpdate.Type.RELEASE_CHANNEL_DONATION_REQUEST -> AuthorData(releaseNotesRecipientId, releaseNotesChatId)
SimpleChatUpdate.Type.IDENTITY_UPDATE,
SimpleChatUpdate.Type.IDENTITY_VERIFIED,
SimpleChatUpdate.Type.IDENTITY_DEFAULT,
SimpleChatUpdate.Type.JOINED_SIGNAL,
SimpleChatUpdate.Type.CHANGE_NUMBER -> listOf(aliceRecipientId)
SimpleChatUpdate.Type.CHANGE_NUMBER -> AuthorData(aliceRecipientId, aliceChatId)
SimpleChatUpdate.Type.CHAT_SESSION_REFRESH,
SimpleChatUpdate.Type.REPORTED_SPAM,
SimpleChatUpdate.Type.BLOCKED,
SimpleChatUpdate.Type.UNBLOCKED,
SimpleChatUpdate.Type.MESSAGE_REQUEST_ACCEPTED -> listOf(selfRecipientId)
SimpleChatUpdate.Type.MESSAGE_REQUEST_ACCEPTED -> AuthorData(selfRecipientId, aliceChatId)
SimpleChatUpdate.Type.END_SESSION,
SimpleChatUpdate.Type.BAD_DECRYPT,
SimpleChatUpdate.Type.PAYMENTS_ACTIVATED,
SimpleChatUpdate.Type.PAYMENT_ACTIVATION_REQUEST,
SimpleChatUpdate.Type.UNSUPPORTED_PROTOCOL_MESSAGE -> listOf(selfRecipientId, aliceRecipientId)
SimpleChatUpdate.Type.UNSUPPORTED_PROTOCOL_MESSAGE -> AuthorData(listOf(selfRecipientId, aliceRecipientId), aliceChatId)
// Impossible, checked above.
SimpleChatUpdate.Type.UNKNOWN -> listOf()
SimpleChatUpdate.Type.UNKNOWN -> throw AssertionError("Impossible")
}

for ((idx, authorId) in authorIds.withIndex()) {
for ((idx, authorId) in authorData.possibleAuthorIds.withIndex()) {
if (authorData.chatId == releaseNotesChatId) {
frames += StandardFrames.chatReleaseNotes
}

frames += Frame(
chatItem = ChatItem(
chatId = StandardFrames.chatAlice.chat!!.id,
chatId = authorData.chatId,
authorId = authorId,
dateSent = dateSentTimestamps[idx],
directionless = ChatItem.DirectionlessMessageDetails(),
Expand All @@ -69,4 +75,11 @@ object ChatItemSimpleUpdatesTestCase : TestCase("chat_item_simple_updates") {
)
}
}

data class AuthorData(
val possibleAuthorIds: List<Long>,
val chatId: Long
) {
constructor(authorId: Long, chatId: Long) : this(listOf(authorId), chatId)
}
}
Binary file modified test-cases/chat_item_simple_updates_05.binproto
Binary file not shown.
10 changes: 9 additions & 1 deletion test-cases/chat_item_simple_updates_05.txtproto
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,18 @@ Frame {
}
}

Frame {
chat = Chat {
expireTimerVersion = 1
id = 4
recipientId = 2
}
}

Frame {
chatItem = ChatItem {
authorId = 2
chatId = 2
chatId = 4
dateSent = 1833527071197
directionless = DirectionlessMessageDetails {}
updateMessage = ChatUpdateMessage {
Expand Down

0 comments on commit c23600b

Please sign in to comment.