diff --git a/src/client.ts b/src/client.ts index 1319ced23..38af3c5c6 100644 --- a/src/client.ts +++ b/src/client.ts @@ -1971,8 +1971,8 @@ export class StreamChat 0) { - channel.data = custom; - channel._data = custom; + channel.data = { ...channel.data, ...custom }; + channel._data = { ...channel._data, ...custom }; } return channel; } diff --git a/test/unit/channel.js b/test/unit/channel.js index 1a04818ed..b72ec4b61 100644 --- a/test/unit/channel.js +++ b/test/unit/channel.js @@ -779,6 +779,17 @@ describe('Channels - Constructor', function () { done(); }); + it('custom data merges to the right with current data', function (done) { + let channel = client.channel('messaging', 'brand_new_123', { cool: true }); + expect(channel.cid).to.eql('messaging:brand_new_123'); + expect(channel.id).to.eql('brand_new_123'); + expect(channel.data).to.eql({ cool: true }); + channel = client.channel('messaging', 'brand_new_123', { custom_cool: true }); + console.log(channel.data); + expect(channel.data).to.eql({ cool: true, custom_cool: true }); + done(); + }); + it('default options', function (done) { const channel = client.channel('messaging', '123'); expect(channel.cid).to.eql('messaging:123');