@ermis-network/ermis-chat-sdk 1.0.0 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ermis-network/ermis-chat-sdk",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "Ermis Chat SDK",
5
5
  "author": "Ermis",
6
6
  "homepage": "https://ermis.network/",
package/src/client.ts CHANGED
@@ -1192,11 +1192,13 @@ export class ErmisChat<ErmisChatGenerics extends ExtendableGenerics = DefaultGen
1192
1192
  return await this.post<APIResponse>(this.baseURL + `/channels/${channelType}/${channelId}/unpin`);
1193
1193
  }
1194
1194
 
1195
+ channel(type: string, custom?: ChannelData<ErmisChatGenerics>): Channel<ErmisChatGenerics>;
1196
+ channel(type: string, id: string, custom?: ChannelData<ErmisChatGenerics>): Channel<ErmisChatGenerics>;
1195
1197
  channel(
1196
1198
  channelType: string,
1197
- channelID: string,
1198
- custom: ChannelData<ErmisChatGenerics> = {} as ChannelData<ErmisChatGenerics>,
1199
- ) {
1199
+ channelIDOrCustom?: string | ChannelData<ErmisChatGenerics>,
1200
+ custom?: ChannelData<ErmisChatGenerics>,
1201
+ ): Channel<ErmisChatGenerics> {
1200
1202
  if (!this.userID) {
1201
1203
  throw Error('Call connectUser before creating a channel');
1202
1204
  }
@@ -1205,11 +1207,20 @@ export class ErmisChat<ErmisChatGenerics extends ExtendableGenerics = DefaultGen
1205
1207
  throw Error(`Invalid channel group ${channelType}, can't contain the : character`);
1206
1208
  }
1207
1209
 
1208
- return this.getChannelById(channelType, channelID, custom);
1210
+ let channelID: string | undefined = undefined;
1211
+ let customData = custom || ({} as ChannelData<ErmisChatGenerics>);
1212
+
1213
+ if (typeof channelIDOrCustom === 'string') {
1214
+ channelID = channelIDOrCustom;
1215
+ } else if (typeof channelIDOrCustom === 'object' && channelIDOrCustom !== null) {
1216
+ customData = channelIDOrCustom as ChannelData<ErmisChatGenerics>;
1217
+ }
1218
+
1219
+ return this.getChannelById(channelType, channelID, customData);
1209
1220
  }
1210
1221
 
1211
- getChannelById = (channelType: string, channelID: string, custom: ChannelData<ErmisChatGenerics>) => {
1212
- const cid = `${channelType}:${channelID}`;
1222
+ getChannelById = (channelType: string, channelID: string | undefined, custom: ChannelData<ErmisChatGenerics>) => {
1223
+ const cid = `${channelType}:${channelID || ''}`;
1213
1224
  if (cid in this.activeChannels && !this.activeChannels[cid].disconnected) {
1214
1225
  const channel = this.activeChannels[cid];
1215
1226
  if (Object.keys(custom).length > 0) {