Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: merge custom data with current one rather than override #1364

Merged
merged 3 commits into from
Sep 13, 2024
Merged
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
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
Loading