From 314fa137e5b8d4ef4d095d2cb5b27a5539151a87 Mon Sep 17 00:00:00 2001 From: Sasha Weiss Date: Tue, 10 Sep 2024 13:28:37 -0700 Subject: [PATCH] Specify recipient IDs for simple chat updates --- .../tests/ChatItemSimpleUpdatesTestCase.kt | 56 ++++++++++++++---- .../chat_item_simple_updates_05.binproto | Bin 431 -> 431 bytes .../chat_item_simple_updates_05.txtproto | 2 +- .../chat_item_simple_updates_06.binproto | Bin 431 -> 453 bytes .../chat_item_simple_updates_06.txtproto | 16 ++++- .../chat_item_simple_updates_07.binproto | Bin 431 -> 431 bytes .../chat_item_simple_updates_07.txtproto | 2 +- .../chat_item_simple_updates_08.binproto | Bin 431 -> 453 bytes .../chat_item_simple_updates_08.txtproto | 16 ++++- .../chat_item_simple_updates_09.binproto | Bin 431 -> 453 bytes .../chat_item_simple_updates_09.txtproto | 16 ++++- .../chat_item_simple_updates_10.binproto | Bin 431 -> 453 bytes .../chat_item_simple_updates_10.txtproto | 16 ++++- .../chat_item_simple_updates_11.binproto | Bin 431 -> 453 bytes .../chat_item_simple_updates_11.txtproto | 16 ++++- .../chat_item_simple_updates_12.binproto | Bin 431 -> 431 bytes .../chat_item_simple_updates_12.txtproto | 2 +- .../chat_item_simple_updates_13.binproto | Bin 431 -> 431 bytes .../chat_item_simple_updates_13.txtproto | 2 +- .../chat_item_simple_updates_14.binproto | Bin 431 -> 431 bytes .../chat_item_simple_updates_14.txtproto | 2 +- .../chat_item_simple_updates_15.binproto | Bin 431 -> 431 bytes .../chat_item_simple_updates_15.txtproto | 2 +- 23 files changed, 127 insertions(+), 21 deletions(-) diff --git a/src/main/kotlin/tests/ChatItemSimpleUpdatesTestCase.kt b/src/main/kotlin/tests/ChatItemSimpleUpdatesTestCase.kt index b281058..7444bba 100644 --- a/src/main/kotlin/tests/ChatItemSimpleUpdatesTestCase.kt +++ b/src/main/kotlin/tests/ChatItemSimpleUpdatesTestCase.kt @@ -18,18 +18,54 @@ object ChatItemSimpleUpdatesTestCase : TestCase("chat_item_simple_updates") { frames += StandardFrames.recipientAlice frames += StandardFrames.chatAlice - frames += Frame( - chatItem = ChatItem( - chatId = StandardFrames.chatAlice.chat!!.id, - authorId = StandardFrames.recipientAlice.recipient!!.id, - dateSent = someNonZeroTimestamp(), - directionless = ChatItem.DirectionlessMessageDetails(), - updateMessage = ChatUpdateMessage( - simpleUpdate = SimpleChatUpdate( - type = someEnum(SimpleChatUpdate.Type::class.java, excluding = SimpleChatUpdate.Type.UNKNOWN) + // Generate timestamps for as many frames as we might want to add depending + // on simpleChatUpdate. (We need to register the max number of generators + // we might eventually use, up-front.) + val dateSentTimestamps = listOf(someNonZeroTimestamp(), someNonZeroTimestamp()) + + val simpleChatUpdate = someEnum(SimpleChatUpdate.Type::class.java, excluding = SimpleChatUpdate.Type.UNKNOWN) + + val selfRecipientId = StandardFrames.recipientSelf.recipient!!.id + val aliceRecipientId = StandardFrames.recipientAlice.recipient!!.id + val releaseNotesRecipientId = StandardFrames.recipientReleaseNotes.recipient!!.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 = when (simpleChatUpdate) { + // ...and release note donation requests should come from the release + // notes recipient. + SimpleChatUpdate.Type.RELEASE_CHANNEL_DONATION_REQUEST -> listOf(releaseNotesRecipientId) + SimpleChatUpdate.Type.IDENTITY_UPDATE, + SimpleChatUpdate.Type.IDENTITY_VERIFIED, + SimpleChatUpdate.Type.IDENTITY_DEFAULT, + SimpleChatUpdate.Type.JOINED_SIGNAL, + SimpleChatUpdate.Type.CHANGE_NUMBER -> listOf(aliceRecipientId) + SimpleChatUpdate.Type.CHAT_SESSION_REFRESH, + SimpleChatUpdate.Type.REPORTED_SPAM, + SimpleChatUpdate.Type.BLOCKED, + SimpleChatUpdate.Type.UNBLOCKED, + SimpleChatUpdate.Type.MESSAGE_REQUEST_ACCEPTED -> listOf(selfRecipientId) + 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) + // Impossible, checked above. + SimpleChatUpdate.Type.UNKNOWN -> listOf() + } + + for ((idx, authorId) in authorIds.withIndex()) { + frames += Frame( + chatItem = ChatItem( + chatId = StandardFrames.chatAlice.chat!!.id, + authorId = authorId, + dateSent = dateSentTimestamps[idx], + directionless = ChatItem.DirectionlessMessageDetails(), + updateMessage = ChatUpdateMessage( + simpleUpdate = SimpleChatUpdate(type = simpleChatUpdate) ) ) ) - ) + } } } diff --git a/test-cases/chat_item_simple_updates_05.binproto b/test-cases/chat_item_simple_updates_05.binproto index 4c2f9560df486d071d6a2c81a83c4fa84fe9e0ed..e33e06bfc33412cf287d5c1d2d9142c1a8eef590 100644 GIT binary patch delta 24 gcmZ3_yqpF diff --git a/test-cases/chat_item_simple_updates_07.txtproto b/test-cases/chat_item_simple_updates_07.txtproto index c30123d..c37e6dc 100644 --- a/test-cases/chat_item_simple_updates_07.txtproto +++ b/test-cases/chat_item_simple_updates_07.txtproto @@ -114,7 +114,7 @@ Frame { Frame { chatItem = ChatItem { - authorId = 4 + authorId = 1 chatId = 2 dateSent = 1695248715439 directionless = DirectionlessMessageDetails {} diff --git a/test-cases/chat_item_simple_updates_08.binproto b/test-cases/chat_item_simple_updates_08.binproto index a89b0977e64ea01f85ff2be87241bd8526f6d5a2..b5d42bb993934785cbeed98f6a19785f6425e2c7 100644 GIT binary patch delta 46 vcmZ3_e3W^^d`2}!i5rVwZ(U~^#8Ab;#l*oWswB+8B)}r^`T6WO3*e#vW!DXu delta 24 gcmX@gyqV!Z delta 24 gcmZ3_yqX8-^I delta 24 gcmZ3_yq