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 for member based channel #586

Merged
merged 24 commits into from
Jan 20, 2021
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
32cc933
Merge branch 'master' of github.com:GetStream/stream-chat-js into vis…
vishalnarkhede Jan 4, 2021
5f16699
Ensure unique member based channel on client
vishalnarkhede Jan 15, 2021
38bfcb9
Merge branch 'master' into vishal/thread_participants_type
vishalnarkhede Jan 15, 2021
8852374
Adding test
vishalnarkhede Jan 15, 2021
30841cd
Merge branch 'vishal/thread_participants_type' of github.com:GetStrea…
vishalnarkhede Jan 15, 2021
506d6be
Updated the test
vishalnarkhede Jan 15, 2021
40bc02c
Merge branch 'master' into vishal/thread_participants_type
Jan 15, 2021
de2ce01
Cover the edge cases of channel creation
vishalnarkhede Jan 18, 2021
3491ee4
Merge branch 'vishal/thread_participants_type' of github.com:GetStrea…
vishalnarkhede Jan 18, 2021
39d3db1
Adding channelType to temporary cid of unique conversation
vishalnarkhede Jan 18, 2021
877bb57
Fixing members related error
vishalnarkhede Jan 18, 2021
3abf6c9
Update test title
Jan 18, 2021
9065826
Fixing comments
vishalnarkhede Jan 18, 2021
5b6d6b9
Merge branch 'vishal/thread_participants_type' of github.com:GetStrea…
vishalnarkhede Jan 18, 2021
f8e9e72
Fixing comment grammer
vishalnarkhede Jan 18, 2021
763c4ab
Merge branch 'master' into vishal/thread_participants_type
vishalnarkhede Jan 18, 2021
3ff1be9
Merge branch 'master' into vishal/thread_participants_type
vishalnarkhede Jan 18, 2021
fcba1a6
Updated temporary cid for member based channels, to keep it consisten…
vishalnarkhede Jan 19, 2021
ba0d5c3
Merge github.com:GetStream/stream-chat-js into vishal/thread_particip…
vishalnarkhede Jan 19, 2021
21c2664
Merge branch 'vishal/thread_participants_type' of github.com:GetStrea…
vishalnarkhede Jan 19, 2021
f4cb2aa
Fixing code comment
vishalnarkhede Jan 19, 2021
f24efb7
Fixing tempCid cleanup from activeChannels
vishalnarkhede Jan 20, 2021
4ef8f28
Fixing memberStr during channel.query
vishalnarkhede Jan 20, 2021
9c7abc8
Moving test to unit-test
vishalnarkhede Jan 20, 2021
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
15 changes: 15 additions & 0 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1513,6 +1513,21 @@ export class StreamChat<
}
// support channel("messaging", {options})
if (typeof channelIDOrCustom === 'object') {
// Check if the channel already exists.
// Only allow 1 channel object per cid
for (const cid in this.activeChannels) {
if (cid.indexOf(`${channelType}:!members-`) === 0) {
const channel = this.activeChannels[cid];
const membersStrInExistingChannel = Object.keys(channel.state.members)
.sort()
.join(',');
const membersStr = channelIDOrCustom.members?.sort().join(',');
if (membersStrInExistingChannel === membersStr) {
return channel;
}
}
}

return new Channel<
AttachmentType,
ChannelType,
Expand Down
32 changes: 32 additions & 0 deletions test/integration/channels.js
Original file line number Diff line number Diff line change
Expand Up @@ -2975,3 +2975,35 @@ describe('Channel - isUpToDate', async () => {
).to.be.equal(-1);
});
});

describe('Ensure single channel per cid on client', async () => {
mahboubii marked this conversation as resolved.
Show resolved Hide resolved
it('channel created using id', async () => {
const userIdVish = 'vishal';
const userIdAmin = 'amin';
await createUsers([userIdVish, userIdAmin]);

const clientVish = await getTestClientForUser(userIdVish);
const channelVishId = uuidv4();
const channelVish_copy1 = clientVish.channel('messaging', channelVishId);
await channelVish_copy1.watch();

const channelVish_copy2 = clientVish.channel('messaging', channelVishId);

expect(channelVish_copy1).to.be.equal(channelVish_copy2);
});
it('channel created using member list', async () => {
const userIdVish = 'vishal';
const userIdAmin = 'amin';
await createUsers([userIdVish, userIdAmin]);

const clientVish = await getTestClientForUser(userIdVish);
const channelVish_copy1 = clientVish.channel('messaging', {
members: ['amin', 'vishal'],
});
await channelVish_copy1.watch();
const channelVish_copy2 = clientVish.channel('messaging', {
members: ['amin', 'vishal'],
vishalnarkhede marked this conversation as resolved.
Show resolved Hide resolved
});
expect(channelVish_copy1).to.be.equal(channelVish_copy2);
});
});