diff --git a/lib/GetStream/StreamChat/Client.php b/lib/GetStream/StreamChat/Client.php index 3cd67cd..7ca49bb 100644 --- a/lib/GetStream/StreamChat/Client.php +++ b/lib/GetStream/StreamChat/Client.php @@ -294,9 +294,21 @@ public function getAppSettings(): StreamResponse */ public function updateAppSettings(array $settings): StreamResponse { + $settings = $this->mapAppSettingsBackwardsCompatibility($settings); return $this->patch("app", $settings); } + /** Maps backwards compatible attribute names for app settings. + * @internal + */ + private function mapAppSettingsBackwardsCompatibility(array $settings): array + { + if (isset($settings['reminders_interval'])) { + $settings['message_re_engagement_hooks_interval'] = $settings['reminders_interval']; + } + return $settings; + } + /** Sends a test push. * @link https://getstream.io/chat/docs/php/push_introduction/?language=php * @throws StreamException @@ -959,9 +971,21 @@ public function listChannelTypes(): StreamResponse */ public function updateChannelType(string $channelTypeName, array $settings): StreamResponse { + $settings = $this->mapChannelTypeBackwardsCompatibility($settings); return $this->put("channeltypes/" . $channelTypeName, $settings); } + /** Maps backwards compatible attribute names for channel type settings. + * @internal + */ + private function mapChannelTypeBackwardsCompatibility(array $settings): array + { + if (isset($settings['reminders'])) { + $settings['message_re_engagement_hooks'] = $settings['reminders']; + } + return $settings; + } + /** Deletes a channel type. * @link https://getstream.io/chat/docs/php/channel_features/?language=php * @throws StreamException diff --git a/tests/integration/IntegrationTest.php b/tests/integration/IntegrationTest.php index 34f4b61..a7b171d 100644 --- a/tests/integration/IntegrationTest.php +++ b/tests/integration/IntegrationTest.php @@ -1828,4 +1828,77 @@ public function testSharedLocations() $this->assertEquals(-118.2437, $newUserLocations["active_live_locations"][0]["longitude"]); $this->assertEquals('test-device-123', $newUserLocations["active_live_locations"][0]["created_by_device_id"]); } + + /** + * Test backwards compatibility for reminders -> message_re_engagement_hooks + * Changes: + * - app_config.reminders_interval -> message_re_engagement_hooks_interval + * - channel_config.reminders -> message_re_engagement_hooks + */ + public function testBackwardsCompatibilityMessageReEngagementHooksIntervalIncludedInAppSettings() + { + $response = $this->client->getAppSettings(); + + $this->assertArrayHasKey('app', $response); + $this->assertArrayHasKey('message_re_engagement_hooks_interval', $response['app']); + $this->assertArrayHasKey('reminders_interval', $response['app']); + } + + public function testBackwardsCompatibilityMessageReEngagementHooksIntervalCanBeChangedServerSide() + { + $this->client->updateAppSettings(['message_re_engagement_hooks_interval' => 68]); + $response = $this->client->getAppSettings(); + + $this->assertEquals(68, $response['app']['message_re_engagement_hooks_interval']); + $this->assertEquals(68, $response['app']['reminders_interval']); + } + + public function testBackwardsCompatibilityCanBeEnabledForChannelType() + { + $response = $this->client->updateChannelType('messaging', [ + 'message_re_engagement_hooks' => true, + ]); + + $this->assertTrue($response['message_re_engagement_hooks']); + $this->assertTrue($response['reminders']); + } + + public function testBackwardsCompatibilityCanBeDisabledForChannelType() + { + $response = $this->client->updateChannelType('messaging', [ + 'message_re_engagement_hooks' => false, + ]); + + $this->assertFalse($response['message_re_engagement_hooks']); + $this->assertFalse($response['reminders']); + } + + public function testBackwardsCompatibilityOldRemindersIntervalStillWorks() + { + $this->client->updateAppSettings(['reminders_interval' => 45]); + $response = $this->client->getAppSettings(); + + $this->assertEquals(45, $response['app']['message_re_engagement_hooks_interval']); + $this->assertEquals(45, $response['app']['reminders_interval']); + } + + public function testBackwardsCompatibilityOldRemindersAttributeCanEnableChannelType() + { + $response = $this->client->updateChannelType('messaging', [ + 'reminders' => true, + ]); + + $this->assertTrue($response['message_re_engagement_hooks']); + $this->assertTrue($response['reminders']); + } + + public function testBackwardsCompatibilityOldRemindersAttributeCanDisableChannelType() + { + $response = $this->client->updateChannelType('messaging', [ + 'reminders' => false, + ]); + + $this->assertFalse($response['message_re_engagement_hooks']); + $this->assertFalse($response['reminders']); + } }