Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions lib/GetStream/StreamChat/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
73 changes: 73 additions & 0 deletions tests/integration/IntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
}
}
Loading