From 6065ef481f92eda4b1d2f5f470db592b94230893 Mon Sep 17 00:00:00 2001 From: Devansh Date: Mon, 13 Jan 2025 20:14:17 +0530 Subject: [PATCH 01/12] Updated getIssuesStarterModal, githubIssuesListModal, githubIssuesShareModal, newIssueStarterModal to SurfaceView --- github/app.json | 2 +- github/handlers/ExecuteBlockActionHandler.ts | 1624 ++++++++++++------ github/handlers/ExecuteViewSubmitHandler.ts | 107 +- github/handlers/HandleIssues.ts | 5 +- github/modals/getIssuesStarterModal.ts | 97 +- github/modals/githubIssuesListModal.ts | 283 +-- github/modals/githubIssuesShareModal.ts | 107 +- github/modals/newIssueStarterModal.ts | 100 +- github/package-lock.json | 985 +++++++++-- github/package.json | 7 +- 10 files changed, 2310 insertions(+), 1007 deletions(-) diff --git a/github/app.json b/github/app.json index 0d2452e..1bcdc0b 100644 --- a/github/app.json +++ b/github/app.json @@ -1,7 +1,7 @@ { "id": "826f0d95-9e25-48a6-a781-a32f147230a5", "version": "0.0.1", - "requiredApiVersion": "^1.36.0", + "requiredApiVersion": "^1.44.0", "iconFile": "icon.png", "author": { "name": "Samad Yar Khan", diff --git a/github/handlers/ExecuteBlockActionHandler.ts b/github/handlers/ExecuteBlockActionHandler.ts index 93c3c88..02f8573 100644 --- a/github/handlers/ExecuteBlockActionHandler.ts +++ b/github/handlers/ExecuteBlockActionHandler.ts @@ -18,12 +18,26 @@ import { } from "@rocket.chat/apps-engine/definition/uikit"; import { AddSubscriptionModal } from "../modals/addSubscriptionsModal"; import { deleteSubscriptionsModal } from "../modals/deleteSubscriptions"; -import { deleteSubscription, updateSubscription, getIssueTemplateCode, getPullRequestComments, getPullRequestData, getRepositoryIssues, getBasicUserInfo, getIssueData, getIssuesComments, approvePullRequest } from "../helpers/githubSDK"; +import { + deleteSubscription, + updateSubscription, + getIssueTemplateCode, + getPullRequestComments, + getPullRequestData, + getRepositoryIssues, + getBasicUserInfo, + getIssueData, + getIssuesComments, + approvePullRequest, +} from "../helpers/githubSDK"; import { Subscription } from "../persistance/subscriptions"; import { getAccessTokenForUser } from "../persistance/auth"; import { GithubApp } from "../GithubApp"; import { IAuthData } from "@rocket.chat/apps-engine/definition/oauth2/IOAuth2"; -import { storeInteractionRoomData, getInteractionRoomData } from "../persistance/roomInteraction"; +import { + storeInteractionRoomData, + getInteractionRoomData, +} from "../persistance/roomInteraction"; import { sendMessage, sendNotification } from "../lib/message"; import { subscriptionsModal } from "../modals/subscriptionsModal"; import { mergePullRequestModal } from "../modals/mergePullReqeustModal"; @@ -42,7 +56,10 @@ import { githubIssuesListModal } from "../modals/githubIssuesListModal"; import { GithubRepoIssuesStorage } from "../persistance/githubIssues"; import { IGitHubIssueData } from "../definitions/githubIssueData"; import { shareProfileModal } from "../modals/profileShareModal"; -import { RocketChatAssociationModel, RocketChatAssociationRecord } from "@rocket.chat/apps-engine/definition/metadata"; +import { + RocketChatAssociationModel, + RocketChatAssociationRecord, +} from "@rocket.chat/apps-engine/definition/metadata"; import { userIssuesModal } from "../modals/UserIssuesModal"; import { IssueDisplayModal } from "../modals/IssueDisplayModal"; import { IGitHubIssue } from "../definitions/githubIssue"; @@ -57,18 +74,16 @@ import { removeRepoReminder, unsubscribedPR } from "../persistance/remind"; import { reminderModal } from "../modals/remindersModal"; export class ExecuteBlockActionHandler { - constructor( private readonly app: GithubApp, private readonly read: IRead, private readonly http: IHttp, private readonly modify: IModify, - private readonly persistence: IPersistence - ) { } - + private readonly persistence: IPersistence, + ) {} public async run( - context: UIKitBlockInteractionContext + context: UIKitBlockInteractionContext, ): Promise { const data = context.getInteractionData(); @@ -93,11 +108,15 @@ export class ExecuteBlockActionHandler { } const repository = param?.substring( 0, - lengthOfRepoString + lengthOfRepoString, ) as String; let { user, room } = await context.getInteractionData(); - let accessToken = await getAccessTokenForUser(this.read, user, this.app.oauth2Config) as IAuthData; - if(room && user){ + let accessToken = (await getAccessTokenForUser( + this.read, + user, + this.app.oauth2Config, + )) as IAuthData; + if (room && user) { await basicQueryMessage({ query, repository, @@ -119,180 +138,257 @@ export class ExecuteBlockActionHandler { }; } } - case ModalsEnum.SHARE_ISSUE_ACTION : { - let {user, value, room} = context.getInteractionData(); - const access_token = await getAccessTokenForUser(this.read, user, this.app.oauth2Config) as IAuthData; + case ModalsEnum.SHARE_ISSUE_ACTION: { + let { user, value, room } = context.getInteractionData(); + const access_token = (await getAccessTokenForUser( + this.read, + user, + this.app.oauth2Config, + )) as IAuthData; const repoName = value?.split(",")[0] ?? ""; const issueNumber = value?.split(",")[1] ?? ""; - const issueInfo : IGitHubIssue = await getIssueData(repoName, issueNumber, access_token.token, this.http); + const issueInfo: IGitHubIssue = await getIssueData( + repoName, + issueNumber, + access_token.token, + this.http, + ); const block = this.modify.getCreator().getBlockBuilder(); CreateIssueStatsBar(issueInfo, block); block.addSectionBlock({ - text : { - text : `*${issueInfo.title}*` ?? "", - type : TextObjectType.MARKDOWN - } + text: { + text: `*${issueInfo.title}*` ?? "", + type: TextObjectType.MARKDOWN, + }, }), - block.addActionsBlock({ - elements : [ - block.newButtonElement({ - text : { - text : "Open Issue in Browser", - type : TextObjectType.PLAINTEXT - }, - url : issueInfo.html_url, - style : ButtonStyle.PRIMARY - }) - ] - }) - issueInfo.body && BodyMarkdownRenderer({body : issueInfo.body, block : block}); + block.addActionsBlock({ + elements: [ + block.newButtonElement({ + text: { + text: "Open Issue in Browser", + type: TextObjectType.PLAINTEXT, + }, + url: issueInfo.html_url, + style: ButtonStyle.PRIMARY, + }), + ], + }); + issueInfo.body && + BodyMarkdownRenderer({ + body: issueInfo.body, + block: block, + }); - if(user?.id){ - if(room?.id){ - await sendMessage(this.modify, room!, user, `Issue`, block) - }else{ + if (user?.id) { + if (room?.id) { + await sendMessage( + this.modify, + room!, + user, + `Issue`, + block, + ); + } else { let roomId = ( await getInteractionRoomData( this.read.getPersistenceReader(), - user.id + user.id, ) ).roomId; - room = await this.read.getRoomReader().getById(roomId) as IRoom; - await sendMessage(this.modify, room, user, `Issue`, block) + room = (await this.read + .getRoomReader() + .getById(roomId)) as IRoom; + await sendMessage( + this.modify, + room, + user, + `Issue`, + block, + ); } } break; } - case ModalsEnum.TRIGGER_ISSUE_DISPLAY_MODAL : { - const {user, value} = context.getInteractionData(); - const access_token = await getAccessTokenForUser(this.read, user, this.app.oauth2Config) as IAuthData; + case ModalsEnum.TRIGGER_ISSUE_DISPLAY_MODAL: { + const { user, value } = context.getInteractionData(); + const access_token = (await getAccessTokenForUser( + this.read, + user, + this.app.oauth2Config, + )) as IAuthData; const repoInfo = value?.split(",")[0] ?? ""; const issueNumber = value?.split(",")[1] ?? ""; const issueDisplayModal = await IssueDisplayModal({ - repoName : repoInfo, - issueNumber : issueNumber, - access_token : access_token.token, - modify : this.modify, - read : this.read, - persistence : this.persistence, - http : this.http, - uikitcontext : context - }) + repoName: repoInfo, + issueNumber: issueNumber, + access_token: access_token.token, + modify: this.modify, + read: this.read, + persistence: this.persistence, + http: this.http, + uikitcontext: context, + }); - return context.getInteractionResponder().updateModalViewResponse(issueDisplayModal); + return context + .getInteractionResponder() + .updateModalViewResponse(issueDisplayModal); } - case ModalsEnum.SWITCH_ISSUE_SORT : - case ModalsEnum.SWITCH_ISSUE_STATE : - case ModalsEnum.SWITCH_ISSUE_FILTER : { - const record = new RocketChatAssociationRecord(RocketChatAssociationModel.MISC, "ISSUE_MAIN_FILTER"); + case ModalsEnum.SWITCH_ISSUE_SORT: + case ModalsEnum.SWITCH_ISSUE_STATE: + case ModalsEnum.SWITCH_ISSUE_FILTER: { + const record = new RocketChatAssociationRecord( + RocketChatAssociationModel.MISC, + "ISSUE_MAIN_FILTER", + ); - const issueFilterArray = await this.read.getPersistenceReader().readByAssociation(record) as {filter : string, state : string, sort: string, order: string}[]; + const issueFilterArray = (await this.read + .getPersistenceReader() + .readByAssociation(record)) as { + filter: string; + state: string; + sort: string; + order: string; + }[]; - const {user, value} = context.getInteractionData(); + const { user, value } = context.getInteractionData(); - let filter : {filter : string, state : string, sort: string, order: string} | undefined; + let filter: + | { + filter: string; + state: string; + sort: string; + order: string; + } + | undefined; - const prev_sort = issueFilterArray.length == 0 ? ModalsEnum.ISSUE_SORT_CREATED : issueFilterArray[0].sort; - const prev_filter = issueFilterArray.length == 0 ? ModalsEnum.ASSIGNED_ISSUE_FILTER : issueFilterArray[0].filter; - const prev_state = issueFilterArray.length == 0 ? ModalsEnum.ISSUE_STATE_OPEN : issueFilterArray[0].state; + const prev_sort = + issueFilterArray.length == 0 + ? ModalsEnum.ISSUE_SORT_CREATED + : issueFilterArray[0].sort; + const prev_filter = + issueFilterArray.length == 0 + ? ModalsEnum.ASSIGNED_ISSUE_FILTER + : issueFilterArray[0].filter; + const prev_state = + issueFilterArray.length == 0 + ? ModalsEnum.ISSUE_STATE_OPEN + : issueFilterArray[0].state; switch (value as string) { case ModalsEnum.ASSIGNED_ISSUE_FILTER: case ModalsEnum.MENTIONED_ISSUE_FILTER: case ModalsEnum.CREATED_ISSUE_FILTER: filter = { - filter : value as string, - sort : prev_sort, - state : prev_state, - order : ModalsEnum.ISSUES_DESCENDING - } + filter: value as string, + sort: prev_sort, + state: prev_state, + order: ModalsEnum.ISSUES_DESCENDING, + }; break; - case ModalsEnum.ISSUE_SORT_CREATED : - case ModalsEnum.ISSUE_SORT_COMMENTS : - case ModalsEnum.ISSUE_SORT_UPDATED : + case ModalsEnum.ISSUE_SORT_CREATED: + case ModalsEnum.ISSUE_SORT_COMMENTS: + case ModalsEnum.ISSUE_SORT_UPDATED: filter = { - filter : prev_filter, - sort : value as string, - state : prev_state, - order : ModalsEnum.ISSUES_DESCENDING - } + filter: prev_filter, + sort: value as string, + state: prev_state, + order: ModalsEnum.ISSUES_DESCENDING, + }; break; - case ModalsEnum.ISSUE_STATE_OPEN : - case ModalsEnum.ISSUE_STATE_CLOSED : + case ModalsEnum.ISSUE_STATE_OPEN: + case ModalsEnum.ISSUE_STATE_CLOSED: filter = { - filter : prev_filter, - sort : prev_sort, - state : value as string, - order : ModalsEnum.ISSUES_DESCENDING - } + filter: prev_filter, + sort: prev_sort, + state: value as string, + order: ModalsEnum.ISSUES_DESCENDING, + }; break; default: filter = { - filter : ModalsEnum.ASSIGNED_ISSUE_FILTER, - sort : ModalsEnum.ISSUE_SORT_CREATED, - state : ModalsEnum.ISSUE_STATE_OPEN, - order : ModalsEnum.ISSUES_DESCENDING - } + filter: ModalsEnum.ASSIGNED_ISSUE_FILTER, + sort: ModalsEnum.ISSUE_SORT_CREATED, + state: ModalsEnum.ISSUE_STATE_OPEN, + order: ModalsEnum.ISSUES_DESCENDING, + }; } - let access_token = await getAccessTokenForUser(this.read, user, this.app.oauth2Config) as IAuthData; + let access_token = (await getAccessTokenForUser( + this.read, + user, + this.app.oauth2Config, + )) as IAuthData; const issueModal = await userIssuesModal({ - access_token : access_token.token, - filter : filter, - modify : this.modify, - read : this.read, - persistence : this.persistence, - http : this.http - }) + access_token: access_token.token, + filter: filter, + modify: this.modify, + read: this.read, + persistence: this.persistence, + http: this.http, + }); await this.persistence.updateByAssociation(record, filter); - return context.getInteractionResponder().updateModalViewResponse(issueModal); + return context + .getInteractionResponder() + .updateModalViewResponse(issueModal); } - case ModalsEnum.TRIGGER_ISSUES_MODAL : { + case ModalsEnum.TRIGGER_ISSUES_MODAL: { + const { user } = context.getInteractionData(); - const {user} = context.getInteractionData(); - - let access_token = await getAccessTokenForUser(this.read, user, this.app.oauth2Config) as IAuthData; + let access_token = (await getAccessTokenForUser( + this.read, + user, + this.app.oauth2Config, + )) as IAuthData; const filter = { - filter : ModalsEnum.ASSIGNED_ISSUE_FILTER, - state : ModalsEnum.ISSUE_STATE_OPEN, - sort : ModalsEnum.ISSUE_SORT_CREATED - } + filter: ModalsEnum.ASSIGNED_ISSUE_FILTER, + state: ModalsEnum.ISSUE_STATE_OPEN, + sort: ModalsEnum.ISSUE_SORT_CREATED, + }; const issuesModal = await userIssuesModal({ - filter : filter, - access_token : access_token.token, + filter: filter, + access_token: access_token.token, modify: this.modify, - read : this.read, - persistence : this.persistence, - http : this.http, - uikitcontext : context + read: this.read, + persistence: this.persistence, + http: this.http, + uikitcontext: context, }); - return context.getInteractionResponder().openModalViewResponse(issuesModal); + return context + .getInteractionResponder() + .openModalViewResponse(issuesModal); } - case ModalsEnum.TRIGGER_REPOS_MODAL : { + case ModalsEnum.TRIGGER_REPOS_MODAL: { break; } - case ModalsEnum.TRIGGER_ACTIVITY_MODAL : { + case ModalsEnum.TRIGGER_ACTIVITY_MODAL: { break; } - case ModalsEnum.SHARE_PROFILE_PARAMS : { - const profileInteractionData = context.getInteractionData().value; - if(Array.isArray(profileInteractionData)) { + case ModalsEnum.SHARE_PROFILE_PARAMS: { + const profileInteractionData = + context.getInteractionData().value; + if (Array.isArray(profileInteractionData)) { const storeData = { - profileParams: profileInteractionData as string[] - } - await this.persistence.updateByAssociation(new RocketChatAssociationRecord(RocketChatAssociationModel.MISC, "ProfileShareParam"), storeData); + profileParams: profileInteractionData as string[], + }; + await this.persistence.updateByAssociation( + new RocketChatAssociationRecord( + RocketChatAssociationModel.MISC, + "ProfileShareParam", + ), + storeData, + ); } break; } @@ -315,55 +411,93 @@ export class ExecuteBlockActionHandler { read: this.read, persistence: this.persistence, http: this.http, - uikitcontext: context - }) + uikitcontext: context, + }); return context .getInteractionResponder() .openModalViewResponse(addSubscriptionModal); } case ModalsEnum.OPEN_DELETE_SUBSCRIPTIONS_MODAL: { - const addSubscriptionModal = await deleteSubscriptionsModal({ - modify: this.modify, - read: this.read, - persistence: this.persistence, - http: this.http, - uikitcontext: context - }) + const addSubscriptionModal = await deleteSubscriptionsModal( + { + modify: this.modify, + read: this.read, + persistence: this.persistence, + http: this.http, + uikitcontext: context, + }, + ); return context .getInteractionResponder() .openModalViewResponse(addSubscriptionModal); } case ModalsEnum.DELETE_SUBSCRIPTION_ACTION: { - let { user, room } = await context.getInteractionData(); - let accessToken = await getAccessTokenForUser(this.read, user, this.app.oauth2Config) as IAuthData; - let value: string = context.getInteractionData().value as string; - let splitted = value.split(','); + let accessToken = (await getAccessTokenForUser( + this.read, + user, + this.app.oauth2Config, + )) as IAuthData; + let value: string = context.getInteractionData() + .value as string; + let splitted = value.split(","); if (splitted.length == 2 && accessToken.token) { let repoName = splitted[0]; let hookId = splitted[1]; let roomId; if (room?.id) { roomId = room.id; - await storeInteractionRoomData(this.persistence, user.id, roomId); + await storeInteractionRoomData( + this.persistence, + user.id, + roomId, + ); } else { - roomId = (await getInteractionRoomData(this.read.getPersistenceReader(), user.id)).roomId; + roomId = ( + await getInteractionRoomData( + this.read.getPersistenceReader(), + user.id, + ) + ).roomId; } //delete the susbscriptions for persistance - let subscriptionStorage = new Subscription(this.persistence, this.read.getPersistenceReader()); - let oldSubscriptions = await subscriptionStorage.getSubscriptionsByRepo(repoName, user.id); - await subscriptionStorage.deleteSubscriptionsByRepoUser(repoName, roomId, user.id); + let subscriptionStorage = new Subscription( + this.persistence, + this.read.getPersistenceReader(), + ); + let oldSubscriptions = + await subscriptionStorage.getSubscriptionsByRepo( + repoName, + user.id, + ); + await subscriptionStorage.deleteSubscriptionsByRepoUser( + repoName, + roomId, + user.id, + ); //check if any subscription events of the repo is left in any other room - let eventSubscriptions = new Map; + let eventSubscriptions = new Map(); for (let subscription of oldSubscriptions) { eventSubscriptions.set(subscription.event, false); } - let updatedsubscriptions = await subscriptionStorage.getSubscriptionsByRepo(repoName, user.id); + let updatedsubscriptions = + await subscriptionStorage.getSubscriptionsByRepo( + repoName, + user.id, + ); if (updatedsubscriptions.length == 0) { - await deleteSubscription(this.http, repoName, accessToken.token, hookId); + await deleteSubscription( + this.http, + repoName, + accessToken.token, + hookId, + ); } else { for (let subscription of updatedsubscriptions) { - eventSubscriptions.set(subscription.event, true); + eventSubscriptions.set( + subscription.event, + true, + ); } let updatedEvents: Array = []; let sameEvents = true; @@ -374,42 +508,96 @@ export class ExecuteBlockActionHandler { } } if (updatedEvents.length && !sameEvents) { - let response = await updateSubscription(this.http, repoName, accessToken.token, hookId, updatedEvents); + let response = await updateSubscription( + this.http, + repoName, + accessToken.token, + hookId, + updatedEvents, + ); } } - let userRoom = await this.read.getRoomReader().getById(roomId) as IRoom; - await sendNotification(this.read, this.modify, user, userRoom, `Unsubscribed to ${repoName} 🔕`); + let userRoom = (await this.read + .getRoomReader() + .getById(roomId)) as IRoom; + await sendNotification( + this.read, + this.modify, + user, + userRoom, + `Unsubscribed to ${repoName} 🔕`, + ); } - const modal = await deleteSubscriptionsModal({ modify: this.modify, read: this.read, persistence: this.persistence, http: this.http, uikitcontext: context }); - await this.modify.getUiController().updateModalView(modal, { triggerId: context.getInteractionData().triggerId }, context.getInteractionData().user); + const modal = await deleteSubscriptionsModal({ + modify: this.modify, + read: this.read, + persistence: this.persistence, + http: this.http, + uikitcontext: context, + }); + await this.modify + .getUiController() + .updateModalView( + modal, + { + triggerId: + context.getInteractionData().triggerId, + }, + context.getInteractionData().user, + ); break; } - case ModalsEnum.SUBSCRIPTION_REFRESH_ACTION:{ - const modal = await subscriptionsModal({ modify: this.modify, read: this.read, persistence: this.persistence, http: this.http, uikitcontext: context }); - await this.modify.getUiController().updateModalView(modal, { triggerId: context.getInteractionData().triggerId }, context.getInteractionData().user); + case ModalsEnum.SUBSCRIPTION_REFRESH_ACTION: { + const modal = await subscriptionsModal({ + modify: this.modify, + read: this.read, + persistence: this.persistence, + http: this.http, + uikitcontext: context, + }); + await this.modify + .getUiController() + .updateModalView( + modal, + { + triggerId: + context.getInteractionData().triggerId, + }, + context.getInteractionData().user, + ); break; } - case ModalsEnum.ISSUE_TEMPLATE_SELECTION_ACTION:{ + case ModalsEnum.ISSUE_TEMPLATE_SELECTION_ACTION: { let { user } = await context.getInteractionData(); - let accessToken = await getAccessTokenForUser(this.read, user, this.app.oauth2Config) as IAuthData; - let value: string = context.getInteractionData().value as string; + let accessToken = (await getAccessTokenForUser( + this.read, + user, + this.app.oauth2Config, + )) as IAuthData; + let value: string = context.getInteractionData() + .value as string; let actionDetailsArray = value?.trim()?.split(" "); - if(accessToken && actionDetailsArray?.length == 2){ - - if(actionDetailsArray[1] !== ModalsEnum.BLANK_GITHUB_TEMPLATE){ - - let templateResponse = await getIssueTemplateCode(this.http,actionDetailsArray[1],accessToken.token); + if (accessToken && actionDetailsArray?.length == 2) { + if ( + actionDetailsArray[1] !== + ModalsEnum.BLANK_GITHUB_TEMPLATE + ) { + let templateResponse = await getIssueTemplateCode( + this.http, + actionDetailsArray[1], + accessToken.token, + ); let data = {}; - if(templateResponse?.template){ + if (templateResponse?.template) { data = { - template : templateResponse.template, - repository:actionDetailsArray[0] + template: templateResponse.template, + repository: actionDetailsArray[0], }; - }else{ + } else { data = { - template : "", - repository:actionDetailsArray[0] + template: "", + repository: actionDetailsArray[0], }; } const newIssueModal = await NewIssueModal({ @@ -423,10 +611,9 @@ export class ExecuteBlockActionHandler { return context .getInteractionResponder() .openModalViewResponse(newIssueModal); - - }else{ + } else { let data = { - repository:actionDetailsArray[0] + repository: actionDetailsArray[0], }; const newIssueModal = await NewIssueModal({ data, @@ -443,366 +630,528 @@ export class ExecuteBlockActionHandler { } break; } - case ModalsEnum.SHARE_SEARCH_RESULT_ACTION:{ + case ModalsEnum.SHARE_SEARCH_RESULT_ACTION: { let { user, room } = await context.getInteractionData(); - let value: string = context.getInteractionData().value as string; - if(user?.id){ - if(room?.id){ - await sendMessage(this.modify,room,user,`${value}`); - }else{ + let value: string = context.getInteractionData() + .value as string; + if (user?.id) { + if (room?.id) { + await sendMessage( + this.modify, + room, + user, + `${value}`, + ); + } else { let roomId = ( await getInteractionRoomData( this.read.getPersistenceReader(), - user.id + user.id, ) ).roomId; - room = await this.read.getRoomReader().getById(roomId) as IRoom; - await sendMessage(this.modify,room,user,`${value}`); + room = (await this.read + .getRoomReader() + .getById(roomId)) as IRoom; + await sendMessage( + this.modify, + room, + user, + `${value}`, + ); } } break; } - case ModalsEnum.VIEW_GITHUB_SEARCH_RESULT_PR_CHANGES:{ + case ModalsEnum.VIEW_GITHUB_SEARCH_RESULT_PR_CHANGES: { let { user, room } = await context.getInteractionData(); - let value: string = context.getInteractionData().value as string; + let value: string = context.getInteractionData() + .value as string; let PullRequestDetails = value.split(" "); - if(PullRequestDetails.length==2){ - const triggerId= context.getInteractionData().triggerId; + if (PullRequestDetails.length == 2) { + const triggerId = + context.getInteractionData().triggerId; const data = { - repository:PullRequestDetails[0], - query:"pulls", - number:PullRequestDetails[1] - } - if(triggerId && data){ + repository: PullRequestDetails[0], + query: "pulls", + number: PullRequestDetails[1], + }; + if (triggerId && data) { const resultsModal = await pullDetailsModal({ data, modify: this.modify, read: this.read, persistence: this.persistence, http: this.http, - uikitcontext: context + uikitcontext: context, }); return context - .getInteractionResponder() - .openModalViewResponse(resultsModal); - }else{ + .getInteractionResponder() + .openModalViewResponse(resultsModal); + } else { console.log("invalid Trigger ID !"); } } - if(user?.id){ - if(room?.id){ - await sendMessage(this.modify,room,user,`${value}`); - }else{ + if (user?.id) { + if (room?.id) { + await sendMessage( + this.modify, + room, + user, + `${value}`, + ); + } else { let roomId = ( await getInteractionRoomData( this.read.getPersistenceReader(), - user.id + user.id, ) ).roomId; - room = await this.read.getRoomReader().getById(roomId) as IRoom; - await sendMessage(this.modify,room,user,`${value}`); + room = (await this.read + .getRoomReader() + .getById(roomId)) as IRoom; + await sendMessage( + this.modify, + room, + user, + `${value}`, + ); } } break; } - case ModalsEnum.MULTI_SHARE_ADD_SEARCH_RESULT_ACTION:{ + case ModalsEnum.MULTI_SHARE_ADD_SEARCH_RESULT_ACTION: { let { user, room } = await context.getInteractionData(); - let searchResultId: string = context.getInteractionData().value as string; - let roomId:string=""; - if(user?.id){ - if(room?.id){ + let searchResultId: string = context.getInteractionData() + .value as string; + let roomId: string = ""; + if (user?.id) { + if (room?.id) { roomId = room.id; - }else{ + } else { roomId = ( await getInteractionRoomData( this.read.getPersistenceReader(), - user.id + user.id, ) ).roomId; - room = await this.read.getRoomReader().getById(roomId) as IRoom; + room = (await this.read + .getRoomReader() + .getById(roomId)) as IRoom; } - let githubSearchStorage = new GithubSearchResultStorage(this.persistence,this.read.getPersistenceReader()); - let searchResultData: IGitHubSearchResultData = await githubSearchStorage.getSearchResults(room?.id as string,user); - if(searchResultData?.search_results?.length){ - let index = -1; - let currentIndex = 0; - for(let searchResult of searchResultData.search_results){ - if(searchResult.result_id == searchResultId ){ - index=currentIndex; - break; - } - currentIndex++; - } - if(index !== -1){ - searchResultData.search_results[index].share=true; - await githubSearchStorage.updateSearchResult(room as IRoom,user,searchResultData); + let githubSearchStorage = new GithubSearchResultStorage( + this.persistence, + this.read.getPersistenceReader(), + ); + let searchResultData: IGitHubSearchResultData = + await githubSearchStorage.getSearchResults( + room?.id as string, + user, + ); + if (searchResultData?.search_results?.length) { + let index = -1; + let currentIndex = 0; + for (let searchResult of searchResultData.search_results) { + if (searchResult.result_id == searchResultId) { + index = currentIndex; + break; } - const resultsModal = await githubSearchResultModal({ - data: searchResultData, - modify: this.modify, - read: this.read, - persistence: this.persistence, - http: this.http, - }) - await this.modify.getUiController().updateModalView(resultsModal, { triggerId: context.getInteractionData().triggerId }, context.getInteractionData().user); + currentIndex++; + } + if (index !== -1) { + searchResultData.search_results[index].share = + true; + await githubSearchStorage.updateSearchResult( + room as IRoom, + user, + searchResultData, + ); } + const resultsModal = await githubSearchResultModal({ + data: searchResultData, + modify: this.modify, + read: this.read, + persistence: this.persistence, + http: this.http, + }); + await this.modify + .getUiController() + .updateModalView( + resultsModal, + { + triggerId: + context.getInteractionData() + .triggerId, + }, + context.getInteractionData().user, + ); + } } break; } - case ModalsEnum.MULTI_SHARE_REMOVE_SEARCH_RESULT_ACTION:{ + case ModalsEnum.MULTI_SHARE_REMOVE_SEARCH_RESULT_ACTION: { let { user, room } = await context.getInteractionData(); - let searchResultId: string = context.getInteractionData().value as string; - let roomId=""; - if(user?.id && searchResultId){ - if(room?.id){ + let searchResultId: string = context.getInteractionData() + .value as string; + let roomId = ""; + if (user?.id && searchResultId) { + if (room?.id) { roomId = room.id; - }else{ + } else { roomId = ( await getInteractionRoomData( this.read.getPersistenceReader(), - user.id + user.id, ) ).roomId; - room = await this.read.getRoomReader().getById(roomId) as IRoom; + room = (await this.read + .getRoomReader() + .getById(roomId)) as IRoom; } - let githubSearchStorage = new GithubSearchResultStorage(this.persistence,this.read.getPersistenceReader()); - let searchResultData: IGitHubSearchResultData = await githubSearchStorage.getSearchResults(room?.id as string,user); - if(searchResultData?.search_results?.length){ - let index = -1; - let currentIndex = 0; - for(let searchResult of searchResultData.search_results){ - if(searchResult.result_id == searchResultId){ - index=currentIndex; - break; - } - currentIndex++; - } - if(index !== -1){ - searchResultData.search_results[index].share=false; - await githubSearchStorage.updateSearchResult(room as IRoom,user,searchResultData); + let githubSearchStorage = new GithubSearchResultStorage( + this.persistence, + this.read.getPersistenceReader(), + ); + let searchResultData: IGitHubSearchResultData = + await githubSearchStorage.getSearchResults( + room?.id as string, + user, + ); + if (searchResultData?.search_results?.length) { + let index = -1; + let currentIndex = 0; + for (let searchResult of searchResultData.search_results) { + if (searchResult.result_id == searchResultId) { + index = currentIndex; + break; } - const resultsModal = await githubSearchResultModal({ - data: searchResultData, - modify: this.modify, - read: this.read, - persistence: this.persistence, - http: this.http, - }) - await this.modify.getUiController().updateModalView(resultsModal, { triggerId: context.getInteractionData().triggerId }, context.getInteractionData().user); + currentIndex++; + } + if (index !== -1) { + searchResultData.search_results[index].share = + false; + await githubSearchStorage.updateSearchResult( + room as IRoom, + user, + searchResultData, + ); } + const resultsModal = await githubSearchResultModal({ + data: searchResultData, + modify: this.modify, + read: this.read, + persistence: this.persistence, + http: this.http, + }); + await this.modify + .getUiController() + .updateModalView( + resultsModal, + { + triggerId: + context.getInteractionData() + .triggerId, + }, + context.getInteractionData().user, + ); + } } break; } - case ModalsEnum.MERGE_PULL_REQUEST_ACTION:{ - let value: string = context.getInteractionData().value as string; + case ModalsEnum.MERGE_PULL_REQUEST_ACTION: { + let value: string = context.getInteractionData() + .value as string; let splittedValues = value?.split(" "); let { user } = await context.getInteractionData(); - let accessToken = await getAccessTokenForUser(this.read, user, this.app.oauth2Config) as IAuthData; - if(splittedValues.length==2 && accessToken?.token){ - let data={ - "repo" : splittedValues[0], - "pullNumber": splittedValues[1] - } - let repoDetails = await getRepoData(this.http,splittedValues[0],accessToken.token); + let accessToken = (await getAccessTokenForUser( + this.read, + user, + this.app.oauth2Config, + )) as IAuthData; + if (splittedValues.length == 2 && accessToken?.token) { + let data = { + repo: splittedValues[0], + pullNumber: splittedValues[1], + }; + let repoDetails = await getRepoData( + this.http, + splittedValues[0], + accessToken.token, + ); - if(repoDetails?.permissions?.admin || repoDetails?.permissions?.push || repoDetails?.permissions?.maintain ){ + if ( + repoDetails?.permissions?.admin || + repoDetails?.permissions?.push || + repoDetails?.permissions?.maintain + ) { const mergePRModal = await mergePullRequestModal({ - data:data, + data: data, modify: this.modify, read: this.read, persistence: this.persistence, http: this.http, - uikitcontext: context - }) + uikitcontext: context, + }); return context .getInteractionResponder() .openModalViewResponse(mergePRModal); - }else{ - const unauthorizedMessageModal = await messageModal({ - message:"Unauthorized Action 🤖 You dont have push rights ⚠️", - modify: this.modify, - read: this.read, - persistence: this.persistence, - http: this.http, - uikitcontext: context - }) + } else { + const unauthorizedMessageModal = await messageModal( + { + message: + "Unauthorized Action 🤖 You dont have push rights ⚠️", + modify: this.modify, + read: this.read, + persistence: this.persistence, + http: this.http, + uikitcontext: context, + }, + ); return context .getInteractionResponder() - .openModalViewResponse(unauthorizedMessageModal); + .openModalViewResponse( + unauthorizedMessageModal, + ); } - } break; } - case ModalsEnum.COMMENT_PR_ACTION:{ - let value: string = context.getInteractionData().value as string; + case ModalsEnum.COMMENT_PR_ACTION: { + let value: string = context.getInteractionData() + .value as string; let splittedValues = value?.split(" "); let { user } = await context.getInteractionData(); - let accessToken = await getAccessTokenForUser(this.read, user, this.app.oauth2Config) as IAuthData; - if(splittedValues.length==2 && accessToken?.token){ - let data={ - "repo" : splittedValues[0], - "pullNumber": splittedValues[1] - } - const addPRCommentModal = await addPullRequestCommentsModal({ - data:data, - modify:this.modify, - read:this.read, - persistence: this.persistence, - http: this.http, - uikitcontext: context - }) + let accessToken = (await getAccessTokenForUser( + this.read, + user, + this.app.oauth2Config, + )) as IAuthData; + if (splittedValues.length == 2 && accessToken?.token) { + let data = { + repo: splittedValues[0], + pullNumber: splittedValues[1], + }; + const addPRCommentModal = + await addPullRequestCommentsModal({ + data: data, + modify: this.modify, + read: this.read, + persistence: this.persistence, + http: this.http, + uikitcontext: context, + }); return context - .getInteractionResponder() - .openModalViewResponse(addPRCommentModal); + .getInteractionResponder() + .openModalViewResponse(addPRCommentModal); } break; } - case ModalsEnum.SHARE_PROFILE : { - + case ModalsEnum.SHARE_PROFILE: { const shareProfileMod = await shareProfileModal({ - modify:this.modify, - read:this.read, + modify: this.modify, + read: this.read, persistence: this.persistence, http: this.http, - uikitcontext: context - }) + uikitcontext: context, + }); - return context.getInteractionResponder().openModalViewResponse(shareProfileMod); + return context + .getInteractionResponder() + .openModalViewResponse(shareProfileMod); } - case ModalsEnum.APPROVE_PULL_REQUEST_ACTION:{ - - let value: string = context.getInteractionData().value as string; + case ModalsEnum.APPROVE_PULL_REQUEST_ACTION: { + let value: string = context.getInteractionData() + .value as string; let splittedValues = value?.split(" "); let { user } = await context.getInteractionData(); - let { room} = await context.getInteractionData(); - let accessToken = await getAccessTokenForUser(this.read, user, this.app.oauth2Config) as IAuthData; - - if(splittedValues.length==2 && accessToken?.token){ - let data={ - "repo" : splittedValues[0], - "pullNumber": splittedValues[1] - } - let repoDetails = await getRepoData(this.http,splittedValues[0],accessToken.token); + let { room } = await context.getInteractionData(); + let accessToken = (await getAccessTokenForUser( + this.read, + user, + this.app.oauth2Config, + )) as IAuthData; - if(repoDetails?.permissions?.admin || repoDetails?.permissions?.push || repoDetails?.permissions?.maintain ){ - const response = await approvePullRequest(this.http,data.repo,accessToken.token,data.pullNumber); + if (splittedValues.length == 2 && accessToken?.token) { + let data = { + repo: splittedValues[0], + pullNumber: splittedValues[1], + }; + let repoDetails = await getRepoData( + this.http, + splittedValues[0], + accessToken.token, + ); - let message = `🤖 Pull Request successfully Approved ✔️ : https://github.com/${data.repo}/pull/${data.pullNumber}` + if ( + repoDetails?.permissions?.admin || + repoDetails?.permissions?.push || + repoDetails?.permissions?.maintain + ) { + const response = await approvePullRequest( + this.http, + data.repo, + accessToken.token, + data.pullNumber, + ); - if(response.state == "APPROVED" && room ){ - sendMessage(this.modify,room,user,message) - } + let message = `🤖 Pull Request successfully Approved ✔️ : https://github.com/${data.repo}/pull/${data.pullNumber}`; - if(response.errors && room){ - sendNotification(this.read,this.modify,user,room,response.errors[0]); + if (response.state == "APPROVED" && room) { + sendMessage(this.modify, room, user, message); } - }else{ - const unauthorizedMessageModal = await messageModal({ - message:"Unauthorized Action 🤖 You dont have push rights ⚠️", - modify: this.modify, - read: this.read, - persistence: this.persistence, - http: this.http, - uikitcontext: context - }) + if (response.errors && room) { + sendNotification( + this.read, + this.modify, + user, + room, + response.errors[0], + ); + } + } else { + const unauthorizedMessageModal = await messageModal( + { + message: + "Unauthorized Action 🤖 You dont have push rights ⚠️", + modify: this.modify, + read: this.read, + persistence: this.persistence, + http: this.http, + uikitcontext: context, + }, + ); return context .getInteractionResponder() - .openModalViewResponse(unauthorizedMessageModal); + .openModalViewResponse( + unauthorizedMessageModal, + ); } } break; } - case ModalsEnum.ISSUE_COMMENT_LIST_ACTION:{ - let value: string = context.getInteractionData().value as string; + case ModalsEnum.ISSUE_COMMENT_LIST_ACTION: { + let value: string = context.getInteractionData() + .value as string; let splittedValues = value?.split(" "); let { user } = await context.getInteractionData(); - let accessToken = await getAccessTokenForUser(this.read, user, this.app.oauth2Config) as IAuthData; - if(splittedValues.length==2){ + let accessToken = (await getAccessTokenForUser( + this.read, + user, + this.app.oauth2Config, + )) as IAuthData; + if (splittedValues.length == 2) { let repoName = splittedValues[0]; let issueNumber = splittedValues[1]; - let issueComments = await getIssuesComments(this.http,repoName,accessToken?.token,issueNumber); - let issueData = await getIssueData(repoName,issueNumber,accessToken?.token,this.http); - if(issueData?.issue_compact === "Error Fetching Issue" || issueComments?.issueData){ - if(issueData?.issue_compact === "Error Fetching Issue"){ - const unauthorizedMessageModal = await messageModal({ - message:`🤖 Error Fetching Issue Data ⚠️`, - modify: this.modify, - read: this.read, - persistence: this.persistence, - http: this.http, - uikitcontext: context - }) + let issueComments = await getIssuesComments( + this.http, + repoName, + accessToken?.token, + issueNumber, + ); + let issueData = await getIssueData( + repoName, + issueNumber, + accessToken?.token, + this.http, + ); + if ( + issueData?.issue_compact === + "Error Fetching Issue" || + issueComments?.issueData + ) { + if ( + issueData?.issue_compact === + "Error Fetching Issue" + ) { + const unauthorizedMessageModal = + await messageModal({ + message: `🤖 Error Fetching Issue Data ⚠️`, + modify: this.modify, + read: this.read, + persistence: this.persistence, + http: this.http, + uikitcontext: context, + }); return context .getInteractionResponder() - .openModalViewResponse(unauthorizedMessageModal); + .openModalViewResponse( + unauthorizedMessageModal, + ); } - if(issueComments?.serverError){ - const unauthorizedMessageModal = await messageModal({ - message:`🤖 Error Fetching Comments ⚠️`, - modify: this.modify, - read: this.read, - persistence: this.persistence, - http: this.http, - uikitcontext: context - }) + if (issueComments?.serverError) { + const unauthorizedMessageModal = + await messageModal({ + message: `🤖 Error Fetching Comments ⚠️`, + modify: this.modify, + read: this.read, + persistence: this.persistence, + http: this.http, + uikitcontext: context, + }); return context .getInteractionResponder() - .openModalViewResponse(unauthorizedMessageModal); + .openModalViewResponse( + unauthorizedMessageModal, + ); } } - let data={ + let data = { repo: repoName, issueNumber: issueNumber, issueData: issueData, - issueComments: issueComments?.data - } + issueComments: issueComments?.data, + }; const addIssueCommentModal = await issueCommentsModal({ - data:data, - modify:this.modify, - read:this.read, + data: data, + modify: this.modify, + read: this.read, persistence: this.persistence, http: this.http, - uikitcontext: context - }) + uikitcontext: context, + }); return context - .getInteractionResponder() - .openModalViewResponse(addIssueCommentModal); + .getInteractionResponder() + .openModalViewResponse(addIssueCommentModal); } break; } - case ModalsEnum.COMMENT_ISSUE_ACTION:{ - let value: string = context.getInteractionData().value as string; + case ModalsEnum.COMMENT_ISSUE_ACTION: { + let value: string = context.getInteractionData() + .value as string; let splittedValues = value?.split(" "); let { user } = await context.getInteractionData(); - let accessToken = await getAccessTokenForUser(this.read, user, this.app.oauth2Config) as IAuthData; - if(splittedValues.length==2 && accessToken?.token){ - let data={ - "repo" : splittedValues[0], - "issueNumber": splittedValues[1] - } - const addIssueCommentModal = await addIssueCommentsModal({ - data:data, - modify:this.modify, - read:this.read, - persistence: this.persistence, - http: this.http, - uikitcontext: context - }) + let accessToken = (await getAccessTokenForUser( + this.read, + user, + this.app.oauth2Config, + )) as IAuthData; + if (splittedValues.length == 2 && accessToken?.token) { + let data = { + repo: splittedValues[0], + issueNumber: splittedValues[1], + }; + const addIssueCommentModal = + await addIssueCommentsModal({ + data: data, + modify: this.modify, + read: this.read, + persistence: this.persistence, + http: this.http, + uikitcontext: context, + }); return context - .getInteractionResponder() - .openModalViewResponse(addIssueCommentModal); - }else{ + .getInteractionResponder() + .openModalViewResponse(addIssueCommentModal); + } else { const unauthorizedMessageModal = await messageModal({ - message:`🤖 Error in adding comments, make sure you are logged in`, + message: `🤖 Error in adding comments, make sure you are logged in`, modify: this.modify, read: this.read, persistence: this.persistence, http: this.http, - uikitcontext: context - }) + uikitcontext: context, + }); return context .getInteractionResponder() .openModalViewResponse(unauthorizedMessageModal); @@ -810,81 +1159,107 @@ export class ExecuteBlockActionHandler { break; } - case ModalsEnum.PR_COMMENT_LIST_ACTION:{ - let value: string = context.getInteractionData().value as string; + case ModalsEnum.PR_COMMENT_LIST_ACTION: { + let value: string = context.getInteractionData() + .value as string; let splittedValues = value?.split(" "); let { user } = await context.getInteractionData(); - let accessToken = await getAccessTokenForUser(this.read, user, this.app.oauth2Config) as IAuthData; - if(splittedValues.length==2 && accessToken?.token){ + let accessToken = (await getAccessTokenForUser( + this.read, + user, + this.app.oauth2Config, + )) as IAuthData; + if (splittedValues.length == 2 && accessToken?.token) { let repoName = splittedValues[0]; let pullNumber = splittedValues[1]; - let pullRequestComments = await getPullRequestComments(this.http,repoName,accessToken.token,pullNumber); - let pullRequestData = await getPullRequestData(this.http,repoName,accessToken.token,pullNumber); - if(pullRequestData?.serverError || pullRequestComments?.pullRequestData){ - if(pullRequestData?.serverError){ - const unauthorizedMessageModal = await messageModal({ - message:`🤖 Error Fetching Repository Data: ⚠️ ${pullRequestData?.message}`, - modify: this.modify, - read: this.read, - persistence: this.persistence, - http: this.http, - uikitcontext: context - }) + let pullRequestComments = await getPullRequestComments( + this.http, + repoName, + accessToken.token, + pullNumber, + ); + let pullRequestData = await getPullRequestData( + this.http, + repoName, + accessToken.token, + pullNumber, + ); + if ( + pullRequestData?.serverError || + pullRequestComments?.pullRequestData + ) { + if (pullRequestData?.serverError) { + const unauthorizedMessageModal = + await messageModal({ + message: `🤖 Error Fetching Repository Data: ⚠️ ${pullRequestData?.message}`, + modify: this.modify, + read: this.read, + persistence: this.persistence, + http: this.http, + uikitcontext: context, + }); return context .getInteractionResponder() - .openModalViewResponse(unauthorizedMessageModal); + .openModalViewResponse( + unauthorizedMessageModal, + ); } - if(pullRequestComments?.serverError){ - const unauthorizedMessageModal = await messageModal({ - message:`🤖 Error Fetching Comments: ⚠️ ${pullRequestData?.message}`, - modify: this.modify, - read: this.read, - persistence: this.persistence, - http: this.http, - uikitcontext: context - }) + if (pullRequestComments?.serverError) { + const unauthorizedMessageModal = + await messageModal({ + message: `🤖 Error Fetching Comments: ⚠️ ${pullRequestData?.message}`, + modify: this.modify, + read: this.read, + persistence: this.persistence, + http: this.http, + uikitcontext: context, + }); return context .getInteractionResponder() - .openModalViewResponse(unauthorizedMessageModal); + .openModalViewResponse( + unauthorizedMessageModal, + ); } } - let data={ + let data = { repo: repoName, pullNumber: pullNumber, pullData: pullRequestData, - pullRequestComments: pullRequestComments?.data - } - const addPRCommentModal = await pullRequestCommentsModal({ - data:data, - modify:this.modify, - read:this.read, - persistence: this.persistence, - http: this.http, - uikitcontext: context - }) + pullRequestComments: pullRequestComments?.data, + }; + const addPRCommentModal = + await pullRequestCommentsModal({ + data: data, + modify: this.modify, + read: this.read, + persistence: this.persistence, + http: this.http, + uikitcontext: context, + }); return context - .getInteractionResponder() - .openModalViewResponse(addPRCommentModal); + .getInteractionResponder() + .openModalViewResponse(addPRCommentModal); } break; } - case ModalsEnum.ADD_GITHUB_ISSUE_ASSIGNEE_PROFILE : + case ModalsEnum.ADD_GITHUB_ISSUE_ASSIGNEE_PROFILE: case ModalsEnum.ADD_GITHUB_ISSUE_ASSIGNEE: { - let value: string = context.getInteractionData().value as string; + let value: string = context.getInteractionData() + .value as string; let splittedValues = value?.split(" "); - if(splittedValues?.length>=3){ + if (splittedValues?.length >= 3) { let repository = splittedValues[0]; let issueNumber = splittedValues[1]; let assignees: string = ""; - for(let i = 2;i0){ + for (let i = 2; i < splittedValues.length; i++) { + if (splittedValues[i].length > 0) { assignees += `${splittedValues[i]} `; } } let data = { repository, issueNumber, - assignees + assignees, }; const addIssueAssignee = await addIssueAssigneeModal({ data, @@ -892,8 +1267,8 @@ export class ExecuteBlockActionHandler { read: this.read, persistence: this.persistence, http: this.http, - uikitcontext: context - }) + uikitcontext: context, + }); return context .getInteractionResponder() .openModalViewResponse(addIssueAssignee); @@ -901,140 +1276,243 @@ export class ExecuteBlockActionHandler { break; } case ModalsEnum.REFRESH_GITHUB_ISSUES_ACTION: { - let repository: string = context.getInteractionData().value as string; - repository=repository?.trim(); + let repository: string = context.getInteractionData() + .value as string; + repository = repository?.trim(); let { user } = await context.getInteractionData(); - let accessToken = await getAccessTokenForUser(this.read, user, this.app.oauth2Config); + let accessToken = await getAccessTokenForUser( + this.read, + user, + this.app.oauth2Config, + ); if (!accessToken) { - let response = await getRepositoryIssues(this.http,repository); + let response = await getRepositoryIssues( + this.http, + repository, + ); let data = { issues: response.issues, - pushRights : false, //no access token, so user has no pushRights to the repo, - repo: repository - } - const issuesListModal = await githubIssuesListModal( {data: data, modify: this.modify, read: this.read, persistence: this.persistence, http: this.http, uikitcontext: context} ); - await this.modify.getUiController().updateModalView(issuesListModal, { triggerId: context.getInteractionData().triggerId }, context.getInteractionData().user); - }else{ - let repoDetails = await getRepoData(this.http,repository,accessToken.token); - let response = await getRepositoryIssues(this.http,repository); + pushRights: false, //no access token, so user has no pushRights to the repo, + repo: repository, + }; + const issuesListModal = await githubIssuesListModal({ + data: data, + modify: this.modify, + read: this.read, + persistence: this.persistence, + http: this.http, + uikitcontext: context, + id: this.app.getID() + }); + await this.modify + .getUiController() + .updateSurfaceView( + issuesListModal, + { + triggerId: + context.getInteractionData().triggerId, + }, + context.getInteractionData().user, + ); + } else { + let repoDetails = await getRepoData( + this.http, + repository, + accessToken.token, + ); + let response = await getRepositoryIssues( + this.http, + repository, + ); let data = { issues: response.issues, - pushRights : repoDetails?.permissions?.push || repoDetails?.permissions?.admin, - repo: repository - } - const issuesListModal = await githubIssuesListModal( {data: data, modify: this.modify, read: this.read, persistence: this.persistence, http: this.http, uikitcontext: context} ); - await this.modify.getUiController().updateModalView(issuesListModal, { triggerId: context.getInteractionData().triggerId }, context.getInteractionData().user); + pushRights: + repoDetails?.permissions?.push || + repoDetails?.permissions?.admin, + repo: repository, + }; + const issuesListModal = await githubIssuesListModal({ + data: data, + modify: this.modify, + read: this.read, + persistence: this.persistence, + http: this.http, + uikitcontext: context, + id: this.app.getID(), + }); + await this.modify + .getUiController() + .updateSurfaceView( + issuesListModal, + { + triggerId: + context.getInteractionData().triggerId, + }, + context.getInteractionData().user, + ); } break; } - case ModalsEnum.MULTI_SHARE_ADD_GITHUB_ISSUE_ACTION:{ + case ModalsEnum.MULTI_SHARE_ADD_GITHUB_ISSUE_ACTION: { let { user, room } = await context.getInteractionData(); - let issueId: string = context.getInteractionData().value as string; - let roomId:string=""; - if(user?.id){ - if(room?.id){ + let issueId: string = context.getInteractionData() + .value as string; + let roomId: string = ""; + if (user?.id) { + if (room?.id) { roomId = room.id; - }else{ + } else { roomId = ( await getInteractionRoomData( this.read.getPersistenceReader(), - user.id + user.id, ) ).roomId; - room = await this.read.getRoomReader().getById(roomId) as IRoom; + room = (await this.read + .getRoomReader() + .getById(roomId)) as IRoom; } - let githubissueStorage = new GithubRepoIssuesStorage(this.persistence,this.read.getPersistenceReader()); - let repoIssuesData: IGitHubIssueData = await githubissueStorage.getIssueData(room?.id as string,user); - if(repoIssuesData?.issue_list?.length){ - let index = -1; - let currentIndex = 0; - for(let issue of repoIssuesData.issue_list){ - if(issue.issue_id == issueId ){ - index=currentIndex; - break; - } - currentIndex++; - } - if(index !== -1){ - repoIssuesData.issue_list[index].share=true; - await githubissueStorage.updateIssueData(room as IRoom,user,repoIssuesData); - } - let data = { - issues: repoIssuesData.issue_list, - pushRights : repoIssuesData.push_rights, //no access token, so user has no pushRights to the repo, - repo: repoIssuesData.repository, - user_id: user.id + let githubissueStorage = new GithubRepoIssuesStorage( + this.persistence, + this.read.getPersistenceReader(), + ); + let repoIssuesData: IGitHubIssueData = + await githubissueStorage.getIssueData( + room?.id as string, + user, + ); + if (repoIssuesData?.issue_list?.length) { + let index = -1; + let currentIndex = 0; + for (let issue of repoIssuesData.issue_list) { + if (issue.issue_id == issueId) { + index = currentIndex; + break; } - const githubIssuesModal = await githubIssuesListModal({ + currentIndex++; + } + if (index !== -1) { + repoIssuesData.issue_list[index].share = true; + await githubissueStorage.updateIssueData( + room as IRoom, + user, + repoIssuesData, + ); + } + let data = { + issues: repoIssuesData.issue_list, + pushRights: repoIssuesData.push_rights, //no access token, so user has no pushRights to the repo, + repo: repoIssuesData.repository, + user_id: user.id, + }; + const githubIssuesModal = + await githubIssuesListModal({ data: data, modify: this.modify, read: this.read, persistence: this.persistence, http: this.http, - }) - await this.modify.getUiController().updateModalView(githubIssuesModal, { triggerId: context.getInteractionData().triggerId }, context.getInteractionData().user); - } + id: this.app.getID(), + }); + await this.modify + .getUiController() + .updateSurfaceView( + githubIssuesModal, + { + triggerId: + context.getInteractionData() + .triggerId, + }, + context.getInteractionData().user, + ); + } } break; } - case ModalsEnum.MULTI_SHARE_REMOVE_GITHUB_ISSUE_ACTION:{ + case ModalsEnum.MULTI_SHARE_REMOVE_GITHUB_ISSUE_ACTION: { let { user, room } = await context.getInteractionData(); - let issueId: string = context.getInteractionData().value as string; - let roomId:string=""; - if(user?.id){ - if(room?.id){ + let issueId: string = context.getInteractionData() + .value as string; + let roomId: string = ""; + if (user?.id) { + if (room?.id) { roomId = room.id; - }else{ + } else { roomId = ( await getInteractionRoomData( this.read.getPersistenceReader(), - user.id + user.id, ) ).roomId; - room = await this.read.getRoomReader().getById(roomId) as IRoom; + room = (await this.read + .getRoomReader() + .getById(roomId)) as IRoom; } - let githubissueStorage = new GithubRepoIssuesStorage(this.persistence,this.read.getPersistenceReader()); - let repoIssuesData: IGitHubIssueData = await githubissueStorage.getIssueData(room?.id as string,user); - if(repoIssuesData?.issue_list?.length){ - let index = -1; - let currentIndex = 0; - for(let issue of repoIssuesData.issue_list){ - if(issue.issue_id == issueId ){ - index=currentIndex; - break; - } - currentIndex++; - } - if(index !== -1){ - repoIssuesData.issue_list[index].share=false; - await githubissueStorage.updateIssueData(room as IRoom,user,repoIssuesData); - } - let data = { - issues: repoIssuesData.issue_list, - pushRights : repoIssuesData.push_rights, //no access token, so user has no pushRights to the repo, - repo: repoIssuesData.repository, - user_id: user.id + let githubissueStorage = new GithubRepoIssuesStorage( + this.persistence, + this.read.getPersistenceReader(), + ); + let repoIssuesData: IGitHubIssueData = + await githubissueStorage.getIssueData( + room?.id as string, + user, + ); + if (repoIssuesData?.issue_list?.length) { + let index = -1; + let currentIndex = 0; + for (let issue of repoIssuesData.issue_list) { + if (issue.issue_id == issueId) { + index = currentIndex; + break; } - const githubIssuesModal = await githubIssuesListModal({ + currentIndex++; + } + if (index !== -1) { + repoIssuesData.issue_list[index].share = false; + await githubissueStorage.updateIssueData( + room as IRoom, + user, + repoIssuesData, + ); + } + let data = { + issues: repoIssuesData.issue_list, + pushRights: repoIssuesData.push_rights, //no access token, so user has no pushRights to the repo, + repo: repoIssuesData.repository, + user_id: user.id, + }; + const githubIssuesModal = + await githubIssuesListModal({ data: data, modify: this.modify, read: this.read, persistence: this.persistence, http: this.http, - }) - await this.modify.getUiController().updateModalView(githubIssuesModal, { triggerId: context.getInteractionData().triggerId }, context.getInteractionData().user); - } + id: this.app.getID(), + }); + await this.modify + .getUiController() + .updateSurfaceView( + githubIssuesModal, + { + triggerId: + context.getInteractionData() + .triggerId, + }, + context.getInteractionData().user, + ); + } } break; - } - - case ModalsEnum.GITHUB_LOGIN_ACTION :{ - const {user, room} = context.getInteractionData(); - if(room){ + } + + case ModalsEnum.GITHUB_LOGIN_ACTION: { + const { user, room } = context.getInteractionData(); + if (room) { await storeInteractionRoomData( this.persistence, user.id, - room.id + room.id, ); } break; @@ -1046,9 +1524,12 @@ export class ExecuteBlockActionHandler { read: this.read, persistence: this.persistence, http: this.http, - uikitcontext: context - }) - return context.getInteractionResponder().openModalViewResponse(assignIssuesModal); + uikitcontext: context, + id: this.app.getID(), + }); + return context + .getInteractionResponder() + .openModalViewResponse(assignIssuesModal); } case ModalsEnum.TRIGGER_SUBSCRIPTIONS_MODAL: { @@ -1057,10 +1538,12 @@ export class ExecuteBlockActionHandler { read: this.read, persistence: this.persistence, http: this.http, - uikitcontext: context + uikitcontext: context, }); - return context.getInteractionResponder().openModalViewResponse(opensubscriptionsModal); + return context + .getInteractionResponder() + .openModalViewResponse(opensubscriptionsModal); } case ModalsEnum.TRIGGER_NEW_ISSUE_MODAL: { @@ -1069,43 +1552,72 @@ export class ExecuteBlockActionHandler { read: this.read, persistence: this.persistence, http: this.http, - uikitcontext: context + uikitcontext: context, + id: this.app.getID(), }); - return context.getInteractionResponder().openModalViewResponse(newIssueModal); + return context + .getInteractionResponder() + .openModalViewResponse(newIssueModal); } - + case ModalsEnum.TRIGGER_SEARCH_MODAL: { const searchModal = await githubSearchModal({ modify: this.modify, read: this.read, persistence: this.persistence, http: this.http, - uikitcontext: context + uikitcontext: context, }); - return context.getInteractionResponder().openModalViewResponse(searchModal); + return context + .getInteractionResponder() + .openModalViewResponse(searchModal); } - case ModalsEnum.UNSUBSCRIBE_REMINDER_ACTION:{ - const param:string[] = data.value?.split('|') as string[]; + case ModalsEnum.UNSUBSCRIBE_REMINDER_ACTION: { + const param: string[] = data.value?.split("|") as string[]; let { user, room } = await context.getInteractionData(); const repo = param[0]; - const number = param[1]; + const number = param[1]; - await unsubscribedPR(this.read,this.persistence,repo,Number(number),user); + await unsubscribedPR( + this.read, + this.persistence, + repo, + Number(number), + user, + ); const message = `You have unsubscribed from repository [${repo} Pull Request #${number}](https://github.com/${repo}/pull/${number})`; - await sendNotification(this.read, this.modify, user, room as IRoom, message); - + await sendNotification( + this.read, + this.modify, + user, + room as IRoom, + message, + ); } - - case ModalsEnum.REMINDER_REMOVE_REPO_ACTION : { - const {value, user} = context.getInteractionData(); - await removeRepoReminder(this.read, this.persistence, value as string, user); - - const updatedReminderModal = await reminderModal({modify: this.modify, read:this.read, persistence: this.persistence, http: this.http, uikitcontext: context}); - return context.getInteractionResponder().updateModalViewResponse( updatedReminderModal); + case ModalsEnum.REMINDER_REMOVE_REPO_ACTION: { + const { value, user } = context.getInteractionData(); + await removeRepoReminder( + this.read, + this.persistence, + value as string, + user, + ); + + const updatedReminderModal = await reminderModal({ + modify: this.modify, + read: this.read, + persistence: this.persistence, + http: this.http, + uikitcontext: context, + }); + + return context + .getInteractionResponder() + .updateModalViewResponse(updatedReminderModal); } } } catch (error) { @@ -1114,4 +1626,4 @@ export class ExecuteBlockActionHandler { return context.getInteractionResponder().successResponse(); } -} \ No newline at end of file +} diff --git a/github/handlers/ExecuteViewSubmitHandler.ts b/github/handlers/ExecuteViewSubmitHandler.ts index 38c34b4..cb35983 100644 --- a/github/handlers/ExecuteViewSubmitHandler.ts +++ b/github/handlers/ExecuteViewSubmitHandler.ts @@ -29,6 +29,7 @@ import { issueCommentsModal } from '../modals/issueCommentsModal'; import { createReminder } from './CreateReminder'; import { RocketChatAssociationModel, RocketChatAssociationRecord } from '@rocket.chat/apps-engine/definition/metadata'; import { IAuthData } from '@rocket.chat/apps-engine/definition/oauth2/IOAuth2'; +import { NewIssueStarterModal } from '../modals/newIssueStarterModal'; export class ExecuteViewSubmitHandler { constructor( private readonly app: GithubApp, @@ -154,12 +155,12 @@ export class ExecuteViewSubmitHandler { }else{ await sendNotification(this.read,this.modify,user,room,`Invalid Issue !`); } - } + } break; } case ModalsEnum.NEW_ISSUE_STARTER_VIEW:{ const { roomId } = await getInteractionRoomData(this.read.getPersistenceReader(), user.id); - + if (roomId) { let room = await this.read.getRoomReader().getById(roomId) as IRoom; let repository = view.state?.[ModalsEnum.REPO_NAME_INPUT]?.[ModalsEnum.REPO_NAME_INPUT_ACTION] as string; @@ -167,7 +168,7 @@ export class ExecuteViewSubmitHandler { if (!accessToken) { await sendNotification(this.read, this.modify, user, room, `Login To Github ! -> /github login`); }else{ - + repository=repository?.trim(); let response = await getIssueTemplates(this.http,repository,accessToken.token); if((!response.template_not_found) && response?.templates?.length){ @@ -185,7 +186,7 @@ export class ExecuteViewSubmitHandler { .openModalViewResponse(createNewIssue); } } - } + } break; } case ModalsEnum.SEARCH_VIEW: { @@ -227,7 +228,7 @@ export class ExecuteViewSubmitHandler { }else{ resourceState = resourceState?.trim(); } - + let accessToken = await getAccessTokenForUser(this.read, user, this.app.oauth2Config); if(repository?.length == 0 && labelsArray?.length == 0 && authorsArray?.length == 0){ await sendNotification(this.read, this.modify, user, room, "*Invalid Search Query !*"); @@ -404,7 +405,7 @@ export class ExecuteViewSubmitHandler { return context .getInteractionResponder() .openModalViewResponse(unauthorizedMessageModal); - }else{ + }else{ let pullRequestComments = await getPullRequestComments(this.http,repository,accessToken.token,pullNumber); let pullRequestData = await getPullRequestData(this.http,repository,accessToken.token,pullNumber); if(pullRequestData?.serverError || pullRequestComments?.pullRequestData){ @@ -482,7 +483,7 @@ export class ExecuteViewSubmitHandler { return context .getInteractionResponder() .openModalViewResponse(unauthorizedMessageModal); - }else{ + }else{ let issueComments = await getIssuesComments(this.http,repository,accessToken?.token,issueNumber); let issueData = await getIssueData(repository,issueNumber,accessToken.token,this.http); if(issueData?.issue_compact === "Error Fetching Issue" || issueComments?.issueData){ @@ -552,45 +553,45 @@ export class ExecuteViewSubmitHandler { response = await getRepositoryIssues(this.http,repository); pushRights = repoDetails?.permissions?.push || repoDetails?.permissions?.admin; } - if(response.serverError){ + if (response.serverError) { let errorMessage = response?.message; - const unauthorizedMessageModal = await messageModal({ - message:`🤖 Error Fetching GitHub Issues : ⚠️ ${errorMessage}`, - modify: this.modify, - read: this.read, - persistence: this.persistence, - http: this.http, - uikitcontext: context - }) - return context - .getInteractionResponder() - .openModalViewResponse(unauthorizedMessageModal); - }else{ + const unauthorizedMessageModal = await messageModal({ + message: `🤖 Error Fetching GitHub Issues : ⚠️ ${errorMessage}`, + modify: this.modify, + read: this.read, + persistence: this.persistence, + http: this.http, + uikitcontext: context + }) + return context + .getInteractionResponder() + .openModalViewResponse(unauthorizedMessageModal); + } else { let issueList: Array = []; - for(let issue of response.issues){ - if(issue.pull_request){ + for (let issue of response.issues) { + if (issue.pull_request) { continue; } let issue_id = issue.id; let labels: Array = []; let assignees: Array = []; - if(issue?.labels && Array.isArray(issue.labels)){ - for(let label of issue.labels){ + if (issue?.labels && Array.isArray(issue.labels)) { + for (let label of issue.labels) { labels.push(`${label.name}`); } } - if(issue?.assignees && Array.isArray(issue.assignees)){ - for(let assignee of issue.assignees){ + if (issue?.assignees && Array.isArray(issue.assignees)) { + for (let assignee of issue.assignees) { assignees.push(assignee.login); } } - let title:string = issue.title; - let user_login:string = issue.user.login; - let number:string|number = issue.number; - let state:string = issue.state; - let html_url:string = issue.html_url; + let title: string = issue.title; + let user_login: string = issue.user.login; + let number: string | number = issue.number; + let state: string = issue.state; + let html_url: string = issue.html_url; let issue_compact = `[ #${issue.number} ](${issue?.html_url?.toString()}) *${issue.title?.toString()?.trim()}* : ${issue?.html_url}`; - let githubIssue: IGitHubIssue={ + let githubIssue: IGitHubIssue = { issue_id, labels, assignees, @@ -600,33 +601,35 @@ export class ExecuteViewSubmitHandler { user_login, title, issue_compact, - share:false + share: false } issueList.push(githubIssue); } - let githubIssueStorage = new GithubRepoIssuesStorage(this.persistence,this.read.getPersistenceReader()); + let githubIssueStorage = new GithubRepoIssuesStorage(this.persistence, this.read.getPersistenceReader()); let room = await this.read.getRoomReader().getById(roomId) as IRoom; - let githubIssueData: IGitHubIssueData={ - repository:repository, + let githubIssueData: IGitHubIssueData = { + repository: repository, room_id: roomId, user_id: user.id, issue_list: issueList, push_rights: pushRights } - await githubIssueStorage.updateIssueData(room,user,githubIssueData); + await githubIssueStorage.updateIssueData(room, user, githubIssueData); data = { issues: issueList, - pushRights : pushRights, //no access token, so user has no pushRights to the repo, + pushRights: pushRights, //no access token, so user has no pushRights to the repo, repo: repository, user_id: user.id } - const issuesListModal = await githubIssuesListModal( {data: data, modify: this.modify, read: this.read, persistence: this.persistence, http: this.http, uikitcontext: context} ); - return context - .getInteractionResponder() - .openModalViewResponse(issuesListModal); + const issuesListModal = await githubIssuesListModal( {data: data, modify: this.modify, read: this.read, persistence: this.persistence, http: this.http, uikitcontext: context, id: this.app.getID()} ); + const triggerId = context.getInteractionData().triggerId; + + if(triggerId) { + return this.modify.getUiController().openSurfaceView(issuesListModal, { triggerId }, user) + } } - } + } break; } case ModalsEnum.ADD_ISSUE_ASSIGNEE_VIEW: { @@ -688,6 +691,7 @@ export class ExecuteViewSubmitHandler { read: this.read, persistence: this.persistence, http: this.http, + id: this.app.getID(), }) let room = await this.read.getRoomReader().getById(roomId) as IRoom; await sendNotification(this.read,this.modify,user,room,"🤖 Assigned Issue Successfully ✔️"); @@ -696,7 +700,7 @@ export class ExecuteViewSubmitHandler { } } } - } + } break; } case ModalsEnum.ISSUE_LIST_VIEW:{ @@ -713,11 +717,13 @@ export class ExecuteViewSubmitHandler { read: this.read, persistence: this.persistence, http: this.http, - uikitcontext: context + uikitcontext: context, + id: this.app.getID(), }); - return context - .getInteractionResponder() - .openModalViewResponse(issueShareModal); + const triggerId = context.getInteractionData().triggerId; + if(triggerId) { + return this.modify.getUiController().openSurfaceView(issueShareModal, {triggerId}, user) + } } } } @@ -729,6 +735,7 @@ export class ExecuteViewSubmitHandler { if (roomId) { let room = await this.read.getRoomReader().getById(roomId) as IRoom; let searchResult: string|undefined = view.state?.[ ModalsEnum.MULTI_SHARE_GITHUB_ISSUES_INPUT]?.[ModalsEnum.MULTI_SHARE_GITHUB_ISSUES_INPUT_ACTION]; + console.log(searchResult); await sendMessage(this.modify,room,user,searchResult as string); } } @@ -742,7 +749,7 @@ export class ExecuteViewSubmitHandler { let repository = view.state?.[ModalsEnum.REPO_NAME_INPUT]?.[ModalsEnum.REPO_NAME_INPUT_ACTION] as string; await createReminder(repository,room,this.read,this.app,this.persistence,this.modify,this.http,user) - + } break; } @@ -816,4 +823,4 @@ export class ExecuteViewSubmitHandler { success: true, }; } -} \ No newline at end of file +} diff --git a/github/handlers/HandleIssues.ts b/github/handlers/HandleIssues.ts index 8227c6e..551d112 100644 --- a/github/handlers/HandleIssues.ts +++ b/github/handlers/HandleIssues.ts @@ -30,6 +30,7 @@ export async function handleNewIssue( persistence: persistence, http: http, slashcommandcontext: context, + id: app.getID() }); await modify .getUiController() @@ -63,8 +64,8 @@ export async function handleIssues( ){ const triggerId= context.getTriggerId(); if(triggerId){ - const modal = await GitHubIssuesStarterModal({modify,read,persistence,http,slashcommandcontext:context}); - await modify.getUiController().openModalView(modal,{triggerId},context.getSender()); + const modal = await GitHubIssuesStarterModal({modify,read,persistence,http,slashcommandcontext:context, id: app.getID()}); + await modify.getUiController().openSurfaceView(modal,{triggerId},context.getSender()); }else{ console.log("invalid Trigger ID !"); } diff --git a/github/modals/getIssuesStarterModal.ts b/github/modals/getIssuesStarterModal.ts index 8fe860d..a06e4ea 100644 --- a/github/modals/getIssuesStarterModal.ts +++ b/github/modals/getIssuesStarterModal.ts @@ -3,6 +3,7 @@ import { IModify, IPersistence, IRead, + IUIKitSurfaceViewParam, } from "@rocket.chat/apps-engine/definition/accessors"; import { TextObjectType } from "@rocket.chat/apps-engine/definition/uikit/blocks"; import { IUIKitModalViewParam } from "@rocket.chat/apps-engine/definition/uikit/UIKitInteractionResponder"; @@ -10,6 +11,7 @@ import { ModalsEnum } from "../enum/Modals"; import { SlashCommandContext } from "@rocket.chat/apps-engine/definition/slashcommands"; import { UIKitInteractionContext, + UIKitSurfaceType, } from "@rocket.chat/apps-engine/definition/uikit"; import { storeInteractionRoomData, @@ -23,6 +25,7 @@ export async function GitHubIssuesStarterModal({ http, slashcommandcontext, uikitcontext, + id, }: { modify: IModify; read: IRead; @@ -30,12 +33,36 @@ export async function GitHubIssuesStarterModal({ http: IHttp; slashcommandcontext?: SlashCommandContext; uikitcontext?: UIKitInteractionContext; -}): Promise { + id: string; +}): Promise { const viewId = ModalsEnum.GITHUB_ISSUES_STARTER_VIEW; - const block = modify.getCreator().getBlockBuilder(); - const room = slashcommandcontext?.getRoom() || uikitcontext?.getInteractionData().room; - const user = slashcommandcontext?.getSender() || uikitcontext?.getInteractionData().user; + const room = + slashcommandcontext?.getRoom() || + uikitcontext?.getInteractionData().room; + const user = + slashcommandcontext?.getSender() || + uikitcontext?.getInteractionData().user; + const modal: IUIKitSurfaceViewParam = { + id: viewId, + type: UIKitSurfaceType.MODAL, + title: { + text: ModalsEnum.GITHUB_ISSUES_TITLE, + type: "plain_text", + }, + blocks: [], + submit: { + type: "button", + text: { + type: "plain_text", + emoji: true, + text: "Next 🚀", + }, + appId: id, + blockId: "submit_block", + actionId: ModalsEnum.NEW_ISSUE_STARTER__ACTION, + }, + }; if (user?.id) { let roomId; @@ -46,49 +73,35 @@ export async function GitHubIssuesStarterModal({ roomId = ( await getInteractionRoomData( read.getPersistenceReader(), - user.id + user.id, ) ).roomId; } - block.addInputBlock({ - blockId: ModalsEnum.REPO_NAME_INPUT, - label: { - text: ModalsEnum.REPO_NAME_LABEL, - type: TextObjectType.PLAINTEXT, - }, - element: block.newPlainTextInputElement({ - actionId: ModalsEnum.REPO_NAME_INPUT_ACTION, - placeholder: { - text: ModalsEnum.REPO_NAME_PLACEHOLDER, - type: TextObjectType.PLAINTEXT, + modal.blocks = [ + { + type: "input", + label: { + type: "plain_text", + text: ModalsEnum.REPO_NAME_LABEL, + }, + element: { + type: "plain_text_input", + appId: id, + actionId: ModalsEnum.REPO_NAME_INPUT_ACTION, + blockId: ModalsEnum.REPO_NAME_INPUT, + placeholder: { + type: "plain_text", + text: ModalsEnum.REPO_NAME_PLACEHOLDER, + }, + multiline: false, }, - }), - }); - } - - block.addDividerBlock(); - - return { - id: viewId, - title: { - type: TextObjectType.PLAINTEXT, - text: ModalsEnum.GITHUB_ISSUES_TITLE, - }, - close: block.newButtonElement({ - text: { - type: TextObjectType.PLAINTEXT, - text: "Close", }, - }), - submit: block.newButtonElement({ - actionId: ModalsEnum.NEW_ISSUE_STARTER__ACTION, - text: { - type: TextObjectType.PLAINTEXT, - emoji:true, - text: "Next 🚀", + { + type: "divider", }, - }), - blocks: block.getBlocks(), - }; + ]; + } + + return modal; } diff --git a/github/modals/githubIssuesListModal.ts b/github/modals/githubIssuesListModal.ts index ad35dbc..9e0435e 100644 --- a/github/modals/githubIssuesListModal.ts +++ b/github/modals/githubIssuesListModal.ts @@ -3,19 +3,28 @@ import { IModify, IPersistence, IRead, + IUIKitSurfaceViewParam, } from "@rocket.chat/apps-engine/definition/accessors"; -import { AccessoryElements, ITextObject, TextObjectType } from "@rocket.chat/apps-engine/definition/uikit/blocks"; +import { + AccessoryElements, + IBlock, + ITextObject, + TextObjectType, +} from "@rocket.chat/apps-engine/definition/uikit/blocks"; import { IUIKitModalViewParam } from "@rocket.chat/apps-engine/definition/uikit/UIKitInteractionResponder"; import { ModalsEnum } from "../enum/Modals"; import { SlashCommandContext } from "@rocket.chat/apps-engine/definition/slashcommands"; import { UIKitBlockInteractionContext, UIKitInteractionContext, + UIKitSurfaceType, } from "@rocket.chat/apps-engine/definition/uikit"; import { storeInteractionRoomData, getInteractionRoomData, } from "../persistance/roomInteraction"; +import { ButtonElement, LayoutBlock } from "@rocket.chat/ui-kit"; +import { ContextBlockElements } from "@rocket.chat/ui-kit/dist/esm/blocks/layout/ContextBlock"; export async function githubIssuesListModal({ data, @@ -25,6 +34,7 @@ export async function githubIssuesListModal({ http, slashcommandcontext, uikitcontext, + id, }: { data: any; modify: IModify; @@ -33,18 +43,47 @@ export async function githubIssuesListModal({ http: IHttp; slashcommandcontext?: SlashCommandContext; uikitcontext?: UIKitInteractionContext; -}): Promise { + id: string; +}): Promise { const viewId = ModalsEnum.ISSUE_LIST_VIEW; - const block = modify.getCreator().getBlockBuilder(); - const room = slashcommandcontext?.getRoom() || uikitcontext?.getInteractionData().room; const user = slashcommandcontext?.getSender() || uikitcontext?.getInteractionData().user || - await read.getUserReader().getById(data?.user_id as string); + (await read.getUserReader().getById(data?.user_id as string)); + + const modal: IUIKitSurfaceViewParam = { + id: viewId, + type: UIKitSurfaceType.MODAL, + title: { + text: ModalsEnum.GITHUB_ISSUES_TITLE, + type: "plain_text", + }, + blocks: [], + submit: { + type: "button", + text: { + type: "plain_text", + text: "Share", + }, + appId: id, + blockId: "submit_block", + actionId: "submit_action", + }, + close: { + type: "button", + text: { + type: "plain_text", + text: "Close", + }, + appId: id, + blockId: "close_block", + actionId: "close_action", + }, + }; if (user?.id) { let roomId; @@ -55,140 +94,154 @@ export async function githubIssuesListModal({ roomId = ( await getInteractionRoomData( read.getPersistenceReader(), - user.id + user.id, ) ).roomId; } - block.addSectionBlock({ - text: { - text: `*${data.repo}*`, - type: TextObjectType.MARKDOWN, + const blocks: (IBlock | LayoutBlock)[] = [ + { + type: "section", + text: { + type: "mrkdwn", + text: `*${data.repo}*`, + }, }, - }); - - block.addDividerBlock(); - let issueList = data?.issues; - let index = 1; - if(issueList && Array.isArray(issueList)){ - for (let issue of issueList) { - block.addSectionBlock({ + { + type: "divider", + }, + ]; + + if (data.issues && Array.isArray(data.issues)) { + let index = 1; + for (const issue of data.issues) { + blocks.push({ + type: "section", text: { + type: "plain_text", text: `#${issue.number} ${issue.title}`, - type: TextObjectType.PLAINTEXT, }, }); - let contextBlockElementsArray = [ - block.newPlainTextObject(`User : ${issue.user_login} | `), - block.newPlainTextObject(`Status: ${issue.state} | `), - ] - if(issue?.labels && Array.isArray(issue.labels)){ - let labelString = ""; - for(let label of issue.labels){ - labelString += `${label} ` - } - if(labelString.length){ - contextBlockElementsArray.push(block.newPlainTextObject(`labels: ${labelString} `),) + + const contextBlockElements: ContextBlockElements[] = [ + { + type: "mrkdwn", + text: `User: ${issue.user_login} | Status: ${issue.state} | `, + }, + ]; + + if (issue.labels && Array.isArray(issue.labels)) { + const labelString = issue.labels.join(" "); + if (labelString.length) { + contextBlockElements.push({ + type: "mrkdwn", + text: `Labels: ${labelString} `, + }); } } - block.addContextBlock({ - elements: contextBlockElementsArray + + blocks.push({ + type: "context", + elements: contextBlockElements, }); - let contextBlockElementAssigneesArray:Array = []; - let assigneesString = ""; - if(issue?.assignees && Array.isArray(issue.assignees)){ - for(let assignee of issue.assignees){ - assigneesString += `${assignee} ` - } - if(assigneesString.length){ - contextBlockElementAssigneesArray.push(block.newPlainTextObject(`assignees: ${assigneesString} `),) + + if (issue.assignees && Array.isArray(issue.assignees)) { + const assigneesString = issue.assignees.join(" "); + if (assigneesString.length) { + blocks.push({ + type: "context", + elements: [ + { + type: "plain_text", + text: `Assignees: ${assigneesString} `, + }, + ], + }); } } - block.addContextBlock({ - elements: contextBlockElementAssigneesArray - }); - //button click actions can only detected `value:string` hence search results object must be parsed to string and stored in `value` and then reparsed to javascript object in `blockActionHandler` - let actionBlockElementsArray = [ - block.newButtonElement({ + + const actionBlockElements: ButtonElement[] = [ + { + type: "button", + appId: id, + blockId: ModalsEnum.OPEN_GITHUB_RESULT_LABEL, actionId: ModalsEnum.OPEN_GITHUB_RESULT_ACTION, text: { + type: "plain_text", text: ModalsEnum.OPEN_GITHUB_RESULT_LABEL, - type: TextObjectType.PLAINTEXT, }, - url: issue?.html_url?.toString() - }), - ] - if(data.pushRights){ - actionBlockElementsArray.push( - block.newButtonElement({ - actionId: ModalsEnum.ADD_GITHUB_ISSUE_ASSIGNEE, - text: { - text: ModalsEnum.ADD_GITHUB_ISSUE_ASSIGNEE_LABEL, - type: TextObjectType.PLAINTEXT, - }, - value:`${data?.repo} ${issue.number} ${assigneesString}`, - }), - ) - } - if(issue.share){ - actionBlockElementsArray.push( - block.newButtonElement({ - actionId: ModalsEnum.MULTI_SHARE_REMOVE_GITHUB_ISSUE_ACTION, - text: { - text: ModalsEnum.MULTI_SHARE_REMOVE_GITHUB_ISSUE_LABEL, - type: TextObjectType.PLAINTEXT, - }, - value: issue.issue_id as string, - }), - ); - }else{ - actionBlockElementsArray.push( - block.newButtonElement({ - actionId: ModalsEnum.MULTI_SHARE_ADD_GITHUB_ISSUE_ACTION, - text: { - text: ModalsEnum.MULTI_SHARE_ADD_GITHUB_ISSUE_LABEL, - type: TextObjectType.PLAINTEXT, - }, - value: issue.issue_id as string, - }), - ); + value: issue.html_url?.toString(), + }, + ]; + + if (data.pushRights) { + actionBlockElements.push({ + type: "button", + appId: id, + blockId: ModalsEnum.ADD_GITHUB_ISSUE_ASSIGNEE_LABEL, + actionId: ModalsEnum.ADD_GITHUB_ISSUE_ASSIGNEE, + text: { + type: "plain_text", + text: ModalsEnum.ADD_GITHUB_ISSUE_ASSIGNEE_LABEL, + }, + value: `${data.repo} ${issue.number} ${issue.assignees?.join(" ") || ""}`, + }); } - actionBlockElementsArray.push( - block.newButtonElement({ - actionId: ModalsEnum.ISSUE_COMMENT_LIST_ACTION, + + if (issue.share) { + actionBlockElements.push({ + type: "button", + appId: id, + actionId: + ModalsEnum.MULTI_SHARE_REMOVE_GITHUB_ISSUE_ACTION, + blockId: + ModalsEnum.MULTI_SHARE_REMOVE_GITHUB_ISSUE_LABEL, text: { - text: ModalsEnum.ISSUE_COMMENT_LIST_LABEL, - type: TextObjectType.PLAINTEXT, + type: "plain_text", + text: ModalsEnum.MULTI_SHARE_REMOVE_GITHUB_ISSUE_LABEL, }, - value: `${data?.repo} ${issue?.number}`, - }) - ) - block.addActionsBlock({ - elements: actionBlockElementsArray, + value: issue.issue_id, + }); + } else { + actionBlockElements.push({ + type: "button", + appId: id, + actionId: + ModalsEnum.MULTI_SHARE_ADD_GITHUB_ISSUE_ACTION, + blockId: ModalsEnum.MULTI_SHARE_ADD_GITHUB_ISSUE_LABEL, + text: { + type: "plain_text", + text: ModalsEnum.MULTI_SHARE_ADD_GITHUB_ISSUE_LABEL, + }, + value: issue.issue_id, + }); + } + + actionBlockElements.push({ + type: "button", + appId: id, + blockId: ModalsEnum.ISSUE_COMMENT_LIST_LABEL, + actionId: ModalsEnum.ISSUE_COMMENT_LIST_ACTION, + text: { + type: "plain_text", + text: ModalsEnum.ISSUE_COMMENT_LIST_LABEL, + }, + value: `${data.repo} ${issue.number}`, + }); + + blocks.push({ + type: "actions", + elements: actionBlockElements, }); + + blocks.push({ + type: "divider", + }); + index++; - block.addDividerBlock(); } } + modal.blocks = blocks; } - return { - id: viewId, - title: { - type: TextObjectType.PLAINTEXT, - text: ModalsEnum.GITHUB_ISSUES_TITLE, - }, - submit: block.newButtonElement({ - text: { - type: TextObjectType.PLAINTEXT, - text: "Share", - }, - }), - close: block.newButtonElement({ - text: { - type: TextObjectType.PLAINTEXT, - text: "Close", - }, - }), - blocks: block.getBlocks(), - }; + return modal; } diff --git a/github/modals/githubIssuesShareModal.ts b/github/modals/githubIssuesShareModal.ts index 7866f48..9d01916 100644 --- a/github/modals/githubIssuesShareModal.ts +++ b/github/modals/githubIssuesShareModal.ts @@ -3,6 +3,7 @@ import { IModify, IPersistence, IRead, + IUIKitSurfaceViewParam, } from "@rocket.chat/apps-engine/definition/accessors"; import { TextObjectType } from "@rocket.chat/apps-engine/definition/uikit/blocks"; import { IUIKitModalViewParam } from "@rocket.chat/apps-engine/definition/uikit/UIKitInteractionResponder"; @@ -14,9 +15,13 @@ import { SlashCommandContext } from "@rocket.chat/apps-engine/definition/slashco import { UIKitBlockInteractionContext, UIKitInteractionContext, + UIKitSurfaceType, } from "@rocket.chat/apps-engine/definition/uikit"; import { IGitHubSearchResultData } from "../definitions/searchResultData"; -import { getInteractionRoomData, storeInteractionRoomData } from "../persistance/roomInteraction"; +import { + getInteractionRoomData, + storeInteractionRoomData, +} from "../persistance/roomInteraction"; import { IGitHubIssueData } from "../definitions/githubIssueData"; export async function githubIssuesShareModal({ @@ -27,6 +32,7 @@ export async function githubIssuesShareModal({ http, slashcommandcontext, uikitcontext, + id, }: { data: IGitHubIssueData; modify: IModify; @@ -35,11 +41,10 @@ export async function githubIssuesShareModal({ http: IHttp; slashcommandcontext?: SlashCommandContext; uikitcontext?: UIKitInteractionContext; -}): Promise { + id: string; +}): Promise { const viewId = ModalsEnum.GITHUB_ISSUES_SHARE_VIEW; - const block = modify.getCreator().getBlockBuilder(); - const room = slashcommandcontext?.getRoom() || uikitcontext?.getInteractionData().room; @@ -47,6 +52,36 @@ export async function githubIssuesShareModal({ slashcommandcontext?.getSender() || uikitcontext?.getInteractionData().user; + const modal: IUIKitSurfaceViewParam = { + id: viewId, + type: UIKitSurfaceType.MODAL, + title: { + text: ModalsEnum.GITHUB_ISSUES_TITLE, + type: "plain_text", + }, + blocks: [], + submit: { + type: "button", + text: { + type: "plain_text", + text: "Share", + }, + appId: id, + blockId: "submit_block", + actionId: "submit_action", + }, + close: { + type: "button", + text: { + type: "plain_text", + text: "Close", + }, + appId: id, + blockId: "close_block", + actionId: "close_action", + }, + }; + if (user?.id) { let roomId; @@ -57,53 +92,41 @@ export async function githubIssuesShareModal({ roomId = ( await getInteractionRoomData( read.getPersistenceReader(), - user.id + user.id, ) ).roomId; } let finalString = `\n`; - if(data.issue_list?.length){ - for(let searchResult of data.issue_list){ - if(searchResult.share){ + if (data.issue_list?.length) { + for (let searchResult of data.issue_list) { + if (searchResult.share) { let searchResultString = `${searchResult.issue_compact} `; - finalString =`${finalString} \n${searchResultString}`; + finalString = `${finalString} \n${searchResultString}`; } } } - - block.addInputBlock({ - blockId: ModalsEnum.MULTI_SHARE_GITHUB_ISSUES_INPUT, - label: { - text: ModalsEnum.MULTI_SHARE_GITHUB_ISSUES_INPUT_LABEL, - type: TextObjectType.MARKDOWN - }, - element: block.newPlainTextInputElement({ - initialValue : `${finalString}`, - multiline:true, - actionId: ModalsEnum.MULTI_SHARE_GITHUB_ISSUES_INPUT_ACTION, - }) - }); - } - block.addDividerBlock(); - return { - id: viewId, - title: { - type: TextObjectType.PLAINTEXT, - text: ModalsEnum.GITHUB_ISSUES_TITLE, - }, - submit: block.newButtonElement({ - text: { - type: TextObjectType.PLAINTEXT, - text: "Send", + modal.blocks = [ + { + type: "input", + label: { + type: "plain_text", + text: ModalsEnum.MULTI_SHARE_GITHUB_ISSUES_INPUT_LABEL, + }, + element: { + type: "plain_text_input", + appId: id, + actionId: ModalsEnum.MULTI_SHARE_GITHUB_ISSUES_INPUT_ACTION, + blockId: ModalsEnum.MULTI_SHARE_GITHUB_ISSUES_INPUT, + initialValue: `${finalString}`, + multiline: true, + }, }, - }), - close: block.newButtonElement({ - text: { - type: TextObjectType.PLAINTEXT, - text: "Close", + { + type: "divider", }, - }), - blocks: block.getBlocks(), - }; + ]; + } + + return modal; } diff --git a/github/modals/newIssueStarterModal.ts b/github/modals/newIssueStarterModal.ts index 251dff3..6756e96 100644 --- a/github/modals/newIssueStarterModal.ts +++ b/github/modals/newIssueStarterModal.ts @@ -3,6 +3,7 @@ import { IModify, IPersistence, IRead, + IUIKitSurfaceViewParam, } from "@rocket.chat/apps-engine/definition/accessors"; import { TextObjectType } from "@rocket.chat/apps-engine/definition/uikit/blocks"; import { IUIKitModalViewParam } from "@rocket.chat/apps-engine/definition/uikit/UIKitInteractionResponder"; @@ -10,6 +11,7 @@ import { ModalsEnum } from "../enum/Modals"; import { SlashCommandContext } from "@rocket.chat/apps-engine/definition/slashcommands"; import { UIKitInteractionContext, + UIKitSurfaceType, } from "@rocket.chat/apps-engine/definition/uikit"; import { storeInteractionRoomData, @@ -23,6 +25,7 @@ export async function NewIssueStarterModal({ http, slashcommandcontext, uikitcontext, + id, }: { modify: IModify; read: IRead; @@ -30,11 +33,36 @@ export async function NewIssueStarterModal({ http: IHttp; slashcommandcontext?: SlashCommandContext; uikitcontext?: UIKitInteractionContext; -}): Promise { + id: string; +}): Promise { const viewId = ModalsEnum.NEW_ISSUE_STARTER_VIEW; - const block = modify.getCreator().getBlockBuilder(); - const room = slashcommandcontext?.getRoom() || uikitcontext?.getInteractionData().room; - const user = slashcommandcontext?.getSender() || uikitcontext?.getInteractionData().user; + const room = + slashcommandcontext?.getRoom() || + uikitcontext?.getInteractionData().room; + const user = + slashcommandcontext?.getSender() || + uikitcontext?.getInteractionData().user; + + const modal: IUIKitSurfaceViewParam = { + id: viewId, + type: UIKitSurfaceType.MODAL, + title: { + text: ModalsEnum.NEW_ISSUE_TITLE, + type: "plain_text", + }, + blocks: [], + submit: { + type: "button", + text: { + type: "plain_text", + emoji: true, + text: "Next 🚀", + }, + appId: id, + blockId: "submit_block", + actionId: ModalsEnum.NEW_ISSUE_STARTER__ACTION, + }, + }; if (user?.id) { let roomId; @@ -46,51 +74,35 @@ export async function NewIssueStarterModal({ roomId = ( await getInteractionRoomData( read.getPersistenceReader(), - user.id + user.id, ) ).roomId; } - // shows indentations in input blocks but not inn section block - block.addInputBlock({ - blockId: ModalsEnum.REPO_NAME_INPUT, - label: { - text: ModalsEnum.REPO_NAME_LABEL, - type: TextObjectType.PLAINTEXT, - }, - element: block.newPlainTextInputElement({ - actionId: ModalsEnum.REPO_NAME_INPUT_ACTION, - placeholder: { - text: ModalsEnum.REPO_NAME_PLACEHOLDER, - type: TextObjectType.PLAINTEXT, + modal.blocks = [ + { + type: "input", + label: { + type: "plain_text", + text: ModalsEnum.REPO_NAME_LABEL, + }, + element: { + type: "plain_text_input", + appId: id, + actionId: ModalsEnum.REPO_NAME_INPUT_ACTION, + blockId: ModalsEnum.REPO_NAME_INPUT, + placeholder: { + type: "plain_text", + text: ModalsEnum.REPO_NAME_PLACEHOLDER, + }, + multiline: false, }, - }), - }); - - } - - block.addDividerBlock(); - - return { - id: viewId, - title: { - type: TextObjectType.PLAINTEXT, - text: ModalsEnum.NEW_ISSUE_TITLE, - }, - close: block.newButtonElement({ - text: { - type: TextObjectType.PLAINTEXT, - text: "Close", }, - }), - submit: block.newButtonElement({ - actionId: ModalsEnum.NEW_ISSUE_STARTER__ACTION, - text: { - type: TextObjectType.PLAINTEXT, - emoji:true, - text: "Next 🚀", + { + type: "divider", }, - }), - blocks: block.getBlocks(), - }; + ]; + } + + return modal; } diff --git a/github/package-lock.json b/github/package-lock.json index 100817a..36a0034 100644 --- a/github/package-lock.json +++ b/github/package-lock.json @@ -4,9 +4,12 @@ "requires": true, "packages": { "": { + "dependencies": { + "@rocket.chat/icons": "^0.40.0", + "@rocket.chat/ui-kit": "^0.31.25" + }, "devDependencies": { - "@rocket.chat/apps-engine": "^1.36.0", - "@rocket.chat/ui-kit": "^0.31.22", + "@rocket.chat/apps-engine": "^1.44.0", "@types/node": "14.14.6", "tslint": "^5.10.0", "typescript": "^4.0.5" @@ -47,30 +50,487 @@ "node": ">=6.9.0" } }, + "node_modules/@esbuild/aix-ppc64": { + "version": "0.24.2", + "resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.24.2.tgz", + "integrity": "sha512-thpVCb/rhxE/BnMLQ7GReQLLN8q9qbHmI55F4489/ByVg2aQaQ6kbcLb6FHkocZzQhxc4gx0sCk0tJkKBFzDhA==", + "cpu": [ + "ppc64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "aix" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/android-arm": { + "version": "0.24.2", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.24.2.tgz", + "integrity": "sha512-tmwl4hJkCfNHwFB3nBa8z1Uy3ypZpxqxfTQOcHX+xRByyYgunVbZ9MzUUfb0RxaHIMnbHagwAxuTL+tnNM+1/Q==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/android-arm64": { + "version": "0.24.2", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.24.2.tgz", + "integrity": "sha512-cNLgeqCqV8WxfcTIOeL4OAtSmL8JjcN6m09XIgro1Wi7cF4t/THaWEa7eL5CMoMBdjoHOTh/vwTO/o2TRXIyzg==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/android-x64": { + "version": "0.24.2", + "resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.24.2.tgz", + "integrity": "sha512-B6Q0YQDqMx9D7rvIcsXfmJfvUYLoP722bgfBlO5cGvNVb5V/+Y7nhBE3mHV9OpxBf4eAS2S68KZztiPaWq4XYw==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/darwin-arm64": { + "version": "0.24.2", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.24.2.tgz", + "integrity": "sha512-kj3AnYWc+CekmZnS5IPu9D+HWtUI49hbnyqk0FLEJDbzCIQt7hg7ucF1SQAilhtYpIujfaHr6O0UHlzzSPdOeA==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/darwin-x64": { + "version": "0.24.2", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.24.2.tgz", + "integrity": "sha512-WeSrmwwHaPkNR5H3yYfowhZcbriGqooyu3zI/3GGpF8AyUdsrrP0X6KumITGA9WOyiJavnGZUwPGvxvwfWPHIA==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/freebsd-arm64": { + "version": "0.24.2", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.24.2.tgz", + "integrity": "sha512-UN8HXjtJ0k/Mj6a9+5u6+2eZ2ERD7Edt1Q9IZiB5UZAIdPnVKDoG7mdTVGhHJIeEml60JteamR3qhsr1r8gXvg==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/freebsd-x64": { + "version": "0.24.2", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.24.2.tgz", + "integrity": "sha512-TvW7wE/89PYW+IevEJXZ5sF6gJRDY/14hyIGFXdIucxCsbRmLUcjseQu1SyTko+2idmCw94TgyaEZi9HUSOe3Q==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-arm": { + "version": "0.24.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.24.2.tgz", + "integrity": "sha512-n0WRM/gWIdU29J57hJyUdIsk0WarGd6To0s+Y+LwvlC55wt+GT/OgkwoXCXvIue1i1sSNWblHEig00GBWiJgfA==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-arm64": { + "version": "0.24.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.24.2.tgz", + "integrity": "sha512-7HnAD6074BW43YvvUmE/35Id9/NB7BeX5EoNkK9obndmZBUk8xmJJeU7DwmUeN7tkysslb2eSl6CTrYz6oEMQg==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-ia32": { + "version": "0.24.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.24.2.tgz", + "integrity": "sha512-sfv0tGPQhcZOgTKO3oBE9xpHuUqguHvSo4jl+wjnKwFpapx+vUDcawbwPNuBIAYdRAvIDBfZVvXprIj3HA+Ugw==", + "cpu": [ + "ia32" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-loong64": { + "version": "0.24.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.24.2.tgz", + "integrity": "sha512-CN9AZr8kEndGooS35ntToZLTQLHEjtVB5n7dl8ZcTZMonJ7CCfStrYhrzF97eAecqVbVJ7APOEe18RPI4KLhwQ==", + "cpu": [ + "loong64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-mips64el": { + "version": "0.24.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.24.2.tgz", + "integrity": "sha512-iMkk7qr/wl3exJATwkISxI7kTcmHKE+BlymIAbHO8xanq/TjHaaVThFF6ipWzPHryoFsesNQJPE/3wFJw4+huw==", + "cpu": [ + "mips64el" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-ppc64": { + "version": "0.24.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.24.2.tgz", + "integrity": "sha512-shsVrgCZ57Vr2L8mm39kO5PPIb+843FStGt7sGGoqiiWYconSxwTiuswC1VJZLCjNiMLAMh34jg4VSEQb+iEbw==", + "cpu": [ + "ppc64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-riscv64": { + "version": "0.24.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.24.2.tgz", + "integrity": "sha512-4eSFWnU9Hhd68fW16GD0TINewo1L6dRrB+oLNNbYyMUAeOD2yCK5KXGK1GH4qD/kT+bTEXjsyTCiJGHPZ3eM9Q==", + "cpu": [ + "riscv64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-s390x": { + "version": "0.24.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.24.2.tgz", + "integrity": "sha512-S0Bh0A53b0YHL2XEXC20bHLuGMOhFDO6GN4b3YjRLK//Ep3ql3erpNcPlEFed93hsQAjAQDNsvcK+hV90FubSw==", + "cpu": [ + "s390x" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-x64": { + "version": "0.24.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.24.2.tgz", + "integrity": "sha512-8Qi4nQcCTbLnK9WoMjdC9NiTG6/E38RNICU6sUNqK0QFxCYgoARqVqxdFmWkdonVsvGqWhmm7MO0jyTqLqwj0Q==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/netbsd-arm64": { + "version": "0.24.2", + "resolved": "https://registry.npmjs.org/@esbuild/netbsd-arm64/-/netbsd-arm64-0.24.2.tgz", + "integrity": "sha512-wuLK/VztRRpMt9zyHSazyCVdCXlpHkKm34WUyinD2lzK07FAHTq0KQvZZlXikNWkDGoT6x3TD51jKQ7gMVpopw==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "netbsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/netbsd-x64": { + "version": "0.24.2", + "resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.24.2.tgz", + "integrity": "sha512-VefFaQUc4FMmJuAxmIHgUmfNiLXY438XrL4GDNV1Y1H/RW3qow68xTwjZKfj/+Plp9NANmzbH5R40Meudu8mmw==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "netbsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/openbsd-arm64": { + "version": "0.24.2", + "resolved": "https://registry.npmjs.org/@esbuild/openbsd-arm64/-/openbsd-arm64-0.24.2.tgz", + "integrity": "sha512-YQbi46SBct6iKnszhSvdluqDmxCJA+Pu280Av9WICNwQmMxV7nLRHZfjQzwbPs3jeWnuAhE9Jy0NrnJ12Oz+0A==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "openbsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/openbsd-x64": { + "version": "0.24.2", + "resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.24.2.tgz", + "integrity": "sha512-+iDS6zpNM6EnJyWv0bMGLWSWeXGN/HTaF/LXHXHwejGsVi+ooqDfMCCTerNFxEkM3wYVcExkeGXNqshc9iMaOA==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "openbsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/sunos-x64": { + "version": "0.24.2", + "resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.24.2.tgz", + "integrity": "sha512-hTdsW27jcktEvpwNHJU4ZwWFGkz2zRJUz8pvddmXPtXDzVKTTINmlmga3ZzwcuMpUvLw7JkLy9QLKyGpD2Yxig==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "sunos" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/win32-arm64": { + "version": "0.24.2", + "resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.24.2.tgz", + "integrity": "sha512-LihEQ2BBKVFLOC9ZItT9iFprsE9tqjDjnbulhHoFxYQtQfai7qfluVODIYxt1PgdoyQkz23+01rzwNwYfutxUQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/win32-ia32": { + "version": "0.24.2", + "resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.24.2.tgz", + "integrity": "sha512-q+iGUwfs8tncmFC9pcnD5IvRHAzmbwQ3GPS5/ceCyHdjXubwQWI12MKWSNSMYLJMq23/IUCvJMS76PDqXe1fxA==", + "cpu": [ + "ia32" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/win32-x64": { + "version": "0.24.2", + "resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.24.2.tgz", + "integrity": "sha512-7VTgWzgMGvup6aSqDPLiW5zHaxYJGTO4OokMjIlrCtf+VpEL+cXKtCvg723iguPYI5oaUNdS+/V7OU2gvXVWEg==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@msgpack/msgpack": { + "version": "3.0.0-beta2", + "resolved": "https://registry.npmjs.org/@msgpack/msgpack/-/msgpack-3.0.0-beta2.tgz", + "integrity": "sha512-y+l1PNV0XDyY8sM3YtuMLK5vE3/hkfId+Do8pLo/OPxfxuFAUwcGz3oiiUuV46/aBpwTzZ+mRWVMtlSKbradhw==", + "dev": true, + "license": "ISC", + "engines": { + "node": ">= 14" + } + }, "node_modules/@rocket.chat/apps-engine": { - "version": "1.38.0", - "resolved": "https://registry.npmjs.org/@rocket.chat/apps-engine/-/apps-engine-1.38.0.tgz", - "integrity": "sha512-qY1LRggfZNieOkxDBuEnaieZK6gHfA2tNLrqvv0xn7vgZWkJlWvfcuhPbfarV14q3tuEJgnqf0uIoqia3+WJFQ==", + "version": "1.48.1", + "resolved": "https://registry.npmjs.org/@rocket.chat/apps-engine/-/apps-engine-1.48.1.tgz", + "integrity": "sha512-tjzJImPT4wN0aqZ7PMKd1MZQl6wRoSGN8SJQC8HEFy8LOMESwS0vbd1Cu/fROhXlcTlWoXS8RbQ72QrKYMP5UA==", "dev": true, + "license": "MIT", "dependencies": { - "adm-zip": "^0.5.9", - "cryptiles": "^4.1.3", - "jose": "^4.11.1", + "@msgpack/msgpack": "3.0.0-beta2", + "adm-zip": "^0.5.16", + "debug": "^4.3.7", + "esbuild": "^0.24.0", + "jose": "^4.15.9", + "jsonrpc-lite": "^2.2.0", "lodash.clonedeep": "^4.5.0", - "semver": "^5.7.1", + "semver": "^7.6.3", "stack-trace": "0.0.10", - "uuid": "^3.4.0", - "vm2": "^3.9.11" + "uuid": "~11.0.3" + } + }, + "node_modules/@rocket.chat/apps-engine/node_modules/semver": { + "version": "7.6.3", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.6.3.tgz", + "integrity": "sha512-oVekP1cKtI+CTDvHWYFUcMtsK/00wmAEfyqKfNdARm8u1wNVhSgaX7A8d4UuIlUI5e84iEwOhs7ZPYRmzU9U6A==", + "dev": true, + "license": "ISC", + "bin": { + "semver": "bin/semver.js" }, - "peerDependencies": { - "@rocket.chat/ui-kit": "next" + "engines": { + "node": ">=10" } }, + "node_modules/@rocket.chat/icons": { + "version": "0.40.0", + "resolved": "https://registry.npmjs.org/@rocket.chat/icons/-/icons-0.40.0.tgz", + "integrity": "sha512-25BFNycdItF47L33a4cfnL6I7Srx/ihZ3YOZ8ZTKm1roKNXgOuxH0abED+am1EHrjTw6fGourkfRqhTLmgzyzA==", + "license": "MIT" + }, "node_modules/@rocket.chat/ui-kit": { - "version": "0.31.22", - "resolved": "https://registry.npmjs.org/@rocket.chat/ui-kit/-/ui-kit-0.31.22.tgz", - "integrity": "sha512-CH7kBVBsAql57DwDMOpMvj8lp+23muEqiaQ4x0cr0CV/HjmOBBiclzJ2wvh7ab7KEkABIhDK8dwSreNgk0LiJQ==", - "dev": true + "version": "0.31.25", + "resolved": "https://registry.npmjs.org/@rocket.chat/ui-kit/-/ui-kit-0.31.25.tgz", + "integrity": "sha512-yTgTKDw9SMlJ6p8n0PDO6zSvox/nHYUrwCIvILQeAK6PvTrgSe/u9CvU7ATTYjnQiQ603yEGR6dxjF4euCGdNA==", + "license": "MIT", + "peerDependencies": { + "@rocket.chat/icons": "*" + } }, "node_modules/@types/node": { "version": "14.14.6", @@ -78,34 +538,14 @@ "integrity": "sha512-6QlRuqsQ/Ox/aJEQWBEJG7A9+u7oSYl3mem/K8IzxXG/kAGbV1YPD9Bg9Zw3vyxC/YP+zONKwy8hGkSt1jxFMw==", "dev": true }, - "node_modules/acorn": { - "version": "8.8.2", - "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.8.2.tgz", - "integrity": "sha512-xjIYgE8HBrkpd/sJqOGNspf8uHG+NOHGOw6a/Urj8taM2EXfdNAH2oFcPeIFfsv3+kz/mJrS5VuMqbNLjCa2vw==", - "dev": true, - "bin": { - "acorn": "bin/acorn" - }, - "engines": { - "node": ">=0.4.0" - } - }, - "node_modules/acorn-walk": { - "version": "8.2.0", - "resolved": "https://registry.npmjs.org/acorn-walk/-/acorn-walk-8.2.0.tgz", - "integrity": "sha512-k+iyHEuPgSw6SbuDpGQM+06HQUa04DZ3o+F6CSzXMvvI5KMvnaEqXe+YVe555R9nn6GPt404fos4wcgpw12SDA==", - "dev": true, - "engines": { - "node": ">=0.4.0" - } - }, "node_modules/adm-zip": { - "version": "0.5.10", - "resolved": "https://registry.npmjs.org/adm-zip/-/adm-zip-0.5.10.tgz", - "integrity": "sha512-x0HvcHqVJNTPk/Bw8JbLWlWoo6Wwnsug0fnYYro1HBrjxZ3G7/AZk7Ahv8JwDe1uIcz8eBqvu86FuF1POiG7vQ==", + "version": "0.5.16", + "resolved": "https://registry.npmjs.org/adm-zip/-/adm-zip-0.5.16.tgz", + "integrity": "sha512-TGw5yVi4saajsSEgz25grObGHEUaDrniwvA2qwSC060KfqGPdglhvPMA2lPIoxs3PQIItj2iag35fONcQqgUaQ==", "dev": true, + "license": "MIT", "engines": { - "node": ">=6.0" + "node": ">=12.0" } }, "node_modules/ansi-styles": { @@ -135,16 +575,6 @@ "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==", "dev": true }, - "node_modules/boom": { - "version": "7.3.0", - "resolved": "https://registry.npmjs.org/boom/-/boom-7.3.0.tgz", - "integrity": "sha512-Swpoyi2t5+GhOEGw8rEsKvTxFLIDiiKoUc2gsoV6Lyr43LHBIzch3k2MvYUs8RTROrIkVJ3Al0TkaOGjnb+B6A==", - "deprecated": "This module has moved and is now available at @hapi/boom. Please update your dependencies as this version is no longer maintained an may contain bugs and security issues.", - "dev": true, - "dependencies": { - "hoek": "6.x.x" - } - }, "node_modules/brace-expansion": { "version": "1.1.11", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", @@ -205,14 +635,22 @@ "integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==", "dev": true }, - "node_modules/cryptiles": { - "version": "4.1.3", - "resolved": "https://registry.npmjs.org/cryptiles/-/cryptiles-4.1.3.tgz", - "integrity": "sha512-gT9nyTMSUC1JnziQpPbxKGBbUg8VL7Zn2NB4E1cJYvuXdElHrwxrV9bmltZGDzet45zSDGyYceueke1TjynGzw==", - "deprecated": "This module has moved and is now available at @hapi/cryptiles. Please update your dependencies as this version is no longer maintained an may contain bugs and security issues.", + "node_modules/debug": { + "version": "4.4.0", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.0.tgz", + "integrity": "sha512-6WTZ/IxCY/T6BALoZHaE4ctp9xm+Z5kY/pzYaCHRFeyVhojxlrm+46y68HA6hr0TcwEssoxNiDEUJQjfPZ/RYA==", "dev": true, + "license": "MIT", "dependencies": { - "boom": "7.x.x" + "ms": "^2.1.3" + }, + "engines": { + "node": ">=6.0" + }, + "peerDependenciesMeta": { + "supports-color": { + "optional": true + } } }, "node_modules/diff": { @@ -224,6 +662,47 @@ "node": ">=0.3.1" } }, + "node_modules/esbuild": { + "version": "0.24.2", + "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.24.2.tgz", + "integrity": "sha512-+9egpBW8I3CD5XPe0n6BfT5fxLzxrlDzqydF3aviG+9ni1lDC/OvMHcxqEFV0+LANZG5R1bFMWfUrjVsdwxJvA==", + "dev": true, + "hasInstallScript": true, + "license": "MIT", + "bin": { + "esbuild": "bin/esbuild" + }, + "engines": { + "node": ">=18" + }, + "optionalDependencies": { + "@esbuild/aix-ppc64": "0.24.2", + "@esbuild/android-arm": "0.24.2", + "@esbuild/android-arm64": "0.24.2", + "@esbuild/android-x64": "0.24.2", + "@esbuild/darwin-arm64": "0.24.2", + "@esbuild/darwin-x64": "0.24.2", + "@esbuild/freebsd-arm64": "0.24.2", + "@esbuild/freebsd-x64": "0.24.2", + "@esbuild/linux-arm": "0.24.2", + "@esbuild/linux-arm64": "0.24.2", + "@esbuild/linux-ia32": "0.24.2", + "@esbuild/linux-loong64": "0.24.2", + "@esbuild/linux-mips64el": "0.24.2", + "@esbuild/linux-ppc64": "0.24.2", + "@esbuild/linux-riscv64": "0.24.2", + "@esbuild/linux-s390x": "0.24.2", + "@esbuild/linux-x64": "0.24.2", + "@esbuild/netbsd-arm64": "0.24.2", + "@esbuild/netbsd-x64": "0.24.2", + "@esbuild/openbsd-arm64": "0.24.2", + "@esbuild/openbsd-x64": "0.24.2", + "@esbuild/sunos-x64": "0.24.2", + "@esbuild/win32-arm64": "0.24.2", + "@esbuild/win32-ia32": "0.24.2", + "@esbuild/win32-x64": "0.24.2" + } + }, "node_modules/escape-string-regexp": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", @@ -299,13 +778,6 @@ "node": ">=4" } }, - "node_modules/hoek": { - "version": "6.1.3", - "resolved": "https://registry.npmjs.org/hoek/-/hoek-6.1.3.tgz", - "integrity": "sha512-YXXAAhmF9zpQbC7LEcREFtXfGq5K1fmd+4PHkBq8NUqmzW3G+Dq10bI/i0KucLRwss3YYFQ0fSfoxBZYiGUqtQ==", - "deprecated": "This module has moved and is now available at @hapi/hoek. Please update your dependencies as this version is no longer maintained an may contain bugs and security issues.", - "dev": true - }, "node_modules/inflight": { "version": "1.0.6", "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", @@ -335,10 +807,11 @@ } }, "node_modules/jose": { - "version": "4.13.1", - "resolved": "https://registry.npmjs.org/jose/-/jose-4.13.1.tgz", - "integrity": "sha512-MSJQC5vXco5Br38mzaQKiq9mwt7lwj2eXpgpRyQYNHYt2lq1PjkWa7DLXX0WVcQLE9HhMh3jPiufS7fhJf+CLQ==", + "version": "4.15.9", + "resolved": "https://registry.npmjs.org/jose/-/jose-4.15.9.tgz", + "integrity": "sha512-1vUQX+IdDMVPj4k8kOxgUqlcK518yluMuGZwqlr44FS1ppZB/5GWh4rZG89erpOBOJjU/OBsnCVFfapsRz6nEA==", "dev": true, + "license": "MIT", "funding": { "url": "https://github.com/sponsors/panva" } @@ -362,6 +835,13 @@ "js-yaml": "bin/js-yaml.js" } }, + "node_modules/jsonrpc-lite": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/jsonrpc-lite/-/jsonrpc-lite-2.2.0.tgz", + "integrity": "sha512-/cbbSxtZWs1O7R4tWqabrCM/t3N8qKUZMAg9IUqpPvUs6UyRvm6pCNYkskyKN/XU0UgffW+NY2ZRr8t0AknX7g==", + "dev": true, + "license": "MIT" + }, "node_modules/lodash.clonedeep": { "version": "4.5.0", "resolved": "https://registry.npmjs.org/lodash.clonedeep/-/lodash.clonedeep-4.5.0.tgz", @@ -398,6 +878,13 @@ "mkdirp": "bin/cmd.js" } }, + "node_modules/ms": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", + "dev": true, + "license": "MIT" + }, "node_modules/once": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", @@ -549,29 +1036,17 @@ } }, "node_modules/uuid": { - "version": "3.4.0", - "resolved": "https://registry.npmjs.org/uuid/-/uuid-3.4.0.tgz", - "integrity": "sha512-HjSDRw6gZE5JMggctHBcjVak08+KEVhSIiDzFnT9S9aegmp85S/bReBVTb4QTFaRNptJ9kuYaNhnbNEOkbKb/A==", - "deprecated": "Please upgrade to version 7 or higher. Older versions may use Math.random() in certain circumstances, which is known to be problematic. See https://v8.dev/blog/math-random for details.", + "version": "11.0.5", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-11.0.5.tgz", + "integrity": "sha512-508e6IcKLrhxKdBbcA2b4KQZlLVp2+J5UwQ6F7Drckkc5N9ZJwFa4TgWtsww9UG8fGHbm6gbV19TdM5pQ4GaIA==", "dev": true, + "funding": [ + "https://github.com/sponsors/broofa", + "https://github.com/sponsors/ctavan" + ], + "license": "MIT", "bin": { - "uuid": "bin/uuid" - } - }, - "node_modules/vm2": { - "version": "3.9.14", - "resolved": "https://registry.npmjs.org/vm2/-/vm2-3.9.14.tgz", - "integrity": "sha512-HgvPHYHeQy8+QhzlFryvSteA4uQLBCOub02mgqdR+0bN/akRZ48TGB1v0aCv7ksyc0HXx16AZtMHKS38alc6TA==", - "dev": true, - "dependencies": { - "acorn": "^8.7.0", - "acorn-walk": "^8.2.0" - }, - "bin": { - "vm2": "bin/vm2" - }, - "engines": { - "node": ">=6.0" + "uuid": "dist/esm/bin/uuid" } }, "node_modules/wrappy": { @@ -608,27 +1083,223 @@ "js-tokens": "^4.0.0" } }, + "@esbuild/aix-ppc64": { + "version": "0.24.2", + "resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.24.2.tgz", + "integrity": "sha512-thpVCb/rhxE/BnMLQ7GReQLLN8q9qbHmI55F4489/ByVg2aQaQ6kbcLb6FHkocZzQhxc4gx0sCk0tJkKBFzDhA==", + "dev": true, + "optional": true + }, + "@esbuild/android-arm": { + "version": "0.24.2", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.24.2.tgz", + "integrity": "sha512-tmwl4hJkCfNHwFB3nBa8z1Uy3ypZpxqxfTQOcHX+xRByyYgunVbZ9MzUUfb0RxaHIMnbHagwAxuTL+tnNM+1/Q==", + "dev": true, + "optional": true + }, + "@esbuild/android-arm64": { + "version": "0.24.2", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.24.2.tgz", + "integrity": "sha512-cNLgeqCqV8WxfcTIOeL4OAtSmL8JjcN6m09XIgro1Wi7cF4t/THaWEa7eL5CMoMBdjoHOTh/vwTO/o2TRXIyzg==", + "dev": true, + "optional": true + }, + "@esbuild/android-x64": { + "version": "0.24.2", + "resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.24.2.tgz", + "integrity": "sha512-B6Q0YQDqMx9D7rvIcsXfmJfvUYLoP722bgfBlO5cGvNVb5V/+Y7nhBE3mHV9OpxBf4eAS2S68KZztiPaWq4XYw==", + "dev": true, + "optional": true + }, + "@esbuild/darwin-arm64": { + "version": "0.24.2", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.24.2.tgz", + "integrity": "sha512-kj3AnYWc+CekmZnS5IPu9D+HWtUI49hbnyqk0FLEJDbzCIQt7hg7ucF1SQAilhtYpIujfaHr6O0UHlzzSPdOeA==", + "dev": true, + "optional": true + }, + "@esbuild/darwin-x64": { + "version": "0.24.2", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.24.2.tgz", + "integrity": "sha512-WeSrmwwHaPkNR5H3yYfowhZcbriGqooyu3zI/3GGpF8AyUdsrrP0X6KumITGA9WOyiJavnGZUwPGvxvwfWPHIA==", + "dev": true, + "optional": true + }, + "@esbuild/freebsd-arm64": { + "version": "0.24.2", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.24.2.tgz", + "integrity": "sha512-UN8HXjtJ0k/Mj6a9+5u6+2eZ2ERD7Edt1Q9IZiB5UZAIdPnVKDoG7mdTVGhHJIeEml60JteamR3qhsr1r8gXvg==", + "dev": true, + "optional": true + }, + "@esbuild/freebsd-x64": { + "version": "0.24.2", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.24.2.tgz", + "integrity": "sha512-TvW7wE/89PYW+IevEJXZ5sF6gJRDY/14hyIGFXdIucxCsbRmLUcjseQu1SyTko+2idmCw94TgyaEZi9HUSOe3Q==", + "dev": true, + "optional": true + }, + "@esbuild/linux-arm": { + "version": "0.24.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.24.2.tgz", + "integrity": "sha512-n0WRM/gWIdU29J57hJyUdIsk0WarGd6To0s+Y+LwvlC55wt+GT/OgkwoXCXvIue1i1sSNWblHEig00GBWiJgfA==", + "dev": true, + "optional": true + }, + "@esbuild/linux-arm64": { + "version": "0.24.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.24.2.tgz", + "integrity": "sha512-7HnAD6074BW43YvvUmE/35Id9/NB7BeX5EoNkK9obndmZBUk8xmJJeU7DwmUeN7tkysslb2eSl6CTrYz6oEMQg==", + "dev": true, + "optional": true + }, + "@esbuild/linux-ia32": { + "version": "0.24.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.24.2.tgz", + "integrity": "sha512-sfv0tGPQhcZOgTKO3oBE9xpHuUqguHvSo4jl+wjnKwFpapx+vUDcawbwPNuBIAYdRAvIDBfZVvXprIj3HA+Ugw==", + "dev": true, + "optional": true + }, + "@esbuild/linux-loong64": { + "version": "0.24.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.24.2.tgz", + "integrity": "sha512-CN9AZr8kEndGooS35ntToZLTQLHEjtVB5n7dl8ZcTZMonJ7CCfStrYhrzF97eAecqVbVJ7APOEe18RPI4KLhwQ==", + "dev": true, + "optional": true + }, + "@esbuild/linux-mips64el": { + "version": "0.24.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.24.2.tgz", + "integrity": "sha512-iMkk7qr/wl3exJATwkISxI7kTcmHKE+BlymIAbHO8xanq/TjHaaVThFF6ipWzPHryoFsesNQJPE/3wFJw4+huw==", + "dev": true, + "optional": true + }, + "@esbuild/linux-ppc64": { + "version": "0.24.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.24.2.tgz", + "integrity": "sha512-shsVrgCZ57Vr2L8mm39kO5PPIb+843FStGt7sGGoqiiWYconSxwTiuswC1VJZLCjNiMLAMh34jg4VSEQb+iEbw==", + "dev": true, + "optional": true + }, + "@esbuild/linux-riscv64": { + "version": "0.24.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.24.2.tgz", + "integrity": "sha512-4eSFWnU9Hhd68fW16GD0TINewo1L6dRrB+oLNNbYyMUAeOD2yCK5KXGK1GH4qD/kT+bTEXjsyTCiJGHPZ3eM9Q==", + "dev": true, + "optional": true + }, + "@esbuild/linux-s390x": { + "version": "0.24.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.24.2.tgz", + "integrity": "sha512-S0Bh0A53b0YHL2XEXC20bHLuGMOhFDO6GN4b3YjRLK//Ep3ql3erpNcPlEFed93hsQAjAQDNsvcK+hV90FubSw==", + "dev": true, + "optional": true + }, + "@esbuild/linux-x64": { + "version": "0.24.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.24.2.tgz", + "integrity": "sha512-8Qi4nQcCTbLnK9WoMjdC9NiTG6/E38RNICU6sUNqK0QFxCYgoARqVqxdFmWkdonVsvGqWhmm7MO0jyTqLqwj0Q==", + "dev": true, + "optional": true + }, + "@esbuild/netbsd-arm64": { + "version": "0.24.2", + "resolved": "https://registry.npmjs.org/@esbuild/netbsd-arm64/-/netbsd-arm64-0.24.2.tgz", + "integrity": "sha512-wuLK/VztRRpMt9zyHSazyCVdCXlpHkKm34WUyinD2lzK07FAHTq0KQvZZlXikNWkDGoT6x3TD51jKQ7gMVpopw==", + "dev": true, + "optional": true + }, + "@esbuild/netbsd-x64": { + "version": "0.24.2", + "resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.24.2.tgz", + "integrity": "sha512-VefFaQUc4FMmJuAxmIHgUmfNiLXY438XrL4GDNV1Y1H/RW3qow68xTwjZKfj/+Plp9NANmzbH5R40Meudu8mmw==", + "dev": true, + "optional": true + }, + "@esbuild/openbsd-arm64": { + "version": "0.24.2", + "resolved": "https://registry.npmjs.org/@esbuild/openbsd-arm64/-/openbsd-arm64-0.24.2.tgz", + "integrity": "sha512-YQbi46SBct6iKnszhSvdluqDmxCJA+Pu280Av9WICNwQmMxV7nLRHZfjQzwbPs3jeWnuAhE9Jy0NrnJ12Oz+0A==", + "dev": true, + "optional": true + }, + "@esbuild/openbsd-x64": { + "version": "0.24.2", + "resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.24.2.tgz", + "integrity": "sha512-+iDS6zpNM6EnJyWv0bMGLWSWeXGN/HTaF/LXHXHwejGsVi+ooqDfMCCTerNFxEkM3wYVcExkeGXNqshc9iMaOA==", + "dev": true, + "optional": true + }, + "@esbuild/sunos-x64": { + "version": "0.24.2", + "resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.24.2.tgz", + "integrity": "sha512-hTdsW27jcktEvpwNHJU4ZwWFGkz2zRJUz8pvddmXPtXDzVKTTINmlmga3ZzwcuMpUvLw7JkLy9QLKyGpD2Yxig==", + "dev": true, + "optional": true + }, + "@esbuild/win32-arm64": { + "version": "0.24.2", + "resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.24.2.tgz", + "integrity": "sha512-LihEQ2BBKVFLOC9ZItT9iFprsE9tqjDjnbulhHoFxYQtQfai7qfluVODIYxt1PgdoyQkz23+01rzwNwYfutxUQ==", + "dev": true, + "optional": true + }, + "@esbuild/win32-ia32": { + "version": "0.24.2", + "resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.24.2.tgz", + "integrity": "sha512-q+iGUwfs8tncmFC9pcnD5IvRHAzmbwQ3GPS5/ceCyHdjXubwQWI12MKWSNSMYLJMq23/IUCvJMS76PDqXe1fxA==", + "dev": true, + "optional": true + }, + "@esbuild/win32-x64": { + "version": "0.24.2", + "resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.24.2.tgz", + "integrity": "sha512-7VTgWzgMGvup6aSqDPLiW5zHaxYJGTO4OokMjIlrCtf+VpEL+cXKtCvg723iguPYI5oaUNdS+/V7OU2gvXVWEg==", + "dev": true, + "optional": true + }, + "@msgpack/msgpack": { + "version": "3.0.0-beta2", + "resolved": "https://registry.npmjs.org/@msgpack/msgpack/-/msgpack-3.0.0-beta2.tgz", + "integrity": "sha512-y+l1PNV0XDyY8sM3YtuMLK5vE3/hkfId+Do8pLo/OPxfxuFAUwcGz3oiiUuV46/aBpwTzZ+mRWVMtlSKbradhw==", + "dev": true + }, "@rocket.chat/apps-engine": { - "version": "1.38.0", - "resolved": "https://registry.npmjs.org/@rocket.chat/apps-engine/-/apps-engine-1.38.0.tgz", - "integrity": "sha512-qY1LRggfZNieOkxDBuEnaieZK6gHfA2tNLrqvv0xn7vgZWkJlWvfcuhPbfarV14q3tuEJgnqf0uIoqia3+WJFQ==", + "version": "1.48.1", + "resolved": "https://registry.npmjs.org/@rocket.chat/apps-engine/-/apps-engine-1.48.1.tgz", + "integrity": "sha512-tjzJImPT4wN0aqZ7PMKd1MZQl6wRoSGN8SJQC8HEFy8LOMESwS0vbd1Cu/fROhXlcTlWoXS8RbQ72QrKYMP5UA==", "dev": true, "requires": { - "adm-zip": "^0.5.9", - "cryptiles": "^4.1.3", - "jose": "^4.11.1", + "@msgpack/msgpack": "3.0.0-beta2", + "adm-zip": "^0.5.16", + "debug": "^4.3.7", + "esbuild": "^0.24.0", + "jose": "^4.15.9", + "jsonrpc-lite": "^2.2.0", "lodash.clonedeep": "^4.5.0", - "semver": "^5.7.1", + "semver": "^7.6.3", "stack-trace": "0.0.10", - "uuid": "^3.4.0", - "vm2": "^3.9.11" + "uuid": "~11.0.3" + }, + "dependencies": { + "semver": { + "version": "7.6.3", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.6.3.tgz", + "integrity": "sha512-oVekP1cKtI+CTDvHWYFUcMtsK/00wmAEfyqKfNdARm8u1wNVhSgaX7A8d4UuIlUI5e84iEwOhs7ZPYRmzU9U6A==", + "dev": true + } } }, + "@rocket.chat/icons": { + "version": "0.40.0", + "resolved": "https://registry.npmjs.org/@rocket.chat/icons/-/icons-0.40.0.tgz", + "integrity": "sha512-25BFNycdItF47L33a4cfnL6I7Srx/ihZ3YOZ8ZTKm1roKNXgOuxH0abED+am1EHrjTw6fGourkfRqhTLmgzyzA==" + }, "@rocket.chat/ui-kit": { - "version": "0.31.22", - "resolved": "https://registry.npmjs.org/@rocket.chat/ui-kit/-/ui-kit-0.31.22.tgz", - "integrity": "sha512-CH7kBVBsAql57DwDMOpMvj8lp+23muEqiaQ4x0cr0CV/HjmOBBiclzJ2wvh7ab7KEkABIhDK8dwSreNgk0LiJQ==", - "dev": true + "version": "0.31.25", + "resolved": "https://registry.npmjs.org/@rocket.chat/ui-kit/-/ui-kit-0.31.25.tgz", + "integrity": "sha512-yTgTKDw9SMlJ6p8n0PDO6zSvox/nHYUrwCIvILQeAK6PvTrgSe/u9CvU7ATTYjnQiQ603yEGR6dxjF4euCGdNA==", + "requires": {} }, "@types/node": { "version": "14.14.6", @@ -636,22 +1307,10 @@ "integrity": "sha512-6QlRuqsQ/Ox/aJEQWBEJG7A9+u7oSYl3mem/K8IzxXG/kAGbV1YPD9Bg9Zw3vyxC/YP+zONKwy8hGkSt1jxFMw==", "dev": true }, - "acorn": { - "version": "8.8.2", - "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.8.2.tgz", - "integrity": "sha512-xjIYgE8HBrkpd/sJqOGNspf8uHG+NOHGOw6a/Urj8taM2EXfdNAH2oFcPeIFfsv3+kz/mJrS5VuMqbNLjCa2vw==", - "dev": true - }, - "acorn-walk": { - "version": "8.2.0", - "resolved": "https://registry.npmjs.org/acorn-walk/-/acorn-walk-8.2.0.tgz", - "integrity": "sha512-k+iyHEuPgSw6SbuDpGQM+06HQUa04DZ3o+F6CSzXMvvI5KMvnaEqXe+YVe555R9nn6GPt404fos4wcgpw12SDA==", - "dev": true - }, "adm-zip": { - "version": "0.5.10", - "resolved": "https://registry.npmjs.org/adm-zip/-/adm-zip-0.5.10.tgz", - "integrity": "sha512-x0HvcHqVJNTPk/Bw8JbLWlWoo6Wwnsug0fnYYro1HBrjxZ3G7/AZk7Ahv8JwDe1uIcz8eBqvu86FuF1POiG7vQ==", + "version": "0.5.16", + "resolved": "https://registry.npmjs.org/adm-zip/-/adm-zip-0.5.16.tgz", + "integrity": "sha512-TGw5yVi4saajsSEgz25grObGHEUaDrniwvA2qwSC060KfqGPdglhvPMA2lPIoxs3PQIItj2iag35fONcQqgUaQ==", "dev": true }, "ansi-styles": { @@ -678,15 +1337,6 @@ "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==", "dev": true }, - "boom": { - "version": "7.3.0", - "resolved": "https://registry.npmjs.org/boom/-/boom-7.3.0.tgz", - "integrity": "sha512-Swpoyi2t5+GhOEGw8rEsKvTxFLIDiiKoUc2gsoV6Lyr43LHBIzch3k2MvYUs8RTROrIkVJ3Al0TkaOGjnb+B6A==", - "dev": true, - "requires": { - "hoek": "6.x.x" - } - }, "brace-expansion": { "version": "1.1.11", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", @@ -741,13 +1391,13 @@ "integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==", "dev": true }, - "cryptiles": { - "version": "4.1.3", - "resolved": "https://registry.npmjs.org/cryptiles/-/cryptiles-4.1.3.tgz", - "integrity": "sha512-gT9nyTMSUC1JnziQpPbxKGBbUg8VL7Zn2NB4E1cJYvuXdElHrwxrV9bmltZGDzet45zSDGyYceueke1TjynGzw==", + "debug": { + "version": "4.4.0", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.0.tgz", + "integrity": "sha512-6WTZ/IxCY/T6BALoZHaE4ctp9xm+Z5kY/pzYaCHRFeyVhojxlrm+46y68HA6hr0TcwEssoxNiDEUJQjfPZ/RYA==", "dev": true, "requires": { - "boom": "7.x.x" + "ms": "^2.1.3" } }, "diff": { @@ -756,6 +1406,39 @@ "integrity": "sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==", "dev": true }, + "esbuild": { + "version": "0.24.2", + "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.24.2.tgz", + "integrity": "sha512-+9egpBW8I3CD5XPe0n6BfT5fxLzxrlDzqydF3aviG+9ni1lDC/OvMHcxqEFV0+LANZG5R1bFMWfUrjVsdwxJvA==", + "dev": true, + "requires": { + "@esbuild/aix-ppc64": "0.24.2", + "@esbuild/android-arm": "0.24.2", + "@esbuild/android-arm64": "0.24.2", + "@esbuild/android-x64": "0.24.2", + "@esbuild/darwin-arm64": "0.24.2", + "@esbuild/darwin-x64": "0.24.2", + "@esbuild/freebsd-arm64": "0.24.2", + "@esbuild/freebsd-x64": "0.24.2", + "@esbuild/linux-arm": "0.24.2", + "@esbuild/linux-arm64": "0.24.2", + "@esbuild/linux-ia32": "0.24.2", + "@esbuild/linux-loong64": "0.24.2", + "@esbuild/linux-mips64el": "0.24.2", + "@esbuild/linux-ppc64": "0.24.2", + "@esbuild/linux-riscv64": "0.24.2", + "@esbuild/linux-s390x": "0.24.2", + "@esbuild/linux-x64": "0.24.2", + "@esbuild/netbsd-arm64": "0.24.2", + "@esbuild/netbsd-x64": "0.24.2", + "@esbuild/openbsd-arm64": "0.24.2", + "@esbuild/openbsd-x64": "0.24.2", + "@esbuild/sunos-x64": "0.24.2", + "@esbuild/win32-arm64": "0.24.2", + "@esbuild/win32-ia32": "0.24.2", + "@esbuild/win32-x64": "0.24.2" + } + }, "escape-string-regexp": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", @@ -809,12 +1492,6 @@ "integrity": "sha512-sKJf1+ceQBr4SMkvQnBDNDtf4TXpVhVGateu0t918bl30FnbE2m4vNLX+VWe/dpjlb+HugGYzW7uQXH98HPEYw==", "dev": true }, - "hoek": { - "version": "6.1.3", - "resolved": "https://registry.npmjs.org/hoek/-/hoek-6.1.3.tgz", - "integrity": "sha512-YXXAAhmF9zpQbC7LEcREFtXfGq5K1fmd+4PHkBq8NUqmzW3G+Dq10bI/i0KucLRwss3YYFQ0fSfoxBZYiGUqtQ==", - "dev": true - }, "inflight": { "version": "1.0.6", "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", @@ -841,9 +1518,9 @@ } }, "jose": { - "version": "4.13.1", - "resolved": "https://registry.npmjs.org/jose/-/jose-4.13.1.tgz", - "integrity": "sha512-MSJQC5vXco5Br38mzaQKiq9mwt7lwj2eXpgpRyQYNHYt2lq1PjkWa7DLXX0WVcQLE9HhMh3jPiufS7fhJf+CLQ==", + "version": "4.15.9", + "resolved": "https://registry.npmjs.org/jose/-/jose-4.15.9.tgz", + "integrity": "sha512-1vUQX+IdDMVPj4k8kOxgUqlcK518yluMuGZwqlr44FS1ppZB/5GWh4rZG89erpOBOJjU/OBsnCVFfapsRz6nEA==", "dev": true }, "js-tokens": { @@ -862,6 +1539,12 @@ "esprima": "^4.0.0" } }, + "jsonrpc-lite": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/jsonrpc-lite/-/jsonrpc-lite-2.2.0.tgz", + "integrity": "sha512-/cbbSxtZWs1O7R4tWqabrCM/t3N8qKUZMAg9IUqpPvUs6UyRvm6pCNYkskyKN/XU0UgffW+NY2ZRr8t0AknX7g==", + "dev": true + }, "lodash.clonedeep": { "version": "4.5.0", "resolved": "https://registry.npmjs.org/lodash.clonedeep/-/lodash.clonedeep-4.5.0.tgz", @@ -892,6 +1575,12 @@ "minimist": "^1.2.6" } }, + "ms": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", + "dev": true + }, "once": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", @@ -1000,21 +1689,11 @@ "dev": true }, "uuid": { - "version": "3.4.0", - "resolved": "https://registry.npmjs.org/uuid/-/uuid-3.4.0.tgz", - "integrity": "sha512-HjSDRw6gZE5JMggctHBcjVak08+KEVhSIiDzFnT9S9aegmp85S/bReBVTb4QTFaRNptJ9kuYaNhnbNEOkbKb/A==", + "version": "11.0.5", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-11.0.5.tgz", + "integrity": "sha512-508e6IcKLrhxKdBbcA2b4KQZlLVp2+J5UwQ6F7Drckkc5N9ZJwFa4TgWtsww9UG8fGHbm6gbV19TdM5pQ4GaIA==", "dev": true }, - "vm2": { - "version": "3.9.14", - "resolved": "https://registry.npmjs.org/vm2/-/vm2-3.9.14.tgz", - "integrity": "sha512-HgvPHYHeQy8+QhzlFryvSteA4uQLBCOub02mgqdR+0bN/akRZ48TGB1v0aCv7ksyc0HXx16AZtMHKS38alc6TA==", - "dev": true, - "requires": { - "acorn": "^8.7.0", - "acorn-walk": "^8.2.0" - } - }, "wrappy": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", diff --git a/github/package.json b/github/package.json index 43584ee..b472193 100644 --- a/github/package.json +++ b/github/package.json @@ -1,9 +1,12 @@ { "devDependencies": { - "@rocket.chat/apps-engine": "^1.36.0", - "@rocket.chat/ui-kit": "^0.31.22", + "@rocket.chat/apps-engine": "^1.44.0", "@types/node": "14.14.6", "tslint": "^5.10.0", "typescript": "^4.0.5" + }, + "dependencies": { + "@rocket.chat/ui-kit": "^0.31.25", + "@rocket.chat/icons": "^0.40.0" } } From 56cb7c5c4a91236555de0cb396e4882ad2897faf Mon Sep 17 00:00:00 2001 From: Devansh Date: Tue, 14 Jan 2025 00:53:55 +0530 Subject: [PATCH 02/12] Updated messageModal newIssueModal --- github/handlers/ExecuteBlockActionHandler.ts | 258 ++++++++++-------- github/handlers/ExecuteViewSubmitHandler.ts | 267 +++++++++++-------- github/modals/githubIssuesListModal.ts | 3 +- github/modals/messageModal.ts | 50 ++-- github/modals/newIssueModal.ts | 201 ++++++++------ 5 files changed, 457 insertions(+), 322 deletions(-) diff --git a/github/handlers/ExecuteBlockActionHandler.ts b/github/handlers/ExecuteBlockActionHandler.ts index 02f8573..4771985 100644 --- a/github/handlers/ExecuteBlockActionHandler.ts +++ b/github/handlers/ExecuteBlockActionHandler.ts @@ -536,16 +536,13 @@ export class ExecuteBlockActionHandler { http: this.http, uikitcontext: context, }); - await this.modify - .getUiController() - .updateModalView( - modal, - { - triggerId: - context.getInteractionData().triggerId, - }, - context.getInteractionData().user, - ); + await this.modify.getUiController().updateModalView( + modal, + { + triggerId: context.getInteractionData().triggerId, + }, + context.getInteractionData().user, + ); break; } case ModalsEnum.SUBSCRIPTION_REFRESH_ACTION: { @@ -556,16 +553,13 @@ export class ExecuteBlockActionHandler { http: this.http, uikitcontext: context, }); - await this.modify - .getUiController() - .updateModalView( - modal, - { - triggerId: - context.getInteractionData().triggerId, - }, - context.getInteractionData().user, - ); + await this.modify.getUiController().updateModalView( + modal, + { + triggerId: context.getInteractionData().triggerId, + }, + context.getInteractionData().user, + ); break; } case ModalsEnum.ISSUE_TEMPLATE_SELECTION_ACTION: { @@ -607,10 +601,12 @@ export class ExecuteBlockActionHandler { persistence: this.persistence, http: this.http, uikitcontext: context, + id: this.app.getID(), }); - return context - .getInteractionResponder() - .openModalViewResponse(newIssueModal); + const triggerId = context.getInteractionData().triggerId; + if(triggerId) { + await this.modify.getUiController().openSurfaceView(newIssueModal, {triggerId}, user) + } } else { let data = { repository: actionDetailsArray[0], @@ -622,10 +618,12 @@ export class ExecuteBlockActionHandler { persistence: this.persistence, http: this.http, uikitcontext: context, + id: this.app.getID(), }); - return context - .getInteractionResponder() - .openModalViewResponse(newIssueModal); + const triggerId = context.getInteractionData().triggerId; + if(triggerId) { + await this.modify.getUiController().openSurfaceView(newIssueModal, {triggerId}, user) + } } } break; @@ -773,17 +771,14 @@ export class ExecuteBlockActionHandler { persistence: this.persistence, http: this.http, }); - await this.modify - .getUiController() - .updateModalView( - resultsModal, - { - triggerId: - context.getInteractionData() - .triggerId, - }, - context.getInteractionData().user, - ); + await this.modify.getUiController().updateModalView( + resultsModal, + { + triggerId: + context.getInteractionData().triggerId, + }, + context.getInteractionData().user, + ); } } break; @@ -842,17 +837,14 @@ export class ExecuteBlockActionHandler { persistence: this.persistence, http: this.http, }); - await this.modify - .getUiController() - .updateModalView( - resultsModal, - { - triggerId: - context.getInteractionData() - .triggerId, - }, - context.getInteractionData().user, - ); + await this.modify.getUiController().updateModalView( + resultsModal, + { + triggerId: + context.getInteractionData().triggerId, + }, + context.getInteractionData().user, + ); } } break; @@ -904,13 +896,20 @@ export class ExecuteBlockActionHandler { persistence: this.persistence, http: this.http, uikitcontext: context, + id: this.app.getID(), }, ); - return context - .getInteractionResponder() - .openModalViewResponse( - unauthorizedMessageModal, - ); + const triggerId = + context.getInteractionData().triggerId; + if (triggerId) { + await this.modify + .getUiController() + .openSurfaceView( + unauthorizedMessageModal, + { triggerId }, + user, + ); + } } } break; @@ -1018,13 +1017,20 @@ export class ExecuteBlockActionHandler { persistence: this.persistence, http: this.http, uikitcontext: context, + id: this.app.getID(), }, ); - return context - .getInteractionResponder() - .openModalViewResponse( - unauthorizedMessageModal, - ); + const triggerId = + context.getInteractionData().triggerId; + if (triggerId) { + await this.modify + .getUiController() + .openSurfaceView( + unauthorizedMessageModal, + { triggerId }, + user, + ); + } } } break; @@ -1065,34 +1071,50 @@ export class ExecuteBlockActionHandler { ) { const unauthorizedMessageModal = await messageModal({ - message: `🤖 Error Fetching Issue Data ⚠️`, + message: + "Unauthorized Action 🤖 You dont have push rights ⚠️", modify: this.modify, read: this.read, persistence: this.persistence, http: this.http, uikitcontext: context, + id: this.app.getID(), }); - return context - .getInteractionResponder() - .openModalViewResponse( - unauthorizedMessageModal, - ); + const triggerId = + context.getInteractionData().triggerId; + if (triggerId) { + await this.modify + .getUiController() + .openSurfaceView( + unauthorizedMessageModal, + { triggerId }, + user, + ); + } } if (issueComments?.serverError) { const unauthorizedMessageModal = await messageModal({ - message: `🤖 Error Fetching Comments ⚠️`, + message: + "Unauthorized Action 🤖 You dont have push rights ⚠️", modify: this.modify, read: this.read, persistence: this.persistence, http: this.http, uikitcontext: context, + id: this.app.getID(), }); - return context - .getInteractionResponder() - .openModalViewResponse( - unauthorizedMessageModal, - ); + const triggerId = + context.getInteractionData().triggerId; + if (triggerId) { + await this.modify + .getUiController() + .openSurfaceView( + unauthorizedMessageModal, + { triggerId }, + user, + ); + } } } let data = { @@ -1145,16 +1167,26 @@ export class ExecuteBlockActionHandler { .openModalViewResponse(addIssueCommentModal); } else { const unauthorizedMessageModal = await messageModal({ - message: `🤖 Error in adding comments, make sure you are logged in`, + message: + "Unauthorized Action 🤖 You dont have push rights ⚠️", modify: this.modify, read: this.read, persistence: this.persistence, http: this.http, uikitcontext: context, + id: this.app.getID(), }); - return context - .getInteractionResponder() - .openModalViewResponse(unauthorizedMessageModal); + const triggerId = + context.getInteractionData().triggerId; + if (triggerId) { + await this.modify + .getUiController() + .openSurfaceView( + unauthorizedMessageModal, + { triggerId }, + user, + ); + } } break; } @@ -1191,34 +1223,50 @@ export class ExecuteBlockActionHandler { if (pullRequestData?.serverError) { const unauthorizedMessageModal = await messageModal({ - message: `🤖 Error Fetching Repository Data: ⚠️ ${pullRequestData?.message}`, + message: + "Unauthorized Action 🤖 You dont have push rights ⚠️", modify: this.modify, read: this.read, persistence: this.persistence, http: this.http, uikitcontext: context, + id: this.app.getID(), }); - return context - .getInteractionResponder() - .openModalViewResponse( - unauthorizedMessageModal, - ); + const triggerId = + context.getInteractionData().triggerId; + if (triggerId) { + await this.modify + .getUiController() + .openSurfaceView( + unauthorizedMessageModal, + { triggerId }, + user, + ); + } } if (pullRequestComments?.serverError) { const unauthorizedMessageModal = await messageModal({ - message: `🤖 Error Fetching Comments: ⚠️ ${pullRequestData?.message}`, + message: + "Unauthorized Action 🤖 You dont have push rights ⚠️", modify: this.modify, read: this.read, persistence: this.persistence, http: this.http, uikitcontext: context, + id: this.app.getID(), }); - return context - .getInteractionResponder() - .openModalViewResponse( - unauthorizedMessageModal, - ); + const triggerId = + context.getInteractionData().triggerId; + if (triggerId) { + await this.modify + .getUiController() + .openSurfaceView( + unauthorizedMessageModal, + { triggerId }, + user, + ); + } } } let data = { @@ -1302,18 +1350,16 @@ export class ExecuteBlockActionHandler { persistence: this.persistence, http: this.http, uikitcontext: context, - id: this.app.getID() + id: this.app.getID(), }); - await this.modify - .getUiController() - .updateSurfaceView( - issuesListModal, - { - triggerId: - context.getInteractionData().triggerId, - }, - context.getInteractionData().user, - ); + await this.modify.getUiController().updateSurfaceView( + issuesListModal, + { + triggerId: + context.getInteractionData().triggerId, + }, + context.getInteractionData().user, + ); } else { let repoDetails = await getRepoData( this.http, @@ -1340,16 +1386,14 @@ export class ExecuteBlockActionHandler { uikitcontext: context, id: this.app.getID(), }); - await this.modify - .getUiController() - .updateSurfaceView( - issuesListModal, - { - triggerId: - context.getInteractionData().triggerId, - }, - context.getInteractionData().user, - ); + await this.modify.getUiController().updateSurfaceView( + issuesListModal, + { + triggerId: + context.getInteractionData().triggerId, + }, + context.getInteractionData().user, + ); } break; } diff --git a/github/handlers/ExecuteViewSubmitHandler.ts b/github/handlers/ExecuteViewSubmitHandler.ts index cb35983..cb41798 100644 --- a/github/handlers/ExecuteViewSubmitHandler.ts +++ b/github/handlers/ExecuteViewSubmitHandler.ts @@ -117,8 +117,8 @@ export class ExecuteViewSubmitHandler { await this.modify.getUiController().updateModalView(modal, { triggerId: context.getInteractionData().triggerId }, context.getInteractionData().user); return context.getInteractionResponder().successResponse(); } + break; } - break; case ModalsEnum.NEW_ISSUE_VIEW: { const { roomId } = await getInteractionRoomData(this.read.getPersistenceReader(), user.id); if (roomId) { @@ -180,10 +180,19 @@ export class ExecuteViewSubmitHandler { let data = { repository: repository } - const createNewIssue = await NewIssueModal({ data: data, modify: this.modify, read: this.read, persistence: this.persistence, http: this.http, uikitcontext: context }); - return context - .getInteractionResponder() - .openModalViewResponse(createNewIssue); + const newIssueModal = await NewIssueModal({ + data, + modify: this.modify, + read: this.read, + persistence: this.persistence, + http: this.http, + uikitcontext: context, + id: this.app.getID(), + }); + const triggerId = context.getInteractionData().triggerId; + if(triggerId) { + return this.modify.getUiController().openSurfaceView(newIssueModal, {triggerId}, user) + } } } } @@ -360,17 +369,22 @@ export class ExecuteViewSubmitHandler { let mergeResponse = await mergePullRequest(this.http,repository,accessToken.token,pullNumber,commitTitle,commitMessage,mergeMethod); if(mergeResponse?.serverError){ let errorMessage = mergeResponse?.message; - const unauthorizedMessageModal = await messageModal({ - message:`🤖 Unable to merge pull request : ⚠️ ${errorMessage}`, - modify: this.modify, - read: this.read, - persistence: this.persistence, - http: this.http, - uikitcontext: context - }) - return context - .getInteractionResponder() - .openModalViewResponse(unauthorizedMessageModal); + const unauthorizedMessageModal = await messageModal( + { + message: + "Unauthorized Action 🤖 You dont have push rights ⚠️", + modify: this.modify, + read: this.read, + persistence: this.persistence, + http: this.http, + uikitcontext: context, + id: this.app.getID(), + }, + ); + const triggerId = context.getInteractionData().triggerId; + if(triggerId) { + return this.modify.getUiController().openSurfaceView(unauthorizedMessageModal, {triggerId}, user) + } }else{ let url = `https://github.com/${repository}/pull/${pullNumber}`; let succesMessage =`🤖 ${mergeResponse?.message} ✔️ : ${url}`; @@ -394,46 +408,61 @@ export class ExecuteViewSubmitHandler { let addCommentResponse = await addNewPullRequestComment(this.http,repository,accessToken.token,pullNumber,newComment); if(addCommentResponse?.serverError){ let errorMessage = addCommentResponse?.message; - const unauthorizedMessageModal = await messageModal({ - message:`🤖 Unable to add comment : ⚠️ ${errorMessage}`, - modify: this.modify, - read: this.read, - persistence: this.persistence, - http: this.http, - uikitcontext: context - }) - return context - .getInteractionResponder() - .openModalViewResponse(unauthorizedMessageModal); + const unauthorizedMessageModal = await messageModal( + { + message: + "Unauthorized Action 🤖 You dont have push rights ⚠️", + modify: this.modify, + read: this.read, + persistence: this.persistence, + http: this.http, + uikitcontext: context, + id: this.app.getID(), + }, + ); + const triggerId = context.getInteractionData().triggerId; + if(triggerId) { + return this.modify.getUiController().openSurfaceView(unauthorizedMessageModal, {triggerId}, user) + } }else{ let pullRequestComments = await getPullRequestComments(this.http,repository,accessToken.token,pullNumber); let pullRequestData = await getPullRequestData(this.http,repository,accessToken.token,pullNumber); if(pullRequestData?.serverError || pullRequestComments?.pullRequestData){ if(pullRequestData?.serverError){ - const unauthorizedMessageModal = await messageModal({ - message:`🤖 Error Fetching Repository Data: ⚠️ ${pullRequestData?.message}`, - modify: this.modify, - read: this.read, - persistence: this.persistence, - http: this.http, - uikitcontext: context - }) - return context - .getInteractionResponder() - .openModalViewResponse(unauthorizedMessageModal); + const unauthorizedMessageModal = await messageModal( + { + message: + "Unauthorized Action 🤖 You dont have push rights ⚠️", + modify: this.modify, + read: this.read, + persistence: this.persistence, + http: this.http, + uikitcontext: context, + id: this.app.getID(), + }, + ); + const triggerId = context.getInteractionData().triggerId; + if(triggerId) { + return this.modify.getUiController().openSurfaceView(unauthorizedMessageModal, {triggerId}, user) + } } if(pullRequestComments?.serverError){ - const unauthorizedMessageModal = await messageModal({ - message:`🤖 Error Fetching Comments: ⚠️ ${pullRequestData?.message}`, - modify: this.modify, - read: this.read, - persistence: this.persistence, - http: this.http, - uikitcontext: context - }) - return context - .getInteractionResponder() - .openModalViewResponse(unauthorizedMessageModal); + const unauthorizedMessageModal = await messageModal( + { + message: + "Unauthorized Action 🤖 You dont have push rights ⚠️", + modify: this.modify, + read: this.read, + persistence: this.persistence, + http: this.http, + uikitcontext: context, + id: this.app.getID(), + }, + ); + const triggerId = context.getInteractionData().triggerId; + if(triggerId) { + return this.modify.getUiController().openSurfaceView(unauthorizedMessageModal, {triggerId}, user) + } } } let data={ @@ -472,46 +501,61 @@ export class ExecuteViewSubmitHandler { let addCommentResponse = await addNewIssueComment(this.http,repository,accessToken.token,issueNumber,newComment); if(addCommentResponse?.serverError){ let errorMessage = addCommentResponse?.message; - const unauthorizedMessageModal = await messageModal({ - message:`🤖 Unable to add comment : ⚠️ ${errorMessage}`, - modify: this.modify, - read: this.read, - persistence: this.persistence, - http: this.http, - uikitcontext: context - }) - return context - .getInteractionResponder() - .openModalViewResponse(unauthorizedMessageModal); + const unauthorizedMessageModal = await messageModal( + { + message: + "Unauthorized Action 🤖 You dont have push rights ⚠️", + modify: this.modify, + read: this.read, + persistence: this.persistence, + http: this.http, + uikitcontext: context, + id: this.app.getID(), + }, + ); + const triggerId = context.getInteractionData().triggerId; + if(triggerId) { + return this.modify.getUiController().openSurfaceView(unauthorizedMessageModal, {triggerId}, user) + } }else{ let issueComments = await getIssuesComments(this.http,repository,accessToken?.token,issueNumber); let issueData = await getIssueData(repository,issueNumber,accessToken.token,this.http); if(issueData?.issue_compact === "Error Fetching Issue" || issueComments?.issueData){ if(issueData?.issue_compact === "Error Fetching Issue"){ - const unauthorizedMessageModal = await messageModal({ - message:`🤖 Error Fetching Issue Data ⚠️`, - modify: this.modify, - read: this.read, - persistence: this.persistence, - http: this.http, - uikitcontext: context - }) - return context - .getInteractionResponder() - .openModalViewResponse(unauthorizedMessageModal); + const unauthorizedMessageModal = await messageModal( + { + message: + "Unauthorized Action 🤖 You dont have push rights ⚠️", + modify: this.modify, + read: this.read, + persistence: this.persistence, + http: this.http, + uikitcontext: context, + id: this.app.getID(), + }, + ); + const triggerId = context.getInteractionData().triggerId; + if(triggerId) { + return this.modify.getUiController().openSurfaceView(unauthorizedMessageModal, {triggerId}, user) + } } if(issueComments?.serverError){ - const unauthorizedMessageModal = await messageModal({ - message:`🤖 Error Fetching Comments ⚠️`, - modify: this.modify, - read: this.read, - persistence: this.persistence, - http: this.http, - uikitcontext: context - }) - return context - .getInteractionResponder() - .openModalViewResponse(unauthorizedMessageModal); + const unauthorizedMessageModal = await messageModal( + { + message: + "Unauthorized Action 🤖 You dont have push rights ⚠️", + modify: this.modify, + read: this.read, + persistence: this.persistence, + http: this.http, + uikitcontext: context, + id: this.app.getID(), + }, + ); + const triggerId = context.getInteractionData().triggerId; + if(triggerId) { + return this.modify.getUiController().openSurfaceView(unauthorizedMessageModal, {triggerId}, user) + } } } let data={ @@ -555,17 +599,22 @@ export class ExecuteViewSubmitHandler { } if (response.serverError) { let errorMessage = response?.message; - const unauthorizedMessageModal = await messageModal({ - message: `🤖 Error Fetching GitHub Issues : ⚠️ ${errorMessage}`, - modify: this.modify, - read: this.read, - persistence: this.persistence, - http: this.http, - uikitcontext: context - }) - return context - .getInteractionResponder() - .openModalViewResponse(unauthorizedMessageModal); + const unauthorizedMessageModal = await messageModal( + { + message: + "Unauthorized Action 🤖 You dont have push rights ⚠️", + modify: this.modify, + read: this.read, + persistence: this.persistence, + http: this.http, + uikitcontext: context, + id: this.app.getID(), + }, + ); + const triggerId = context.getInteractionData().triggerId; + if(triggerId) { + return this.modify.getUiController().openSurfaceView(unauthorizedMessageModal, {triggerId}, user) + } } else { let issueList: Array = []; for (let issue of response.issues) { @@ -650,17 +699,22 @@ export class ExecuteViewSubmitHandler { let response = await updateGithubIssues(this.http,repository,assigneesArray,issueNumber,accessToken.token); if(response.serverError){ let errorMessage = response?.message; - const unauthorizedMessageModal = await messageModal({ - message:`🤖 Unable to assign issues : ⚠️ ${errorMessage}`, - modify: this.modify, - read: this.read, - persistence: this.persistence, - http: this.http, - uikitcontext: context - }) - return context - .getInteractionResponder() - .openModalViewResponse(unauthorizedMessageModal); + const unauthorizedMessageModal = await messageModal( + { + message: + "Unauthorized Action 🤖 You dont have push rights ⚠️", + modify: this.modify, + read: this.read, + persistence: this.persistence, + http: this.http, + uikitcontext: context, + id: this.app.getID(), + }, + ); + const triggerId = context.getInteractionData().triggerId; + if(triggerId) { + return this.modify.getUiController().openSurfaceView(unauthorizedMessageModal, {triggerId}, user) + } }else{ let githubissueStorage = new GithubRepoIssuesStorage(this.persistence,this.read.getPersistenceReader()); let repoIssuesData: IGitHubIssueData = await githubissueStorage.getIssueData(roomId as string,user); @@ -695,8 +749,8 @@ export class ExecuteViewSubmitHandler { }) let room = await this.read.getRoomReader().getById(roomId) as IRoom; await sendNotification(this.read,this.modify,user,room,"🤖 Assigned Issue Successfully ✔️"); - await this.modify.getUiController().updateModalView(githubIssuesModal, { triggerId: context.getInteractionData().triggerId }, context.getInteractionData().user); - return context.getInteractionResponder().successResponse(); + return await this.modify.getUiController().updateSurfaceView(githubIssuesModal, { triggerId: context.getInteractionData().triggerId }, context.getInteractionData().user); + } } } @@ -735,7 +789,6 @@ export class ExecuteViewSubmitHandler { if (roomId) { let room = await this.read.getRoomReader().getById(roomId) as IRoom; let searchResult: string|undefined = view.state?.[ ModalsEnum.MULTI_SHARE_GITHUB_ISSUES_INPUT]?.[ModalsEnum.MULTI_SHARE_GITHUB_ISSUES_INPUT_ACTION]; - console.log(searchResult); await sendMessage(this.modify,room,user,searchResult as string); } } diff --git a/github/modals/githubIssuesListModal.ts b/github/modals/githubIssuesListModal.ts index 9e0435e..e928ba3 100644 --- a/github/modals/githubIssuesListModal.ts +++ b/github/modals/githubIssuesListModal.ts @@ -7,7 +7,6 @@ import { } from "@rocket.chat/apps-engine/definition/accessors"; import { AccessoryElements, - IBlock, ITextObject, TextObjectType, } from "@rocket.chat/apps-engine/definition/uikit/blocks"; @@ -99,7 +98,7 @@ export async function githubIssuesListModal({ ).roomId; } - const blocks: (IBlock | LayoutBlock)[] = [ + const blocks: LayoutBlock[] = [ { type: "section", text: { diff --git a/github/modals/messageModal.ts b/github/modals/messageModal.ts index 0903801..d003716 100644 --- a/github/modals/messageModal.ts +++ b/github/modals/messageModal.ts @@ -3,6 +3,7 @@ import { IModify, IPersistence, IRead, + IUIKitSurfaceViewParam, } from "@rocket.chat/apps-engine/definition/accessors"; import { TextObjectType } from "@rocket.chat/apps-engine/definition/uikit/blocks"; import { IUIKitModalViewParam } from "@rocket.chat/apps-engine/definition/uikit/UIKitInteractionResponder"; @@ -13,8 +14,12 @@ import { SlashCommandContext } from "@rocket.chat/apps-engine/definition/slashco import { UIKitBlockInteractionContext, UIKitInteractionContext, + UIKitSurfaceType, } from "@rocket.chat/apps-engine/definition/uikit"; -import { storeInteractionRoomData, getInteractionRoomData } from "../persistance/roomInteraction"; +import { + storeInteractionRoomData, + getInteractionRoomData, +} from "../persistance/roomInteraction"; export async function messageModal({ message, @@ -24,39 +29,44 @@ export async function messageModal({ http, slashcommandcontext, uikitcontext, + id }: { - message:string; + message: string; modify: IModify; read: IRead; persistence: IPersistence; http: IHttp; slashcommandcontext?: SlashCommandContext; uikitcontext?: UIKitInteractionContext; -}): Promise { + id: string +}): Promise { const viewId = ModalsEnum.MESSAGE_MODAL_VIEW; - const block = modify.getCreator().getBlockBuilder(); - - block.addSectionBlock({ - text: { - text: `*${message}*`, - type: TextObjectType.MARKDOWN, - emoji:true, - }, - }); - - return { - id: viewId, + const modal: IUIKitSurfaceViewParam = { + type: UIKitSurfaceType.MODAL, title: { - type: TextObjectType.PLAINTEXT, + type: "plain_text", text: AppEnum.DEFAULT_TITLE, }, - close: block.newButtonElement({ + blocks: [ + { + type: "section", + text: { + text: `*${message}*`, + type: TextObjectType.MARKDOWN, + }, + }, + ], + close: { + appId: id, + type: "button", text: { - type: TextObjectType.PLAINTEXT, + type: 'plain_text', text: "Close", }, - }), - blocks: block.getBlocks(), + blockId: 'close_block', + actionId: 'close_action', + } }; + return modal; } diff --git a/github/modals/newIssueModal.ts b/github/modals/newIssueModal.ts index 18da9ee..f0dbb85 100644 --- a/github/modals/newIssueModal.ts +++ b/github/modals/newIssueModal.ts @@ -3,8 +3,11 @@ import { IModify, IPersistence, IRead, + IUIKitSurfaceViewParam, } from "@rocket.chat/apps-engine/definition/accessors"; -import { TextObjectType } from "@rocket.chat/apps-engine/definition/uikit/blocks"; +import { + TextObjectType, +} from "@rocket.chat/apps-engine/definition/uikit/blocks"; import { IUIKitModalViewParam } from "@rocket.chat/apps-engine/definition/uikit/UIKitInteractionResponder"; import { IUser } from "@rocket.chat/apps-engine/definition/users"; import { ModalsEnum } from "../enum/Modals"; @@ -13,11 +16,13 @@ import { SlashCommandContext } from "@rocket.chat/apps-engine/definition/slashco import { UIKitBlockInteractionContext, UIKitInteractionContext, + UIKitSurfaceType, } from "@rocket.chat/apps-engine/definition/uikit"; import { storeInteractionRoomData, getInteractionRoomData, } from "../persistance/roomInteraction"; +import { LayoutBlock } from "@rocket.chat/ui-kit"; export async function NewIssueModal({ data, @@ -27,19 +32,43 @@ export async function NewIssueModal({ http, slashcommandcontext, uikitcontext, + id, }: { - data: any, + data: any; modify: IModify; read: IRead; persistence: IPersistence; http: IHttp; slashcommandcontext?: SlashCommandContext; uikitcontext?: UIKitInteractionContext; -}): Promise { + id: string; +}): Promise { const viewId = ModalsEnum.NEW_ISSUE_VIEW; - const block = modify.getCreator().getBlockBuilder(); - const room = slashcommandcontext?.getRoom() || uikitcontext?.getInteractionData().room; - const user = slashcommandcontext?.getSender() || uikitcontext?.getInteractionData().user; + const room = + slashcommandcontext?.getRoom() || + uikitcontext?.getInteractionData().room; + const user = + slashcommandcontext?.getSender() || + uikitcontext?.getInteractionData().user; + + const modal: IUIKitSurfaceViewParam = { + type: UIKitSurfaceType.MODAL, + title: { + type: "plain_text", + text: ModalsEnum.NEW_ISSUE_TITLE, + }, + blocks: [], + submit: { + type: "button", + appId: id, + actionId: ModalsEnum.NEW_ISSUE_ACTION, + blockId: "NEW_ISSUE_BLOCK", + text: { + type: "plain_text", + text: "Create Issue", + }, + }, + }; if (user?.id) { let roomId; @@ -51,147 +80,147 @@ export async function NewIssueModal({ roomId = ( await getInteractionRoomData( read.getPersistenceReader(), - user.id + user.id, ) ).roomId; } - if(data?.repository != undefined){ - block.addInputBlock({ - blockId: ModalsEnum.REPO_NAME_INPUT, + let blocks: LayoutBlock[] = []; + + if (data?.repository != undefined) { + blocks.push({ + type: "input", label: { + type: "plain_text", text: ModalsEnum.REPO_NAME_LABEL, - type: TextObjectType.PLAINTEXT, }, - element: block.newPlainTextInputElement({ + element: { + type: "plain_text_input", + appId: id, actionId: ModalsEnum.REPO_NAME_INPUT_ACTION, placeholder: { text: ModalsEnum.REPO_NAME_PLACEHOLDER, - type: TextObjectType.PLAINTEXT, + type: "plain_text", }, - initialValue: data?.repository - }), + blockId: ModalsEnum.REPO_NAME_INPUT, + initialValue: data?.repository, + }, }); - }else{ - block.addInputBlock({ - blockId: ModalsEnum.REPO_NAME_INPUT, + } else { + blocks.push({ + type: "input", label: { + type: "plain_text", text: ModalsEnum.REPO_NAME_LABEL, - type: TextObjectType.PLAINTEXT, }, - element: block.newPlainTextInputElement({ + element: { + type: "plain_text_input", + appId: id, actionId: ModalsEnum.REPO_NAME_INPUT_ACTION, + blockId: ModalsEnum.REPO_NAME_INPUT, placeholder: { text: ModalsEnum.REPO_NAME_PLACEHOLDER, - type: TextObjectType.PLAINTEXT, + type: "plain_text", }, - }), + }, }); } - - block.addInputBlock({ - blockId: ModalsEnum.ISSUE_TITLE_INPUT, + blocks.push({ + type: "input", label: { + type: "plain_text", text: ModalsEnum.ISSUE_TITLE_LABEL, - type: TextObjectType.PLAINTEXT, }, - element: block.newPlainTextInputElement({ + element: { + type: "plain_text_input", + appId: id, actionId: ModalsEnum.ISSUE_TITLE_ACTION, + blockId: ModalsEnum.ISSUE_TITLE_INPUT, placeholder: { text: ModalsEnum.ISSUE_TITLE_PLACEHOLDER, - type: TextObjectType.PLAINTEXT, + type: "plain_text", }, - }), + }, }); - if(data?.template != undefined){ - block.addInputBlock({ - blockId: ModalsEnum.ISSUE_BODY_INPUT, + if (data?.template != undefined) { + blocks.push({ + type: "input", label: { - text: ModalsEnum.ISSUE_BODY_INPUT_LABEL, - type: TextObjectType.PLAINTEXT, + type: "plain_text", + text: ModalsEnum.ISSUE_TITLE_LABEL, }, - element: block.newPlainTextInputElement({ - actionId: ModalsEnum.ISSUE_BODY_INPUT_ACTION, + element: { + type: "plain_text_input", + appId: id, + actionId: ModalsEnum.ISSUE_TITLE_ACTION, + blockId: ModalsEnum.ISSUE_BODY_INPUT, placeholder: { text: ModalsEnum.ISSUE_BODY_INPUT_PLACEHOLDER, - type: TextObjectType.PLAINTEXT, + type: "plain_text", }, multiline: true, - initialValue:data?.template - }), + initialValue: data?.template, + }, }); - }else{ - block.addInputBlock({ - blockId: ModalsEnum.ISSUE_BODY_INPUT, + } else { + blocks.push({ + type: "input", label: { - text: ModalsEnum.ISSUE_BODY_INPUT_LABEL, - type: TextObjectType.PLAINTEXT, + type: "plain_text", + text: ModalsEnum.ISSUE_TITLE_LABEL, }, - element: block.newPlainTextInputElement({ - actionId: ModalsEnum.ISSUE_BODY_INPUT_ACTION, + element: { + type: "plain_text_input", + appId: id, + actionId: ModalsEnum.ISSUE_TITLE_ACTION, + blockId: ModalsEnum.ISSUE_BODY_INPUT, placeholder: { text: ModalsEnum.ISSUE_BODY_INPUT_PLACEHOLDER, - type: TextObjectType.PLAINTEXT, + type: "plain_text", }, - multiline: true - }), + multiline: true, + }, }); } - block.addInputBlock({ - blockId: ModalsEnum.ISSUE_LABELS_INPUT, + blocks.push({ + type: "input", label: { + type: "plain_text", text: ModalsEnum.ISSUE_LABELS_INPUT_LABEL, - type: TextObjectType.PLAINTEXT, }, - element: block.newPlainTextInputElement({ + element: { + type: "plain_text_input", + appId: id, actionId: ModalsEnum.ISSUE_LABELS_INPUT_ACTION, + blockId: ModalsEnum.ISSUE_LABELS_INPUT, placeholder: { text: ModalsEnum.ISSUE_LABELS_INPUT_PLACEHOLDER, - type: TextObjectType.PLAINTEXT, + type: "plain_text", }, - }), + }, }); - - block.addInputBlock({ - blockId: ModalsEnum.ISSUE_ASSIGNEES_INPUT, + blocks.push({ + type: "input", label: { + type: "plain_text", text: ModalsEnum.ISSUE_ASSIGNEES_INPUT_LABEL, - type: TextObjectType.PLAINTEXT, }, - element: block.newPlainTextInputElement({ + element: { + type: "plain_text_input", + appId: id, actionId: ModalsEnum.ISSUE_ASSIGNEES_INPUT_ACTION, + blockId: ModalsEnum.ISSUE_ASSIGNEES_INPUT, placeholder: { text: ModalsEnum.ISSUE_ASSIGNEES_INPUT_PLACEHOLDER, - type: TextObjectType.PLAINTEXT, + type: "plain_text", }, - }), + }, }); - } - - block.addDividerBlock(); - return { - id: viewId, - title: { - type: TextObjectType.PLAINTEXT, - text: ModalsEnum.NEW_ISSUE_TITLE, - }, - close: block.newButtonElement({ - text: { - type: TextObjectType.PLAINTEXT, - text: "Close", - }, - }), - submit: block.newButtonElement({ - actionId: ModalsEnum.NEW_ISSUE_ACTION, - text: { - type: TextObjectType.PLAINTEXT, - text: "Create Issue", - }, - }), - blocks: block.getBlocks(), - }; + modal.blocks = blocks; + } + return modal; } From ef77652d38b3e91a3f5366695f23f376c666b04e Mon Sep 17 00:00:00 2001 From: Devansh Date: Wed, 15 Jan 2025 01:42:50 +0530 Subject: [PATCH 03/12] Fixed the Share issues in channel Bug --- github/handlers/ExecuteBlockActionHandler.ts | 154 ++++++++++--------- github/handlers/HandleIssues.ts | 2 +- 2 files changed, 86 insertions(+), 70 deletions(-) diff --git a/github/handlers/ExecuteBlockActionHandler.ts b/github/handlers/ExecuteBlockActionHandler.ts index 4771985..1513a4f 100644 --- a/github/handlers/ExecuteBlockActionHandler.ts +++ b/github/handlers/ExecuteBlockActionHandler.ts @@ -603,9 +603,16 @@ export class ExecuteBlockActionHandler { uikitcontext: context, id: this.app.getID(), }); - const triggerId = context.getInteractionData().triggerId; - if(triggerId) { - await this.modify.getUiController().openSurfaceView(newIssueModal, {triggerId}, user) + const triggerId = + context.getInteractionData().triggerId; + if (triggerId) { + await this.modify + .getUiController() + .openSurfaceView( + newIssueModal, + { triggerId }, + user, + ); } } else { let data = { @@ -620,9 +627,16 @@ export class ExecuteBlockActionHandler { uikitcontext: context, id: this.app.getID(), }); - const triggerId = context.getInteractionData().triggerId; - if(triggerId) { - await this.modify.getUiController().openSurfaceView(newIssueModal, {triggerId}, user) + const triggerId = + context.getInteractionData().triggerId; + if (triggerId) { + await this.modify + .getUiController() + .openSurfaceView( + newIssueModal, + { triggerId }, + user, + ); } } } @@ -1398,77 +1412,79 @@ export class ExecuteBlockActionHandler { break; } case ModalsEnum.MULTI_SHARE_ADD_GITHUB_ISSUE_ACTION: { - let { user, room } = await context.getInteractionData(); + let { user } = context.getInteractionData(); + let room: IRoom | undefined; let issueId: string = context.getInteractionData() .value as string; let roomId: string = ""; if (user?.id) { - if (room?.id) { - roomId = room.id; - } else { - roomId = ( - await getInteractionRoomData( + roomId = ( + await getInteractionRoomData( + this.read.getPersistenceReader(), + user.id, + ) + ).roomId; + room = (await this.read + .getRoomReader() + .getById(roomId)) as IRoom; + + if (room) { + let githubissueStorage = + new GithubRepoIssuesStorage( + this.persistence, this.read.getPersistenceReader(), - user.id, - ) - ).roomId; - room = (await this.read - .getRoomReader() - .getById(roomId)) as IRoom; - } - let githubissueStorage = new GithubRepoIssuesStorage( - this.persistence, - this.read.getPersistenceReader(), - ); - let repoIssuesData: IGitHubIssueData = - await githubissueStorage.getIssueData( - room?.id as string, - user, - ); - if (repoIssuesData?.issue_list?.length) { - let index = -1; - let currentIndex = 0; - for (let issue of repoIssuesData.issue_list) { - if (issue.issue_id == issueId) { - index = currentIndex; - break; - } - currentIndex++; - } - if (index !== -1) { - repoIssuesData.issue_list[index].share = true; - await githubissueStorage.updateIssueData( - room as IRoom, + ); + let repoIssuesData: IGitHubIssueData = + await githubissueStorage.getIssueData( + room?.id as string, user, - repoIssuesData, ); + if (repoIssuesData?.issue_list?.length) { + let index = -1; + let currentIndex = 0; + for (let issue of repoIssuesData.issue_list) { + if (issue.issue_id == issueId) { + index = currentIndex; + break; + } + currentIndex++; + } + if (index !== -1) { + repoIssuesData.issue_list[index].share = + true; + await githubissueStorage.updateIssueData( + room as IRoom, + user, + repoIssuesData, + ); + } + let data = { + issues: repoIssuesData.issue_list, + pushRights: repoIssuesData.push_rights, //no access token, so user has no pushRights to the repo, + repo: repoIssuesData.repository, + user_id: user.id, + }; + const githubIssuesModal = + await githubIssuesListModal({ + data: data, + modify: this.modify, + read: this.read, + persistence: this.persistence, + http: this.http, + id: this.app.getID(), + }); + await this.modify + .getUiController() + .updateSurfaceView( + githubIssuesModal, + { + triggerId: + context.getInteractionData() + .triggerId, + }, + context.getInteractionData().user, + ); } - let data = { - issues: repoIssuesData.issue_list, - pushRights: repoIssuesData.push_rights, //no access token, so user has no pushRights to the repo, - repo: repoIssuesData.repository, - user_id: user.id, - }; - const githubIssuesModal = - await githubIssuesListModal({ - data: data, - modify: this.modify, - read: this.read, - persistence: this.persistence, - http: this.http, - id: this.app.getID(), - }); - await this.modify - .getUiController() - .updateSurfaceView( - githubIssuesModal, - { - triggerId: - context.getInteractionData() - .triggerId, - }, - context.getInteractionData().user, - ); } } break; diff --git a/github/handlers/HandleIssues.ts b/github/handlers/HandleIssues.ts index 551d112..7d1d0cc 100644 --- a/github/handlers/HandleIssues.ts +++ b/github/handlers/HandleIssues.ts @@ -34,7 +34,7 @@ export async function handleNewIssue( }); await modify .getUiController() - .openModalView( + .openSurfaceView( modal, { triggerId }, context.getSender() From 5c8a0d126ba994e01efd9704286afe5408d22678 Mon Sep 17 00:00:00 2001 From: Devansh Date: Wed, 15 Jan 2025 02:46:24 +0530 Subject: [PATCH 04/12] Updated addIssueAssigneeModal --- github/handlers/ExecuteBlockActionHandler.ts | 8 +- github/modals/addIssueAssigneeModal.ts | 188 +++++++++++-------- 2 files changed, 119 insertions(+), 77 deletions(-) diff --git a/github/handlers/ExecuteBlockActionHandler.ts b/github/handlers/ExecuteBlockActionHandler.ts index 1513a4f..0557de1 100644 --- a/github/handlers/ExecuteBlockActionHandler.ts +++ b/github/handlers/ExecuteBlockActionHandler.ts @@ -1330,10 +1330,12 @@ export class ExecuteBlockActionHandler { persistence: this.persistence, http: this.http, uikitcontext: context, + id: this.app.getID(), }); - return context - .getInteractionResponder() - .openModalViewResponse(addIssueAssignee); + const triggerId = context.getInteractionData().triggerId; + if(triggerId) { + await this.modify.getUiController().openSurfaceView(addIssueAssignee, {triggerId}, context.getInteractionData().user) + } } break; } diff --git a/github/modals/addIssueAssigneeModal.ts b/github/modals/addIssueAssigneeModal.ts index 7248881..a1de8be 100644 --- a/github/modals/addIssueAssigneeModal.ts +++ b/github/modals/addIssueAssigneeModal.ts @@ -3,6 +3,7 @@ import { IModify, IPersistence, IRead, + IUIKitSurfaceViewParam, } from "@rocket.chat/apps-engine/definition/accessors"; import { TextObjectType } from "@rocket.chat/apps-engine/definition/uikit/blocks"; import { IUIKitModalViewParam } from "@rocket.chat/apps-engine/definition/uikit/UIKitInteractionResponder"; @@ -13,11 +14,13 @@ import { SlashCommandContext } from "@rocket.chat/apps-engine/definition/slashco import { UIKitBlockInteractionContext, UIKitInteractionContext, + UIKitSurfaceType, } from "@rocket.chat/apps-engine/definition/uikit"; import { storeInteractionRoomData, getInteractionRoomData, } from "../persistance/roomInteraction"; +import { LayoutBlock } from "@rocket.chat/ui-kit"; export async function addIssueAssigneeModal({ data, @@ -27,20 +30,54 @@ export async function addIssueAssigneeModal({ http, slashcommandcontext, uikitcontext, + id, }: { - data: any, + data: any; modify: IModify; read: IRead; persistence: IPersistence; http: IHttp; slashcommandcontext?: SlashCommandContext; uikitcontext?: UIKitInteractionContext; -}): Promise { + id: string; +}): Promise { const viewId = ModalsEnum.ADD_ISSUE_ASSIGNEE_VIEW; - const block = modify.getCreator().getBlockBuilder(); - const room = slashcommandcontext?.getRoom() || uikitcontext?.getInteractionData().room; - const user = slashcommandcontext?.getSender() || uikitcontext?.getInteractionData().user; + const room = + slashcommandcontext?.getRoom() || + uikitcontext?.getInteractionData().room; + const user = + slashcommandcontext?.getSender() || + uikitcontext?.getInteractionData().user; + const modal: IUIKitSurfaceViewParam = { + id: viewId, + type: UIKitSurfaceType.MODAL, + title: { + text: ModalsEnum.GITHUB_ISSUES_TITLE, + type: "plain_text", + }, + blocks: [], + submit: { + type: "button", + text: { + type: "plain_text", + text: "Assign", + }, + appId: id, + blockId: "submit_block", + actionId: ModalsEnum.NEW_ISSUE_ACTION, + }, + close: { + type: "button", + text: { + type: "plain_text", + text: "Close", + }, + appId: id, + blockId: "close_block", + actionId: "close_action", + }, + }; if (user?.id) { let roomId; if (room?.id) { @@ -50,132 +87,135 @@ export async function addIssueAssigneeModal({ roomId = ( await getInteractionRoomData( read.getPersistenceReader(), - user.id + user.id, ) ).roomId; } - if(data?.repository != undefined){ - block.addInputBlock({ - blockId: ModalsEnum.REPO_NAME_INPUT, + let blocks: LayoutBlock[] = []; + + if (data?.repository != undefined) { + blocks.push({ + type: "input", label: { + type: "plain_text", text: ModalsEnum.REPO_NAME_LABEL, - type: TextObjectType.PLAINTEXT, }, - element: block.newPlainTextInputElement({ + element: { + type: "plain_text_input", + appId: id, actionId: ModalsEnum.REPO_NAME_INPUT_ACTION, placeholder: { text: ModalsEnum.REPO_NAME_PLACEHOLDER, - type: TextObjectType.PLAINTEXT, + type: "plain_text", }, - initialValue: data?.repository - }), + blockId: ModalsEnum.REPO_NAME_INPUT, + initialValue: data?.repository, + }, }); - }else{ - block.addInputBlock({ - blockId: ModalsEnum.REPO_NAME_INPUT, + } else { + blocks.push({ + type: "input", label: { + type: "plain_text", text: ModalsEnum.REPO_NAME_LABEL, - type: TextObjectType.PLAINTEXT, }, - element: block.newPlainTextInputElement({ + element: { + type: "plain_text_input", + appId: id, actionId: ModalsEnum.REPO_NAME_INPUT_ACTION, + blockId: ModalsEnum.REPO_NAME_INPUT, placeholder: { text: ModalsEnum.REPO_NAME_PLACEHOLDER, - type: TextObjectType.PLAINTEXT, + type: "plain_text", }, - }), + }, }); } - if(data?.issueNumber){ - block.addInputBlock({ - blockId: ModalsEnum.ISSUE_NUMBER_INPUT, + if (data?.issueNumber) { + blocks.push({ + type: "input", label: { + type: "plain_text", text: ModalsEnum.ISSUE_NUMBER_INPUT_LABEL, - type: TextObjectType.PLAINTEXT, }, - element: block.newPlainTextInputElement({ + element: { + type: "plain_text_input", + appId: id, actionId: ModalsEnum.ISSUE_NUMBER_INPUT_ACTION, + blockId: ModalsEnum.ISSUE_NUMBER_INPUT, placeholder: { text: ModalsEnum.ISSUE_NUMBER_INPUT_PLACEHOLDER, - type: TextObjectType.PLAINTEXT, + type: "plain_text", }, - initialValue: data.issueNumber - }), + initialValue: data.issueNumber, + }, }); - }else{ - block.addInputBlock({ - blockId: ModalsEnum.ISSUE_NUMBER_INPUT, + } else { + blocks.push({ + type: "input", label: { + type: "plain_text", text: ModalsEnum.ISSUE_NUMBER_INPUT_LABEL, - type: TextObjectType.PLAINTEXT, }, - element: block.newPlainTextInputElement({ + element: { + type: "plain_text_input", + appId: id, actionId: ModalsEnum.ISSUE_NUMBER_INPUT_ACTION, + blockId: ModalsEnum.ISSUE_NUMBER_INPUT, placeholder: { text: ModalsEnum.ISSUE_NUMBER_INPUT_PLACEHOLDER, - type: TextObjectType.PLAINTEXT, + type: "plain_text", }, - }), + }, }); } - if(data?.assignees){ - block.addInputBlock({ - blockId: ModalsEnum.ISSUE_ASSIGNEE_INPUT, + if (data?.assignees) { + blocks.push({ + type: "input", label: { + type: "plain_text", text: ModalsEnum.ISSUE_ASSIGNEE_LABEL, - type: TextObjectType.PLAINTEXT, }, - element: block.newPlainTextInputElement({ + element: { + type: "plain_text_input", + appId: id, actionId: ModalsEnum.ISSUE_ASSIGNEE_INPUT_ACTION, + blockId: ModalsEnum.ISSUE_ASSIGNEE_INPUT, placeholder: { text: ModalsEnum.ISSUE_ASSIGNEE_PLACEHOLDER, - type: TextObjectType.PLAINTEXT, + type: "plain_text", }, - initialValue: data.assignees - }), + initialValue: data.assignees, + }, }); - }else{ - block.addInputBlock({ - blockId: ModalsEnum.ISSUE_ASSIGNEE_INPUT, + } else { + blocks.push({ + type: "input", label: { + type: "plain_text", text: ModalsEnum.ISSUE_ASSIGNEE_LABEL, - type: TextObjectType.PLAINTEXT, }, - element: block.newPlainTextInputElement({ + element: { + type: "plain_text_input", + appId: id, actionId: ModalsEnum.ISSUE_ASSIGNEE_INPUT_ACTION, + blockId: ModalsEnum.ISSUE_ASSIGNEE_INPUT, placeholder: { text: ModalsEnum.ISSUE_ASSIGNEE_PLACEHOLDER, - type: TextObjectType.PLAINTEXT, + type: "plain_text", }, - }), + }, }); } - } + blocks.push({ + type: 'divider', + }) - block.addDividerBlock(); + modal.blocks = blocks; + } - return { - id: viewId, - title: { - type: TextObjectType.PLAINTEXT, - text: ModalsEnum.GITHUB_ISSUES_TITLE, - }, - close: block.newButtonElement({ - text: { - type: TextObjectType.PLAINTEXT, - text: "Close", - }, - }), - submit: block.newButtonElement({ - actionId: ModalsEnum.NEW_ISSUE_ACTION, - text: { - type: TextObjectType.PLAINTEXT, - text: "Assign", - }, - }), - blocks: block.getBlocks(), - }; + return modal; } From 969c706f0e0c9cc35a858da4b7ad26c403cda9fa Mon Sep 17 00:00:00 2001 From: Devansh Date: Thu, 16 Jan 2025 14:33:17 +0530 Subject: [PATCH 05/12] Updated pullDetailsModal --- github/handlers/ExecuteBlockActionHandler.ts | 8 +- github/handlers/ExecuteViewClosedHandler.ts | 9 +- github/lib/commandUtility.ts | 3 +- github/modals/pullDetailsModal.ts | 175 ++++++++++++------- 4 files changed, 126 insertions(+), 69 deletions(-) diff --git a/github/handlers/ExecuteBlockActionHandler.ts b/github/handlers/ExecuteBlockActionHandler.ts index 0557de1..4c6c03e 100644 --- a/github/handlers/ExecuteBlockActionHandler.ts +++ b/github/handlers/ExecuteBlockActionHandler.ts @@ -695,10 +695,12 @@ export class ExecuteBlockActionHandler { persistence: this.persistence, http: this.http, uikitcontext: context, + id: this.app.getID(), }); - return context - .getInteractionResponder() - .openModalViewResponse(resultsModal); + const triggerId = context.getInteractionData().triggerId; + if(triggerId) { + await this.modify.getUiController().openSurfaceView(resultsModal, {triggerId}, user) + } } else { console.log("invalid Trigger ID !"); } diff --git a/github/handlers/ExecuteViewClosedHandler.ts b/github/handlers/ExecuteViewClosedHandler.ts index dab8273..a12b461 100644 --- a/github/handlers/ExecuteViewClosedHandler.ts +++ b/github/handlers/ExecuteViewClosedHandler.ts @@ -33,8 +33,9 @@ export class ExecuteViewClosedHandler { persistence: this.persistence, http: this.http, uikitcontext: context, + id: this.app.getID(), }); - await this.modify.getUiController().updateModalView( + await this.modify.getUiController().updateSurfaceView( modal, { triggerId: context.getInteractionData() @@ -46,10 +47,10 @@ export class ExecuteViewClosedHandler { case ModalsEnum.SEARCH_RESULT_VIEW:{ const room = context.getInteractionData().room; const user = context.getInteractionData().user; - + if (user?.id) { let roomId; - + if (room?.id) { roomId = room.id; await storeInteractionRoomData(this.persistence, user.id, roomId); @@ -69,7 +70,7 @@ export class ExecuteViewClosedHandler { case ModalsEnum.ISSUE_LIST_VIEW: { const room = context.getInteractionData().room; const user = context.getInteractionData().user; - + if (user?.id) { let roomId; if (room?.id) { diff --git a/github/lib/commandUtility.ts b/github/lib/commandUtility.ts index ec627d1..95d048a 100644 --- a/github/lib/commandUtility.ts +++ b/github/lib/commandUtility.ts @@ -293,10 +293,11 @@ export class CommandUtility implements ExecutorProps { persistence: this.persistence, http: this.http, slashcommandcontext: this.context, + id: this.app.getID(), }); await this.modify .getUiController() - .openModalView(modal, { triggerId }, this.context.getSender()); + .openSurfaceView(modal, { triggerId }, this.context.getSender()); } else { console.log("invalid Trigger ID !"); } diff --git a/github/modals/pullDetailsModal.ts b/github/modals/pullDetailsModal.ts index a400e9e..2e4bb39 100644 --- a/github/modals/pullDetailsModal.ts +++ b/github/modals/pullDetailsModal.ts @@ -3,6 +3,7 @@ import { IModify, IPersistence, IRead, + IUIKitSurfaceViewParam, } from "@rocket.chat/apps-engine/definition/accessors"; import { TextObjectType } from "@rocket.chat/apps-engine/definition/uikit/blocks"; import { IUIKitModalViewParam } from "@rocket.chat/apps-engine/definition/uikit/UIKitInteractionResponder"; @@ -13,8 +14,13 @@ import { SlashCommandContext } from "@rocket.chat/apps-engine/definition/slashco import { UIKitBlockInteractionContext, UIKitInteractionContext, + UIKitSurfaceType, } from "@rocket.chat/apps-engine/definition/uikit"; -import { storeInteractionRoomData, getInteractionRoomData } from "../persistance/roomInteraction"; +import { + storeInteractionRoomData, + getInteractionRoomData, +} from "../persistance/roomInteraction"; +import { LayoutBlock } from "@rocket.chat/ui-kit"; export async function pullDetailsModal({ data, @@ -24,6 +30,7 @@ export async function pullDetailsModal({ http, slashcommandcontext, uikitcontext, + id, }: { data?; modify: IModify; @@ -32,11 +39,9 @@ export async function pullDetailsModal({ http: IHttp; slashcommandcontext?: SlashCommandContext; uikitcontext?: UIKitInteractionContext; -}): Promise { + id: string; +}): Promise { const viewId = ModalsEnum.PULL_VIEW; - - const block = modify.getCreator().getBlockBuilder(); - const room = slashcommandcontext?.getRoom() || uikitcontext?.getInteractionData().room; @@ -44,74 +49,109 @@ export async function pullDetailsModal({ slashcommandcontext?.getSender() || uikitcontext?.getInteractionData().user; + const modal: IUIKitSurfaceViewParam = { + id: viewId, + type: UIKitSurfaceType.MODAL, + title: { + text: AppEnum.DEFAULT_TITLE, + type: "plain_text", + }, + blocks: [], + close: { + type: "button", + text: { + type: "plain_text", + text: "Close", + }, + appId: id, + blockId: "close_block", + actionId: "close_action", + }, + }; + + let blocks: LayoutBlock[] = []; if (user?.id) { let roomId; + if (room?.id) { roomId = room.id; await storeInteractionRoomData(persistence, user.id, roomId); } else { - roomId = (await getInteractionRoomData(read.getPersistenceReader(), user.id)).roomId; + roomId = ( + await getInteractionRoomData( + read.getPersistenceReader(), + user.id, + ) + ).roomId; } const pullRawData = await http.get( - `https://api.github.com/repos/${data?.repository}/pulls/${data?.number}` + `https://api.github.com/repos/${data?.repository}/pulls/${data?.number}`, ); // If pullsNumber doesn't exist, notify the user if (pullRawData.statusCode === 404) { - block.addSectionBlock({ + blocks.push({ + type: "section", text: { text: `Pull request #${data?.number} doesn't exist.`, type: TextObjectType.PLAINTEXT, }, }); - return { - title: { - type: TextObjectType.PLAINTEXT, - text: AppEnum.DEFAULT_TITLE, - }, - close: block.newButtonElement({ - text: { - type: TextObjectType.PLAINTEXT, - text: "Close", - }, - }), - blocks: block.getBlocks(), - }; + modal.blocks = blocks; + + return modal; } const pullData = pullRawData.data; const pullRequestFilesRaw = await http.get( - `https://api.github.com/repos/${data?.repository}/pulls/${data?.number}/files` + `https://api.github.com/repos/${data?.repository}/pulls/${data?.number}/files`, ); const pullRequestFiles = pullRequestFilesRaw.data; - block.addSectionBlock({ + blocks.push({ + type: "section", text: { text: `*${pullData?.title}*`, type: TextObjectType.MARKDOWN, }, - accessory: block.newButtonElement({ + accessory: { + type: "button", actionId: ModalsEnum.VIEW_FILE_ACTION, text: { text: ModalsEnum.VIEW_DIFFS_ACTION_LABEL, type: TextObjectType.PLAINTEXT, }, + appId: id, + blockId: "view-diffs-block", value: pullData["diff_url"], - }), + }, }); - block.addContextBlock({ + + blocks.push({ + type: "context", elements: [ - block.newPlainTextObject(`Author: ${pullData?.user?.login} | `), - block.newPlainTextObject(`State : ${pullData?.state} | `), - block.newPlainTextObject(`Mergeable : ${pullData?.mergeable}`), + { + type: "plain_text", + text: `Author: ${pullData?.user?.login} | `, + }, + { + type: "plain_text", + text: `State : ${pullData?.state} | `, + }, + { + type: "plain_text", + text: `Mergeable : ${pullData?.mergeable}`, + }, ], }); - block.addDividerBlock(); + blocks.push({ + type: "divider", + }); let index = 1; @@ -121,25 +161,41 @@ export async function pullDetailsModal({ let status = file["status"]; let addition = file["additions"]; let deletions = file["deletions"]; - block.addSectionBlock({ + + blocks.push({ + type: "section", text: { text: `${index} ${fileName}`, type: TextObjectType.PLAINTEXT, }, - accessory: block.newButtonElement({ + accessory: { + type: "button", actionId: ModalsEnum.VIEW_FILE_ACTION, text: { - text: ModalsEnum.VIEW_FILE_ACTION_LABEL, + text: ModalsEnum.VIEW_DIFFS_ACTION_LABEL, type: TextObjectType.PLAINTEXT, }, + appId: id, + blockId: "view-diffs-block", value: rawUrl, - }), + }, }); - block.addContextBlock({ + + blocks.push({ + type: "context", elements: [ - block.newPlainTextObject(`Status: ${status} | `), - block.newPlainTextObject(`Additions : ${addition} | `), - block.newPlainTextObject(`Deletions : ${deletions}`), + { + type: "plain_text", + text: `Status: ${status} | `, + }, + { + type: "plain_text", + text: `Additions : ${addition} | `, + }, + { + type: "plain_text", + text: `Deletions : ${deletions}`, + }, ], }); @@ -147,47 +203,44 @@ export async function pullDetailsModal({ } } - block.addActionsBlock({ + blocks.push({ + type: 'actions', elements: [ - block.newButtonElement({ + { + appId: id, + type: 'button', actionId: ModalsEnum.MERGE_PULL_REQUEST_ACTION, text: { text: ModalsEnum.MERGE_PULL_REQUEST_LABEL, type: TextObjectType.PLAINTEXT, }, value: `${data?.repository} ${data?.number}`, - }), - block.newButtonElement({ + blockId: 'MERGE_PULL_REQUEST_BLOCK', + }, + { + appId: id, + type: 'button', actionId: ModalsEnum.PR_COMMENT_LIST_ACTION, text: { text: ModalsEnum.PR_COMMENT_LIST_LABEL, type: TextObjectType.PLAINTEXT, }, value: `${data?.repository} ${data?.number}`, - }), - block.newButtonElement({ + blockId: 'PR_COMMENT_LIST_BLOCK', + }, + { + appId: id, + type: 'button', actionId: ModalsEnum.APPROVE_PULL_REQUEST_ACTION, text: { text: ModalsEnum.APPROVE_PULL_REQUEST_LABEL, type: TextObjectType.PLAINTEXT, }, value: `${data?.repository} ${data?.number}`, - }), - ], - }); - - return { - id: viewId, - title: { - type: TextObjectType.PLAINTEXT, - text: AppEnum.DEFAULT_TITLE, - }, - close: block.newButtonElement({ - text: { - type: TextObjectType.PLAINTEXT, - text: "Close", + blockId: 'APPROVE_PULL_REQUEST_BLOCK', }, - }), - blocks: block.getBlocks(), - }; + ] + }) + modal.blocks = blocks; + return modal; } From ac84052077d22e1de9dc1bca10f47f194c236e3b Mon Sep 17 00:00:00 2001 From: Devansh Date: Thu, 16 Jan 2025 21:09:23 +0530 Subject: [PATCH 06/12] Updated githubSearchErrorModal, githubSearchModal, githubSearchResultModal, githubSearchResultsShareModal --- github/handlers/ExecuteBlockActionHandler.ts | 82 ++++-- github/handlers/ExecuteViewSubmitHandler.ts | 35 ++- github/handlers/SearchHandler.ts | 3 +- github/modals/githubSearchErrorModal.ts | 41 +-- github/modals/githubSearchModal.ts | 275 ++++++++++-------- github/modals/githubSearchResultModal.ts | 252 ++++++++++------ .../modals/githubSearchResultsShareModal.ts | 92 +++--- 7 files changed, 473 insertions(+), 307 deletions(-) diff --git a/github/handlers/ExecuteBlockActionHandler.ts b/github/handlers/ExecuteBlockActionHandler.ts index 4c6c03e..8d647c5 100644 --- a/github/handlers/ExecuteBlockActionHandler.ts +++ b/github/handlers/ExecuteBlockActionHandler.ts @@ -697,9 +697,16 @@ export class ExecuteBlockActionHandler { uikitcontext: context, id: this.app.getID(), }); - const triggerId = context.getInteractionData().triggerId; - if(triggerId) { - await this.modify.getUiController().openSurfaceView(resultsModal, {triggerId}, user) + const triggerId = + context.getInteractionData().triggerId; + if (triggerId) { + await this.modify + .getUiController() + .openSurfaceView( + resultsModal, + { triggerId }, + user, + ); } } else { console.log("invalid Trigger ID !"); @@ -786,21 +793,25 @@ export class ExecuteBlockActionHandler { read: this.read, persistence: this.persistence, http: this.http, + id: this.app.getID(), }); - await this.modify.getUiController().updateModalView( - resultsModal, - { - triggerId: - context.getInteractionData().triggerId, - }, - context.getInteractionData().user, - ); + await this.modify + .getUiController() + .updateSurfaceView( + resultsModal, + { + triggerId: + context.getInteractionData() + .triggerId, + }, + context.getInteractionData().user, + ); } } break; } case ModalsEnum.MULTI_SHARE_REMOVE_SEARCH_RESULT_ACTION: { - let { user, room } = await context.getInteractionData(); + let { user, room } = context.getInteractionData(); let searchResultId: string = context.getInteractionData() .value as string; let roomId = ""; @@ -852,15 +863,19 @@ export class ExecuteBlockActionHandler { read: this.read, persistence: this.persistence, http: this.http, + id: this.app.getID(), }); - await this.modify.getUiController().updateModalView( - resultsModal, - { - triggerId: - context.getInteractionData().triggerId, - }, - context.getInteractionData().user, - ); + await this.modify + .getUiController() + .updateSurfaceView( + resultsModal, + { + triggerId: + context.getInteractionData() + .triggerId, + }, + context.getInteractionData().user, + ); } } break; @@ -1334,9 +1349,16 @@ export class ExecuteBlockActionHandler { uikitcontext: context, id: this.app.getID(), }); - const triggerId = context.getInteractionData().triggerId; - if(triggerId) { - await this.modify.getUiController().openSurfaceView(addIssueAssignee, {triggerId}, context.getInteractionData().user) + const triggerId = + context.getInteractionData().triggerId; + if (triggerId) { + await this.modify + .getUiController() + .openSurfaceView( + addIssueAssignee, + { triggerId }, + context.getInteractionData().user, + ); } } break; @@ -1631,11 +1653,19 @@ export class ExecuteBlockActionHandler { persistence: this.persistence, http: this.http, uikitcontext: context, + id: this.app.getID(), }); - return context - .getInteractionResponder() - .openModalViewResponse(searchModal); + const triggerId = context.getInteractionData().triggerId; + if (triggerId) { + await this.modify + .getUiController() + .openSurfaceView( + searchModal, + { triggerId }, + context.getInteractionData().user, + ); + } } case ModalsEnum.UNSUBSCRIBE_REMINDER_ACTION: { diff --git a/github/handlers/ExecuteViewSubmitHandler.ts b/github/handlers/ExecuteViewSubmitHandler.ts index cb41798..0b58841 100644 --- a/github/handlers/ExecuteViewSubmitHandler.ts +++ b/github/handlers/ExecuteViewSubmitHandler.ts @@ -298,21 +298,26 @@ export class ExecuteViewSubmitHandler { read: this.read, persistence: this.persistence, http: this.http, - uikitcontext: context}); - return context - .getInteractionResponder() - .openModalViewResponse(resultsModal); + uikitcontext: context, + id: this.app.getID(), + }); + const triggerId = context.getInteractionData().triggerId; + if(triggerId) { + return this.modify.getUiController().openSurfaceView(resultsModal, {triggerId}, user) + } } }else{ - const searchErrorModal =await githubSearchErrorModal({ + const searchErrorModal = await githubSearchErrorModal({ errorMessage:resultResponse.message, modify:this.modify, read:this.read, - uikitcontext:context + uikitcontext:context, + id: this.app.getID(), }) - return context - .getInteractionResponder() - .openModalViewResponse(searchErrorModal); + const triggerId = context.getInteractionData().triggerId; + if(triggerId) { + return this.modify.getUiController().openSurfaceView(searchErrorModal, {triggerId}, user) + } } } } @@ -323,7 +328,6 @@ export class ExecuteViewSubmitHandler { if (user.id) { const { roomId } = await getInteractionRoomData(this.read.getPersistenceReader(), user.id); if (roomId) { - let room = await this.read.getRoomReader().getById(roomId) as IRoom; let githubSearchStorage = new GithubSearchResultStorage(this.persistence,this.read.getPersistenceReader()); let searchResults = await githubSearchStorage.getSearchResults(roomId,user); if(searchResults){ @@ -333,11 +337,14 @@ export class ExecuteViewSubmitHandler { read: this.read, persistence: this.persistence, http: this.http, - uikitcontext: context + uikitcontext: context, + id: this.app.getID(), }); - return context - .getInteractionResponder() - .openModalViewResponse(searchResultShareModal); + + const triggerId = context.getInteractionData().triggerId; + if(triggerId) { + return this.modify.getUiController().openSurfaceView(searchResultShareModal, {triggerId}, user) + } } } } diff --git a/github/handlers/SearchHandler.ts b/github/handlers/SearchHandler.ts index b863818..d6ce031 100644 --- a/github/handlers/SearchHandler.ts +++ b/github/handlers/SearchHandler.ts @@ -29,10 +29,11 @@ export async function handleSearch( persistence: persistence, http: http, slashcommandcontext: context, + id: app.getID(), }); await modify .getUiController() - .openModalView( + .openSurfaceView( modal, { triggerId }, context.getSender() diff --git a/github/modals/githubSearchErrorModal.ts b/github/modals/githubSearchErrorModal.ts index 0301c0f..a3ffb0e 100644 --- a/github/modals/githubSearchErrorModal.ts +++ b/github/modals/githubSearchErrorModal.ts @@ -3,6 +3,7 @@ import { IModify, IPersistence, IRead, + IUIKitSurfaceViewParam, } from "@rocket.chat/apps-engine/definition/accessors"; import { TextObjectType } from "@rocket.chat/apps-engine/definition/uikit/blocks"; import { IUIKitModalViewParam } from "@rocket.chat/apps-engine/definition/uikit/UIKitInteractionResponder"; @@ -14,6 +15,7 @@ import { SlashCommandContext } from "@rocket.chat/apps-engine/definition/slashco import { UIKitBlockInteractionContext, UIKitInteractionContext, + UIKitSurfaceType, } from "@rocket.chat/apps-engine/definition/uikit"; export async function githubSearchErrorModal({ @@ -22,37 +24,42 @@ export async function githubSearchErrorModal({ read, slashcommandcontext, uikitcontext, + id, }: { errorMessage?: string; modify: IModify; read: IRead; slashcommandcontext?: SlashCommandContext; uikitcontext?: UIKitInteractionContext; -}): Promise { + id: string; +}): Promise { const viewId = ModalsEnum.GITHUB_SEARCH_ERROR_VIEW; - const block = modify.getCreator().getBlockBuilder(); - - block.addSectionBlock({ - text: { - text: `🤖 GitHub Search Error : ${errorMessage}`, - type: TextObjectType.MARKDOWN, - }, - }); - - - return { + const modal: IUIKitSurfaceViewParam = { id: viewId, + type: UIKitSurfaceType.MODAL, title: { - type: TextObjectType.PLAINTEXT, text: AppEnum.DEFAULT_TITLE, + type: TextObjectType.MARKDOWN, }, - close: block.newButtonElement({ + blocks: [{ + type: 'section', text: { - type: TextObjectType.PLAINTEXT, + type: TextObjectType.MARKDOWN, + text: `🤖 GitHub Search Error : ${errorMessage}` + } + }], + close: { + type: 'button', + text: { + type: 'plain_text', text: "Close", }, - }), - blocks: block.getBlocks(), + actionId: '', + blockId: '', + appId: id, + } }; + + return modal; } diff --git a/github/modals/githubSearchModal.ts b/github/modals/githubSearchModal.ts index ed893b6..64b4c19 100644 --- a/github/modals/githubSearchModal.ts +++ b/github/modals/githubSearchModal.ts @@ -3,6 +3,7 @@ import { IModify, IPersistence, IRead, + IUIKitSurfaceViewParam, } from "@rocket.chat/apps-engine/definition/accessors"; import { TextObjectType } from "@rocket.chat/apps-engine/definition/uikit/blocks"; import { IUIKitModalViewParam } from "@rocket.chat/apps-engine/definition/uikit/UIKitInteractionResponder"; @@ -14,12 +15,13 @@ import { SlashCommandContext } from "@rocket.chat/apps-engine/definition/slashco import { UIKitBlockInteractionContext, UIKitInteractionContext, + UIKitSurfaceType, } from "@rocket.chat/apps-engine/definition/uikit"; import { storeInteractionRoomData, getInteractionRoomData, } from "../persistance/roomInteraction"; - +import { LayoutBlock } from "@rocket.chat/ui-kit"; export async function githubSearchModal({ modify, @@ -28,6 +30,7 @@ export async function githubSearchModal({ http, slashcommandcontext, uikitcontext, + id, }: { modify: IModify; read: IRead; @@ -35,9 +38,9 @@ export async function githubSearchModal({ http: IHttp; slashcommandcontext?: SlashCommandContext; uikitcontext?: UIKitInteractionContext; -}): Promise { + id: string; +}): Promise { const viewId = ModalsEnum.SEARCH_VIEW; - const block = modify.getCreator().getBlockBuilder(); const room = slashcommandcontext?.getRoom() || uikitcontext?.getInteractionData().room; @@ -45,6 +48,40 @@ export async function githubSearchModal({ slashcommandcontext?.getSender() || uikitcontext?.getInteractionData().user; + const modal: IUIKitSurfaceViewParam = { + id: viewId, + type: UIKitSurfaceType.MODAL, + title: { + text: ModalsEnum.SEARCH_VIEW_TITLE, + type: "plain_text", + }, + blocks: [], + submit: { + type: "button", + text: { + type: "plain_text", + emoji: true, + text: "Search", + }, + appId: id, + blockId: "search_block", + actionId: ModalsEnum.GITHUB_SEARCH_ACTION, + }, + close: { + type: "button", + text: { + type: "plain_text", + emoji: true, + text: "Close", + }, + appId: id, + blockId: "close_block", + actionId: "close_action", + }, + }; + + let blocks: LayoutBlock[] = []; + if (user?.id) { let roomId; @@ -55,180 +92,180 @@ export async function githubSearchModal({ roomId = ( await getInteractionRoomData( read.getPersistenceReader(), - user.id + user.id, ) ).roomId; } // shows indentations in input blocks but not inn section block - block.addInputBlock({ - blockId: ModalsEnum.REPO_NAME_INPUT, + blocks.push({ + type: "input", label: { + type: "plain_text", text: ModalsEnum.REPO_NAME_LABEL, - type: TextObjectType.PLAINTEXT, }, - element: block.newPlainTextInputElement({ + element: { + type: "plain_text_input", + appId: id, actionId: ModalsEnum.REPO_NAME_INPUT_ACTION, + blockId: ModalsEnum.REPO_NAME_INPUT, placeholder: { + type: "plain_text", text: ModalsEnum.REPO_NAME_PLACEHOLDER, - type: TextObjectType.PLAINTEXT, }, - }), - }); - - let newResourceStaticElement = block.newStaticSelectElement({ - actionId: ModalsEnum.ADD_MAIN_SEARCH_PARAMATER_OPTION, - options: [ - { - value: "issue", - text: { - type: TextObjectType.PLAINTEXT, - text: "Issues", - emoji: true, - }, - }, - { - value: "pull_request", - text: { - type: TextObjectType.PLAINTEXT, - text: "Pull Request", - emoji: true, - }, - }, - { - value: "issue/pull_request", - text: { - type: TextObjectType.PLAINTEXT, - text: "Issues/Pull Request", - emoji: true, - }, - }, - ], - placeholder: { - type: TextObjectType.PLAINTEXT, - text: "Search Issues/Pull Request", + multiline: false, }, }); - block.addInputBlock({ + blocks.push({ + type: "input", + blockId: ModalsEnum.ADD_SEARCH_STATE_PARAMATER_INPUT, label: { - text: ModalsEnum.ADD_MAIN_SEARCH_PARAMATER_INPUT_LABEL, + text: ModalsEnum.ADD_SEARCH_STATE_PARAMATER_INPUT_LABEL, type: TextObjectType.PLAINTEXT, }, - element: newResourceStaticElement, - blockId: ModalsEnum.ADD_MAIN_SEARCH_PARAMATER_INPUT, - }); - - let newResourceStateStaticElement = block.newStaticSelectElement({ - actionId: ModalsEnum.ADD_SEARCH_STATE_PARAMATER_INPUT_OPTION, - options: [ - { - value: "open", - text: { - type: TextObjectType.PLAINTEXT, - text: "Open", - emoji: true, + element: { + type: "static_select", + actionId: ModalsEnum.ADD_MAIN_SEARCH_PARAMATER_OPTION, + blockId: "add-main-search-block", + options: [ + { + value: "issue", + text: { + type: TextObjectType.PLAINTEXT, + text: "Issues", + emoji: true, + }, }, - }, - { - value: "closed", - text: { - type: TextObjectType.PLAINTEXT, - text: "Closed", - emoji: true, + { + value: "pull_request", + text: { + type: TextObjectType.PLAINTEXT, + text: "Pull Request", + emoji: true, + }, }, - }, - { - value: "any", - text: { - type: TextObjectType.PLAINTEXT, - text: "Any", - emoji: true, + { + value: "issue/pull_request", + text: { + type: TextObjectType.PLAINTEXT, + text: "Issues/Pull Request", + emoji: true, + }, }, + ], + placeholder: { + type: TextObjectType.PLAINTEXT, + text: "Search Issues/Pull Request", }, - ], - placeholder: { - type: TextObjectType.PLAINTEXT, - text: "Open/Closed", + appId: id, }, }); - block.addInputBlock({ + blocks.push({ + type: "input", + blockId: ModalsEnum.ADD_SEARCH_STATE_PARAMATER_INPUT, label: { text: ModalsEnum.ADD_SEARCH_STATE_PARAMATER_INPUT_LABEL, type: TextObjectType.PLAINTEXT, }, - element: newResourceStateStaticElement, - blockId: ModalsEnum.ADD_SEARCH_STATE_PARAMATER_INPUT, + element: { + type: "static_select", + actionId: ModalsEnum.ADD_SEARCH_STATE_PARAMATER_INPUT_OPTION, + blockId: ModalsEnum.ADD_SEARCH_STATE_PARAMATER_INPUT_LABEL, + options: [ + { + value: "open", + text: { + type: TextObjectType.PLAINTEXT, + text: "Open", + emoji: true, + }, + }, + { + value: "closed", + text: { + type: TextObjectType.PLAINTEXT, + text: "Closed", + emoji: true, + }, + }, + { + value: "any", + text: { + type: TextObjectType.PLAINTEXT, + text: "Any", + emoji: true, + }, + }, + ], + placeholder: { + type: TextObjectType.PLAINTEXT, + text: "Open/Closed", + }, + appId: id, + }, }); - block.addInputBlock({ - blockId: ModalsEnum.AUTHOR_NAMES_INPUT, + blocks.push({ + type: "input", label: { + type: "plain_text", text: ModalsEnum.AUTHOR_NAMES_INPUT_LABEL, - type: TextObjectType.PLAINTEXT, }, - element: block.newPlainTextInputElement({ + element: { + type: "plain_text_input", + appId: id, actionId: ModalsEnum.AUTHOR_NAMES_INPUT_ACTION, + blockId: ModalsEnum.AUTHOR_NAMES_INPUT, placeholder: { + type: "plain_text", text: ModalsEnum.AUTHOR_NAMES_INPUT_PLACEHOLDERS, - type: TextObjectType.PLAINTEXT, }, - }), + }, }); - block.addInputBlock({ - blockId: ModalsEnum.RESOURCE_LABELS_INPUT, + blocks.push({ + type: "input", label: { + type: "plain_text", text: ModalsEnum.RESOURCE_LABELS_INPUT_LABEL, - type: TextObjectType.PLAINTEXT, }, - element: block.newPlainTextInputElement({ + element: { + type: "plain_text_input", + appId: id, actionId: ModalsEnum.RESOURCE_LABELS_INPUT_ACTION, + blockId: ModalsEnum.RESOURCE_LABELS_INPUT, placeholder: { + type: "plain_text", text: ModalsEnum.RESOURCE_LABELS_INPUT_PLACEHOLDER, - type: TextObjectType.PLAINTEXT, }, - }), + }, }); - block.addInputBlock({ - blockId: ModalsEnum.RESOURCE_MILESTONES_INPUT, + blocks.push({ + type: "input", label: { + type: "plain_text", text: ModalsEnum.RESOURCE_MILESTONES_INPUT_LABEL, - type: TextObjectType.PLAINTEXT, }, - element: block.newPlainTextInputElement({ + element: { + type: "plain_text_input", + appId: id, actionId: ModalsEnum.RESOURCE_MILESTONES_INPUT_ACTION, + blockId: ModalsEnum.RESOURCE_MILESTONES_INPUT, placeholder: { + type: "plain_text", text: ModalsEnum.RESOURCE_MILESTONES_PLACEHOLDER, - type: TextObjectType.PLAINTEXT, }, - }), + }, }); } - block.addDividerBlock(); + blocks.push({ + type: 'divider', + }) - return { - id: viewId, - title: { - type: TextObjectType.PLAINTEXT, - text: ModalsEnum.SEARCH_VIEW_TITLE, - }, - close: block.newButtonElement({ - text: { - type: TextObjectType.PLAINTEXT, - text: "Close", - }, - }), - submit: block.newButtonElement({ - actionId: ModalsEnum.GITHUB_SEARCH_ACTION, - text: { - type: TextObjectType.PLAINTEXT, - text: "Search", - }, - }), - blocks: block.getBlocks(), - }; + modal.blocks = blocks; + return modal; } diff --git a/github/modals/githubSearchResultModal.ts b/github/modals/githubSearchResultModal.ts index 02a8a7b..e365d1a 100644 --- a/github/modals/githubSearchResultModal.ts +++ b/github/modals/githubSearchResultModal.ts @@ -3,8 +3,12 @@ import { IModify, IPersistence, IRead, + IUIKitSurfaceViewParam, } from "@rocket.chat/apps-engine/definition/accessors"; -import { AccessoryElements, TextObjectType } from "@rocket.chat/apps-engine/definition/uikit/blocks"; +import { + AccessoryElements, + TextObjectType, +} from "@rocket.chat/apps-engine/definition/uikit/blocks"; import { IUIKitModalViewParam } from "@rocket.chat/apps-engine/definition/uikit/UIKitInteractionResponder"; import { IUser } from "@rocket.chat/apps-engine/definition/users"; import { ModalsEnum } from "../enum/Modals"; @@ -13,6 +17,7 @@ import { SlashCommandContext } from "@rocket.chat/apps-engine/definition/slashco import { UIKitBlockInteractionContext, UIKitInteractionContext, + UIKitSurfaceType, } from "@rocket.chat/apps-engine/definition/uikit"; import { storeInteractionRoomData, @@ -20,6 +25,7 @@ import { } from "../persistance/roomInteraction"; import { IGitHubSearchResult } from "../definitions/searchResult"; import { IGitHubSearchResultData } from "../definitions/searchResultData"; +import { ButtonElement, LayoutBlock } from "@rocket.chat/ui-kit"; export async function githubSearchResultModal({ data, @@ -29,27 +35,57 @@ export async function githubSearchResultModal({ http, slashcommandcontext, uikitcontext, + id, }: { - data:IGitHubSearchResultData; + data: IGitHubSearchResultData; modify: IModify; read: IRead; persistence: IPersistence; http: IHttp; slashcommandcontext?: SlashCommandContext; uikitcontext?: UIKitInteractionContext; -}): Promise { + id: string; +}): Promise { const viewId = ModalsEnum.SEARCH_RESULT_VIEW; - - const block = modify.getCreator().getBlockBuilder(); - const room = slashcommandcontext?.getRoom() || uikitcontext?.getInteractionData().room; const user = slashcommandcontext?.getSender() || uikitcontext?.getInteractionData().user || - await read.getUserReader().getById(data?.user_id as string); + (await read.getUserReader().getById(data?.user_id as string)); + + const modal: IUIKitSurfaceViewParam = { + id: viewId, + type: UIKitSurfaceType.MODAL, + title: { + type: TextObjectType.PLAINTEXT, + text: ModalsEnum.SEARCH_VIEW_TITLE, + }, + blocks: [], + submit: { + type: "button", + text: { + type: TextObjectType.PLAINTEXT, + text: "Share", + }, + actionId: "share-action", + blockId: "share-block", + appId: id, + }, + close: { + type: "button", + text: { + type: TextObjectType.PLAINTEXT, + text: "close", + }, + actionId: "close_action", + blockId: "close_block", + appId: id, + }, + }; + let blocks: LayoutBlock[] = []; if (user?.id) { let roomId; if (room?.id) { @@ -59,142 +95,170 @@ export async function githubSearchResultModal({ roomId = ( await getInteractionRoomData( read.getPersistenceReader(), - user.id + user.id, ) ).roomId; } - block.addSectionBlock({ - text: { - text: `Total Search Results : ${data?.total_count}`, - type: TextObjectType.PLAINTEXT, + blocks.push( + { + type: "section", + text: { + text: `Total Search Results : ${data?.total_count}`, + type: TextObjectType.PLAINTEXT, + }, }, - }); + { type: "divider" }, + ); - block.addDividerBlock(); let searchItems = data?.search_results; let index = 1; - if(searchItems && Array.isArray(searchItems)){ + if (searchItems && Array.isArray(searchItems)) { for (let item of searchItems) { let title = item.title; - - block.addSectionBlock({ + + blocks.push({ + type: "section", text: { text: `#${item.number} ${title}`, type: TextObjectType.PLAINTEXT, }, }); - + //context block should only have labels section if labels exist on a resource let contextBlockElementsArray = [ - block.newPlainTextObject(`User : ${item.user_login} | `), - block.newPlainTextObject(`Status: ${item.state} | `), - ] - if(item?.labels && Array.isArray(item.labels)){ + { + type: TextObjectType.PLAINTEXT, + text: `User : ${item.user_login} | `, + }, + { + type: TextObjectType.PLAINTEXT, + text: `User : ${item.user_login} | `, + }, + { + type: TextObjectType.PLAINTEXT, + text: `Status: ${item.state} | `, + }, + ]; + if (item?.labels && Array.isArray(item.labels)) { let labelString = ""; - for(let label of item.labels){ - labelString += `${label.name} ` + for (let label of item.labels) { + labelString += `${label.name} `; } - if(labelString.length){ - contextBlockElementsArray.push(block.newPlainTextObject(`labels: ${labelString} `),) + if (labelString.length) { + contextBlockElementsArray.push({ + type: TextObjectType.PLAINTEXT, + text: `labels: ${labelString} `, + }); } } - block.addContextBlock({ - elements: contextBlockElementsArray + blocks.push({ + type: "context", + elements: contextBlockElementsArray, + blockId: "", + appId: id, }); - //button click actions can only detected `value:string` hence search results object must be parsed to string and stored in `value` and then reparsed to javascript object in `blockActionHandler` - let actionBlockElementsArray = [ - block.newButtonElement({ + //button click actions can only detected `value:string` hence search results object must be parsed to string and stored in `value` and then reparsed to javascript object in `blockActionHandler` + let actionBlockElementsArray: ButtonElement[] = [ + { + type: "button", + appId: id, + blockId: '', actionId: ModalsEnum.OPEN_GITHUB_RESULT_ACTION, text: { text: ModalsEnum.OPEN_GITHUB_RESULT_LABEL, type: TextObjectType.PLAINTEXT, }, - url: item?.html_url?.toString() - }), - block.newButtonElement({ + url: item?.html_url?.toString(), + }, + { + type: "button", + appId: id, + blockId: '', actionId: ModalsEnum.SHARE_SEARCH_RESULT_ACTION, text: { text: ModalsEnum.SHARE_SEARCH_RESULT_LABEL, type: TextObjectType.PLAINTEXT, }, - value:`[ #${item.number} ](${item?.html_url?.toString()}) *${item.title?.toString()?.trim()}* : ${item?.html_url}`, - }), - ] + value: `[ #${item.number} ](${item?.html_url?.toString()}) *${item.title?.toString()?.trim()}* : ${item?.html_url}`, + }, + ]; //if item is already is selected to to be shared, we rendered `remove` button, else we render `add` button - if(item.share){ - actionBlockElementsArray.push( - block.newButtonElement({ - actionId: ModalsEnum.MULTI_SHARE_REMOVE_SEARCH_RESULT_ACTION, - text: { - text: ModalsEnum.MULTI_SHARE_REMOVE_SEARCH_RESULT_LABEL, - type: TextObjectType.PLAINTEXT, - }, - value: item.result_id as string, - }), - ); - }else{ - actionBlockElementsArray.push( - block.newButtonElement({ - actionId: ModalsEnum.MULTI_SHARE_ADD_SEARCH_RESULT_ACTION, - text: { - text: ModalsEnum.MULTI_SHARE_ADD_SEARCH_RESULT_LABEL, - type: TextObjectType.PLAINTEXT, - }, - value: item.result_id as string, - }), - ); + if (item.share) { + actionBlockElementsArray.push({ + type: "button", + appId: id, + blockId: ModalsEnum.MULTI_SHARE_REMOVE_GITHUB_ISSUE_LABEL, + actionId: + ModalsEnum.MULTI_SHARE_REMOVE_SEARCH_RESULT_ACTION, + text: { + text: ModalsEnum.MULTI_SHARE_REMOVE_SEARCH_RESULT_LABEL, + type: 'plain_text', + }, + value: item.result_id as string, + }); + } else { + actionBlockElementsArray.push({ + type: "button", + appId: id, + blockId: ModalsEnum.MULTI_SHARE_ADD_SEARCH_RESULT_LABEL, + actionId: + ModalsEnum.MULTI_SHARE_ADD_SEARCH_RESULT_ACTION, + text: { + text: ModalsEnum.MULTI_SHARE_ADD_SEARCH_RESULT_LABEL, + type: 'plain_text', + }, + value: item.result_id as string, + }); } //if resource is PR we need to show a code changes option and for that we need to destructure the url to find the repository and PR details - if(item.pull_request){ + if (item.pull_request) { let url = item.pull_request_url as string; - if(url){ + if (url) { let urlParams = url.split("/"); - if(urlParams.length>=4){ - let pullNumber = urlParams[urlParams.length-1]?.toString()?.trim(); - let repoName = urlParams[urlParams.length-3]?.toString()?.trim(); - let ownerName = urlParams[urlParams.length-4]?.toString()?.trim(); + if (urlParams.length >= 4) { + let pullNumber = urlParams[urlParams.length - 1] + ?.toString() + ?.trim(); + let repoName = urlParams[urlParams.length - 3] + ?.toString() + ?.trim(); + let ownerName = urlParams[urlParams.length - 4] + ?.toString() + ?.trim(); actionBlockElementsArray.push( - block.newButtonElement({ - actionId: ModalsEnum.VIEW_GITHUB_SEARCH_RESULT_PR_CHANGES, + { + type: "button", + appId: id, + blockId: '', + actionId: + ModalsEnum.VIEW_GITHUB_SEARCH_RESULT_PR_CHANGES, text: { text: ModalsEnum.VIEW_GITHUB_SEARCH_RESULT_PR_CHANGES_LABEL, type: TextObjectType.PLAINTEXT, }, - value:`${ownerName}/${repoName} ${pullNumber}` - }), - ) + value: `${ownerName}/${repoName} ${pullNumber}`, + }, + ); } } } - block.addActionsBlock({ + blocks.push({ + type: 'actions', elements: actionBlockElementsArray, - }); - + blockId: '', + appId: id, + }) + index++; - block.addDividerBlock(); + blocks.push({ + type: 'divider' + }) } } + + modal.blocks = blocks; } - return { - id: viewId, - title: { - type: TextObjectType.PLAINTEXT, - text: ModalsEnum.SEARCH_VIEW_TITLE, - }, - submit: block.newButtonElement({ - text: { - type: TextObjectType.PLAINTEXT, - text: "Share", - }, - }), - close: block.newButtonElement({ - text: { - type: TextObjectType.PLAINTEXT, - text: "Close", - }, - }), - blocks: block.getBlocks(), - }; + return modal; } diff --git a/github/modals/githubSearchResultsShareModal.ts b/github/modals/githubSearchResultsShareModal.ts index 49c7b38..566c089 100644 --- a/github/modals/githubSearchResultsShareModal.ts +++ b/github/modals/githubSearchResultsShareModal.ts @@ -3,6 +3,7 @@ import { IModify, IPersistence, IRead, + IUIKitSurfaceViewParam, } from "@rocket.chat/apps-engine/definition/accessors"; import { TextObjectType } from "@rocket.chat/apps-engine/definition/uikit/blocks"; import { IUIKitModalViewParam } from "@rocket.chat/apps-engine/definition/uikit/UIKitInteractionResponder"; @@ -14,6 +15,7 @@ import { SlashCommandContext } from "@rocket.chat/apps-engine/definition/slashco import { UIKitBlockInteractionContext, UIKitInteractionContext, + UIKitSurfaceType, } from "@rocket.chat/apps-engine/definition/uikit"; import { IGitHubSearchResultData } from "../definitions/searchResultData"; import { getInteractionRoomData, storeInteractionRoomData } from "../persistance/roomInteraction"; @@ -26,6 +28,7 @@ export async function githubSearchResultShareModal({ http, slashcommandcontext, uikitcontext, + id, }: { data: IGitHubSearchResultData; modify: IModify; @@ -34,11 +37,10 @@ export async function githubSearchResultShareModal({ http: IHttp; slashcommandcontext?: SlashCommandContext; uikitcontext?: UIKitInteractionContext; -}): Promise { + id: string; +}): Promise { const viewId = ModalsEnum.SEARCH_RESULT_SHARE_VIEW; - const block = modify.getCreator().getBlockBuilder(); - const room = slashcommandcontext?.getRoom() || uikitcontext?.getInteractionData().room; @@ -46,6 +48,36 @@ export async function githubSearchResultShareModal({ slashcommandcontext?.getSender() || uikitcontext?.getInteractionData().user; + const modal: IUIKitSurfaceViewParam = { + id: viewId, + type: UIKitSurfaceType.MODAL, + title: { + text: ModalsEnum.SEARCH_RESULT_SHARE_VIEW_TITLE, + type: "plain_text", + }, + blocks: [], + submit: { + type: "button", + text: { + type: "plain_text", + text: "Send", + }, + appId: id, + blockId: "submit_block", + actionId: "submit_action", + }, + close: { + type: "button", + text: { + type: "plain_text", + text: "Close", + }, + appId: id, + blockId: "close_block", + actionId: "close_action", + }, + }; + if (user?.id) { let roomId; @@ -69,40 +101,28 @@ export async function githubSearchResultShareModal({ } } } - - block.addInputBlock({ - blockId: ModalsEnum.MULTI_SHARE_SEARCH_INPUT, - label: { - text: ModalsEnum.MULTI_SHARE_SEARCH_INPUT_LABEL, - type: TextObjectType.MARKDOWN - }, - element: block.newPlainTextInputElement({ - initialValue : `${finalString}`, - multiline:true, - actionId: ModalsEnum.MULTI_SHARE_SEARCH_INPUT_ACTION, - }) - }); - } - block.addDividerBlock(); - return { - id: viewId, - title: { - type: TextObjectType.PLAINTEXT, - text: ModalsEnum.SEARCH_RESULT_SHARE_VIEW_TITLE, - }, - submit: block.newButtonElement({ - text: { - type: TextObjectType.PLAINTEXT, - text: "Send", + modal.blocks = [ + { + type: "input", + label: { + type: 'plain_text', + text: ModalsEnum.MULTI_SHARE_SEARCH_INPUT_LABEL, + }, + element: { + type: "plain_text_input", + appId: id, + actionId: ModalsEnum.MULTI_SHARE_SEARCH_INPUT_ACTION, + blockId: ModalsEnum.MULTI_SHARE_SEARCH_INPUT, + initialValue: `${finalString}`, + multiline: true, + }, }, - }), - close: block.newButtonElement({ - text: { - type: TextObjectType.PLAINTEXT, - text: "Close", + { + type: "divider", }, - }), - blocks: block.getBlocks(), - }; + ]; + } + + return modal; } From 732fbdab1dfcc3936b012c27717df4aa71ccedc9 Mon Sep 17 00:00:00 2001 From: Devansh Date: Fri, 17 Jan 2025 19:38:37 +0530 Subject: [PATCH 07/12] Fixed the display of merge button in pull details modal accoding to pushrights and mergable state --- github/handlers/ExecuteBlockActionHandler.ts | 2 + github/lib/commandUtility.ts | 3 + github/modals/pullDetailsModal.ts | 97 ++++++++++++-------- 3 files changed, 64 insertions(+), 38 deletions(-) diff --git a/github/handlers/ExecuteBlockActionHandler.ts b/github/handlers/ExecuteBlockActionHandler.ts index 8d647c5..71720ae 100644 --- a/github/handlers/ExecuteBlockActionHandler.ts +++ b/github/handlers/ExecuteBlockActionHandler.ts @@ -679,6 +679,7 @@ export class ExecuteBlockActionHandler { let value: string = context.getInteractionData() .value as string; let PullRequestDetails = value.split(" "); + let accessToken = await getAccessTokenForUser(this.read, user, this.app.oauth2Config); if (PullRequestDetails.length == 2) { const triggerId = context.getInteractionData().triggerId; @@ -686,6 +687,7 @@ export class ExecuteBlockActionHandler { repository: PullRequestDetails[0], query: "pulls", number: PullRequestDetails[1], + accessToken: accessToken, }; if (triggerId && data) { const resultsModal = await pullDetailsModal({ diff --git a/github/lib/commandUtility.ts b/github/lib/commandUtility.ts index 95d048a..d74b71c 100644 --- a/github/lib/commandUtility.ts +++ b/github/lib/commandUtility.ts @@ -27,6 +27,7 @@ import { HandleInvalidRepoName } from "../handlers/HandleInvalidRepoName"; import { handleMainModal } from "../handlers/MainModalHandler"; import { createReminder } from "../handlers/CreateReminder"; import { ManageReminders, handleReminder } from "../handlers/HandleRemider"; +import { getAccessTokenForUser } from "../persistance/auth"; export class CommandUtility implements ExecutorProps { sender: IUser; @@ -264,10 +265,12 @@ export class CommandUtility implements ExecutorProps { } private async handleTriParamCommand() { + let accessToken = await getAccessTokenForUser(this.read, this.sender, this.app.oauth2Config); const data = { repository: this.command[0], query: this.command[1], number: this.command[2], + accessToken: accessToken, }; const isValidRepo = await HandleInvalidRepoName( diff --git a/github/modals/pullDetailsModal.ts b/github/modals/pullDetailsModal.ts index 2e4bb39..9827e0f 100644 --- a/github/modals/pullDetailsModal.ts +++ b/github/modals/pullDetailsModal.ts @@ -21,6 +21,7 @@ import { getInteractionRoomData, } from "../persistance/roomInteraction"; import { LayoutBlock } from "@rocket.chat/ui-kit"; +import { getRepoData } from "../helpers/githubSDK"; export async function pullDetailsModal({ data, @@ -48,6 +49,8 @@ export async function pullDetailsModal({ const user = slashcommandcontext?.getSender() || uikitcontext?.getInteractionData().user; + let repoDetails: any; + let pushRights: boolean = false; const modal: IUIKitSurfaceViewParam = { id: viewId, @@ -89,6 +92,17 @@ export async function pullDetailsModal({ `https://api.github.com/repos/${data?.repository}/pulls/${data?.number}`, ); + if (data?.accessToken) { + repoDetails = await getRepoData( + http, + data?.repository, + data?.accessToken.token, + ); + pushRights = + repoDetails?.permissions?.push || + repoDetails?.permissions?.admin; + } + // If pullsNumber doesn't exist, notify the user if (pullRawData.statusCode === 404) { blocks.push({ @@ -153,6 +167,47 @@ export async function pullDetailsModal({ type: "divider", }); + let actionElements: any = []; + + if (pullData?.mergeable && pushRights) { + actionElements.push({ + appId: id, + type: "button", + actionId: ModalsEnum.MERGE_PULL_REQUEST_ACTION, + text: { + text: ModalsEnum.MERGE_PULL_REQUEST_LABEL, + type: TextObjectType.PLAINTEXT, + }, + value: `${data?.repository} ${data?.number}`, + blockId: "MERGE_PULL_REQUEST_BLOCK", + }); + } + + actionElements.push({ + appId: id, + type: "button", + actionId: ModalsEnum.PR_COMMENT_LIST_ACTION, + text: { + text: ModalsEnum.PR_COMMENT_LIST_LABEL, + type: TextObjectType.PLAINTEXT, + }, + value: `${data?.repository} ${data?.number}`, + blockId: "PR_COMMENT_LIST_BLOCK", + }); + + if (!pullData?.merged) { + actionElements.push({ + appId: id, + type: "button", + actionId: ModalsEnum.APPROVE_PULL_REQUEST_ACTION, + text: { + text: ModalsEnum.APPROVE_PULL_REQUEST_LABEL, + type: TextObjectType.PLAINTEXT, + }, + value: `${data?.repository} ${data?.number}`, + blockId: "APPROVE_PULL_REQUEST_BLOCK", + }); + } let index = 1; for (let file of pullRequestFiles) { @@ -201,46 +256,12 @@ export async function pullDetailsModal({ index++; } + blocks.push({ + type: "actions", + elements: actionElements, + }); } - blocks.push({ - type: 'actions', - elements: [ - { - appId: id, - type: 'button', - actionId: ModalsEnum.MERGE_PULL_REQUEST_ACTION, - text: { - text: ModalsEnum.MERGE_PULL_REQUEST_LABEL, - type: TextObjectType.PLAINTEXT, - }, - value: `${data?.repository} ${data?.number}`, - blockId: 'MERGE_PULL_REQUEST_BLOCK', - }, - { - appId: id, - type: 'button', - actionId: ModalsEnum.PR_COMMENT_LIST_ACTION, - text: { - text: ModalsEnum.PR_COMMENT_LIST_LABEL, - type: TextObjectType.PLAINTEXT, - }, - value: `${data?.repository} ${data?.number}`, - blockId: 'PR_COMMENT_LIST_BLOCK', - }, - { - appId: id, - type: 'button', - actionId: ModalsEnum.APPROVE_PULL_REQUEST_ACTION, - text: { - text: ModalsEnum.APPROVE_PULL_REQUEST_LABEL, - type: TextObjectType.PLAINTEXT, - }, - value: `${data?.repository} ${data?.number}`, - blockId: 'APPROVE_PULL_REQUEST_BLOCK', - }, - ] - }) modal.blocks = blocks; return modal; } From 879b5ad6c9d1ce93e1db2318836b2e7e7d2e462b Mon Sep 17 00:00:00 2001 From: Devansh Date: Sat, 18 Jan 2025 01:23:42 +0530 Subject: [PATCH 08/12] Fix dynamic displaying of approve button --- github/modals/pullDetailsModal.ts | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/github/modals/pullDetailsModal.ts b/github/modals/pullDetailsModal.ts index 9827e0f..4177b41 100644 --- a/github/modals/pullDetailsModal.ts +++ b/github/modals/pullDetailsModal.ts @@ -22,6 +22,8 @@ import { } from "../persistance/roomInteraction"; import { LayoutBlock } from "@rocket.chat/ui-kit"; import { getRepoData } from "../helpers/githubSDK"; +import { AppSettingsEnum } from "../settings/settings"; +import { GitHubApi } from "../helpers/githubSDKclass"; export async function pullDetailsModal({ data, @@ -88,6 +90,27 @@ export async function pullDetailsModal({ ).roomId; } + let userInfo: any; + try { + let BaseHost = await read + .getEnvironmentReader() + .getSettings() + .getValueById(AppSettingsEnum.BaseHostID); + let BaseApiHost = await read + .getEnvironmentReader() + .getSettings() + .getValueById(AppSettingsEnum.BaseApiHostID); + const gitHubApiClient = new GitHubApi( + http, + data?.accessToken.token, + BaseHost, + BaseApiHost, + ); + userInfo = await gitHubApiClient.getBasicUserInfo(); + } catch (error) { + console.log("Error occurred while fetching user info:", error); + } + const pullRawData = await http.get( `https://api.github.com/repos/${data?.repository}/pulls/${data?.number}`, ); @@ -169,6 +192,7 @@ export async function pullDetailsModal({ let actionElements: any = []; + // Display the button based on merge access and whether the pull request is mergeable or not. if (pullData?.mergeable && pushRights) { actionElements.push({ appId: id, @@ -195,7 +219,8 @@ export async function pullDetailsModal({ blockId: "PR_COMMENT_LIST_BLOCK", }); - if (!pullData?.merged) { + // Display the approve button if the user is not attempting self-approval and if the pull request has not already been merged. + if (!pullData?.merged && (userInfo?.username !== pullData.head.user.login)) { actionElements.push({ appId: id, type: "button", From b27a6d40f6b9999e6489ded71336acb9ab02d2ce Mon Sep 17 00:00:00 2001 From: Devansh Date: Sat, 18 Jan 2025 23:09:16 +0530 Subject: [PATCH 09/12] Updated issueTemplateSelectionModal and mergePullReqeustModal --- github/handlers/ExecuteBlockActionHandler.ts | 8 +- github/handlers/ExecuteViewSubmitHandler.ts | 12 +- github/modals/issueTemplateSelectionModal.ts | 101 ++++++--- github/modals/mergePullReqeustModal.ts | 225 +++++++++++-------- 4 files changed, 210 insertions(+), 136 deletions(-) diff --git a/github/handlers/ExecuteBlockActionHandler.ts b/github/handlers/ExecuteBlockActionHandler.ts index 71720ae..10d4b88 100644 --- a/github/handlers/ExecuteBlockActionHandler.ts +++ b/github/handlers/ExecuteBlockActionHandler.ts @@ -915,10 +915,12 @@ export class ExecuteBlockActionHandler { persistence: this.persistence, http: this.http, uikitcontext: context, + id: this.app.getID(), }); - return context - .getInteractionResponder() - .openModalViewResponse(mergePRModal); + const triggerId = context.getInteractionData().triggerId; + if(triggerId) { + await this.modify.getUiController().openSurfaceView(mergePRModal, { triggerId }, user) + } } else { const unauthorizedMessageModal = await messageModal( { diff --git a/github/handlers/ExecuteViewSubmitHandler.ts b/github/handlers/ExecuteViewSubmitHandler.ts index 0b58841..048c938 100644 --- a/github/handlers/ExecuteViewSubmitHandler.ts +++ b/github/handlers/ExecuteViewSubmitHandler.ts @@ -172,10 +172,11 @@ export class ExecuteViewSubmitHandler { repository=repository?.trim(); let response = await getIssueTemplates(this.http,repository,accessToken.token); if((!response.template_not_found) && response?.templates?.length){ - const issueTemplateSelection = await issueTemplateSelectionModal({ data: response, modify: this.modify, read: this.read, persistence: this.persistence, http: this.http, uikitcontext: context }); - return context - .getInteractionResponder() - .openModalViewResponse(issueTemplateSelection); + const issueTemplateSelection = await issueTemplateSelectionModal({ data: response, modify: this.modify, read: this.read, persistence: this.persistence, http: this.http, uikitcontext: context, id: this.app.getID() }); + const triggerId = context.getInteractionData().triggerId; + if(triggerId) { + return this.modify.getUiController().openSurfaceView(issueTemplateSelection, {triggerId}, user) + } }else{ let data = { repository: repository @@ -378,8 +379,7 @@ export class ExecuteViewSubmitHandler { let errorMessage = mergeResponse?.message; const unauthorizedMessageModal = await messageModal( { - message: - "Unauthorized Action 🤖 You dont have push rights ⚠️", + message:errorMessage, modify: this.modify, read: this.read, persistence: this.persistence, diff --git a/github/modals/issueTemplateSelectionModal.ts b/github/modals/issueTemplateSelectionModal.ts index dfb3e7f..567c593 100644 --- a/github/modals/issueTemplateSelectionModal.ts +++ b/github/modals/issueTemplateSelectionModal.ts @@ -3,6 +3,7 @@ import { IModify, IPersistence, IRead, + IUIKitSurfaceViewParam, } from "@rocket.chat/apps-engine/definition/accessors"; import { TextObjectType } from "@rocket.chat/apps-engine/definition/uikit/blocks"; import { IUIKitModalViewParam } from "@rocket.chat/apps-engine/definition/uikit/UIKitInteractionResponder"; @@ -14,7 +15,9 @@ import { SlashCommandContext } from "@rocket.chat/apps-engine/definition/slashco import { UIKitBlockInteractionContext, UIKitInteractionContext, + UIKitSurfaceType, } from "@rocket.chat/apps-engine/definition/uikit"; +import { LayoutBlock } from "@rocket.chat/ui-kit"; export async function issueTemplateSelectionModal({ data, @@ -24,6 +27,7 @@ export async function issueTemplateSelectionModal({ http, slashcommandcontext, uikitcontext, + id, }: { data?; modify: IModify; @@ -32,11 +36,10 @@ export async function issueTemplateSelectionModal({ http: IHttp; slashcommandcontext?: SlashCommandContext; uikitcontext?: UIKitInteractionContext; -}): Promise { + id: string; +}): Promise { const viewId = ModalsEnum.ISSUE_TEMPLATE_SELECTION_VIEW; - const block = modify.getCreator().getBlockBuilder(); - const room = slashcommandcontext?.getRoom() || uikitcontext?.getInteractionData().room; @@ -44,66 +47,92 @@ export async function issueTemplateSelectionModal({ slashcommandcontext?.getSender() || uikitcontext?.getInteractionData().user; - if (user?.id && data?.repository && data?.templates?.length) { + const modal: IUIKitSurfaceViewParam = { + id: viewId, + type: UIKitSurfaceType.MODAL, + title: { + type: TextObjectType.PLAINTEXT, + text: ModalsEnum.NEW_ISSUE_TITLE, + }, + blocks: [], + close: { + type: "button", + text: { + type: "plain_text", + emoji: true, + text: "Close", + }, + appId: id, + blockId: "", + actionId: "", + }, + }; + + let blocks: LayoutBlock[] = []; + if (user?.id && data?.repository && data?.templates?.length) { let repositoryName = data.repository as string; let templates = data.templates as Array; - block.addSectionBlock({ - text: { - text: `Choose Issue Template for ${repositoryName}`, - type: TextObjectType.PLAINTEXT, - }, - }); - block.addDividerBlock(); + blocks.push( + { + type: "section", + text: { + text: `Choose Issue Template for ${repositoryName}`, + type: TextObjectType.PLAINTEXT, + }, + }, + { + type: "divider", + }, + ); let index = 1; for (let template of templates) { - block.addSectionBlock({ + + blocks.push({ + type: 'section', text: { text: `${template.name}`, type: TextObjectType.PLAINTEXT, }, - accessory: block.newButtonElement({ - actionId: ModalsEnum.ISSUE_TEMPLATE_SELECTION_ACTION, + accessory : { + type: 'button', text: { text: ModalsEnum.ISSUE_TEMPLATE_SELECTION_LABEL, type: TextObjectType.PLAINTEXT, }, value: `${repositoryName} ${template.download_url}`, - }), - }); + actionId: ModalsEnum.ISSUE_TEMPLATE_SELECTION_ACTION, + blockId: '', + appId: id, + } + }) index++; } - block.addSectionBlock({ + + blocks.push({ + type: 'section', text: { - text: `Blank Template`, + text: 'Blank Template', type: TextObjectType.PLAINTEXT, }, - accessory: block.newButtonElement({ - actionId: ModalsEnum.ISSUE_TEMPLATE_SELECTION_ACTION, + accessory : { + type: 'button', text: { text: ModalsEnum.ISSUE_TEMPLATE_SELECTION_LABEL, type: TextObjectType.PLAINTEXT, }, value: `${repositoryName} ${ModalsEnum.BLANK_GITHUB_TEMPLATE}`, - }), - }); + actionId: ModalsEnum.ISSUE_TEMPLATE_SELECTION_ACTION, + blockId: '', + appId: id, + } + }) } - return { - id: viewId, - title: { - type: TextObjectType.PLAINTEXT, - text: ModalsEnum.NEW_ISSUE_TITLE, - }, - close: block.newButtonElement({ - text: { - type: TextObjectType.PLAINTEXT, - text: "Close", - }, - }), - blocks: block.getBlocks(), - }; + modal.blocks = blocks; + + return modal; } diff --git a/github/modals/mergePullReqeustModal.ts b/github/modals/mergePullReqeustModal.ts index d232a7a..bac44b4 100644 --- a/github/modals/mergePullReqeustModal.ts +++ b/github/modals/mergePullReqeustModal.ts @@ -3,6 +3,7 @@ import { IModify, IPersistence, IRead, + IUIKitSurfaceViewParam, } from "@rocket.chat/apps-engine/definition/accessors"; import { TextObjectType } from "@rocket.chat/apps-engine/definition/uikit/blocks"; import { IUIKitModalViewParam } from "@rocket.chat/apps-engine/definition/uikit/UIKitInteractionResponder"; @@ -10,11 +11,13 @@ import { ModalsEnum } from "../enum/Modals"; import { SlashCommandContext } from "@rocket.chat/apps-engine/definition/slashcommands"; import { UIKitInteractionContext, + UIKitSurfaceType, } from "@rocket.chat/apps-engine/definition/uikit"; import { storeInteractionRoomData, getInteractionRoomData, } from "../persistance/roomInteraction"; +import { LayoutBlock } from "@rocket.chat/ui-kit"; export async function mergePullRequestModal({ data, @@ -24,17 +27,18 @@ export async function mergePullRequestModal({ http, slashcommandcontext, uikitcontext, + id, }: { - data?:any, + data?: any; modify: IModify; read: IRead; persistence: IPersistence; http: IHttp; slashcommandcontext?: SlashCommandContext; uikitcontext?: UIKitInteractionContext; -}): Promise { + id: string; +}): Promise { const viewId = ModalsEnum.MERGE_PULL_REQUEST_VIEW; - const block = modify.getCreator().getBlockBuilder(); const room = slashcommandcontext?.getRoom() || uikitcontext?.getInteractionData().room; @@ -42,6 +46,38 @@ export async function mergePullRequestModal({ slashcommandcontext?.getSender() || uikitcontext?.getInteractionData().user; + const modal: IUIKitSurfaceViewParam = { + id: viewId, + type: UIKitSurfaceType.MODAL, + title: { + text: ModalsEnum.MERGE_PULL_REQUEST_VIEW_TITLE, + type: "plain_text", + }, + blocks: [], + submit: { + type: "button", + text: { + type: "plain_text", + text: "Merge", + }, + appId: id, + blockId: "submit_block", + actionId: "submit_action", + }, + close: { + type: "button", + text: { + type: "plain_text", + text: "Close", + }, + appId: id, + blockId: "close_block", + actionId: "close_action", + }, + }; + + let blocks: LayoutBlock[] = []; + if (user?.id) { let roomId; @@ -52,7 +88,7 @@ export async function mergePullRequestModal({ roomId = ( await getInteractionRoomData( read.getPersistenceReader(), - user.id + user.id, ) ).roomId; } @@ -60,87 +96,103 @@ export async function mergePullRequestModal({ // shows indentations in input blocks but not inn section block let defualtPullNumberInput = ""; let defaultRepoInfoInput = ""; - if(data?.repo?.length){ + if (data?.repo?.length) { defaultRepoInfoInput = data?.repo as string; - } - if(data?.pullNumber?.length){ + } + if (data?.pullNumber?.length) { defualtPullNumberInput = data?.pullNumber as string; - } - block.addInputBlock({ - blockId: ModalsEnum.REPO_NAME_INPUT, + } + + blocks.push({ + type: "input", label: { + type: "plain_text", text: ModalsEnum.REPO_NAME_LABEL, - type: TextObjectType.PLAINTEXT, }, - element: block.newPlainTextInputElement({ + element: { + type: "plain_text_input", + appId: id, actionId: ModalsEnum.REPO_NAME_INPUT_ACTION, + blockId: ModalsEnum.REPO_NAME_INPUT, placeholder: { + type: "plain_text", text: ModalsEnum.REPO_NAME_PLACEHOLDER, - type: TextObjectType.PLAINTEXT, }, - initialValue:defaultRepoInfoInput - }), + multiline: false, + initialValue: defaultRepoInfoInput, + }, }); - block.addInputBlock({ - blockId: ModalsEnum.PULL_REQUEST_NUMBER_INPUT, + blocks.push({ + type: "input", label: { + type: "plain_text", text: ModalsEnum.PULL_REQUEST_NUMBER_LABEL, - type: TextObjectType.PLAINTEXT, }, - element: block.newPlainTextInputElement({ + element: { + type: "plain_text_input", + appId: id, actionId: ModalsEnum.PULL_REQUEST_NUMBER_INPUT_ACTION, + blockId: ModalsEnum.PULL_REQUEST_NUMBER_INPUT, placeholder: { + type: "plain_text", text: ModalsEnum.PULL_REQUEST_NUMBER_INPUT_PLACEHOLDER, - type: TextObjectType.PLAINTEXT, }, - initialValue:defualtPullNumberInput - }), + multiline: false, + initialValue: defualtPullNumberInput, + }, }); - - block.addInputBlock({ - blockId: ModalsEnum.PULL_REQUEST_COMMIT_TITLE_INPUT, + blocks.push({ + type: "input", label: { + type: "plain_text", text: ModalsEnum.PULL_REQUEST_COMMIT_TITLE_LABEL, - type: TextObjectType.PLAINTEXT, }, - element: block.newPlainTextInputElement({ + element: { + type: "plain_text_input", + appId: id, actionId: ModalsEnum.PULL_REQUEST_COMMIT_TITLE_ACTION, + blockId: ModalsEnum.PULL_REQUEST_COMMIT_TITLE_INPUT, placeholder: { + type: "plain_text", text: ModalsEnum.PULL_REQUEST_COMMIT_TITLE_PLACEHOLDER, - type: TextObjectType.PLAINTEXT, }, - }), + multiline: false, + }, }); - - block.addInputBlock({ - blockId: ModalsEnum.PULL_REQUEST_COMMIT_MESSAGE_INPUT, + blocks.push({ + type: "input", label: { + type: "plain_text", text: ModalsEnum.PULL_REQUEST_COMMIT_MESSAGE_LABEL, - type: TextObjectType.PLAINTEXT, }, - element: block.newPlainTextInputElement({ + element: { + type: "plain_text_input", + appId: id, actionId: ModalsEnum.PULL_REQUEST_COMMIT_MESSAGE_ACTION, + blockId: ModalsEnum.PULL_REQUEST_COMMIT_MESSAGE_INPUT, placeholder: { + type: "plain_text", text: ModalsEnum.PULL_REQUEST_COMMIT_MESSAGE_PLACEHOLDER, - type: TextObjectType.PLAINTEXT, }, - multiline:true - }), + multiline: true, + }, }); - let newMultiStaticElemnt = block.newStaticSelectElement({ - actionId: ModalsEnum.PULL_REQUEST_MERGE_METHOD_OPTION, - options: [ - { - value: "rebase", - text: { - type: TextObjectType.PLAINTEXT, - text: "Rebase", - emoji: true, - }, - }, - { + let newMultiStaticElemnt: any = []; + + newMultiStaticElemnt.push(); + + blocks.push({ + type: "input", + label: { + text: ModalsEnum.PULL_REQUEST_MERGE_METHOD_INPUT_LABEL, + type: TextObjectType.PLAINTEXT, + }, + element: { + type: "static_select", + actionId: ModalsEnum.PULL_REQUEST_MERGE_METHOD_OPTION, + initialOption: { value: "merge", text: { type: TextObjectType.PLAINTEXT, @@ -148,52 +200,43 @@ export async function mergePullRequestModal({ emoji: true, }, }, - { - value: "squash", - text: { - type: TextObjectType.PLAINTEXT, - text: "Squash", - emoji: true, + options: [ + { + value: "rebase", + text: { + type: TextObjectType.PLAINTEXT, + text: "Rebase", + emoji: true, + }, }, - } - ], - placeholder: { - type: TextObjectType.PLAINTEXT, - text: "Select Events", - }, - }); - - block.addInputBlock({ - label: { - text: ModalsEnum.PULL_REQUEST_MERGE_METHOD_INPUT_LABEL, - type: TextObjectType.PLAINTEXT, + { + value: "merge", + text: { + type: TextObjectType.PLAINTEXT, + text: "Merge", + emoji: true, + }, + }, + { + value: "squash", + text: { + type: TextObjectType.PLAINTEXT, + text: "Squash", + emoji: true, + }, + }, + ], + placeholder: { + type: TextObjectType.PLAINTEXT, + text: "Select Events", + }, + blockId: ModalsEnum.PULL_REQUEST_MERGE_METHOD_INPUT, + appId: id, }, - element: newMultiStaticElemnt, - blockId: ModalsEnum.PULL_REQUEST_MERGE_METHOD_INPUT, }); } - block.addDividerBlock(); + modal.blocks = blocks; - return { - id: viewId, - title: { - type: TextObjectType.PLAINTEXT, - text: ModalsEnum.MERGE_PULL_REQUEST_VIEW_TITLE, - }, - close: block.newButtonElement({ - text: { - type: TextObjectType.PLAINTEXT, - text: "Close", - }, - }), - submit: block.newButtonElement({ - actionId: ModalsEnum.ADD_SUBSCRIPTION_ACTION, - text: { - type: TextObjectType.PLAINTEXT, - text: "Merge", - }, - }), - blocks: block.getBlocks(), - }; + return modal; } From 3b305982789d9b548b98cd62c9a504d42da555f1 Mon Sep 17 00:00:00 2001 From: Devansh Date: Mon, 20 Jan 2025 22:27:25 +0530 Subject: [PATCH 10/12] Updated fileCodeModal, profileShareModal, UserProfileModal --- github/handlers/ExecuteBlockActionHandler.ts | 12 +- github/handlers/UserProfileHandler.ts | 5 +- github/modals/UserProfileModal.ts | 195 +++++++++++------- github/modals/fileCodeModal.ts | 61 +++--- github/modals/newIssueModal.ts | 1 + github/modals/profileShareModal.ts | 201 +++++++++++-------- 6 files changed, 288 insertions(+), 187 deletions(-) diff --git a/github/handlers/ExecuteBlockActionHandler.ts b/github/handlers/ExecuteBlockActionHandler.ts index 10d4b88..254256e 100644 --- a/github/handlers/ExecuteBlockActionHandler.ts +++ b/github/handlers/ExecuteBlockActionHandler.ts @@ -400,10 +400,10 @@ export class ExecuteBlockActionHandler { persistence: this.persistence, http: this.http, uikitcontext: context, + id: this.app.getID(), }); - return context - .getInteractionResponder() - .openModalViewResponse(codeModal); + const triggerId = context.getInteractionData().triggerId + await this.modify.getUiController().openSurfaceView(codeModal, { triggerId }, context.getInteractionData().user); } case ModalsEnum.OPEN_ADD_SUBSCRIPTIONS_MODAL: { const addSubscriptionModal = await AddSubscriptionModal({ @@ -986,11 +986,11 @@ export class ExecuteBlockActionHandler { persistence: this.persistence, http: this.http, uikitcontext: context, + id: this.app.getID(), }); - return context - .getInteractionResponder() - .openModalViewResponse(shareProfileMod); + const triggerId = context.getInteractionData().triggerId; + await this.modify.getUiController().openSurfaceView(shareProfileMod, { triggerId }, context.getInteractionData().user); } case ModalsEnum.APPROVE_PULL_REQUEST_ACTION: { let value: string = context.getInteractionData() diff --git a/github/handlers/UserProfileHandler.ts b/github/handlers/UserProfileHandler.ts index 0c94295..e877c27 100644 --- a/github/handlers/UserProfileHandler.ts +++ b/github/handlers/UserProfileHandler.ts @@ -31,9 +31,10 @@ export async function handleUserProfileRequest( read: read, persistence: persistence, http: http, - slashcommandcontext: context + slashcommandcontext: context, + id: app.getID(), }); - await modify.getUiController().openModalView( + await modify.getUiController().openSurfaceView( modal, {triggerId}, context.getSender() diff --git a/github/modals/UserProfileModal.ts b/github/modals/UserProfileModal.ts index 77ca4cf..e8f7f7e 100644 --- a/github/modals/UserProfileModal.ts +++ b/github/modals/UserProfileModal.ts @@ -1,6 +1,17 @@ -import { IHttp, IModify, IPersistence, IRead } from "@rocket.chat/apps-engine/definition/accessors"; +import { + IHttp, + IModify, + IPersistence, + IRead, + IUIKitSurfaceViewParam, +} from "@rocket.chat/apps-engine/definition/accessors"; import { SlashCommandContext } from "@rocket.chat/apps-engine/definition/slashcommands"; -import { ButtonStyle, TextObjectType, UIKitInteractionContext } from "@rocket.chat/apps-engine/definition/uikit"; +import { + ButtonStyle, + TextObjectType, + UIKitInteractionContext, + UIKitSurfaceType, +} from "@rocket.chat/apps-engine/definition/uikit"; import { IUIKitModalViewParam } from "@rocket.chat/apps-engine/definition/uikit/UIKitInteractionResponder"; import { ModalsEnum } from "../enum/Modals"; import { GitHubApi } from "../helpers/githubSDKclass"; @@ -10,6 +21,7 @@ import { storeInteractionRoomData, } from "../persistance/roomInteraction"; import { AppSettingsEnum } from "../settings/settings"; +import { LayoutBlock } from "@rocket.chat/ui-kit"; export async function userProfileModal({ access_token, @@ -18,104 +30,147 @@ export async function userProfileModal({ persistence, http, slashcommandcontext, - uikitcontext -} : { - access_token: String, - modify : IModify, - read: IRead, - persistence: IPersistence, - http: IHttp, - slashcommandcontext: SlashCommandContext, - uikitcontext?: UIKitInteractionContext -}) : Promise { - + uikitcontext, + id, +}: { + access_token: String; + modify: IModify; + read: IRead; + persistence: IPersistence; + http: IHttp; + slashcommandcontext: SlashCommandContext; + uikitcontext?: UIKitInteractionContext; + id: string; +}): Promise { const viewId = ModalsEnum.USER_PROFILE_VIEW; - const block = modify.getCreator().getBlockBuilder(); - const room = slashcommandcontext?.getRoom() || uikitcontext?.getInteractionData().room; - const user = slashcommandcontext?.getSender() || uikitcontext?.getInteractionData().user; + const room = + slashcommandcontext?.getRoom() || + uikitcontext?.getInteractionData().room; + const user = + slashcommandcontext?.getSender() || + uikitcontext?.getInteractionData().user; + + const modal: IUIKitSurfaceViewParam = { + id: viewId, + type: UIKitSurfaceType.MODAL, + title: { text: "", type: "plain_text" }, + blocks: [], + }; - if (user?.id){ + let blocks: LayoutBlock[] = []; + if (user?.id) { let roomId; - if (room?.id){ + if (room?.id) { roomId = room.id; await storeInteractionRoomData(persistence, user.id, roomId); - } - else { - roomId = (await getInteractionRoomData(read.getPersistenceReader(), user.id)).roomId; + } else { + roomId = ( + await getInteractionRoomData( + read.getPersistenceReader(), + user.id, + ) + ).roomId; } } let userInfo: UserInformation | undefined; try { - let BaseHost = await read.getEnvironmentReader().getSettings().getValueById(AppSettingsEnum.BaseHostID); - let BaseApiHost = await read.getEnvironmentReader().getSettings().getValueById(AppSettingsEnum.BaseApiHostID); + let BaseHost = await read + .getEnvironmentReader() + .getSettings() + .getValueById(AppSettingsEnum.BaseHostID); + let BaseApiHost = await read + .getEnvironmentReader() + .getSettings() + .getValueById(AppSettingsEnum.BaseApiHostID); const gitHubApiClient = new GitHubApi( http, access_token, BaseHost, - BaseApiHost + BaseApiHost, ); userInfo = await gitHubApiClient.getBasicUserInfo(); + + modal.title.text = userInfo ? userInfo.name : "User Profile"; } catch (error) { console.log("Error occurred while fetching user info:", error); } if (userInfo) { - block.addContextBlock({ - elements: [block.newPlainTextObject(userInfo.email, true)], + blocks.push({ + type: "context", + elements: [ + { + type: "plain_text", + text: userInfo.email, + }, + ], + }); + blocks.push({ + type: "section", + text: { + type: "plain_text", + text: userInfo.bio, + }, + accessory: { + type: "image", + imageUrl: userInfo.avatar, + altText: userInfo.name, + }, }); - block.addSectionBlock({ - text: block.newPlainTextObject(userInfo.bio), - accessory : block.newImageElement({ - imageUrl: userInfo.avatar, - altText: userInfo.name - }) - }) - - block.addContextBlock({ - elements: [ - block.newPlainTextObject(`followers: ${userInfo.followers}`), - block.newPlainTextObject(`following: ${userInfo.following}`) - ] - }); + blocks.push({ + type: "context", + elements: [ + { + type: "plain_text", + text: `followers: ${userInfo?.followers}`, + }, + { + type: "plain_text", + text: `following: ${userInfo?.following}`, + }, + ], + }); - block.addDividerBlock(); + blocks.push({ type: "divider" }); - block.addSectionBlock({ - text: block.newPlainTextObject("Select from the following options.") - }) + blocks.push({ + type: "section", + text: { + type: "plain_text", + text: "Select from the following options.", + }, + }); - block.addActionsBlock({ - elements : [ - block.newButtonElement({ - text : { - text : "Share Profile", - type : TextObjectType.PLAINTEXT + blocks.push({ + type: "actions", + elements: [ + { + type: "button", + text: { + text: "Share Profile", + type: TextObjectType.PLAINTEXT, + }, + actionId: ModalsEnum.SHARE_PROFILE, + style: ButtonStyle.PRIMARY, + blockId: "", + appId: id, }, - actionId: ModalsEnum.SHARE_PROFILE, - style : ButtonStyle.PRIMARY - }), - block.newButtonElement( { - actionId: ModalsEnum.TRIGGER_ISSUES_MODAL, - value: "Trigger Issues Modal", + type: "button", text: { + text: "Issues", type: TextObjectType.PLAINTEXT, - text: "Issues" }, - style: ButtonStyle.PRIMARY + actionId: ModalsEnum.TRIGGER_ISSUES_MODAL, + style: ButtonStyle.PRIMARY, + blockId: "", + value: "Trigger Issues Modal", + appId: id, }, - ) - ] - }) -} - return { - id: viewId, - title: { - type: TextObjectType.PLAINTEXT, - text: userInfo ? userInfo.name : "User Profile", - }, - blocks: block.getBlocks() + ], + }); + modal.blocks = blocks; } - + return modal; } diff --git a/github/modals/fileCodeModal.ts b/github/modals/fileCodeModal.ts index 22c7d0e..9c0ff7c 100644 --- a/github/modals/fileCodeModal.ts +++ b/github/modals/fileCodeModal.ts @@ -3,6 +3,7 @@ import { IModify, IPersistence, IRead, + IUIKitSurfaceViewParam, } from "@rocket.chat/apps-engine/definition/accessors"; import { TextObjectType } from "@rocket.chat/apps-engine/definition/uikit/blocks"; import { IUIKitModalViewParam } from "@rocket.chat/apps-engine/definition/uikit/UIKitInteractionResponder"; @@ -14,8 +15,9 @@ import { SlashCommandContext } from "@rocket.chat/apps-engine/definition/slashco import { UIKitBlockInteractionContext, UIKitInteractionContext, + UIKitSurfaceType, } from "@rocket.chat/apps-engine/definition/uikit"; - +import { LayoutBlock } from "@rocket.chat/ui-kit"; export async function fileCodeModal({ data, @@ -25,6 +27,7 @@ export async function fileCodeModal({ http, slashcommandcontext, uikitcontext, + id, }: { data; modify: IModify; @@ -33,11 +36,10 @@ export async function fileCodeModal({ http: IHttp; slashcommandcontext?: SlashCommandContext; uikitcontext?: UIKitInteractionContext; -}): Promise { + id: string; +}): Promise { const viewId = ModalsEnum.CODE_VIEW; - const block = modify.getCreator().getBlockBuilder(); - const room = slashcommandcontext?.getRoom() || uikitcontext?.getInteractionData().room; @@ -45,13 +47,40 @@ export async function fileCodeModal({ slashcommandcontext?.getSender() || uikitcontext?.getInteractionData().user; + const modal: IUIKitSurfaceViewParam = { + id: viewId, + type: UIKitSurfaceType.MODAL, + title: { + text: AppEnum.DEFAULT_TITLE, + type: "plain_text", + }, + blocks: [], + close: { + type: "button", + text: { + type: "plain_text", + emoji: true, + text: "Close", + }, + appId: id, + blockId: "submit_block", + actionId: "", + }, + }; + + let blocks: LayoutBlock[] = []; if (user?.id) { let roomId; const pullRawData = await http.get(data.value); const pullData = pullRawData.content; - block.addSectionBlock({ - text: { text: `${pullData}`, type: TextObjectType.MARKDOWN }, - }); + + blocks.push( + { + type: "section", + text: { text: `${pullData}`, type: TextObjectType.MARKDOWN }, + }, + { type: "divider" }, + ); // shows indentations in input blocks but not inn section block // block.addInputBlock({ @@ -65,20 +94,6 @@ export async function fileCodeModal({ // }); } - block.addDividerBlock(); - - return { - id: viewId, - title: { - type: TextObjectType.PLAINTEXT, - text: AppEnum.DEFAULT_TITLE, - }, - close: block.newButtonElement({ - text: { - type: TextObjectType.PLAINTEXT, - text: "Close", - }, - }), - blocks: block.getBlocks(), - }; + modal.blocks = blocks; + return modal; } diff --git a/github/modals/newIssueModal.ts b/github/modals/newIssueModal.ts index f0dbb85..7941bf3 100644 --- a/github/modals/newIssueModal.ts +++ b/github/modals/newIssueModal.ts @@ -52,6 +52,7 @@ export async function NewIssueModal({ uikitcontext?.getInteractionData().user; const modal: IUIKitSurfaceViewParam = { + id: viewId, type: UIKitSurfaceType.MODAL, title: { type: "plain_text", diff --git a/github/modals/profileShareModal.ts b/github/modals/profileShareModal.ts index f23e7ca..771158e 100644 --- a/github/modals/profileShareModal.ts +++ b/github/modals/profileShareModal.ts @@ -1,10 +1,23 @@ -import { IModify, IRead, IPersistence, IHttp } from "@rocket.chat/apps-engine/definition/accessors"; +import { + IModify, + IRead, + IPersistence, + IHttp, + IUIKitSurfaceViewParam, +} from "@rocket.chat/apps-engine/definition/accessors"; import { SlashCommandContext } from "@rocket.chat/apps-engine/definition/slashcommands"; -import { TextObjectType, UIKitInteractionContext } from "@rocket.chat/apps-engine/definition/uikit"; +import { + TextObjectType, + UIKitInteractionContext, + UIKitSurfaceType, +} from "@rocket.chat/apps-engine/definition/uikit"; import { IUIKitModalViewParam } from "@rocket.chat/apps-engine/definition/uikit/UIKitInteractionResponder"; import { ModalsEnum } from "../enum/Modals"; import { getBasicUserInfo } from "../helpers/githubSDK"; -import { storeInteractionRoomData, getInteractionRoomData } from "../persistance/roomInteraction"; +import { + storeInteractionRoomData, + getInteractionRoomData, +} from "../persistance/roomInteraction"; export async function shareProfileModal({ modify, @@ -12,94 +25,110 @@ export async function shareProfileModal({ persistence, http, slashcommandcontext, - uikitcontext -} : { - modify : IModify, - read: IRead, - persistence: IPersistence, - http: IHttp, - slashcommandcontext?: SlashCommandContext, - uikitcontext?: UIKitInteractionContext -}) : Promise { - + uikitcontext, + id, +}: { + modify: IModify; + read: IRead; + persistence: IPersistence; + http: IHttp; + slashcommandcontext?: SlashCommandContext; + uikitcontext?: UIKitInteractionContext; + id: string; +}): Promise { const viewId = ModalsEnum.SHARE_PROFILE_EXEC; - const block = modify.getCreator().getBlockBuilder(); - - block.addActionsBlock({ - - elements : [ - block.newMultiStaticElement({ - actionId: ModalsEnum.SHARE_PROFILE_PARAMS, - initialValue: ['username', 'avatar', 'email', 'bio', 'followers', 'following'], - options: [ - { - value: 'followers', - text: { - type: TextObjectType.PLAINTEXT, - text: 'Followers', - emoji: true, - } - }, - { - value: 'following', - text: { - type: TextObjectType.PLAINTEXT, - text: 'Following', - emoji: true, - } - }, - { - value : 'avatar', - text : { - text: "Avatar", - type: TextObjectType.PLAINTEXT - } - }, - { - value : 'username', - text : { - text : "Github ID", - type : TextObjectType.PLAINTEXT - } - }, - { - value: 'email', - text: { - type: TextObjectType.PLAINTEXT, - text: 'Email', - emoji: true, - } - }, - { - value : 'bio', - text : { - type: TextObjectType.PLAINTEXT, - text: 'bio' - } - }, - ], - placeholder: { - type: TextObjectType.PLAINTEXT, - text: 'Select Property to Share', - }, - }), - ] - }) - return { + const modal: IUIKitSurfaceViewParam = { id: viewId, + type: UIKitSurfaceType.MODAL, title: { - type: TextObjectType.PLAINTEXT, - text: "Share Profile" + type: "plain_text", + text: "Share Profile", }, - blocks: block.getBlocks(), - submit:block.newButtonElement({ - text : { - text : "Share to Chat", - type : TextObjectType.PLAINTEXT + blocks: [ + { + type: "actions", + elements: [ + { + type: "multi_static_select", + actionId: ModalsEnum.SHARE_PROFILE_PARAMS, + blockId: "", + initialValue: [ + "username", + "avatar", + "email", + "bio", + "followers", + "following", + ], + options: [ + { + value: "followers", + text: { + type: TextObjectType.PLAINTEXT, + text: "Followers", + emoji: true, + }, + }, + { + value: "following", + text: { + type: TextObjectType.PLAINTEXT, + text: "Following", + emoji: true, + }, + }, + { + value: "avatar", + text: { + text: "Avatar", + type: TextObjectType.PLAINTEXT, + }, + }, + { + value: "username", + text: { + text: "Github ID", + type: TextObjectType.PLAINTEXT, + }, + }, + { + value: "email", + text: { + type: TextObjectType.PLAINTEXT, + text: "Email", + emoji: true, + }, + }, + { + value: "bio", + text: { + type: TextObjectType.PLAINTEXT, + text: "bio", + }, + }, + ], + placeholder: { + type: TextObjectType.PLAINTEXT, + text: "Select Property to Share", + }, + appId: id, + }, + ], + }, + ], + submit: { + type: "button", + appId: id, + actionId: ModalsEnum.NEW_ISSUE_ACTION, + blockId: "NEW_ISSUE_BLOCK", + text: { + type: "plain_text", + text: "Share to Chat", }, - value : "shareChat" - }) - } + value: "shareChat", + }, + }; + return modal; } From 0652132caa869e307f7f169e1e873d3d78ee5d48 Mon Sep 17 00:00:00 2001 From: Devansh Date: Tue, 21 Jan 2025 22:25:08 +0530 Subject: [PATCH 11/12] Updated addIssueCommentModal, addPullRequestCommentsModal, issueCommentsModal, MainModal, pullRequestCommentsModal, UserIssuesModal --- github/handlers/ExecuteBlockActionHandler.ts | 38 ++- github/handlers/ExecuteViewSubmitHandler.ts | 14 +- github/handlers/MainModalHandler.ts | 3 +- github/modals/MainModal.ts | 311 +++++++++++-------- github/modals/UserIssuesModal.ts | 309 ++++++++++-------- github/modals/addIssueCommentModal.ts | 129 +++++--- github/modals/addPullRequestCommentsModal.ts | 119 ++++--- github/modals/issueCommentsModal.ts | 173 +++++++---- github/modals/pullRequestCommentsModal.ts | 184 ++++++----- 9 files changed, 772 insertions(+), 508 deletions(-) diff --git a/github/handlers/ExecuteBlockActionHandler.ts b/github/handlers/ExecuteBlockActionHandler.ts index 254256e..684baa9 100644 --- a/github/handlers/ExecuteBlockActionHandler.ts +++ b/github/handlers/ExecuteBlockActionHandler.ts @@ -332,13 +332,12 @@ export class ExecuteBlockActionHandler { read: this.read, persistence: this.persistence, http: this.http, + id: this.app.getID(), }); await this.persistence.updateByAssociation(record, filter); - - return context - .getInteractionResponder() - .updateModalViewResponse(issueModal); + const triggerId = context.getInteractionData().triggerId; + await this.modify.getUiController().updateSurfaceView(issueModal, {triggerId}, user) } case ModalsEnum.TRIGGER_ISSUES_MODAL: { const { user } = context.getInteractionData(); @@ -363,11 +362,10 @@ export class ExecuteBlockActionHandler { persistence: this.persistence, http: this.http, uikitcontext: context, + id: this.app.getID(), }); - - return context - .getInteractionResponder() - .openModalViewResponse(issuesModal); + const triggerId = context.getInteractionData().triggerId; + await this.modify.getUiController().openSurfaceView(issuesModal, {triggerId}, user) } case ModalsEnum.TRIGGER_REPOS_MODAL: { break; @@ -972,10 +970,10 @@ export class ExecuteBlockActionHandler { persistence: this.persistence, http: this.http, uikitcontext: context, + id: this.app.getID() }); - return context - .getInteractionResponder() - .openModalViewResponse(addPRCommentModal); + const triggerId = context.getInteractionData().triggerId; + await this.modify.getUiController().openSurfaceView(addPRCommentModal, {triggerId}, user) } break; } @@ -1165,10 +1163,10 @@ export class ExecuteBlockActionHandler { persistence: this.persistence, http: this.http, uikitcontext: context, + id: this.app.getID(), }); - return context - .getInteractionResponder() - .openModalViewResponse(addIssueCommentModal); + const triggerId = context.getInteractionData().triggerId; + await this.modify.getUiController().openSurfaceView(addIssueCommentModal, {triggerId}, user) } break; } @@ -1196,10 +1194,10 @@ export class ExecuteBlockActionHandler { persistence: this.persistence, http: this.http, uikitcontext: context, + id: this.app.getID() }); - return context - .getInteractionResponder() - .openModalViewResponse(addIssueCommentModal); + const triggerId = context.getInteractionData().triggerId; + await this.modify.getUiController().openSurfaceView(addIssueCommentModal, {triggerId}, user) } else { const unauthorizedMessageModal = await messageModal({ message: @@ -1318,10 +1316,10 @@ export class ExecuteBlockActionHandler { persistence: this.persistence, http: this.http, uikitcontext: context, + id: this.app.getID(), }); - return context - .getInteractionResponder() - .openModalViewResponse(addPRCommentModal); + const triggerId = context.getInteractionData().triggerId; + await this.modify.getUiController().openSurfaceView(addPRCommentModal, { triggerId }, user); } break; } diff --git a/github/handlers/ExecuteViewSubmitHandler.ts b/github/handlers/ExecuteViewSubmitHandler.ts index 048c938..26986e3 100644 --- a/github/handlers/ExecuteViewSubmitHandler.ts +++ b/github/handlers/ExecuteViewSubmitHandler.ts @@ -484,10 +484,11 @@ export class ExecuteViewSubmitHandler { read:this.read, persistence: this.persistence, http: this.http, - uikitcontext: context + uikitcontext: context, + id: this.app.getID(), }) await sendNotification(this.read,this.modify,user,room,`New Comment posted to ${repository} pull request #${pullNumber} by ${addCommentResponse?.user?.login} : ${addCommentResponse?.html_url}`); - await this.modify.getUiController().updateModalView(addPRCommentModal, { triggerId: context.getInteractionData().triggerId }, context.getInteractionData().user); + return await this.modify.getUiController().updateSurfaceView(addPRCommentModal, { triggerId: context.getInteractionData().triggerId }, context.getInteractionData().user); } } } @@ -510,8 +511,7 @@ export class ExecuteViewSubmitHandler { let errorMessage = addCommentResponse?.message; const unauthorizedMessageModal = await messageModal( { - message: - "Unauthorized Action 🤖 You dont have push rights ⚠️", + message: errorMessage, modify: this.modify, read: this.read, persistence: this.persistence, @@ -577,14 +577,14 @@ export class ExecuteViewSubmitHandler { read:this.read, persistence: this.persistence, http: this.http, - uikitcontext: context + uikitcontext: context, + id: this.app.getID(), }) await sendNotification(this.read,this.modify,user,room,`New Comment posted to ${repository} issue #${issueNumber} by ${addCommentResponse?.user?.login} : ${addCommentResponse?.html_url}`); - await this.modify.getUiController().updateModalView(addIssueCommentModal, { triggerId: context.getInteractionData().triggerId }, context.getInteractionData().user); + return await this.modify.getUiController().openSurfaceView(addIssueCommentModal, { triggerId: context.getInteractionData().triggerId }, context.getInteractionData().user); } } } - return context.getInteractionResponder().successResponse(); } break; } diff --git a/github/handlers/MainModalHandler.ts b/github/handlers/MainModalHandler.ts index 9ea6a44..c49298e 100644 --- a/github/handlers/MainModalHandler.ts +++ b/github/handlers/MainModalHandler.ts @@ -29,10 +29,11 @@ export async function handleMainModal( persistence: persistence, http: http, slashcommandcontext: context, + id: app.getID(), }); await modify .getUiController() - .openModalView( + .openSurfaceView( modal, { triggerId }, context.getSender() diff --git a/github/modals/MainModal.ts b/github/modals/MainModal.ts index b421433..16d72e3 100644 --- a/github/modals/MainModal.ts +++ b/github/modals/MainModal.ts @@ -1,137 +1,200 @@ -import { IModify, IRead, IPersistence, IHttp } from "@rocket.chat/apps-engine/definition/accessors"; +import { + IModify, + IRead, + IPersistence, + IHttp, + IUIKitSurfaceViewParam, +} from "@rocket.chat/apps-engine/definition/accessors"; import { SlashCommandContext } from "@rocket.chat/apps-engine/definition/slashcommands"; -import { TextObjectType, UIKitInteractionContext } from "@rocket.chat/apps-engine/definition/uikit"; +import { + TextObjectType, + UIKitInteractionContext, + UIKitSurfaceType, +} from "@rocket.chat/apps-engine/definition/uikit"; import { IUIKitModalViewParam } from "@rocket.chat/apps-engine/definition/uikit/UIKitInteractionResponder"; import { ModalsEnum } from "../enum/Modals"; - -export async function MainModal( - { - modify, - read, - persistence, - http, - slashcommandcontext, - uikitcontext, - }: { - modify: IModify; - read: IRead; - persistence: IPersistence; - http: IHttp; - slashcommandcontext?: SlashCommandContext; - uikitcontext?: UIKitInteractionContext; - }): Promise { +import { LayoutBlock } from "@rocket.chat/ui-kit"; + +export async function MainModal({ + modify, + read, + persistence, + http, + slashcommandcontext, + uikitcontext, + id, +}: { + modify: IModify; + read: IRead; + persistence: IPersistence; + http: IHttp; + slashcommandcontext?: SlashCommandContext; + uikitcontext?: UIKitInteractionContext; + id: string; +}): Promise { const viewId = ModalsEnum.MAIN_MODAL_VIEW; - const block = modify.getCreator().getBlockBuilder(); - - const user = slashcommandcontext?.getSender() || uikitcontext?.getInteractionData().user; - - block.addContextBlock( - { - blockId: ModalsEnum.MAIN_MODAL_VIEW, - elements: [ - block.newMarkdownTextObject(`Hey 👋 Welcome ${user?.username}`), - ], - } - ); + const user = + slashcommandcontext?.getSender() || + uikitcontext?.getInteractionData().user; - block.addDividerBlock(); - - block.addSectionBlock({ - blockId: ModalsEnum.MAIN_MODAL_VIEW, - text: block.newMarkdownTextObject(ModalsEnum.MAIN_MODAL_GITHUB_SEARCH_LABLE), - accessory: block.newButtonElement({ - text: { - type: TextObjectType.PLAINTEXT, - text: ModalsEnum.MAIN_MODAL_OPEN_LABLE, + const modal: IUIKitSurfaceViewParam = { + id: viewId, + type: UIKitSurfaceType.MODAL, + title: { + text: ModalsEnum.MAIN_MODAL_TITLE, + type: "plain_text", + }, + blocks: [ + { + type: 'context', + blockId: ModalsEnum.MAIN_MODAL_VIEW, + elements: [ + { + type: 'plain_text', + text: `Hey 👋 Welcome ${user?.username}`, + } + ] }, - actionId: ModalsEnum.TRIGGER_SEARCH_MODAL, - }), - }) - - block.addContextBlock({ - blockId: ModalsEnum.MAIN_MODAL_VIEW, - elements: [ - block.newMarkdownTextObject(ModalsEnum.MAIN_MODAL_GITHUB_SEARCH_DESCRIPTION), - ], - }); - - block.addDividerBlock(); - - block.addSectionBlock({ - blockId: ModalsEnum.MAIN_MODAL_VIEW, - text: block.newMarkdownTextObject(ModalsEnum.MAIN_MODAL_NEW_ISSUE_LABLE), - accessory: block.newButtonElement({ - text: { - type: TextObjectType.PLAINTEXT, - text: ModalsEnum.MAIN_MODAL_OPEN_LABLE, + { + type: 'divider', }, - actionId: ModalsEnum.TRIGGER_NEW_ISSUE_MODAL, - }), - }); - - block.addContextBlock({ - blockId: ModalsEnum.MAIN_MODAL_VIEW, - elements: [ - block.newMarkdownTextObject(ModalsEnum.MAIN_MODAL_NEW_ISSUE_DESCRIPTION), - ], - }); - - block.addDividerBlock(); - - block.addSectionBlock({ - blockId: ModalsEnum.MAIN_MODAL_VIEW, - text: block.newMarkdownTextObject(ModalsEnum.MAIN_MODAL_REPOSITORY_SUBSCRIPTIONS_LABLE), - accessory: block.newButtonElement({ - text: { - type: TextObjectType.PLAINTEXT, - text: ModalsEnum.MAIN_MODAL_OPEN_LABLE, + { + type: 'section', + blockId: ModalsEnum.MAIN_MODAL_VIEW, + text: { + type: TextObjectType.MARKDOWN, + text: ModalsEnum.MAIN_MODAL_GITHUB_SEARCH_LABLE + }, + accessory: { + type: 'button', + text: { + type: TextObjectType.PLAINTEXT, + text: ModalsEnum.MAIN_MODAL_OPEN_LABLE, + }, + actionId: ModalsEnum.TRIGGER_SEARCH_MODAL, + appId: id, + blockId: '', + } }, - actionId: ModalsEnum.TRIGGER_SUBSCRIPTIONS_MODAL, - }), - }) - - block.addContextBlock({ - blockId: ModalsEnum.MAIN_MODAL_VIEW, - elements: [ - block.newMarkdownTextObject(ModalsEnum.MAIN_MODAL_REPOSITORY_SUBSCRIPTIONS_DESCRIPTION), - ], - }); - - block.addDividerBlock(); - - block.addSectionBlock({ - blockId: ModalsEnum.MAIN_MODAL_VIEW, - text: block.newMarkdownTextObject(ModalsEnum.MAIN_MODAL_ASSIGN_ISSUES_LABLE), - accessory: block.newButtonElement({ - text: { - type: TextObjectType.PLAINTEXT, - text: ModalsEnum.MAIN_MODAL_OPEN_LABLE, + { + type: 'context', + blockId: ModalsEnum.MAIN_MODAL_VIEW, + elements: [ + { + type: TextObjectType.MARKDOWN, + text: ModalsEnum.MAIN_MODAL_GITHUB_SEARCH_DESCRIPTION, + } + ] }, - actionId: ModalsEnum.TRIGGER_ASSIGN_ISSUES_MODAL, - }), - }) - - block.addContextBlock({ - blockId: ModalsEnum.MAIN_MODAL_VIEW, - elements: [ - block.newMarkdownTextObject(ModalsEnum.MAIN_MODAL_ASSIGN_ISSUES_DESCRIPTION), + { + type: 'divider', + }, + { + type: 'section', + blockId: ModalsEnum.MAIN_MODAL_VIEW, + text: { + type: 'mrkdwn', + text: ModalsEnum.MAIN_MODAL_NEW_ISSUE_LABLE, + }, + accessory: { + type: 'button', + actionId: ModalsEnum.TRIGGER_NEW_ISSUE_MODAL, + text: { + type: TextObjectType.PLAINTEXT, + text: ModalsEnum.MAIN_MODAL_OPEN_LABLE, + }, + appId: id, + blockId: '', + } + }, + { + type: 'context', + blockId: ModalsEnum.MAIN_MODAL_VIEW, + elements: [ + { + type: 'mrkdwn', + text: ModalsEnum.MAIN_MODAL_NEW_ISSUE_DESCRIPTION + } + ] + }, + { + type: 'divider', + }, + { + type: 'section', + blockId: ModalsEnum.MAIN_MODAL_VIEW, + text: { + type: 'mrkdwn', + text: ModalsEnum.MAIN_MODAL_REPOSITORY_SUBSCRIPTIONS_LABLE, + }, + accessory: { + type: 'button', + text: { + type: TextObjectType.PLAINTEXT, + text: ModalsEnum.MAIN_MODAL_OPEN_LABLE, + }, + actionId: ModalsEnum.TRIGGER_SUBSCRIPTIONS_MODAL, + blockId: '', + appId: id, + } + }, + { + type: 'context', + blockId: ModalsEnum.MAIN_MODAL_VIEW, + elements: [ + { + type: 'mrkdwn', + text: ModalsEnum.MAIN_MODAL_REPOSITORY_SUBSCRIPTIONS_DESCRIPTION + } + ] + }, + { + type: 'divider', + }, + { + blockId: ModalsEnum.MAIN_MODAL_VIEW, + type: 'section', + text: { + type: 'mrkdwn', + text: ModalsEnum.MAIN_MODAL_ASSIGN_ISSUES_LABLE, + }, + accessory: { + type: 'button', + text: { + type: TextObjectType.PLAINTEXT, + text: ModalsEnum.MAIN_MODAL_OPEN_LABLE, + }, + actionId: ModalsEnum.TRIGGER_ASSIGN_ISSUES_MODAL, + blockId: '', + appId: id, + } + }, + { + type: 'context', + blockId: ModalsEnum.MAIN_MODAL_VIEW, + elements: [ + { + type: 'mrkdwn', + text: ModalsEnum.MAIN_MODAL_ASSIGN_ISSUES_DESCRIPTION, + } + ] + }, + { + type: 'divider', + } ], - }); - - block.addDividerBlock(); - - return { - id: viewId, - title: { - type: TextObjectType.PLAINTEXT, - text: ModalsEnum.MAIN_MODAL_TITLE - }, - close: block.newButtonElement({ + close: { + type: "button", text: { - type: TextObjectType.PLAINTEXT, + type: "plain_text", + emoji: true, text: "Close", - } - }), - blocks: block.getBlocks(), + }, + appId: id, + actionId: '', + blockId: '', + }, }; -} \ No newline at end of file + + return modal; +} diff --git a/github/modals/UserIssuesModal.ts b/github/modals/UserIssuesModal.ts index 435688e..b723bfb 100644 --- a/github/modals/UserIssuesModal.ts +++ b/github/modals/UserIssuesModal.ts @@ -3,13 +3,18 @@ import { IRead, IPersistence, IHttp, + IUIKitSurfaceViewParam, } from "@rocket.chat/apps-engine/definition/accessors"; -import { RocketChatAssociationModel, RocketChatAssociationRecord } from "@rocket.chat/apps-engine/definition/metadata"; +import { + RocketChatAssociationModel, + RocketChatAssociationRecord, +} from "@rocket.chat/apps-engine/definition/metadata"; import { SlashCommandContext } from "@rocket.chat/apps-engine/definition/slashcommands"; import { ButtonStyle, TextObjectType, UIKitInteractionContext, + UIKitSurfaceType, } from "@rocket.chat/apps-engine/definition/uikit"; import { IUIKitModalViewParam } from "@rocket.chat/apps-engine/definition/uikit/UIKitInteractionResponder"; import { ModalsEnum } from "../enum/Modals"; @@ -19,6 +24,7 @@ import { getInteractionRoomData, storeInteractionRoomData, } from "../persistance/roomInteraction"; +import { LayoutBlock } from "@rocket.chat/ui-kit"; export async function userIssuesModal({ filter, @@ -29,6 +35,7 @@ export async function userIssuesModal({ http, slashcommandcontext, uikitcontext, + id, }: { filter: { filter: string; @@ -42,9 +49,9 @@ export async function userIssuesModal({ http: IHttp; slashcommandcontext?: SlashCommandContext; uikitcontext?: UIKitInteractionContext; -}): Promise { + id: string; +}): Promise { const viewId = ModalsEnum.USER_ISSUE_VIEW; - const block = modify.getCreator().getBlockBuilder(); const room = slashcommandcontext?.getRoom() || uikitcontext?.getInteractionData().room; @@ -52,6 +59,17 @@ export async function userIssuesModal({ slashcommandcontext?.getSender() || uikitcontext?.getInteractionData().user; + const modal: IUIKitSurfaceViewParam = { + id: viewId, + type: UIKitSurfaceType.MODAL, + title: { + type: "plain_text", + text: "Your Issues", + }, + blocks: [], + }; + + let blocks: LayoutBlock[] = []; if (user?.id) { let roomId; if (room?.id) { @@ -61,7 +79,7 @@ export async function userIssuesModal({ roomId = ( await getInteractionRoomData( read.getPersistenceReader(), - user.id + user.id, ) ).roomId; } @@ -73,12 +91,14 @@ export async function userIssuesModal({ http, userInfo.username, access_token, - filter + filter, ); - block.addActionsBlock({ + blocks.push({ + type: "actions", elements: [ - block.newStaticSelectElement({ + { + type: "static_select", placeholder: { text: "Select an Issue Filter", type: TextObjectType.PLAINTEXT, @@ -108,19 +128,25 @@ export async function userIssuesModal({ }, }, ], - }), + blockId: "", + appId: id, + }, ], }); - block.addActionsBlock({ + blocks.push({ + type: "actions", elements: [ - block.newStaticSelectElement({ + { + type: "static_select", placeholder: { text: "Select Issues State", type: TextObjectType.PLAINTEXT, }, initialValue: filter.state, actionId: ModalsEnum.SWITCH_ISSUE_STATE, + blockId: "", + appId: id, options: [ { value: ModalsEnum.ISSUE_STATE_OPEN, @@ -128,7 +154,6 @@ export async function userIssuesModal({ text: "Open Issues", type: TextObjectType.PLAINTEXT, }, - }, { value: ModalsEnum.ISSUE_STATE_CLOSED, @@ -138,26 +163,29 @@ export async function userIssuesModal({ }, }, ], - }), - block.newStaticSelectElement({ - actionId: ModalsEnum.SWITCH_ISSUE_SORT, + }, + { + type: "static_select", placeholder: { text: "Sort Issues By...", type: TextObjectType.PLAINTEXT, }, - initialValue: filter.sort, + initialValue: filter.state, + actionId: ModalsEnum.SWITCH_ISSUE_STATE, + blockId: "", + appId: id, options: [ { - value: ModalsEnum.ISSUE_SORT_CREATED, + value: ModalsEnum.ISSUE_SORT_UPDATED, text: { - text: "Created", + text: "Updated", type: TextObjectType.PLAINTEXT, }, }, { - value: ModalsEnum.ISSUE_SORT_UPDATED, + value: ModalsEnum.ISSUE_STATE_CLOSED, text: { - text: "Updated", + text: "Closed Issues", type: TextObjectType.PLAINTEXT, }, }, @@ -169,123 +197,154 @@ export async function userIssuesModal({ }, }, ], - }), + }, ], }); if (repoInfo.length == 0) { - block.addContextBlock({ + blocks.push({ + type: "context", elements: [ - block.newPlainTextObject( - "Sorry, there are no issues to display" - ), + { + type: "plain_text", + text: "Sorry, there are no issues to display", + }, ], }); } else { - repoInfo.map( - (value) => { - const repoURL = value.repo_url ?? ""; - const repoName = repoURL.substring(29, repoURL.length); - block.addContextBlock({ - elements: [ - block.newImageElement({ - imageUrl: OcticonIcons.REPOSITORY, - altText: "REPO_ICON", - }), - block.newPlainTextObject(repoName, false), - block.newImageElement({ - imageUrl: value.user_avatar ?? "", - altText: "User Image", - }), - block.newPlainTextObject(value.user_login ?? ""), - ], - }); - block.addSectionBlock({ - text: { - text: `\`#${value.number}\` ${value.title}` ?? "None", - type: TextObjectType.MARKDOWN, + repoInfo.map((value) => { + const repoURL = value.repo_url ?? ""; + const repoName = repoURL.substring(29, repoURL.length); + + blocks.push({ + type: "context", + elements: [ + { + type: "image", + imageUrl: OcticonIcons.REPOSITORY, + altText: "REPO_ICON", + }, + { + type: "plain_text", + text: repoName, + }, + { + type: "image", + imageUrl: value.user_avatar ?? "", + altText: "User Image", + }, + { + type: "plain_text", + text: value.user_login ?? "", + }, + ], + }); + + blocks.push({ + type: "section", + text: { + text: `\`#${value.number}\` ${value.title}` ?? "None", + type: TextObjectType.MARKDOWN, + }, + }); + const lastUpdated = new Date(value.last_updated_at ?? ""); + + blocks.push({ + type: "context", + elements: [ + { + type: "image", + imageUrl: OcticonIcons.COMMENTS, + altText: "Comments", + }, + { + type: "plain_text", + text: `${value.comments}`, }, - }); - const lastUpdated = new Date(value.last_updated_at ?? ""); - block.addContextBlock({ - elements: [ - block.newImageElement({ - imageUrl: OcticonIcons.COMMENTS, - altText: "Comments", - }), - block.newPlainTextObject( - `${value.comments}`, - false - ), - block.newImageElement({ - imageUrl: OcticonIcons.ISSUE_OPEN, - altText: "Assignees Icon", - }), - block.newPlainTextObject( - value.assignees ? (value.assignees.length == 0 + { + type: "image", + imageUrl: OcticonIcons.ISSUE_OPEN, + altText: "Assignees Icon", + }, + { + type: "plain_text", + text: value.assignees + ? value.assignees.length == 0 ? "No Assignees" - : `${value.assignees.length} Assignees`) : "" - ), - block.newImageElement({ - imageUrl: - value.state == "open" - ? OcticonIcons.ISSUE_OPEN - : OcticonIcons.ISSUE_CLOSED, - altText: "State", - }), - block.newPlainTextObject(`${value.state}`), - block.newImageElement({ - imageUrl: OcticonIcons.PENCIL, - altText: "Last Update At", - }), - block.newPlainTextObject( - `Last Updated at ${lastUpdated.toUTCString()}` - ), - ], - }); + : `${value.assignees.length} Assignees` + : "", + }, + { + type: "image", + imageUrl: + value.state == "open" + ? OcticonIcons.ISSUE_OPEN + : OcticonIcons.ISSUE_CLOSED, + altText: "State", + }, + { + type: 'plain_text', + text: `${value.state}`, + }, + { + type: 'image', + imageUrl: OcticonIcons.PENCIL, + altText: "Last Update At", + }, + { + type: 'plain_text', + text: `Last Updated at ${lastUpdated.toUTCString()}`, + } + ], + }); - block.addActionsBlock({ - elements: [ - block.newButtonElement({ - actionId: ModalsEnum.SHARE_ISSUE_ACTION, - value: `${repoName}, ${value.number}`, - text: { - text: "Share Issue", - type: TextObjectType.PLAINTEXT, - }, - style: ButtonStyle.PRIMARY, - }), - block.newButtonElement({ - actionId: ModalsEnum.TRIGGER_ISSUE_DISPLAY_MODAL, - value: `${repoName}, ${value.number}`, - text: { - text: "Open Issue", - type: TextObjectType.PLAINTEXT, - }, - style: ButtonStyle.PRIMARY, - }), - block.newButtonElement({ - actionId: ModalsEnum.ADD_GITHUB_ISSUE_ASSIGNEE_PROFILE, - value: `${repoName}, ${value.number}`, - text: { - text: "Assign Issue", - type: TextObjectType.PLAINTEXT, - }, - style: ButtonStyle.PRIMARY, - }), - ], - }); - block.addDividerBlock(); - } - ); + blocks.push({ + type: 'actions', + elements: [ + { + type: 'button', + actionId: ModalsEnum.SHARE_ISSUE_ACTION, + value: `${repoName}, ${value.number}`, + text: { + text: "Share Issue", + type: TextObjectType.PLAINTEXT, + }, + style: ButtonStyle.PRIMARY, + blockId: '', + appId: id, + }, + { + type: 'button', + actionId: ModalsEnum.TRIGGER_ISSUE_DISPLAY_MODAL, + value: `${repoName}, ${value.number}`, + text: { + text: "Open Issue", + type: TextObjectType.PLAINTEXT, + }, + style: ButtonStyle.PRIMARY, + blockId: '', + appId: id, + }, + { + type: 'button', + actionId: ModalsEnum.ADD_GITHUB_ISSUE_ASSIGNEE_PROFILE, + value: `${repoName}, ${value.number}`, + text: { + text: "Assign Issue", + type: TextObjectType.PLAINTEXT, + }, + style: ButtonStyle.PRIMARY, + blockId: '', + appId: id, + }, + ] + }) + blocks.push({ + type: 'divider', + }) + }); } - return { - id: viewId, - title: { - text: "Your Issues", - type: TextObjectType.PLAINTEXT, - }, - blocks: block.getBlocks(), - }; + modal.blocks = blocks; + return modal; } diff --git a/github/modals/addIssueCommentModal.ts b/github/modals/addIssueCommentModal.ts index f4ed26f..c892519 100644 --- a/github/modals/addIssueCommentModal.ts +++ b/github/modals/addIssueCommentModal.ts @@ -3,6 +3,7 @@ import { IModify, IPersistence, IRead, + IUIKitSurfaceViewParam, } from "@rocket.chat/apps-engine/definition/accessors"; import { TextObjectType } from "@rocket.chat/apps-engine/definition/uikit/blocks"; import { IUIKitModalViewParam } from "@rocket.chat/apps-engine/definition/uikit/UIKitInteractionResponder"; @@ -13,6 +14,7 @@ import { SlashCommandContext } from "@rocket.chat/apps-engine/definition/slashco import { UIKitBlockInteractionContext, UIKitInteractionContext, + UIKitSurfaceType, } from "@rocket.chat/apps-engine/definition/uikit"; import { storeInteractionRoomData, @@ -20,6 +22,7 @@ import { } from "../persistance/roomInteraction"; import { Subscription } from "../persistance/subscriptions"; import { ISubscription } from "../definitions/subscription"; +import { LayoutBlock } from "@rocket.chat/ui-kit"; export async function addIssueCommentsModal({ data, @@ -29,17 +32,18 @@ export async function addIssueCommentsModal({ http, slashcommandcontext, uikitcontext, + id, }: { - data?:any + data?: any; modify: IModify; read: IRead; persistence: IPersistence; http: IHttp; slashcommandcontext?: SlashCommandContext; uikitcontext?: UIKitInteractionContext; -}): Promise { + id: string; +}): Promise { const viewId = ModalsEnum.ADD_ISSUE_COMMENT_VIEW; - const block = modify.getCreator().getBlockBuilder(); const room = slashcommandcontext?.getRoom() || uikitcontext?.getInteractionData().room; @@ -47,6 +51,39 @@ export async function addIssueCommentsModal({ slashcommandcontext?.getSender() || uikitcontext?.getInteractionData().user; + const modal: IUIKitSurfaceViewParam = { + id: viewId, + type: UIKitSurfaceType.MODAL, + title: { + text: ModalsEnum.GITHUB_ISSUES_TITLE, + type: "plain_text", + }, + blocks: [], + submit: { + type: "button", + text: { + type: "plain_text", + emoji: true, + text: "Comment", + }, + appId: id, + blockId: '', + actionId: '', + }, + close: { + type: "button", + text: { + type: "plain_text", + emoji: true, + text: "Close", + }, + appId: id, + blockId: '', + actionId: '', + }, + }; + + let blocks: LayoutBlock[] = []; if (user?.id) { let roomId; @@ -57,90 +94,82 @@ export async function addIssueCommentsModal({ roomId = ( await getInteractionRoomData( read.getPersistenceReader(), - user.id + user.id, ) ).roomId; } let repoName = ""; let issueNumber = ""; - if(data?.repo?.length){ + if (data?.repo?.length) { repoName = data?.repo; } - if(data?.issueNumber?.length){ + if (data?.issueNumber?.length) { issueNumber = data?.issueNumber; } - // shows indentations in input blocks but not inn section block - block.addInputBlock({ + + blocks.push({ + type: 'input', blockId: ModalsEnum.REPO_NAME_INPUT, label: { text: ModalsEnum.REPO_NAME_LABEL, type: TextObjectType.PLAINTEXT, }, - element: block.newPlainTextInputElement({ + element: { + type: 'plain_text_input', actionId: ModalsEnum.REPO_NAME_INPUT_ACTION, placeholder: { text: ModalsEnum.REPO_NAME_PLACEHOLDER, - type: TextObjectType.PLAINTEXT, + type: TextObjectType.PLAINTEXT }, - initialValue:repoName - }), - }); - - block.addInputBlock({ + initialValue: repoName, + blockId: ModalsEnum.REPO_NAME_INPUT, + appId: id, + } + }) + blocks.push({ + type: 'input', blockId: ModalsEnum.ISSUE_NUMBER_INPUT, label: { text: ModalsEnum.ISSUE_NUMBER_LABEL, type: TextObjectType.PLAINTEXT, }, - element: block.newPlainTextInputElement({ + element: { + type: 'plain_text_input', actionId: ModalsEnum.ISSUE_NUMBER_INPUT_ACTION, placeholder: { text: ModalsEnum.ISSUE_NUMBER_INPUT_PLACEHOLDER, - type: TextObjectType.PLAINTEXT, + type: TextObjectType.PLAINTEXT }, - initialValue:issueNumber - }), - }); - - block.addInputBlock({ - blockId: ModalsEnum.ISSUE_COMMENT_INPUT, + initialValue: issueNumber, + blockId: ModalsEnum.ISSUE_NUMBER_INPUT, + appId: id, + } + }) + blocks.push({ + type: 'input', label: { text: ModalsEnum.ISSUE_COMMENT_INPUT_LABEL, type: TextObjectType.PLAINTEXT, }, - element: block.newPlainTextInputElement({ + element: { + type: 'plain_text_input', actionId: ModalsEnum.ISSUE_COMMENT_INPUT_ACTION, placeholder: { text: ModalsEnum.ISSUE_COMMENT_INPUT_PLACEHOLDER, - type: TextObjectType.PLAINTEXT, + type: TextObjectType.PLAINTEXT }, - multiline: true - }), - }); + multiline: true, + appId: id, + blockId: ModalsEnum.ISSUE_COMMENT_INPUT, + } + }) } - block.addDividerBlock(); + blocks.push({ + type: 'divider', + }) - return { - id: viewId, - title: { - type: TextObjectType.PLAINTEXT, - text: ModalsEnum.ADD_ISSUE_COMMENT_VIEW_TITLE, - }, - close: block.newButtonElement({ - text: { - type: TextObjectType.PLAINTEXT, - text: "Close", - }, - }), - submit: block.newButtonElement({ - actionId: ModalsEnum.ADD_SUBSCRIPTION_ACTION, - text: { - type: TextObjectType.PLAINTEXT, - text: "Comment", - }, - }), - blocks: block.getBlocks(), - }; + modal.blocks = blocks; + return modal; } diff --git a/github/modals/addPullRequestCommentsModal.ts b/github/modals/addPullRequestCommentsModal.ts index 05d20e1..9431097 100644 --- a/github/modals/addPullRequestCommentsModal.ts +++ b/github/modals/addPullRequestCommentsModal.ts @@ -3,6 +3,7 @@ import { IModify, IPersistence, IRead, + IUIKitSurfaceViewParam, } from "@rocket.chat/apps-engine/definition/accessors"; import { TextObjectType } from "@rocket.chat/apps-engine/definition/uikit/blocks"; import { IUIKitModalViewParam } from "@rocket.chat/apps-engine/definition/uikit/UIKitInteractionResponder"; @@ -14,6 +15,7 @@ import { SlashCommandContext } from "@rocket.chat/apps-engine/definition/slashco import { UIKitBlockInteractionContext, UIKitInteractionContext, + UIKitSurfaceType, } from "@rocket.chat/apps-engine/definition/uikit"; import { storeInteractionRoomData, @@ -21,6 +23,7 @@ import { } from "../persistance/roomInteraction"; import { Subscription } from "../persistance/subscriptions"; import { ISubscription } from "../definitions/subscription"; +import { LayoutBlock } from "@rocket.chat/ui-kit"; export async function addPullRequestCommentsModal({ data, @@ -30,17 +33,18 @@ export async function addPullRequestCommentsModal({ http, slashcommandcontext, uikitcontext, + id, }: { - data?:any + data?: any; modify: IModify; read: IRead; persistence: IPersistence; http: IHttp; slashcommandcontext?: SlashCommandContext; uikitcontext?: UIKitInteractionContext; -}): Promise { + id: string; +}): Promise { const viewId = ModalsEnum.ADD_PULL_REQUEST_COMMENT_VIEW; - const block = modify.getCreator().getBlockBuilder(); const room = slashcommandcontext?.getRoom() || uikitcontext?.getInteractionData().room; @@ -48,6 +52,39 @@ export async function addPullRequestCommentsModal({ slashcommandcontext?.getSender() || uikitcontext?.getInteractionData().user; + const modal: IUIKitSurfaceViewParam = { + id: viewId, + type: UIKitSurfaceType.MODAL, + title: { + text: ModalsEnum.ADD_PULL_REQUEST_COMMENT_VIEW_TITLE, + type: "plain_text", + }, + blocks: [], + submit: { + type: "button", + text: { + type: "plain_text", + emoji: true, + text: "Comment", + }, + appId: id, + blockId: "", + actionId: "", + }, + close: { + type: "button", + text: { + type: "plain_text", + emoji: true, + text: "Close", + }, + appId: id, + blockId: "", + actionId: "", + }, + }; + + let blocks: LayoutBlock[] = []; if (user?.id) { let roomId; @@ -58,90 +95,82 @@ export async function addPullRequestCommentsModal({ roomId = ( await getInteractionRoomData( read.getPersistenceReader(), - user.id + user.id, ) ).roomId; } let repoName = ""; let pullRequestNumber = ""; - if(data?.repo?.length){ + if (data?.repo?.length) { repoName = data?.repo; } - if(data?.pullNumber?.length){ + if (data?.pullNumber?.length) { pullRequestNumber = data?.pullNumber; } - // shows indentations in input blocks but not inn section block - block.addInputBlock({ + + blocks.push({ + type: "input", blockId: ModalsEnum.REPO_NAME_INPUT, label: { text: ModalsEnum.REPO_NAME_LABEL, type: TextObjectType.PLAINTEXT, }, - element: block.newPlainTextInputElement({ + element: { + type: "plain_text_input", actionId: ModalsEnum.REPO_NAME_INPUT_ACTION, placeholder: { text: ModalsEnum.REPO_NAME_PLACEHOLDER, type: TextObjectType.PLAINTEXT, }, - initialValue:repoName - }), + initialValue: repoName, + blockId: ModalsEnum.REPO_NAME_INPUT, + appId: id, + }, }); - - block.addInputBlock({ + blocks.push({ + type: "input", blockId: ModalsEnum.PULL_REQUEST_NUMBER_INPUT, label: { text: ModalsEnum.PULL_REQUEST_NUMBER_LABEL, type: TextObjectType.PLAINTEXT, }, - element: block.newPlainTextInputElement({ + element: { + type: "plain_text_input", actionId: ModalsEnum.PULL_REQUEST_NUMBER_INPUT_ACTION, placeholder: { text: ModalsEnum.PULL_REQUEST_NUMBER_INPUT_PLACEHOLDER, type: TextObjectType.PLAINTEXT, }, - initialValue:pullRequestNumber - }), + initialValue: pullRequestNumber, + blockId: ModalsEnum.PULL_REQUEST_NUMBER_INPUT, + appId: id, + }, }); - - block.addInputBlock({ - blockId: ModalsEnum.PULL_REQUEST_COMMENT_INPUT, + blocks.push({ + type: "input", label: { text: ModalsEnum.PULL_REQUEST_COMMENT_INPUT_LABEL, type: TextObjectType.PLAINTEXT, }, - element: block.newPlainTextInputElement({ + element: { + type: "plain_text_input", actionId: ModalsEnum.PULL_REQUEST_COMMENT_INPUT_ACTION, placeholder: { text: ModalsEnum.PULL_REQUEST_COMMENT_INPUT_PLACEHOLDER, type: TextObjectType.PLAINTEXT, }, - multiline: true - }), - }); + blockId: ModalsEnum.PULL_REQUEST_COMMENT_INPUT, + appId: id, + multiline: true, + }, + }); } - block.addDividerBlock(); + blocks.push({ + type: 'divider', + }) - return { - id: viewId, - title: { - type: TextObjectType.PLAINTEXT, - text: ModalsEnum.ADD_PULL_REQUEST_COMMENT_VIEW_TITLE, - }, - close: block.newButtonElement({ - text: { - type: TextObjectType.PLAINTEXT, - text: "Close", - }, - }), - submit: block.newButtonElement({ - actionId: ModalsEnum.ADD_SUBSCRIPTION_ACTION, - text: { - type: TextObjectType.PLAINTEXT, - text: "Comment", - }, - }), - blocks: block.getBlocks(), - }; + modal.blocks = blocks; + return modal; } diff --git a/github/modals/issueCommentsModal.ts b/github/modals/issueCommentsModal.ts index c7de76a..ea62326 100644 --- a/github/modals/issueCommentsModal.ts +++ b/github/modals/issueCommentsModal.ts @@ -3,6 +3,7 @@ import { IModify, IPersistence, IRead, + IUIKitSurfaceViewParam, } from "@rocket.chat/apps-engine/definition/accessors"; import { TextObjectType } from "@rocket.chat/apps-engine/definition/uikit/blocks"; import { IUIKitModalViewParam } from "@rocket.chat/apps-engine/definition/uikit/UIKitInteractionResponder"; @@ -13,9 +14,14 @@ import { SlashCommandContext } from "@rocket.chat/apps-engine/definition/slashco import { UIKitBlockInteractionContext, UIKitInteractionContext, + UIKitSurfaceType, } from "@rocket.chat/apps-engine/definition/uikit"; -import { storeInteractionRoomData, getInteractionRoomData } from "../persistance/roomInteraction"; +import { + storeInteractionRoomData, + getInteractionRoomData, +} from "../persistance/roomInteraction"; import { parseDate, parseTime } from "../helpers/dateTime"; +import { LayoutBlock } from "@rocket.chat/ui-kit"; export async function issueCommentsModal({ data, @@ -25,6 +31,7 @@ export async function issueCommentsModal({ http, slashcommandcontext, uikitcontext, + id, }: { data?; modify: IModify; @@ -33,11 +40,10 @@ export async function issueCommentsModal({ http: IHttp; slashcommandcontext?: SlashCommandContext; uikitcontext?: UIKitInteractionContext; -}): Promise { + id: string; +}): Promise { const viewId = ModalsEnum.ISSUE_COMMENTS_MODAL_VIEW; - const block = modify.getCreator().getBlockBuilder(); - const room = slashcommandcontext?.getRoom() || uikitcontext?.getInteractionData().room; @@ -45,6 +51,28 @@ export async function issueCommentsModal({ slashcommandcontext?.getSender() || uikitcontext?.getInteractionData().user; + const modal: IUIKitSurfaceViewParam = { + id: viewId, + type: UIKitSurfaceType.MODAL, + title: { + text: ModalsEnum.ISSUE_COMMENT_VIEW_TITLE, + type: "plain_text", + }, + blocks: [], + close: { + type: "button", + text: { + type: "plain_text", + emoji: true, + text: "Close", + }, + appId: id, + blockId: "", + actionId: "", + }, + }; + + let blocks: LayoutBlock[] = []; if (user?.id) { let roomId; if (room?.id) { @@ -56,49 +84,72 @@ export async function issueCommentsModal({ let issueData = data?.issueData; let issueComments = data?.issueComments; - block.addSectionBlock({ + blocks.push({ + type: "section", text: { text: `*${issueData?.title}*`, type: TextObjectType.MARKDOWN, - } + }, }); - block.addContextBlock({ + + blocks.push({ + type: "context", elements: [ - block.newPlainTextObject(`Author: ${issueData?.user_login} | `), - block.newPlainTextObject(`State : ${issueData?.state} | `), - block.newPlainTextObject(`Total Comments : ${issueComments?.length} |` ), + { + type: "plain_text", + text: `Author: ${issueData?.user_login} | `, + }, + { + type: "plain_text", + text: `State : ${issueData?.state} | `, + }, + { + type: "plain_text", + text: `Total Comments : ${issueComments?.length} |`, + }, ], }); - - block.addActionsBlock({ - elements: [ - block.newButtonElement({ - actionId: ModalsEnum.COMMENT_ISSUE_ACTION, - text: { - text: ModalsEnum.COMMENT_ISSUE_LABEL, - type: TextObjectType.PLAINTEXT, + + blocks.push( + { + type: "actions", + elements: [ + { + type: "button", + appId: id, + actionId: ModalsEnum.COMMENT_ISSUE_ACTION, + text: { + text: ModalsEnum.COMMENT_ISSUE_LABEL, + type: TextObjectType.PLAINTEXT, + }, + value: `${data?.repo} ${data?.issueNumber}`, + blockId: "", }, - value: `${data?.repo} ${data?.issueNumber}`, - }), - block.newButtonElement({ - text: { - text: AppEnum.DEFAULT_TITLE, - type: TextObjectType.PLAINTEXT, + { + type: "button", + appId: id, + actionId: "", + text: { + text: AppEnum.DEFAULT_TITLE, + type: TextObjectType.PLAINTEXT, + }, + url: issueData?.html_url, + blockId: "", }, - url: issueData?.html_url - }), - ], - }); + ], + }, + { type: "divider" }, + ); - block.addDividerBlock(); + if (issueComments?.length === 0) { - if(issueComments?.length === 0){ - block.addSectionBlock({ + blocks.push({ + type: 'section', text: { text: `📝 No comments so far !`, type: TextObjectType.MARKDOWN, - }, - }); + } + }) } let index = 1; @@ -107,52 +158,50 @@ export async function issueCommentsModal({ let username = comment?.user?.login; let avatarUrl = comment?.user?.avatar_url; let commentBody = comment?.body; - let userProfileUrl = comment?.user?.html_url + let userProfileUrl = comment?.user?.html_url; - block.addSectionBlock({ + blocks.push({ + type: 'section', text: { text: `*@${username}*`, type: TextObjectType.MARKDOWN, }, - accessory: block.newButtonElement({ + accessory: { + type: 'button', actionId: ModalsEnum.VIEW_USER_ACTION, text: { text: ModalsEnum.VIEW_USER_LABEL, - type: TextObjectType.PLAINTEXT, + type: TextObjectType.PLAINTEXT }, - url:userProfileUrl - }), - }); - block.addSectionBlock({ + blockId: '', + url: userProfileUrl, + appId: id, + } + }) + + blocks.push({ + type: 'section', text: { text: `${commentBody}`, type: TextObjectType.MARKDOWN, - }, - }); + } + }) let date = parseDate(comment?.created_at); let time = parseTime(comment?.created_at); - block.addContextBlock({ + + blocks.push({ + type: 'context', elements: [ - block.newPlainTextObject(`Created at : ${date} ${time} UTC`), - ], - }); - block.addDividerBlock(); + { + type: 'plain_text', + text: `Created at : ${date} ${time} UTC`, + } + ] + }, {type: 'divider'}) index++; } } - return { - id: viewId, - title: { - type: TextObjectType.PLAINTEXT, - text: ModalsEnum.ISSUE_COMMENT_VIEW_TITLE, - }, - close: block.newButtonElement({ - text: { - type: TextObjectType.PLAINTEXT, - text: "Close", - }, - }), - blocks: block.getBlocks(), - }; + modal.blocks = blocks; + return modal; } diff --git a/github/modals/pullRequestCommentsModal.ts b/github/modals/pullRequestCommentsModal.ts index b00b296..151ad76 100644 --- a/github/modals/pullRequestCommentsModal.ts +++ b/github/modals/pullRequestCommentsModal.ts @@ -3,6 +3,7 @@ import { IModify, IPersistence, IRead, + IUIKitSurfaceViewParam, } from "@rocket.chat/apps-engine/definition/accessors"; import { TextObjectType } from "@rocket.chat/apps-engine/definition/uikit/blocks"; import { IUIKitModalViewParam } from "@rocket.chat/apps-engine/definition/uikit/UIKitInteractionResponder"; @@ -13,9 +14,14 @@ import { SlashCommandContext } from "@rocket.chat/apps-engine/definition/slashco import { UIKitBlockInteractionContext, UIKitInteractionContext, + UIKitSurfaceType, } from "@rocket.chat/apps-engine/definition/uikit"; -import { storeInteractionRoomData, getInteractionRoomData } from "../persistance/roomInteraction"; +import { + storeInteractionRoomData, + getInteractionRoomData, +} from "../persistance/roomInteraction"; import { parseDate, parseTime } from "../helpers/dateTime"; +import { LayoutBlock } from "@rocket.chat/ui-kit"; export async function pullRequestCommentsModal({ data, @@ -25,6 +31,7 @@ export async function pullRequestCommentsModal({ http, slashcommandcontext, uikitcontext, + id, }: { data?; modify: IModify; @@ -33,11 +40,10 @@ export async function pullRequestCommentsModal({ http: IHttp; slashcommandcontext?: SlashCommandContext; uikitcontext?: UIKitInteractionContext; -}): Promise { + id: string; +}): Promise { const viewId = ModalsEnum.PULL_REQUEST_COMMENTS_MODAL_VIEW; - const block = modify.getCreator().getBlockBuilder(); - const room = slashcommandcontext?.getRoom() || uikitcontext?.getInteractionData().room; @@ -45,6 +51,28 @@ export async function pullRequestCommentsModal({ slashcommandcontext?.getSender() || uikitcontext?.getInteractionData().user; + const modal: IUIKitSurfaceViewParam = { + id: viewId, + type: UIKitSurfaceType.MODAL, + title: { + text: ModalsEnum.PULL_REQUEST_COMMENT_VIEW_TITLE, + type: "plain_text", + }, + blocks: [], + close: { + type: "button", + text: { + type: "plain_text", + emoji: true, + text: "Close", + }, + appId: id, + actionId: '', + blockId: '', + }, + }; + + let blocks: LayoutBlock[] = []; if (user?.id) { let roomId; if (room?.id) { @@ -53,115 +81,123 @@ export async function pullRequestCommentsModal({ } else { roomId = (await getInteractionRoomData(read.getPersistenceReader(), user.id)).roomId; } - let pullData = data?.pullData; - let pullRequestComments = data?.pullRequestComments; + const pullData = data?.pullData; + const pullRequestComments = data?.pullRequestComments; - block.addSectionBlock({ + blocks.push({ + type: "section", text: { text: `*${pullData?.title}*`, type: TextObjectType.MARKDOWN, }, - accessory: block.newButtonElement({ + accessory: { + type: "button", actionId: ModalsEnum.VIEW_FILE_ACTION, text: { text: ModalsEnum.VIEW_DIFFS_ACTION_LABEL, type: TextObjectType.PLAINTEXT, }, value: pullData?.diff_url, - }), + blockId: '', + appId: id, + }, }); - block.addContextBlock({ + + blocks.push({ + type: "context", elements: [ - block.newPlainTextObject(`Author: ${pullData?.user?.login} | `), - block.newPlainTextObject(`State : ${pullData?.state} | `), - block.newPlainTextObject(`Mergeable : ${pullData?.mergeable} |` ), - block.newPlainTextObject(`Total Comments : ${pullRequestComments?.length} |` ), + { type: "plain_text", text: `Author: ${pullData?.user?.login} | ` }, + { type: "plain_text", text: `State: ${pullData?.state} | ` }, + { type: "plain_text", text: `Mergeable: ${pullData?.mergeable} | ` }, + { type: "plain_text", text: `Total Comments: ${pullRequestComments?.length} |` }, ], }); - - block.addActionsBlock({ + + blocks.push({ + type: "actions", elements: [ - block.newButtonElement({ + { + type: "button", actionId: ModalsEnum.COMMENT_PR_ACTION, text: { text: ModalsEnum.COMMENT_PR_LABEL, type: TextObjectType.PLAINTEXT, }, value: `${data?.repo} ${data?.pullNumber}`, - }), - block.newButtonElement({ + appId: id, + blockId: '', + }, + { + type: "button", text: { text: AppEnum.DEFAULT_TITLE, type: TextObjectType.PLAINTEXT, }, - url: pullData ?.html_url - }), + url: pullData?.html_url, + appId: id, + blockId: '', + actionId: '', + }, ], }); - block.addDividerBlock(); + blocks.push({ type: "divider" }); - if(pullRequestComments?.length === 0){ - block.addSectionBlock({ + if (pullRequestComments?.length === 0) { + blocks.push({ + type: "section", text: { - text: `📝 No comments so far !`, + text: "📝 No comments so far!", type: TextObjectType.MARKDOWN, }, }); - } - - let index = 1; + } else { + for (const comment of pullRequestComments) { + const username = comment?.user?.login; + const userProfileUrl = comment?.user?.html_url; + const commentBody = comment?.body; + const date = parseDate(comment?.created_at); + const time = parseTime(comment?.created_at); - for (let comment of pullRequestComments) { - let username = comment?.user?.login; - let avatarUrl = comment?.user?.avatar_url; - let commentBody = comment?.body; - let userProfileUrl = comment?.user?.html_url + blocks.push({ + type: "section", + text: { + text: `*@${username}*`, + type: TextObjectType.MARKDOWN, + }, + accessory: { + type: "button", + actionId: ModalsEnum.VIEW_USER_ACTION, + text: { + text: ModalsEnum.VIEW_USER_LABEL, + type: TextObjectType.PLAINTEXT, + }, + url: userProfileUrl, + appId: id, + blockId: '', + }, + }); - block.addSectionBlock({ - text: { - text: `*@${username}*`, - type: TextObjectType.MARKDOWN, - }, - accessory: block.newButtonElement({ - actionId: ModalsEnum.VIEW_USER_ACTION, + blocks.push({ + type: "section", text: { - text: ModalsEnum.VIEW_USER_LABEL, - type: TextObjectType.PLAINTEXT, + text: commentBody, + type: TextObjectType.MARKDOWN, }, - url:userProfileUrl - }), - }); - block.addSectionBlock({ - text: { - text: `${commentBody}`, - type: TextObjectType.MARKDOWN, - }, - }); - let date = parseDate(comment?.created_at); - let time = parseTime(comment?.created_at); - block.addContextBlock({ - elements: [ - block.newPlainTextObject(`Created at : ${date} ${time} UTC`), - ], - }); - block.addDividerBlock(); - index++; + }); + + blocks.push({ + type: "context", + elements: [ + { type: "plain_text", text: `Created at: ${date} ${time} UTC` }, + ], + }); + + blocks.push({ type: "divider" }); + } } } - return { - id: viewId, - title: { - type: TextObjectType.PLAINTEXT, - text: ModalsEnum.PULL_REQUEST_COMMENT_VIEW_TITLE, - }, - close: block.newButtonElement({ - text: { - type: TextObjectType.PLAINTEXT, - text: "Close", - }, - }), - blocks: block.getBlocks(), - }; + modal.blocks = blocks; + return modal; } From cfbeff8d06c665821bc0c40cf85dadbde4b1a138 Mon Sep 17 00:00:00 2001 From: Devansh Date: Wed, 22 Jan 2025 18:20:20 +0530 Subject: [PATCH 12/12] Updated addSubscriptionsModal, deleteSubscriptions, newreminderModal, remindersModal, subscriptionsModal --- github/handlers/EventHandler.ts | 5 +- github/handlers/ExecuteBlockActionHandler.ts | 36 ++- github/handlers/ExecuteViewSubmitHandler.ts | 4 +- github/handlers/HandleRemider.ts | 8 +- github/modals/addSubscriptionsModal.ts | 146 +++++++--- github/modals/deleteSubscriptions.ts | 237 ++++++++++------ github/modals/newreminderModal.ts | 81 +++--- github/modals/remindersModal.ts | 169 ++++++++---- github/modals/subscriptionsModal.ts | 269 +++++++++++++------ 9 files changed, 657 insertions(+), 298 deletions(-) diff --git a/github/handlers/EventHandler.ts b/github/handlers/EventHandler.ts index 2d74cca..2a660b2 100644 --- a/github/handlers/EventHandler.ts +++ b/github/handlers/EventHandler.ts @@ -177,7 +177,7 @@ export async function UnsubscribeAllEvents( if (!isValidRepo) { return; } - + let events: Array = [ "pull_request", "push", @@ -287,10 +287,11 @@ export async function ManageSubscriptions( persistence: persistence, http: http, slashcommandcontext: context, + id: app.getID(), }); await modify .getUiController() - .openModalView(modal, { triggerId }, context.getSender()); + .openSurfaceView(modal, { triggerId }, context.getSender()); } else { console.log("Invalid Trigger ID !"); } diff --git a/github/handlers/ExecuteBlockActionHandler.ts b/github/handlers/ExecuteBlockActionHandler.ts index 684baa9..d7bc2fa 100644 --- a/github/handlers/ExecuteBlockActionHandler.ts +++ b/github/handlers/ExecuteBlockActionHandler.ts @@ -410,10 +410,10 @@ export class ExecuteBlockActionHandler { persistence: this.persistence, http: this.http, uikitcontext: context, + id: this.app.getID(), }); - return context - .getInteractionResponder() - .openModalViewResponse(addSubscriptionModal); + const triggerId = context.getInteractionData().triggerId; + await this.modify.getUiController().openSurfaceView(addSubscriptionModal, { triggerId }, context.getInteractionData().user); } case ModalsEnum.OPEN_DELETE_SUBSCRIPTIONS_MODAL: { const addSubscriptionModal = await deleteSubscriptionsModal( @@ -423,11 +423,10 @@ export class ExecuteBlockActionHandler { persistence: this.persistence, http: this.http, uikitcontext: context, + id: this.app.getID(), }, ); - return context - .getInteractionResponder() - .openModalViewResponse(addSubscriptionModal); + await this.modify.getUiController().openSurfaceView(addSubscriptionModal, {triggerId: context.getInteractionData().triggerId}, context.getInteractionData().user) } case ModalsEnum.DELETE_SUBSCRIPTION_ACTION: { let { user, room } = await context.getInteractionData(); @@ -533,8 +532,9 @@ export class ExecuteBlockActionHandler { persistence: this.persistence, http: this.http, uikitcontext: context, + id: this.app.getID() }); - await this.modify.getUiController().updateModalView( + await this.modify.getUiController().updateSurfaceView( modal, { triggerId: context.getInteractionData().triggerId, @@ -550,8 +550,9 @@ export class ExecuteBlockActionHandler { persistence: this.persistence, http: this.http, uikitcontext: context, + id: this.app.getID(), }); - await this.modify.getUiController().updateModalView( + await this.modify.getUiController().updateSurfaceView( modal, { triggerId: context.getInteractionData().triggerId, @@ -1627,11 +1628,10 @@ export class ExecuteBlockActionHandler { persistence: this.persistence, http: this.http, uikitcontext: context, + id: this.app.getID(), }); - return context - .getInteractionResponder() - .openModalViewResponse(opensubscriptionsModal); + await this.modify.getUiController().updateSurfaceView(opensubscriptionsModal, { triggerId: context.getInteractionData().triggerId }, context.getInteractionData().user); } case ModalsEnum.TRIGGER_NEW_ISSUE_MODAL: { @@ -1709,11 +1709,19 @@ export class ExecuteBlockActionHandler { persistence: this.persistence, http: this.http, uikitcontext: context, + id: this.app.getID(), }); + const triggerId = context.getInteractionData().triggerId; + if (triggerId) { + await this.modify + .getUiController() + .openSurfaceView( + updatedReminderModal, + { triggerId }, + context.getInteractionData().user, + ); + } - return context - .getInteractionResponder() - .updateModalViewResponse(updatedReminderModal); } } } catch (error) { diff --git a/github/handlers/ExecuteViewSubmitHandler.ts b/github/handlers/ExecuteViewSubmitHandler.ts index 26986e3..11369b8 100644 --- a/github/handlers/ExecuteViewSubmitHandler.ts +++ b/github/handlers/ExecuteViewSubmitHandler.ts @@ -113,8 +113,8 @@ export class ExecuteViewSubmitHandler { } } - const modal = await subscriptionsModal({ modify: this.modify, read: this.read, persistence: this.persistence, http: this.http, uikitcontext: context }); - await this.modify.getUiController().updateModalView(modal, { triggerId: context.getInteractionData().triggerId }, context.getInteractionData().user); + const modal = await subscriptionsModal({ modify: this.modify, read: this.read, persistence: this.persistence, http: this.http, uikitcontext: context, id: this.app.getID() }); + await this.modify.getUiController().updateSurfaceView(modal, { triggerId: context.getInteractionData().triggerId }, context.getInteractionData().user); return context.getInteractionResponder().successResponse(); } break; diff --git a/github/handlers/HandleRemider.ts b/github/handlers/HandleRemider.ts index 57058e2..6048b3e 100644 --- a/github/handlers/HandleRemider.ts +++ b/github/handlers/HandleRemider.ts @@ -32,10 +32,11 @@ export async function handleReminder( persistence: persistence, http: http, slashcommandcontext: context, + id: app.getID(), }); await modify .getUiController() - .openModalView( + .openSurfaceView( modal, { triggerId }, context.getSender() @@ -77,10 +78,11 @@ export async function ManageReminders( persistence: persistence, http: http, slashcommandcontext: context, + id: app.getID(), }); await modify .getUiController() - .openModalView(modal, { triggerId }, context.getSender()); + .openSurfaceView(modal, { triggerId }, context.getSender()); } else { console.log("Invalid Trigger ID !"); } @@ -93,4 +95,4 @@ export async function ManageReminders( "Login to see to pull request reminders! `/github login`" ); } -} \ No newline at end of file +} diff --git a/github/modals/addSubscriptionsModal.ts b/github/modals/addSubscriptionsModal.ts index 60f25d2..040ff37 100644 --- a/github/modals/addSubscriptionsModal.ts +++ b/github/modals/addSubscriptionsModal.ts @@ -3,6 +3,7 @@ import { IModify, IPersistence, IRead, + IUIKitSurfaceViewParam, } from "@rocket.chat/apps-engine/definition/accessors"; import { TextObjectType } from "@rocket.chat/apps-engine/definition/uikit/blocks"; import { IUIKitModalViewParam } from "@rocket.chat/apps-engine/definition/uikit/UIKitInteractionResponder"; @@ -14,6 +15,7 @@ import { SlashCommandContext } from "@rocket.chat/apps-engine/definition/slashco import { UIKitBlockInteractionContext, UIKitInteractionContext, + UIKitSurfaceType, } from "@rocket.chat/apps-engine/definition/uikit"; import { storeInteractionRoomData, @@ -21,6 +23,7 @@ import { } from "../persistance/roomInteraction"; import { Subscription } from "../persistance/subscriptions"; import { ISubscription } from "../definitions/subscription"; +import { LayoutBlock } from "@rocket.chat/ui-kit"; export async function AddSubscriptionModal({ modify, @@ -29,6 +32,7 @@ export async function AddSubscriptionModal({ http, slashcommandcontext, uikitcontext, + id, }: { modify: IModify; read: IRead; @@ -36,9 +40,9 @@ export async function AddSubscriptionModal({ http: IHttp; slashcommandcontext?: SlashCommandContext; uikitcontext?: UIKitInteractionContext; -}): Promise { + id: string; +}): Promise { const viewId = ModalsEnum.ADD_SUBSCRIPTION_VIEW; - const block = modify.getCreator().getBlockBuilder(); const room = slashcommandcontext?.getRoom() || uikitcontext?.getInteractionData().room; @@ -46,6 +50,38 @@ export async function AddSubscriptionModal({ slashcommandcontext?.getSender() || uikitcontext?.getInteractionData().user; + const modal: IUIKitSurfaceViewParam = { + type: UIKitSurfaceType.MODAL, + id: viewId, + title: { + type: TextObjectType.PLAINTEXT, + text: ModalsEnum.ADD_SUBSCIPTIONS_TITLE, + }, + blocks: [], + close: { + type: "button", + text: { + type: TextObjectType.PLAINTEXT, + text: "Close", + }, + actionId: "", + blockId: "", + appId: id, + }, + submit: { + type: "button", + actionId: ModalsEnum.ADD_SUBSCRIPTION_ACTION, + text: { + type: TextObjectType.PLAINTEXT, + text: "Subscribe", + }, + blockId: "", + appId: id, + }, + }; + + let blocks: LayoutBlock[] = []; + if (user?.id) { let roomId; @@ -56,35 +92,40 @@ export async function AddSubscriptionModal({ roomId = ( await getInteractionRoomData( read.getPersistenceReader(), - user.id + user.id, ) ).roomId; } let subscriptionStorage = new Subscription( persistence, - read.getPersistenceReader() + read.getPersistenceReader(), ); let roomSubscriptions: Array = await subscriptionStorage.getSubscriptions(roomId); // shows indentations in input blocks but not inn section block - block.addInputBlock({ - blockId: ModalsEnum.REPO_NAME_INPUT, + // + blocks.push({ + type: "input", label: { text: ModalsEnum.REPO_NAME_LABEL, type: TextObjectType.PLAINTEXT, }, - element: block.newPlainTextInputElement({ + element: { + type: "plain_text_input", actionId: ModalsEnum.REPO_NAME_INPUT_ACTION, placeholder: { text: ModalsEnum.REPO_NAME_PLACEHOLDER, type: TextObjectType.PLAINTEXT, }, - }), + appId: id, + blockId: ModalsEnum.REPO_NAME_INPUT, + }, }); - let newMultiStaticElemnt = block.newMultiStaticElement({ + let newMultiStaticElemnt = { + type: "multi_static_select", actionId: ModalsEnum.ADD_SUBSCRIPTION_EVENT_OPTIONS, options: [ { @@ -132,39 +173,72 @@ export async function AddSubscriptionModal({ type: TextObjectType.PLAINTEXT, text: "Select Events", }, - }); + }; - block.addInputBlock({ + blocks.push({ + type: "input", label: { text: ModalsEnum.ADD_SUBSCRIPTION_EVENT_LABEL, type: TextObjectType.PLAINTEXT, }, - element: newMultiStaticElemnt, - blockId: ModalsEnum.ADD_SUBSCRIPTION_EVENT_INPUT, + element: { + type: "multi_static_select", + actionId: ModalsEnum.ADD_SUBSCRIPTION_EVENT_OPTIONS, + blockId: "", + options: [ + { + value: "issues", + text: { + type: TextObjectType.PLAINTEXT, + text: "New Issues", + emoji: true, + }, + }, + { + value: "pull_request", + text: { + type: TextObjectType.PLAINTEXT, + text: "New Pull Request", + emoji: true, + }, + }, + { + value: "push", + text: { + type: TextObjectType.PLAINTEXT, + text: "New Commits", + emoji: true, + }, + }, + { + value: "deployment_status", + text: { + type: TextObjectType.PLAINTEXT, + text: "Deployment", + emoji: true, + }, + }, + { + value: "star", + text: { + type: TextObjectType.PLAINTEXT, + text: "New Stars", + emoji: true, + }, + }, + ], + placeholder: { + type: TextObjectType.PLAINTEXT, + text: "Select Events", + }, + appId: id, + }, }); } + blocks.push({ + type: 'divider', + }) + modal.blocks = blocks; - block.addDividerBlock(); - - return { - id: viewId, - title: { - type: TextObjectType.PLAINTEXT, - text: ModalsEnum.ADD_SUBSCIPTIONS_TITLE, - }, - close: block.newButtonElement({ - text: { - type: TextObjectType.PLAINTEXT, - text: "Close", - }, - }), - submit: block.newButtonElement({ - actionId: ModalsEnum.ADD_SUBSCRIPTION_ACTION, - text: { - type: TextObjectType.PLAINTEXT, - text: "Subscribe", - }, - }), - blocks: block.getBlocks(), - }; + return modal; } diff --git a/github/modals/deleteSubscriptions.ts b/github/modals/deleteSubscriptions.ts index 0f5b48b..6939506 100644 --- a/github/modals/deleteSubscriptions.ts +++ b/github/modals/deleteSubscriptions.ts @@ -1,115 +1,200 @@ -import { IHttp, IModify, IPersistence, IRead } from '@rocket.chat/apps-engine/definition/accessors'; -import { ITextObject, TextObjectType } from '@rocket.chat/apps-engine/definition/uikit/blocks'; -import { IUIKitModalViewParam } from '@rocket.chat/apps-engine/definition/uikit/UIKitInteractionResponder'; -import { IUser } from '@rocket.chat/apps-engine/definition/users'; -import { ModalsEnum } from '../enum/Modals'; -import { AppEnum } from '../enum/App'; +import { + IHttp, + IModify, + IPersistence, + IRead, + IUIKitSurfaceViewParam, +} from "@rocket.chat/apps-engine/definition/accessors"; +import { + ITextObject, + TextObjectType, +} from "@rocket.chat/apps-engine/definition/uikit/blocks"; +import { IUIKitModalViewParam } from "@rocket.chat/apps-engine/definition/uikit/UIKitInteractionResponder"; +import { IUser } from "@rocket.chat/apps-engine/definition/users"; +import { ModalsEnum } from "../enum/Modals"; +import { AppEnum } from "../enum/App"; // import { getRoomTasks, getUIData, persistUIData } from '../lib/persistence'; -import { SlashCommandContext } from '@rocket.chat/apps-engine/definition/slashcommands'; -import { UIKitBlockInteractionContext, UIKitInteractionContext } from '@rocket.chat/apps-engine/definition/uikit'; -import { getInteractionRoomData, storeInteractionRoomData } from '../persistance/roomInteraction'; -import { Subscription } from '../persistance/subscriptions'; -import { ISubscription } from '../definitions/subscription'; -import { IRepositorySubscriptions } from '../definitions/repositorySubscriptions'; +import { SlashCommandContext } from "@rocket.chat/apps-engine/definition/slashcommands"; +import { + UIKitBlockInteractionContext, + UIKitInteractionContext, + UIKitSurfaceType, +} from "@rocket.chat/apps-engine/definition/uikit"; +import { + getInteractionRoomData, + storeInteractionRoomData, +} from "../persistance/roomInteraction"; +import { Subscription } from "../persistance/subscriptions"; +import { ISubscription } from "../definitions/subscription"; +import { IRepositorySubscriptions } from "../definitions/repositorySubscriptions"; +import { LayoutBlock } from "@rocket.chat/ui-kit"; -export async function deleteSubscriptionsModal({ modify, read, persistence, http, slashcommandcontext, uikitcontext }: { modify: IModify, read: IRead, persistence: IPersistence, http: IHttp ,slashcommandcontext?: SlashCommandContext, uikitcontext?: UIKitInteractionContext }): Promise { +export async function deleteSubscriptionsModal({ + modify, + read, + persistence, + http, + slashcommandcontext, + uikitcontext, + id, +}: { + modify: IModify; + read: IRead; + persistence: IPersistence; + http: IHttp; + slashcommandcontext?: SlashCommandContext; + uikitcontext?: UIKitInteractionContext; + id: string; +}): Promise { const viewId = ModalsEnum.DELETE_SUBSCRIPTION_VIEW; - const block = modify.getCreator().getBlockBuilder(); + const modal: IUIKitSurfaceViewParam = { + type: UIKitSurfaceType.MODAL, + id: viewId, + title: { + type: TextObjectType.PLAINTEXT, + text: ModalsEnum.DELETE_SUBSCIPTIONS_TITLE, + }, + blocks: [], + close: { + type: 'button', + text: { + type: TextObjectType.PLAINTEXT, + text: "Close", + }, + actionId: '', + appId: id, + blockId: '', + }, + } + + let blocks: LayoutBlock[] = []; + const room = + slashcommandcontext?.getRoom() || + uikitcontext?.getInteractionData().room; + const user = + slashcommandcontext?.getSender() || + uikitcontext?.getInteractionData().user; - const room = slashcommandcontext?.getRoom() || uikitcontext?.getInteractionData().room; - const user = slashcommandcontext?.getSender() || uikitcontext?.getInteractionData().user; - if (user?.id) { let roomId; if (room?.id) { roomId = room.id; await storeInteractionRoomData(persistence, user.id, roomId); } else { - roomId = (await getInteractionRoomData(read.getPersistenceReader(), user.id)).roomId; + roomId = ( + await getInteractionRoomData( + read.getPersistenceReader(), + user.id, + ) + ).roomId; } - - let subscriptionStorage = new Subscription(persistence,read.getPersistenceReader()); - let roomSubscriptions: Array = await subscriptionStorage.getSubscriptions(roomId); - block.addDividerBlock(); + let subscriptionStorage = new Subscription( + persistence, + read.getPersistenceReader(), + ); + let roomSubscriptions: Array = + await subscriptionStorage.getSubscriptions(roomId); - let repositoryData = new Map; - for (let subscription of roomSubscriptions) { + blocks.push({ + type: 'divider', + }) + let repositoryData = new Map(); + for (let subscription of roomSubscriptions) { let repoName = subscription.repoName; let userId = subscription.user; let event = subscription.event; let user = await read.getUserReader().getById(userId); - - if(repositoryData.has(repoName)){ - let repoData = repositoryData.get(repoName) as IRepositorySubscriptions; + + if (repositoryData.has(repoName)) { + let repoData = repositoryData.get( + repoName, + ) as IRepositorySubscriptions; repoData.events.push(event); - repoData.user=user; - repositoryData.set(repoName,repoData); - }else{ - let events:Array = []; + repoData.user = user; + repositoryData.set(repoName, repoData); + } else { + let events: Array = []; events.push(event); - let repoData:IRepositorySubscriptions={ - webhookId:subscription.webhookId, - events:events, - user:user, - repoName:repoName + let repoData: IRepositorySubscriptions = { + webhookId: subscription.webhookId, + events: events, + user: user, + repoName: repoName, }; - repositoryData.set(repoName,repoData); + repositoryData.set(repoName, repoData); } - } - let index=1; + let index = 1; for (let repository of repositoryData.values()) { - let repoName = repository.repoName; let repoUser = repository.user; - let events = repository.events; - if(repoUser.id == user.id){ - block.addSectionBlock({ - text: { text: `${index}) ${repoName}`, type: TextObjectType.PLAINTEXT}, - accessory: block.newButtonElement({ + let events = repository.events; + if (repoUser.id == user.id) { + + blocks.push({ + type: 'section', + text: { + text: `${index}) ${repoName}`, + type: TextObjectType.PLAINTEXT, + }, + accessory: { + type: 'button', actionId: ModalsEnum.DELETE_SUBSCRIPTION_ACTION, text: { text: ModalsEnum.DELETE_SUBSCRIPTION_LABEL, - type: TextObjectType.PLAINTEXT + type: TextObjectType.PLAINTEXT, }, value: repoName + "," + repository.webhookId, - }) - }); - - }else{ - block.addSectionBlock({ - text: { text: `${index}) ${repoName}`, type: TextObjectType.PLAINTEXT}, - }); + appId: id, + blockId: '', + } + }) + } else { + blocks.push({ + type: 'section', + text: { + text: `${index}) ${repoName}`, + type: TextObjectType.PLAINTEXT, + }, + }) } - - let eventList : Array=[]; - eventList.push(block.newPlainTextObject("Events : ")); - for(let event of events){ - eventList.push(block.newPlainTextObject(`${event} `)); + + let eventList: any[] = []; + eventList.push(blocks.push({ + type: 'context', + elements: [ + { + type: 'plain_text', + text: "Events: ", + } + ] + })); + for (let event of events) { + eventList.push(blocks.push({ + type: 'context', + elements: [ + { + type: 'plain_text', + text: `${event}`, + } + ] + })); } - block.addContextBlock({ elements: eventList}); + blocks.push({ + type: 'context', + elements: eventList, + }) index++; } } - block.addDividerBlock(); - - return { - id: viewId, - title: { - type: TextObjectType.PLAINTEXT, - text: ModalsEnum.DELETE_SUBSCIPTIONS_TITLE, - }, - close: block.newButtonElement({ - text: { - type: TextObjectType.PLAINTEXT, - text: 'Close', - }, - }), - blocks: block.getBlocks(), - }; -} \ No newline at end of file + blocks.push({ + type: 'divider', + }) + modal.blocks = blocks; + return modal; +} diff --git a/github/modals/newreminderModal.ts b/github/modals/newreminderModal.ts index 4cf9d20..196dc81 100644 --- a/github/modals/newreminderModal.ts +++ b/github/modals/newreminderModal.ts @@ -3,6 +3,7 @@ import { IModify, IPersistence, IRead, + IUIKitSurfaceViewParam, } from "@rocket.chat/apps-engine/definition/accessors"; import { TextObjectType } from "@rocket.chat/apps-engine/definition/uikit/blocks"; import { IUIKitModalViewParam } from "@rocket.chat/apps-engine/definition/uikit/UIKitInteractionResponder"; @@ -10,11 +11,13 @@ import { ModalsEnum } from "../enum/Modals"; import { SlashCommandContext } from "@rocket.chat/apps-engine/definition/slashcommands"; import { UIKitInteractionContext, + UIKitSurfaceType, } from "@rocket.chat/apps-engine/definition/uikit"; import { storeInteractionRoomData, getInteractionRoomData, } from "../persistance/roomInteraction"; +import { LayoutBlock } from "@rocket.chat/ui-kit"; export async function NewReminderStarterModal({ modify, @@ -23,6 +26,7 @@ export async function NewReminderStarterModal({ http, slashcommandcontext, uikitcontext, + id, }: { modify: IModify; read: IRead; @@ -30,12 +34,44 @@ export async function NewReminderStarterModal({ http: IHttp; slashcommandcontext?: SlashCommandContext; uikitcontext?: UIKitInteractionContext; -}): Promise { + id: string, +}): Promise { const viewId = ModalsEnum.NEW_REMINDER_VIEW; - const block = modify.getCreator().getBlockBuilder(); const room = slashcommandcontext?.getRoom() || uikitcontext?.getInteractionData().room; const user = slashcommandcontext?.getSender() || uikitcontext?.getInteractionData().user; + const modal: IUIKitSurfaceViewParam = { + type: UIKitSurfaceType.MODAL, + id: viewId, + title: { + type: TextObjectType.PLAINTEXT, + text: 'Create New reminder', + }, + close: { + type: 'button', + blockId: '', + appId: id, + text: { + type: TextObjectType.PLAINTEXT, + text: "Close", + }, + actionId: '', + }, + submit: { + type: 'button', + blockId: '', + appId: id, + actionId: "new-reminder-action", + text: { + type: TextObjectType.PLAINTEXT, + emoji:true, + text: "Create", + }, + }, + blocks:[], + } + + let blocks: LayoutBlock[] = []; if (user?.id) { let roomId; @@ -51,45 +87,30 @@ export async function NewReminderStarterModal({ ).roomId; } - block.addInputBlock({ + blocks.push({ + type: 'input', blockId: ModalsEnum.REPO_NAME_INPUT, label: { text: ModalsEnum.REPO_NAME_LABEL, type: TextObjectType.PLAINTEXT, }, - element: block.newPlainTextInputElement({ + element: { + type: 'plain_text_input', actionId: ModalsEnum.REPO_NAME_INPUT_ACTION, placeholder: { text: ModalsEnum.REPO_NAME_PLACEHOLDER, type: TextObjectType.PLAINTEXT, }, - }), - }); - + blockId: '', + appId: id, + }, + }) } - block.addDividerBlock(); + blocks.push({ + type: 'divider', + }) - return { - id: viewId, - title: { - type: TextObjectType.PLAINTEXT, - text: 'Create New reminder', - }, - close: block.newButtonElement({ - text: { - type: TextObjectType.PLAINTEXT, - text: "Close", - }, - }), - submit: block.newButtonElement({ - actionId: "new-reminder-action", - text: { - type: TextObjectType.PLAINTEXT, - emoji:true, - text: "Create", - }, - }), - blocks: block.getBlocks(), - }; + modal.blocks = blocks; + return modal; } diff --git a/github/modals/remindersModal.ts b/github/modals/remindersModal.ts index 8962b5b..89a9284 100644 --- a/github/modals/remindersModal.ts +++ b/github/modals/remindersModal.ts @@ -1,71 +1,134 @@ -import { IHttp, IModify, IPersistence, IRead } from '@rocket.chat/apps-engine/definition/accessors'; -import { ButtonStyle, ITextObject, TextObjectType } from '@rocket.chat/apps-engine/definition/uikit/blocks'; -import { IUIKitModalViewParam } from '@rocket.chat/apps-engine/definition/uikit/UIKitInteractionResponder'; -import { ModalsEnum } from '../enum/Modals'; -import { SlashCommandContext } from '@rocket.chat/apps-engine/definition/slashcommands'; -import { UIKitBlockInteractionContext, UIKitInteractionContext } from '@rocket.chat/apps-engine/definition/uikit'; -import { getUserReminder } from '../persistance/remind'; -import { IReminder } from '../definitions/Reminder'; +import { + IHttp, + IModify, + IPersistence, + IRead, + IUIKitSurfaceViewParam, +} from "@rocket.chat/apps-engine/definition/accessors"; +import { + ButtonStyle, + ITextObject, + TextObjectType, +} from "@rocket.chat/apps-engine/definition/uikit/blocks"; +import { IUIKitModalViewParam } from "@rocket.chat/apps-engine/definition/uikit/UIKitInteractionResponder"; +import { ModalsEnum } from "../enum/Modals"; +import { SlashCommandContext } from "@rocket.chat/apps-engine/definition/slashcommands"; +import { + UIKitBlockInteractionContext, + UIKitInteractionContext, + UIKitSurfaceType, +} from "@rocket.chat/apps-engine/definition/uikit"; +import { getUserReminder } from "../persistance/remind"; +import { IReminder } from "../definitions/Reminder"; +import { LayoutBlock } from "@rocket.chat/ui-kit"; -export async function reminderModal({ modify, read, persistence, http, slashcommandcontext, uikitcontext }: { modify: IModify, read: IRead, persistence: IPersistence, http: IHttp, slashcommandcontext?: SlashCommandContext, uikitcontext?: UIKitInteractionContext }): Promise { +export async function reminderModal({ + modify, + read, + persistence, + http, + slashcommandcontext, + uikitcontext, + id, +}: { + modify: IModify; + read: IRead; + persistence: IPersistence; + http: IHttp; + slashcommandcontext?: SlashCommandContext; + uikitcontext?: UIKitInteractionContext; + id: string; +}): Promise { const viewId = ModalsEnum.REMINDER_LIST_MODAL_VIEW; - const block = modify.getCreator().getBlockBuilder(); + const room = + slashcommandcontext?.getRoom() || + uikitcontext?.getInteractionData().room; + const user = + slashcommandcontext?.getSender() || + uikitcontext?.getInteractionData().user; - const room = slashcommandcontext?.getRoom() || uikitcontext?.getInteractionData().room; - const user = slashcommandcontext?.getSender() || uikitcontext?.getInteractionData().user; + const modal: IUIKitSurfaceViewParam = { + type: UIKitSurfaceType.MODAL, + id: viewId, + title: { + type: TextObjectType.PLAINTEXT, + text: "Reminder List", + }, + blocks: [], + close: { + type: "button", + blockId: "", + actionId: "", + appId: id, + text: { + type: TextObjectType.PLAINTEXT, + text: "Close", + }, + }, + }; - block.addDividerBlock(); + let blocks: LayoutBlock[] = []; if (user?.id) { const reminders: IReminder = await getUserReminder(read, user); if (reminders && reminders.repos.length > 0) { for (let repository of reminders.repos) { - block.addSectionBlock({ - text: { text: `${repository}`, type: TextObjectType.PLAINTEXT }, + blocks.push({ + type: "section", + text: { + text: `${repository}`, + type: TextObjectType.PLAINTEXT, + }, }); - block.addActionsBlock({ - blockId:ModalsEnum.REMINDER_LIST_MODAL, - - elements:[ - block.newButtonElement({ - actionId: ModalsEnum.OPEN_REPO_ACTION, - text: block.newPlainTextObject("Open"), - url:`https://github.com/${repository}`, - style: ButtonStyle.PRIMARY, - - }), - block.newButtonElement({ - actionId: ModalsEnum.REMINDER_REMOVE_REPO_ACTION, - text: block.newPlainTextObject("Remove"), - value: `${repository}`, - style: ButtonStyle.DANGER, - })] - }) - - block.addDividerBlock(); + blocks.push( + { + type: "actions", + elements: [ + { + type: "button", + appId: id, + blockId: "", + actionId: ModalsEnum.OPEN_REPO_ACTION, + text: { + type: "plain_text", + text: "Open", + }, + url: `https://github.com/${repository}`, + style: ButtonStyle.PRIMARY, + }, + { + type: "button", + appId: id, + blockId: "", + actionId: + ModalsEnum.REMINDER_REMOVE_REPO_ACTION, + text: { + type: "plain_text", + text: "Remove", + }, + value: `${repository}`, + style: ButtonStyle.DANGER, + }, + ], + }, + { type: "divider" }, + ); } } else { - block.addSectionBlock({ - text: { text: "You have no reminders.", type: TextObjectType.PLAINTEXT } - }); + + blocks.push({ + type: 'section', + text: { + text: "You have no reminders.", + type: TextObjectType.PLAINTEXT, + }, + }) } } - return { - id: viewId, - title: { - type: TextObjectType.PLAINTEXT, - text: "Reminder List", - }, - close: block.newButtonElement({ - text: { - type: TextObjectType.PLAINTEXT, - text: 'Close', - }, - }), - blocks: block.getBlocks(), - }; -} \ No newline at end of file + modal.blocks = blocks; + return modal; +} diff --git a/github/modals/subscriptionsModal.ts b/github/modals/subscriptionsModal.ts index 5542ba0..a785957 100644 --- a/github/modals/subscriptionsModal.ts +++ b/github/modals/subscriptionsModal.ts @@ -1,127 +1,232 @@ -import { IHttp, IModify, IPersistence, IRead } from '@rocket.chat/apps-engine/definition/accessors'; -import { ITextObject, TextObjectType } from '@rocket.chat/apps-engine/definition/uikit/blocks'; -import { IUIKitModalViewParam } from '@rocket.chat/apps-engine/definition/uikit/UIKitInteractionResponder'; -import { IUser } from '@rocket.chat/apps-engine/definition/users'; -import { ModalsEnum } from '../enum/Modals'; -import { AppEnum } from '../enum/App'; +import { + IHttp, + IModify, + IPersistence, + IRead, + IUIKitSurfaceViewParam, +} from "@rocket.chat/apps-engine/definition/accessors"; +import { + ITextObject, + TextObjectType, +} from "@rocket.chat/apps-engine/definition/uikit/blocks"; +import { IUIKitModalViewParam } from "@rocket.chat/apps-engine/definition/uikit/UIKitInteractionResponder"; +import { IUser } from "@rocket.chat/apps-engine/definition/users"; +import { ModalsEnum } from "../enum/Modals"; +import { AppEnum } from "../enum/App"; // import { getRoomTasks, getUIData, persistUIData } from '../lib/persistence'; -import { SlashCommandContext } from '@rocket.chat/apps-engine/definition/slashcommands'; -import { UIKitBlockInteractionContext, UIKitInteractionContext } from '@rocket.chat/apps-engine/definition/uikit'; -import { getInteractionRoomData, storeInteractionRoomData } from '../persistance/roomInteraction'; -import { Subscription } from '../persistance/subscriptions'; -import { ISubscription } from '../definitions/subscription'; -import { IRepositorySubscriptions } from '../definitions/repositorySubscriptions'; +import { SlashCommandContext } from "@rocket.chat/apps-engine/definition/slashcommands"; +import { + IUIKitSurface, + UIKitBlockInteractionContext, + UIKitInteractionContext, + UIKitSurfaceType, +} from "@rocket.chat/apps-engine/definition/uikit"; +import { + getInteractionRoomData, + storeInteractionRoomData, +} from "../persistance/roomInteraction"; +import { Subscription } from "../persistance/subscriptions"; +import { ISubscription } from "../definitions/subscription"; +import { IRepositorySubscriptions } from "../definitions/repositorySubscriptions"; +import { LayoutBlock } from "@rocket.chat/ui-kit"; -export async function subscriptionsModal({ modify, read, persistence, http, slashcommandcontext, uikitcontext }: { modify: IModify, read: IRead, persistence: IPersistence, http: IHttp ,slashcommandcontext?: SlashCommandContext, uikitcontext?: UIKitInteractionContext }): Promise { +export async function subscriptionsModal({ + modify, + read, + persistence, + http, + slashcommandcontext, + uikitcontext, + id, +}: { + modify: IModify; + read: IRead; + persistence: IPersistence; + http: IHttp; + slashcommandcontext?: SlashCommandContext; + uikitcontext?: UIKitInteractionContext; + id: string; +}): Promise { const viewId = ModalsEnum.SUBSCRIPTION_VIEW; - const block = modify.getCreator().getBlockBuilder(); + const room = + slashcommandcontext?.getRoom() || + uikitcontext?.getInteractionData().room; + const user = + slashcommandcontext?.getSender() || + uikitcontext?.getInteractionData().user; - const room = slashcommandcontext?.getRoom() || uikitcontext?.getInteractionData().room; - const user = slashcommandcontext?.getSender() || uikitcontext?.getInteractionData().user; - + const modal: IUIKitSurfaceViewParam = { + type: UIKitSurfaceType.MODAL, + id: viewId, + title: { + type: TextObjectType.PLAINTEXT, + text: ModalsEnum.SUBSCRIPTION_TITLE, + }, + blocks: [], + close: { + type: "button", + text: { + type: TextObjectType.PLAINTEXT, + text: "Close", + }, + blockId: "", + actionId: "", + appId: id, + }, + }; + + let blocks: LayoutBlock[] = []; if (user?.id) { let roomId; if (room?.id) { roomId = room.id; await storeInteractionRoomData(persistence, user.id, roomId); } else { - roomId = (await getInteractionRoomData(read.getPersistenceReader(), user.id)).roomId; + roomId = ( + await getInteractionRoomData( + read.getPersistenceReader(), + user.id, + ) + ).roomId; } - - let subscriptionStorage = new Subscription(persistence,read.getPersistenceReader()); - let roomSubscriptions: Array = await subscriptionStorage.getSubscriptions(roomId); - block.addDividerBlock(); - - - let repositoryData = new Map; - for (let subscription of roomSubscriptions) { + let subscriptionStorage = new Subscription( + persistence, + read.getPersistenceReader(), + ); + let roomSubscriptions: Array = + await subscriptionStorage.getSubscriptions(roomId); + blocks.push({ + type: "divider", + }); + + let repositoryData = new Map(); + for (let subscription of roomSubscriptions) { let repoName = subscription.repoName; let userId = subscription.user; let event = subscription.event; let user = await read.getUserReader().getById(userId); - - if(repositoryData.has(repoName)){ - let repoData = repositoryData.get(repoName) as IRepositorySubscriptions; + + if (repositoryData.has(repoName)) { + let repoData = repositoryData.get( + repoName, + ) as IRepositorySubscriptions; repoData.events.push(event); - repoData.user=user; - repositoryData.set(repoName,repoData); - }else{ - let events:Array = []; + repoData.user = user; + repositoryData.set(repoName, repoData); + } else { + let events: Array = []; events.push(event); - let repoData:IRepositorySubscriptions={ - webhookId:subscription.webhookId, - events:events, - user:user, - repoName:repoName + let repoData: IRepositorySubscriptions = { + webhookId: subscription.webhookId, + events: events, + user: user, + repoName: repoName, }; - repositoryData.set(repoName,repoData); + repositoryData.set(repoName, repoData); } - } - let index=1; + let index = 1; for (let repository of repositoryData.values()) { let repoName = repository.repoName; let repoUser = repository.user; let events = repository.events; - block.addSectionBlock({ - text: { text: `${index}) ${repoName}`, type: TextObjectType.PLAINTEXT}, - accessory: block.newButtonElement({ + + blocks.push({ + type: "section", + text: { + text: `${index}) ${repoName}`, + type: TextObjectType.PLAINTEXT, + }, + accessory: { + type: "button", actionId: ModalsEnum.OPEN_REPO_ACTION, text: { text: ModalsEnum.OPEN_REPO_LABEL, - type: TextObjectType.PLAINTEXT + type: TextObjectType.PLAINTEXT, }, value: repository.webhookId, - url:`https://github.com/${repoName}` - }) + url: `https://github.com/${repoName}`, + blockId: "", + appId: id, + }, }); - let eventList : Array=[]; - eventList.push(block.newPlainTextObject("Events : ")); - for(let event of events){ - eventList.push(block.newPlainTextObject(`${event} `)); + let eventList: any[] = []; + eventList.push( + blocks.push({ + type: "context", + elements: [ + { + type: "plain_text", + text: "Events: ", + }, + ], + }), + ); + for (let event of events) { + eventList.push(blocks.push({ + type:'context', + elements: [ + { + type: 'plain_text', + text: `${event}`, + } + ] + })); } - block.addContextBlock({ elements: eventList}); + blocks.push({ + type: 'context', + elements: eventList + }) index++; } } - block.addDividerBlock(); + blocks.push({ + type: 'divider', + }) - block.addActionsBlock({ + blocks.push({ + type: 'actions', elements: [ - block.newButtonElement({ + { + type: 'button', actionId: ModalsEnum.OPEN_ADD_SUBSCRIPTIONS_MODAL, - text: { text: ModalsEnum.OPEN_ADD_SUBSCRIPTIONS_LABEL, type: TextObjectType.PLAINTEXT }, - value: room?.id - }), - block.newButtonElement({ + text: { + text: ModalsEnum.OPEN_ADD_SUBSCRIPTIONS_LABEL, + type: TextObjectType.PLAINTEXT, + }, + value: room?.id, + blockId: '', + appId: id, + }, + { + type: 'button', actionId: ModalsEnum.OPEN_DELETE_SUBSCRIPTIONS_MODAL, - text: { text: ModalsEnum.OPEN_DELETE_SUBSCRIPTIONS_LABEL, type: TextObjectType.PLAINTEXT }, - value: room?.id - }), - block.newButtonElement({ + text: { + text: ModalsEnum.OPEN_DELETE_SUBSCRIPTIONS_LABEL, + type: TextObjectType.PLAINTEXT, + }, + value: room?.id, + blockId: '', + appId: id, + }, + { + type: 'button', actionId: ModalsEnum.SUBSCRIPTION_REFRESH_ACTION, - text: { text: ModalsEnum.SUBSCRIPTION_REFRESH_LABEL, type: TextObjectType.PLAINTEXT }, - value: room?.id - }), + text: { + text: ModalsEnum.SUBSCRIPTION_REFRESH_LABEL, + type: TextObjectType.PLAINTEXT, + }, + value: room?.id, + appId: id, + blockId: '', + } ] - }); + }) - return { - id: viewId, - title: { - type: TextObjectType.PLAINTEXT, - text: ModalsEnum.SUBSCRIPTION_TITLE, - }, - close: block.newButtonElement({ - text: { - type: TextObjectType.PLAINTEXT, - text: 'Close', - }, - }), - blocks: block.getBlocks(), - }; -} \ No newline at end of file + modal.blocks = blocks; + return modal; +}