Skip to content

Commit

Permalink
fix: merge custom data with current one rather than override (#1364)
Browse files Browse the repository at this point in the history
  • Loading branch information
isekovanic committed Sep 13, 2024
1 parent bd0f9ae commit ff59d54
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1971,8 +1971,8 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
if (cid in this.activeChannels && !this.activeChannels[cid].disconnected) {
const channel = this.activeChannels[cid];
if (Object.keys(custom).length > 0) {
channel.data = custom;
channel._data = custom;
channel.data = { ...channel.data, ...custom };
channel._data = { ...channel._data, ...custom };
}
return channel;
}
Expand Down
11 changes: 11 additions & 0 deletions test/unit/channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit ff59d54

Please sign in to comment.