Skip to content

Commit

Permalink
Merge pull request #296 from GetStream/vishal/typescript-fixes
Browse files Browse the repository at this point in the history
Adding missing types
  • Loading branch information
vishalnarkhede authored Apr 9, 2020
2 parents 70ada30 + f0ecb7e commit 2c78981
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export * from './client_state';
export { logChatPromiseExecution } from './utils';
export * from './channel';
export * from './channel_state';
export * from './connection';
export * from './permissions';
export * from './events';
export * from './signing';
Expand Down
6 changes: 6 additions & 0 deletions types/stream-chat/api-response-tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ const executables = [
{ f: rg.partialUpdateUser, type: 'UpdateUsersAPIResponse' },
{ f: rg.partialUpdateUsers, type: 'UpdateUsersAPIResponse' },
{ f: rg.banUsers, type: 'BanUserAPIResponse' },
{ f: rg.deleteUser, type: 'DeleteUserAPIResponse' },
{ f: rg.reactivateUser, type: 'ReactivateUserAPIResponse' },
{ f: rg.deactivateUser, type: 'DeactiveUserAPIResponse' },
{ f: rg.exportUser, type: 'ExportUserAPIResponse' },
{ f: rg.unbanUsers, type: 'UnbanUserAPIResponse' },
{ f: rg.muteUser, type: 'MuteAPIResponse' },
{ f: rg.unmuteUser, type: 'UnmuteAPIResponse' },
Expand Down Expand Up @@ -42,6 +46,8 @@ const executables = [
{ f: rg.getReactions, type: 'GetReactionsAPIResponse' },
{ f: rg.updateChannel, type: 'UpdateChannelAPIResponse' },
{ f: rg.deleteChannel, type: 'DeleteChannelAPIResponse' },
/** Keeping truncate quite for now. Needs some fixes on backend regarding commands array in response */
// { f: rg.truncateChannel, type: 'TruncateChannelAPIResponse' },
{ f: rg.acceptInvite, type: 'AcceptInviteAPIResponse' },
{ f: rg.rejectInvite, type: 'RejectInviteAPIResponse' },
{ f: rg.addMembers, type: 'AddMembersAPIResponse' },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,16 @@ async function deleteChannel() {
return await channel.delete();
}

async function truncateChannel() {
const authClient = await utils.getTestClientForUser(johnID, {});
const id = uuidv4();
const channel = authClient.channel('messaging', id);
await channel.create();
await channel.watch();

return await channel.truncate();
}

async function acceptInvite() {
const c = await createTestInviteChannel();
const nickC = await utils.getTestClientForUser('nick');
Expand Down Expand Up @@ -141,6 +151,7 @@ module.exports = {
stopWatching,
updateChannel,
deleteChannel,
truncateChannel,
acceptInvite,
rejectInvite,
addMembers,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,66 @@ async function partialUpdateUsers() {
]);
}

async function deactivateUser() {
const client = utils.getServerTestClient();
const userID = uuid4();
await client.upsertUser({
id: userID,
name: 'Vishal',
});

return await client.deactivateUser(userID);
}

async function reactivateUser() {
const client = utils.getServerTestClient();
const userID = uuid4();
await client.upsertUser({
id: userID,
name: 'Vishal',
});

await client.deactivateUser(userID);

return await client.reactivateUser(userID);
}

async function deleteUser() {
const client = utils.getServerTestClient();
const userID = uuid4();
await client.upsertUser({
id: userID,
name: 'Vishal',
});

return client.deleteUser(userID);
}

async function exportUser() {
const client = utils.getServerTestClient();
const userID = uuid4();
await client.upsertUser({
id: userID,
name: 'Vishal',
});

const id = uuid4();
const channel = client.channel('messaging', id, { created_by_id: userID });
await channel.create();
const { message } = await channel.sendMessage({
text: 'this is great',
user_id: userID,
});
await channel.sendReaction(message.id, { type: 'love', user_id: userID });

return client.exportUser(userID);
}

module.exports = {
deactivateUser,
reactivateUser,
deleteUser,
exportUser,
updateUsers,
partialUpdateUser,
partialUpdateUsers,
Expand Down
40 changes: 40 additions & 0 deletions types/stream-chat/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,15 @@ export class StreamChat {
user: OwnUserResponse;
browser: boolean;
wsConnection: StableWSConnection;

testPushSettings(userID: string, data: object): Promise<APIResponse>;

deleteUser(userID: string, params: object): Promise<DeleteUserAPIResponse>;
reactivateUser(userID: string, options: object): Promise<ReactivateUserAPIResponse>;
deactivateUser(userID: string, options: object): Promise<DeactiveUserAPIResponse>;
exportUser(userID: string, options: object): Promise<ExportUserAPIResponse>;
markAllRead(data: object): Promise<void>;

devToken(userID: string): string;
createToken(userID: string, exp?: number): string;
getAuthType(): string;
Expand Down Expand Up @@ -312,6 +321,16 @@ export class Channel {
disconnected: boolean;
state: ChannelState;

getClient(): StreamChat;
truncate(): Promise<TruncateChannelAPIResponse>;
muteStatus(): {
muted: boolean;
createdAt?: string | null;
expiredAt?: string | null;
};
lastRead(): string | null;
countUnreadMentions(): number;

getConfig(): {
created_at: string;
updated_at: string;
Expand Down Expand Up @@ -437,6 +456,9 @@ export class ChannelState {
}>;
membership: SeamlessImmutable.Immutable<ChannelMembership>;
last_message_at: string;
addReaction(reaction: Reaction, message: MessageResponse): void;
removeReaction(reaction: Reaction, message: MessageResponse): void;
clearMessages(): void;
addMessageSorted(newMessage: Message): void;
addMessagesSorted(newMessages: Message[]): void;
messageToImmutable(message: Message): SeamlessImmutable.Immutable<Message>;
Expand Down Expand Up @@ -544,6 +566,21 @@ export interface UsersAPIResponse extends APIResponse {
users: UserResponse[];
}

export interface DeleteUserAPIResponse extends APIResponse {
user: UserResponse;
}
export interface ReactivateUserAPIResponse extends APIResponse {
user: UserResponse;
}
export interface DeactiveUserAPIResponse extends APIResponse {
user: UserResponse;
}
export interface ExportUserAPIResponse extends APIResponse {
user: UserResponse;
messages?: MessageResponse[];
reactions?: ReactionResponse[];
}

export interface SearchAPIResponse extends APIResponse {
results: Array<{
message: MessageResponse;
Expand Down Expand Up @@ -627,6 +664,9 @@ export interface UpdateChannelAPIResponse extends APIResponse {
export interface DeleteChannelAPIResponse extends APIResponse {
channel: ChannelResponse;
}
export interface TruncateChannelAPIResponse extends APIResponse {
channel: ChannelResponse;
}

export interface AcceptInviteAPIResponse extends UpdateChannelAPIResponse {}
export interface RejectInviteAPIResponse extends UpdateChannelAPIResponse {}
Expand Down

0 comments on commit 2c78981

Please sign in to comment.