Skip to content
Open
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
13 changes: 7 additions & 6 deletions whiteboard/WhiteboardApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ export class WhiteboardApp extends App implements IUIKitInteractionHandler {
\`/whiteboard delete <board name>\` - Delete a whiteboard
\`/whiteboard help\` - Display helper message
\`/whiteboard list\` - List all the board names in the room
\`/whiteboard delete <board name>\` - Delete a board
\`/whiteboard search <board name>\` - Search a board
You can use \`Create Whiteboard\` Action Button to create a new whiteboard as well \n
Refer https://github.com/RocketChat/Apps.Whiteboard documentation for more details 🚀`,
persistence
Expand Down Expand Up @@ -252,14 +254,13 @@ export class UpdateBoardEndpoint extends ApiEndpoint {
const boardId = request.content.boardId;
const boardData = request.content.boardData;
const cover = request.content.cover;
const title = request.content.title;


const savedBoardata = await getBoardRecord(
read.getPersistenceReader(),
boardId
);
console.log("savedBoardata", savedBoardata)
const { messageId, privateMessageId, status, boardOwner } = savedBoardata;
);
const { messageId, privateMessageId, status, boardOwner } = savedBoardata;
const title = request.content.title ? request.content.title : savedBoardata.title;
const user = (await read.getMessageReader().getSenderUser(messageId))!;
const room = await read.getMessageReader().getRoom(messageId);
const AppSender = (await read.getUserReader().getAppUser()) as IUser;
Expand Down Expand Up @@ -366,4 +367,4 @@ export class DeleteBoardEndpoint extends ApiEndpoint {
},
});
}
}
}
29 changes: 28 additions & 1 deletion whiteboard/blocks/UtilityBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,34 @@ export async function buildHeaderBlockAfterPermission(
return block;
}

// Header block when whiteboard is deleted
// Header block to take user back to the board

