Skip to content

Commit

Permalink
Extend channel truncation params (#815)
Browse files Browse the repository at this point in the history
* Extend channel truncation params
  • Loading branch information
Vova Maksimchuk authored Nov 25, 2021
1 parent 55e6e6d commit c27a999
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 7 deletions.
19 changes: 13 additions & 6 deletions src/channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,17 @@ import {
QueryMembersOptions,
Reaction,
ReactionAPIResponse,
SearchAPIResponse,
SearchMessageSortBase,
SearchOptions,
SearchPayload,
SearchAPIResponse,
SendMessageAPIResponse,
TruncateChannelAPIResponse,
TruncateOptions,
UnknownType,
UpdateChannelAPIResponse,
UserFilters,
UserResponse,
SearchMessageSortBase,
} from './types';
import { Role } from './permissions';

Expand Down Expand Up @@ -608,12 +609,18 @@ export class Channel<

/**
* truncate - Removes all messages from the channel
* @param {boolean} [options.hard_delete] Defines if messages of the channel must be hard deleted
* @return {Promise<TruncateChannelAPIResponse<ChannelType, CommandType, UserType>>} The server response
* @param {TruncateOptions<AttachmentType, MessageType, UserType>} [options] Defines truncation options
* @return {Promise<TruncateChannelAPIResponse<ChannelType, CommandType, UserType, MessageType, ReactionType>>} The server response
*/
async truncate(options: { hard_delete?: boolean } = {}) {
async truncate(options: TruncateOptions<AttachmentType, MessageType, UserType> = {}) {
return await this.getClient().post<
TruncateChannelAPIResponse<ChannelType, CommandType, UserType>
TruncateChannelAPIResponse<
ChannelType,
CommandType,
UserType,
MessageType,
ReactionType
>
>(this._channelURL() + '/truncate', options);
}

Expand Down
21 changes: 20 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ export type ChannelResponse<
name?: string;
own_capabilities?: string[];
team?: string;
truncated_at?: string;
updated_at?: string;
};

Expand Down Expand Up @@ -699,9 +700,20 @@ export type SendMessageAPIResponse<
export type TruncateChannelAPIResponse<
ChannelType = UnknownType,
CommandType extends string = LiteralStringForUnion,
UserType = UnknownType
UserType = UnknownType,
AttachmentType = UnknownType,
MessageType = UnknownType,
ReactionType = UnknownType
> = APIResponse & {
channel: ChannelResponse<ChannelType, CommandType, UserType>;
message?: MessageResponse<
AttachmentType,
ChannelType,
CommandType,
MessageType,
ReactionType,
UserType
>;
};

export type UpdateChannelAPIResponse<
Expand Down Expand Up @@ -2238,3 +2250,10 @@ export type TaskStatus = {
};
result?: UnknownType;
};

export type TruncateOptions<AttachmentType, MessageType, UserType> = {
hard_delete?: boolean;
message?: Message<AttachmentType, MessageType, UserType>;
skip_push?: boolean;
truncated_at?: Date;
};

0 comments on commit c27a999

Please sign in to comment.