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

chore: rm deprecated functions #612

Merged
merged 1 commit into from
Feb 10, 2021
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
63 changes: 5 additions & 58 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ChannelType, CommandType, UserType> | UserResponse<UserType>} user Data about this user. IE {name: "john"}
* @param {TokenOrProvider} userTokenOrProvider Token or provider
*
* @return {ConnectAPIResponse<ChannelType, CommandType, UserType>} Returns a promise that resolves when the connection is setup
*/
setUser = (
user: OwnUserResponse<ChannelType, CommandType, UserType> | UserResponse<UserType>,
userTokenOrProvider: TokenOrProvider,
): ConnectAPIResponse<ChannelType, CommandType, UserType> =>
this.connectUser(user, userTokenOrProvider);

_setToken = (user: UserResponse<UserType>, userTokenOrProvider: TokenOrProvider) =>
this.tokenManager.setTokenOrProvider(userTokenOrProvider, user);

Expand Down Expand Up @@ -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
*
Expand Down Expand Up @@ -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<UserType>} userObject user object, the only required field is the user id. IE {id: "myuser"} is valid
*
* @return {Promise<APIResponse & { users: { [key: string]: UserResponse<UserType> } }>}
*/
async updateUser(userObject: UserResponse<UserType>) {
return await this.upsertUsers([userObject]);
}

/**
* partialUpdateUser - Update the given user object
*
Expand Down Expand Up @@ -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<UserType>[]} users list of users
*
* @return {Promise<APIResponse & { users: { [key: string]: UserResponse<UserType> } }>}
*/
updateUsers(users: UserResponse<UserType>[]) {
return this.upsertUsers(users);
}

/**
* partialUpdateUsers - Batch partial update of users
*
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -2357,13 +2311,6 @@ export class StreamChat<
>(this.baseURL + `/messages/${messageID}`);
}

/**
* @deprecated Please use getUserAgent instead
*/
_userAgent() {
return this.getUserAgent();
}

getUserAgent() {
return (
this.userAgent ||
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/token_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export class TokenManager<UserType extends UnknownType = UnknownType> {
}

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`,
);
};

Expand Down
4 changes: 2 additions & 2 deletions test/integration/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
Expand Down Expand Up @@ -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);
Expand Down
12 changes: 6 additions & 6 deletions test/typescript/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -424,10 +424,10 @@ const executables = [
"Unpacked<ReturnType<Channel<{}, { description?: string }, string & {}, {}, {}, {}, {}>['sendReaction']>>",
},
{
f: rg.setAnonymousUser,
f: rg.connectAnonymousUser,
imports: ['StreamChat', 'Unpacked'],
type:
"Unpacked<ReturnType<StreamChat<{}, {}, string & {}, {}, {}, {}, {}>['setAnonymousUser']>>",
"Unpacked<ReturnType<StreamChat<{}, {}, string & {}, {}, {}, {}, {}>['connectAnonymousUser']>>",
},
{
f: rg.setGuestUser,
Expand All @@ -436,10 +436,10 @@ const executables = [
"Unpacked<ReturnType<StreamChat<{}, {}, string & {}, {}, {}, {}, {}>['setGuestUser']>>",
},
{
f: rg.setUser,
f: rg.connectUser,
imports: ['StreamChat', 'Unpacked'],
type:
"Unpacked<ReturnType<StreamChat<{}, {}, string & {}, {}, {}, {}, {}>['setUser']>>",
"Unpacked<ReturnType<StreamChat<{}, {}, string & {}, {}, {}, {}, {}>['connectUser']>>",
},
{
f: rg.show,
Expand Down Expand Up @@ -557,10 +557,10 @@ const executables = [
"Unpacked<ReturnType<StreamChat<{}, {}, string & {}, {}, {}, {}, {}>['updatePermission']>>",
},
{
f: rg.updateUsers,
f: rg.upsertUsers,
imports: ['StreamChat', 'Unpacked'],
type:
"Unpacked<ReturnType<StreamChat<{}, {}, string & {}, {}, {}, {}, { unique: string }>['updateUsers']>>",
"Unpacked<ReturnType<StreamChat<{}, {}, string & {}, {}, {}, {}, { unique: string }>['upsertUsers']>>",
},
{
f: rg.upsertUser,
Expand Down
14 changes: 7 additions & 7 deletions test/typescript/response-generators/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -114,17 +114,17 @@ 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() {
const authClient = await utils.getTestClient(true);
return await authClient.setGuestUser({ id: 'steven' });
}

async function setUser() {
async function connectUser() {
const user1 = uuidv4();
const user2 = uuidv4();
await utils.createUsers([user1, user2]);
Expand Down Expand Up @@ -192,9 +192,9 @@ module.exports = {
listCommands,
markAllRead,
queryUsers,
setAnonymousUser,
connectAnonymousUser,
setGuestUser,
setUser,
connectUser,
sync,
updateAppSettings,
updateCommand,
Expand Down
6 changes: 3 additions & 3 deletions test/typescript/response-generators/message.js
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down Expand Up @@ -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],
});
Expand Down
12 changes: 6 additions & 6 deletions test/typescript/response-generators/moderation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand Down
10 changes: 5 additions & 5 deletions test/typescript/response-generators/update-users.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ async function partialUpdateUser() {
const userID = uuid4();
const unique = uuid4();

await client.updateUsers([
await client.upsertUsers([
{
id: userID,
unique,
Expand All @@ -72,7 +72,7 @@ async function partialUpdateUsers() {
const userID3 = uuid4();
const unique = uuid4();

await client.updateUsers([
await client.upsertUsers([
{
id: userID,
unique,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -178,6 +178,6 @@ module.exports = {
partialUpdateUser,
partialUpdateUsers,
reactivateUser,
updateUsers,
upsertUsers,
upsertUser,
};
2 changes: 1 addition & 1 deletion test/typescript/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion test/unit/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});

Expand Down