Skip to content
This repository was archived by the owner on Nov 5, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 3 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
7 changes: 3 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
},
"homepage": "https://github.com/RocketChat/Rocket.Chat.Apps-engine#readme",
"devDependencies": {
"@types/node": "^12.7.12",
"@types/adm-zip": "^0.4.31",
"@types/lodash.clonedeep": "^4.5.3",
"@types/nedb": "^1.8.5",
Expand Down
13 changes: 13 additions & 0 deletions src/definition/accessors/IMessageBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,19 @@ export interface IMessageBuilder {
*/
setData(message: IMessage): IMessageBuilder;

/**
* Sets the thread to which this message belongs, if any.
*
* @param threadId The id of the thread
*/
setThreadId(threadId: string): IMessageBuilder;

/**
* Retrieves the thread to which this message belongs,
* if any.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* if any.
* if any. Use the message reader to get the thread's message.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated it (see below). WDYT? 😛

*/
getThreadId(): string;

/**
* Sets the room where this message should be sent to.
*
Expand Down
1 change: 1 addition & 0 deletions src/definition/messages/IMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { IMessageReactions } from './IMessageReaction';

export interface IMessage {
id?: string;
threadId?: string;
room: IRoom;
sender: IUser;
text?: string;
Expand Down
11 changes: 10 additions & 1 deletion src/definition/slashcommands/SlashCommandContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ import { IUser } from '../users';
* executes a slash command.
*/
export class SlashCommandContext {
constructor(private sender: IUser, private room: IRoom, private params: Array<string>) { }
constructor(
private sender: IUser,
private room: IRoom,
private params: Array<string>,
private threadId?: string,
) { }

/** The user who sent the command. */
public getSender(): IUser {
Expand All @@ -22,4 +27,8 @@ export class SlashCommandContext {
public getArguments(): Array<string> {
return this.params;
}

public getThreadId(): string | undefined {
return this.threadId;
}
}
10 changes: 10 additions & 0 deletions src/server/accessors/MessageBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ export class MessageBuilder implements IMessageBuilder {
return this;
}

public setThreadId(threadId: string): IMessageBuilder {
this.msg.threadId = threadId;

return this;
}

public getThreadId(): string {
return this.msg.threadId;
}

public setRoom(room: IRoom): IMessageBuilder {
this.msg.room = room;
return this;
Expand Down
2 changes: 1 addition & 1 deletion src/server/managers/AppSlashCommandManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ export class AppSlashCommandManager {
room = new Room(context.getRoom(), this.manager);
}

return new SlashCommandContext(context.getSender(), room, context.getArguments());
return new SlashCommandContext(context.getSender(), room, context.getArguments(), context.getThreadId());
}

/**
Expand Down
5 changes: 5 additions & 0 deletions tests/server/accessors/MessageBuilder.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ export class MessageBuilderAccessorTestFixture {

const msg: IMessage = {} as IMessage;
const mb = new MessageBuilder(msg);

Expect(mb.setThreadId('a random thread id')).toBe(mb);
Expect(msg.threadId).toBe('a random thread id');
Expect(mb.getThreadId()).toBe('a random thread id');

Expect(mb.setRoom(TestData.getRoom())).toBe(mb);
Expect(msg.room).toEqual(TestData.getRoom());
Expect(mb.getRoom()).toEqual(TestData.getRoom());
Expand Down