export async function goToBoardBlock(
boardURL: string,
appId: string,
boardname?: string
): Promise<Array<Block>> {
const block: Block[] = [];
const goToBoardButton = getButton(
`Go to the ${boardname} board`,
UtilityEnum.GOTO_BOARD_BLOCK_ID,
UtilityEnum.GOTO_BOARD_BUTTON_ACTION_ID,
appId,
"GOTO",
ButtonStyle.PRIMARY,
boardURL
);

let markdownBlock: SectionBlock;
markdownBlock = getMarkdownBlock(`*${boardname}* board`);

const actionBlock = getActionsBlock(UtilityEnum.PREVIEW_BLOCK_ID, [
goToBoardButton,
]);
block.push(markdownBlock);
block.push(actionBlock);
return block;
}
// export async function deletionHeaderBlock(
// username: string,
// boardname: string
Expand Down
2 changes: 2 additions & 0 deletions whiteboard/enum/uitlityEnum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ export enum UtilityEnum {
DELETE_BLOCK_ID = "delete-block-id",
NAME_ALREADY_EXISTS = "Name already exists. Try different name",

GOTO_BOARD_BLOCK_ID = "goto-board-block-id",
GOTO_BOARD_BUTTON_ACTION_ID = "goto-board-button-action-id",
EDIT = "Edit",
EDIT_DESC = "Do you want to edit this whiteboard?",
EDIT_MODAL_ID = "edit-modal-id",
Expand Down
87 changes: 79 additions & 8 deletions whiteboard/lib/commandUtility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,16 @@ import {
import { ExecutorProps } from "../definitions/ExecutorProps";
import { WhiteboardApp } from "../WhiteboardApp";
import {
handleListCommand,
handleBoardSearch,
handleList,
helperMessage,
sendMessage,
sendMessageWithAttachment,
} from "./messages";
import { buildHeaderBlock, buildHeaderBlockAfterPermission, deletionHeaderBlock } from "../blocks/UtilityBlock";
import { buildHeaderBlock, deletionHeaderBlock, goToBoardBlock } from "../blocks/UtilityBlock";
import { WhiteboardSlashCommandContext } from "../commands/WhiteboardCommand";
import {
deleteBoards,
getBoardName,
getMessageIdByRoomName,
storeBoardRecord,
} from "../persistence/boardInteraction";
import { randomId } from "./utilts";
Expand All @@ -31,6 +30,7 @@ import {
getMessageIdByBoardName,
deleteBoardByMessageId,
} from "../persistence/boardInteraction";

import { IMessage } from "@rocket.chat/apps-engine/definition/messages";
//CommandUtility is used to handle the commands

Expand Down Expand Up @@ -118,7 +118,7 @@ export class CommandUtility implements ExecutorProps {
if (room) {
const randomBoardId = randomId();
const boardURL = `${boardEndpoint.computedPath}?id=${randomBoardId}`;

console.log("boardURL ", boardURL)
// The variable "untitledName" stores "Untitled" if the name is not specified
const untitledName = await getBoardName(
read.getPersistenceReader(),
Expand Down Expand Up @@ -211,10 +211,78 @@ export class CommandUtility implements ExecutorProps {
const appSender: IUser = (await this.read
.getUserReader()
.getAppUser()) as IUser;
await handleListCommand(this.read, this.modify, this.room, appSender);
await handleList(this.read, this.modify, this.room, appSender);
}

// handleListCommand is used to handle the /whiteboard delete command
// handleBoardSearchCommand is used to handle the /whiteboard search {boardname} command

private async handleBoardSearchCommand(
name: string,
{
app,
context,
read,
}: WhiteboardSlashCommandContext
) {
try {

const appUser = (await read.getUserReader().getAppUser())!;
const boardData = await handleBoardSearch(
this.read,
this.room,
name
);

const sender = context.getSender()!;
const room = context.getRoom();
let roomType = "channel"
if(room.type === "c"){
roomType = "channel"
}
else if(room.type === "p"){
roomType = "group"
}
else if(room.type === "d"){
roomType = "direct"
}


const appId = app.getID();
const boardURL = `/${roomType}/${room.slugifiedName}?msg=${boardData?.messageId}`


if (room && boardData?.id) {

const goToBoard = await goToBoardBlock(
boardURL,
appId,
name
)

const attachments = [
{
collapsed: true,
color: "#00000000",
imageUrl: boardData.cover !== "" ? boardData.cover : defaultPreview,
},
];

await sendMessageWithAttachment(
this.modify,
room,
appUser,
`Whiteboard created by @${sender.username}`,
attachments,
goToBoard
);
}
} catch (err) {
console.error(err);
}
}


// deleteBoardCommand is used to handle the /whiteboard delete command

private async deleteBoardCommand() {
const appId = this.app.getID();
Expand Down Expand Up @@ -371,6 +439,9 @@ export class CommandUtility implements ExecutorProps {
case "list":
await this.handleListCommand();
break;
case "search":
await this.handleBoardSearchCommand(this.command.slice(1).join(' '), context);
break;
case "delete":
await this.deleteBoardCommand();
break;
Expand All @@ -393,4 +464,4 @@ export class CommandUtility implements ExecutorProps {
break;
}
}
}
}
34 changes: 33 additions & 1 deletion whiteboard/lib/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { NotificationsController } from "./notifications";
import { Block } from "@rocket.chat/ui-kit";
import { IMessageAttachment } from "@rocket.chat/apps-engine/definition/messages";
import { AppEnum } from "../enum/App";
import { getMessagebyMessageID } from "../persistence/boardInteraction";
import {
getBoardRecordByMessageId,
getBoardRecordByRoomId,
Expand Down Expand Up @@ -179,6 +180,10 @@ export async function helperMessage(
appUser: IUser
) {
const text = `*Whiteboard App Commands*
\`/whiteboard help\` - Display helper message
\`/whiteboard list\` - List all the whiteboard names in the room
\`/whiteboard delete <board name>\` - Delete a board
\`/whiteboard search <board name>\` - Search a board
\`/whiteboard new <board name>\` - Create a new whiteboard
\`/whiteboard delete <board name>\` - Delete a whiteboard
\`/whiteboard help\` - Display helper message
Expand All @@ -199,7 +204,7 @@ export async function helperMessage(
}

// function to handle /whiteboard list command
export async function handleListCommand(
export async function handleList(
read: IRead,
modify: IModify,
room: IRoom,
Expand All @@ -224,6 +229,8 @@ export async function handleListCommand(
boardDataCheck ? boardDataCheck.title : "Error here messages.ts"
);
}

console.log("boardData checking list" , boardData)

const text = `*All existing boards are*:
${boardDataArray.join("\n")}
Expand Down Expand Up @@ -356,3 +363,28 @@ export async function addUsertoBoardOwner(
return undefined
}
}

// Function to search for a board

export async function handleBoardSearch(
read: IRead,
room: IRoom,
boardName: string
) {
try {
const boardData = await getBoardRecordByRoomId(read.getPersistenceReader(), room.id);

const foundBoard = boardData.find(board => board.title === boardName);

if (foundBoard) {
const messageInfo = await getMessagebyMessageID(read.getPersistenceReader(), foundBoard.messageId);

return { id: foundBoard.id, cover: messageInfo[0].cover, messageId: messageInfo[0].messageId };
}

return undefined;
} catch (error) {
console.log('Error in handleBoardSearch:', error);
throw error;
}
}
15 changes: 15 additions & 0 deletions whiteboard/persistence/boardInteraction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,21 @@ export const storeBoardRecord = async (
return recordId
};

// query all records with the messageID
export const getMessagebyMessageID = async (
persistenceRead: IPersistenceRead,
messageId: string
): Promise<any> => {
const association = new RocketChatAssociationRecord(
RocketChatAssociationModel.MESSAGE,
`${messageId}#MessageId`
);
const result = (await persistenceRead.readByAssociation(
association
)) as Array<any>;
return result;
};

// query all records within the "scope" - room
export const getBoardRecordByRoomId = async (
persistenceRead: IPersistenceRead,
Expand Down