From 553689a3b4d0c18bd07a1b18b21491eec8aa4017 Mon Sep 17 00:00:00 2001 From: Amin Mahboubi Date: Tue, 9 Feb 2021 16:02:43 +0100 Subject: [PATCH] chore: rm deprecated functions --- src/client.ts | 63 ++----------------- src/token_manager.ts | 2 +- test/integration/test.js | 4 +- test/typescript/index.js | 12 ++-- test/typescript/response-generators/client.js | 14 ++--- .../typescript/response-generators/message.js | 6 +- .../response-generators/moderation.js | 12 ++-- .../response-generators/update-users.js | 10 +-- test/typescript/utils.js | 2 +- test/unit/client.js | 2 +- 10 files changed, 37 insertions(+), 90 deletions(-) diff --git a/src/client.ts b/src/client.ts index 02da1f9ab..ad60c32bd 100644 --- a/src/client.ts +++ b/src/client.ts @@ -515,22 +515,6 @@ export class StreamChat< return this.setUserPromise; }; - /** - * @deprecated Please use connectUser() function instead. Its naming is more consistent with its functionality. - * - * setUser - Set the current user and open a WebSocket connection - * - * @param {OwnUserResponse | UserResponse} user Data about this user. IE {name: "john"} - * @param {TokenOrProvider} userTokenOrProvider Token or provider - * - * @return {ConnectAPIResponse} Returns a promise that resolves when the connection is setup - */ - setUser = ( - user: OwnUserResponse | UserResponse, - userTokenOrProvider: TokenOrProvider, - ): ConnectAPIResponse => - this.connectUser(user, userTokenOrProvider); - _setToken = (user: UserResponse, userTokenOrProvider: TokenOrProvider) => this.tokenManager.setTokenOrProvider(userTokenOrProvider, user); @@ -691,11 +675,6 @@ export class StreamChat< return this._setupConnection(); }; - /** - * @deprecated Please use connectAnonymousUser. Its naming is more consistent with its functionality. - */ - setAnonymousUser = () => this.connectAnonymousUser(); - /** * setGuestUser - Setup a temporary guest user * @@ -1764,19 +1743,6 @@ export class StreamChat< return channel; }; - /** - * @deprecated Please use upsertUser() function instead. - * - * updateUser - Update or Create the given user object - * - * @param {UserResponse} userObject user object, the only required field is the user id. IE {id: "myuser"} is valid - * - * @return {Promise } }>} - */ - async updateUser(userObject: UserResponse) { - return await this.upsertUsers([userObject]); - } - /** * partialUpdateUser - Update the given user object * @@ -1825,19 +1791,6 @@ export class StreamChat< return this.upsertUsers([userObject]); } - /** - * @deprecated Please use upsertUsers() function instead. - * - * updateUsers - Batch update the list of users - * - * @param {UserResponse[]} users list of users - * - * @return {Promise } }>} - */ - updateUsers(users: UserResponse[]) { - return this.upsertUsers(users); - } - /** * partialUpdateUsers - Batch partial update of users * @@ -2021,14 +1974,15 @@ export class StreamChat< }); } - /** userMuteStatus - check if a user is muted or not, can be used after setUser() is called + /** userMuteStatus - check if a user is muted or not, can be used after connectUser() is called * * @param {string} targetID * @returns {boolean} */ userMuteStatus(targetID: string) { - if (!this.user || !this.wsPromise) - throw new Error('Make sure to await setUser() first.'); + if (!this.user || !this.wsPromise) { + throw new Error('Make sure to await connectUser() first.'); + } for (let i = 0; i < this.mutedUsers.length; i += 1) { if (this.mutedUsers[i].target.id === targetID) return true; @@ -2357,13 +2311,6 @@ export class StreamChat< >(this.baseURL + `/messages/${messageID}`); } - /** - * @deprecated Please use getUserAgent instead - */ - _userAgent() { - return this.getUserAgent(); - } - getUserAgent() { return ( this.userAgent || @@ -2401,7 +2348,7 @@ export class StreamChat< headers: { Authorization: token, 'stream-auth-type': this.getAuthType(), - 'x-stream-client': this._userAgent(), + 'x-stream-client': this.getUserAgent(), ...options.headers, }, ...options.config, diff --git a/src/token_manager.ts b/src/token_manager.ts index 2c755ddd8..298c4ae4e 100644 --- a/src/token_manager.ts +++ b/src/token_manager.ts @@ -146,7 +146,7 @@ export class TokenManager { } throw new Error( - `Both secret and user tokens are not set. Either client.setUser wasn't called or client.disconnect was called`, + `Both secret and user tokens are not set. Either client.connectUser wasn't called or client.disconnect was called`, ); }; diff --git a/test/integration/test.js b/test/integration/test.js index 378171a69..585755422 100644 --- a/test/integration/test.js +++ b/test/integration/test.js @@ -376,7 +376,7 @@ describe('Chat', () => { describe('User is not set', () => { it('device management does not work', async () => { - const errorMsg = `Both secret and user tokens are not set. Either client.setUser wasn't called or client.disconnect was called`; + const errorMsg = `Both secret and user tokens are not set. Either client.connectUser wasn't called or client.disconnect was called`; await expect(client.addDevice(deviceId, 'apn')).to.be.rejectedWith( errorMsg, ); @@ -839,7 +839,7 @@ describe('Chat', () => { await chan.watch(); await client2.disconnect(5000); - const errorMsg = `Both secret and user tokens are not set. Either client.setUser wasn't called or client.disconnect was called`; + const errorMsg = `Both secret and user tokens are not set. Either client.connectUser wasn't called or client.disconnect was called`; let p = client2.addDevice('deviceID', 'apn'); await expect(p).to.be.rejectedWith(errorMsg); diff --git a/test/typescript/index.js b/test/typescript/index.js index 2dedffd74..088f7828a 100644 --- a/test/typescript/index.js +++ b/test/typescript/index.js @@ -424,10 +424,10 @@ const executables = [ "Unpacked['sendReaction']>>", }, { - f: rg.setAnonymousUser, + f: rg.connectAnonymousUser, imports: ['StreamChat', 'Unpacked'], type: - "Unpacked['setAnonymousUser']>>", + "Unpacked['connectAnonymousUser']>>", }, { f: rg.setGuestUser, @@ -436,10 +436,10 @@ const executables = [ "Unpacked['setGuestUser']>>", }, { - f: rg.setUser, + f: rg.connectUser, imports: ['StreamChat', 'Unpacked'], type: - "Unpacked['setUser']>>", + "Unpacked['connectUser']>>", }, { f: rg.show, @@ -557,10 +557,10 @@ const executables = [ "Unpacked['updatePermission']>>", }, { - f: rg.updateUsers, + f: rg.upsertUsers, imports: ['StreamChat', 'Unpacked'], type: - "Unpacked['updateUsers']>>", + "Unpacked['upsertUsers']>>", }, { f: rg.upsertUser, diff --git a/test/typescript/response-generators/client.js b/test/typescript/response-generators/client.js index 281a1698e..e0e98638a 100644 --- a/test/typescript/response-generators/client.js +++ b/test/typescript/response-generators/client.js @@ -10,7 +10,7 @@ async function addDevice() { async function connect() { const authClient = await utils.getTestClient(true); - await authClient.setAnonymousUser(); + await authClient.connectAnonymousUser(); return await authClient.connect(); } @@ -47,7 +47,7 @@ async function deleteCommand() { async function disconnect() { const authClient = await utils.getTestClient(true); - await authClient.setAnonymousUser(); + await authClient.connectAnonymousUser(); await authClient.connect(); return await authClient.disconnect(); } @@ -114,9 +114,9 @@ async function queryUsers() { return await client.queryUsers({ nickname: { $eq: user2 } }); } -async function setAnonymousUser() { +async function connectAnonymousUser() { const authClient = await utils.getTestClient(true); - return await authClient.setAnonymousUser(); + return await authClient.connectAnonymousUser(); } async function setGuestUser() { @@ -124,7 +124,7 @@ async function setGuestUser() { return await authClient.setGuestUser({ id: 'steven' }); } -async function setUser() { +async function connectUser() { const user1 = uuidv4(); const user2 = uuidv4(); await utils.createUsers([user1, user2]); @@ -192,9 +192,9 @@ module.exports = { listCommands, markAllRead, queryUsers, - setAnonymousUser, + connectAnonymousUser, setGuestUser, - setUser, + connectUser, sync, updateAppSettings, updateCommand, diff --git a/test/typescript/response-generators/message.js b/test/typescript/response-generators/message.js index 9e83ec17c..033024241 100644 --- a/test/typescript/response-generators/message.js +++ b/test/typescript/response-generators/message.js @@ -51,8 +51,8 @@ async function getReplies() { instrument: 'saxophone', }; - await utils.getTestClient(true).updateUser(thierry); - await utils.getTestClient(true).updateUser({ id: userID, instrument: 'guitar' }); + await utils.getTestClient(true).upsertUser(thierry); + await utils.getTestClient(true).upsertUser({ id: userID, instrument: 'guitar' }); const channel = serverAuthClient.channel('team', channelID, { created_by: { id: thierry.id }, members: [userID, thierry.id], @@ -107,7 +107,7 @@ async function translateMessage() { async function updateMessage() { const authClient = await utils.getTestClientForUser(johnID, {}); const userID = 'tommaso-' + uuidv4(); - await utils.getTestClient(true).updateUser({ id: userID }); + await utils.getTestClient(true).upsertUser({ id: userID }); const channel = authClient.channel('messaging', `poppins-${uuidv4()}`, { members: [userID], }); diff --git a/test/typescript/response-generators/moderation.js b/test/typescript/response-generators/moderation.js index f06f7e15f..20d69d68a 100644 --- a/test/typescript/response-generators/moderation.js +++ b/test/typescript/response-generators/moderation.js @@ -109,7 +109,7 @@ async function flagMessage() { role: 'admin', }; - await serverAuthClient.updateUsers([thierry, tommaso, { id: 'thierry' }]); + await serverAuthClient.upsertUsers([thierry, tommaso, { id: 'thierry' }]); // delete thierry.role; // await isn't needed but makes testing a bit easier await authClient.connectUser(thierry); @@ -144,7 +144,7 @@ async function flagUser() { role: 'admin', }; - await serverAuthClient.updateUsers([thierry, tommaso, { id: 'thierry' }]); + await serverAuthClient.upsertUsers([thierry, tommaso, { id: 'thierry' }]); // delete thierry.role; // await isn't needed but makes testing a bit easier await authClient.connectUser(thierry); @@ -160,7 +160,7 @@ async function flagUser() { const modUserID = uuidv4(); await utils.createUsers([modUserID]); - await serverAuthClient.updateUser(evil); + await serverAuthClient.upsertUser(evil); return await authClient.flagUser(evilId); } @@ -263,7 +263,7 @@ async function unflagMessage() { role: 'admin', }; - await serverAuthClient.updateUsers([thierry, tommaso, { id: 'thierry' }]); + await serverAuthClient.upsertUsers([thierry, tommaso, { id: 'thierry' }]); // delete thierry.role; // await isn't needed but makes testing a bit easier await authClient.connectUser(thierry); @@ -308,14 +308,14 @@ async function unflagUser() { role: 'admin', }; - await serverAuthClient.updateUsers([thierry, tommaso, { id: 'thierry' }]); + await serverAuthClient.upsertUsers([thierry, tommaso, { id: 'thierry' }]); // delete thierry.role; // await isn't needed but makes testing a bit easier await authClient.connectUser(thierry); const modUserID = uuidv4(); await utils.createUsers([modUserID]); - await serverAuthClient.updateUser(evil); + await serverAuthClient.upsertUser(evil); await authClient.flagUser(evilId); diff --git a/test/typescript/response-generators/update-users.js b/test/typescript/response-generators/update-users.js index ea82409bd..313bc0b7d 100644 --- a/test/typescript/response-generators/update-users.js +++ b/test/typescript/response-generators/update-users.js @@ -46,7 +46,7 @@ async function partialUpdateUser() { const userID = uuid4(); const unique = uuid4(); - await client.updateUsers([ + await client.upsertUsers([ { id: userID, unique, @@ -72,7 +72,7 @@ async function partialUpdateUsers() { const userID3 = uuid4(); const unique = uuid4(); - await client.updateUsers([ + await client.upsertUsers([ { id: userID, unique, @@ -135,14 +135,14 @@ async function reactivateUser() { return await client.reactivateUser(userID); } -async function updateUsers() { +async function upsertUsers() { const client = utils.getServerTestClient(); const userID = uuid4(); const userID2 = uuid4(); const userID3 = uuid4(); const unique = uuid4(); - return await client.updateUsers([ + return await client.upsertUsers([ { id: userID, unique, @@ -178,6 +178,6 @@ module.exports = { partialUpdateUser, partialUpdateUsers, reactivateUser, - updateUsers, + upsertUsers, upsertUser, }; diff --git a/test/typescript/utils.js b/test/typescript/utils.js index d76d5ca50..154fa6625 100644 --- a/test/typescript/utils.js +++ b/test/typescript/utils.js @@ -10,7 +10,7 @@ module.exports = { for (const userID of userIDs) { users.push({ id: userID, ...additionalInfo }); } - return await serverClient.updateUsers(users); + return await serverClient.upsertUsers(users); }, createUserToken: function createUserToken(userID) { const chat = new StreamChat(apiKey, apiSecret); diff --git a/test/unit/client.js b/test/unit/client.js index f5808b84c..91d95201d 100644 --- a/test/unit/client.js +++ b/test/unit/client.js @@ -75,7 +75,7 @@ describe('Client userMuteStatus', function () { expect(client.mutedUsers).to.have.length(0); }); - it('should throw error if setUser is not called', function () { + it('should throw error if connectUser is not called', function () { expect(() => client.userMuteStatus('')).to.throw(); });