diff --git a/github/enum/Modals.ts b/github/enum/Modals.ts index d4f102e..c52736a 100644 --- a/github/enum/Modals.ts +++ b/github/enum/Modals.ts @@ -21,7 +21,7 @@ export enum ModalsEnum { TRIGGER_REPOS_MODAL = 'trigger-repos-modal', TRIGGER_ACTIVITY_MODAL = 'trigger-activity-modal', TRIGGER_NOTIFICATIONS_MODAL = 'trigger-notifications-modal', - SHARE_PROFILE_EXEC = 'share-profile-exec', + SHARE_PROFILE_VIEW = 'share-profile-view', SHARE_PROFILE_PARAMS = 'share-profile-params', SHARE_PROFILE = 'share-profile', PULL_VIEW = 'pull-view', diff --git a/github/handlers/ExecuteBlockActionHandler.ts b/github/handlers/ExecuteBlockActionHandler.ts index 066a4b4..77058e1 100644 --- a/github/handlers/ExecuteBlockActionHandler.ts +++ b/github/handlers/ExecuteBlockActionHandler.ts @@ -289,71 +289,6 @@ export class ExecuteBlockActionHandler { await this.persistence.updateByAssociation(new RocketChatAssociationRecord(RocketChatAssociationModel.MISC, "ProfileShareParam"), storeData); break; } - case ModalsEnum.SHARE_PROFILE_EXEC : { - let {user, room} = context.getInteractionData(); - const block = this.modify.getCreator().getBlockBuilder(); - let accessToken = await getAccessTokenForUser(this.read, user ,this.app.oauth2Config) as IAuthData; - const userProfile = await getBasicUserInfo(this.http, accessToken.token); - - const idRecord = new RocketChatAssociationRecord(RocketChatAssociationModel.MISC, "ProfileShareParam") - - const profileData = await this.read.getPersistenceReader().readByAssociation(idRecord); - - let profileShareParams: string[] = []; - - if (profileData.length == 0){ - profileShareParams = ['username', 'avatar', 'email', 'bio', 'followers', 'following' , 'contributionGraph']; - } - else { - const dat = profileData[0] as {profileParams : string[]}; - profileShareParams = dat.profileParams; - } - - if (profileShareParams.includes('avatar')){ - block.addImageBlock({ - imageUrl : userProfile.avatar, - altText : "User Info" - }) - } - - profileShareParams.map((value) => { - if (value != 'contributionGraph' && value != 'avatar'){ - block.addSectionBlock({ - text : block.newPlainTextObject(value), - }) - block.addContextBlock({ - elements : [ - block.newPlainTextObject(userProfile[value], true), - ] - }); - block.addDividerBlock(); - } - }) - - if (profileShareParams.includes('contributionGraph')){ - block.addImageBlock({imageUrl : `https://activity-graph.herokuapp.com/graph?username=${userProfile.username}&bg_color=ffffff&color=708090&line=24292e&point=24292e`, altText: "Github Contribution Graph"}) - } - - - if(user?.id){ - if(room?.id){ - await sendMessage(this.modify, room!, user, `${userProfile.name}'s Github Profile`, block) - }else{ - let roomId = ( - await getInteractionRoomData( - this.read.getPersistenceReader(), - user.id - ) - ).roomId; - room = await this.read.getRoomReader().getById(roomId) as IRoom; - await sendMessage(this.modify, room, user, `${userProfile.name}'s Github Profile`, block) - } - } - - this.persistence.removeByAssociation(idRecord); - - break; - } case ModalsEnum.VIEW_FILE_ACTION: { const codeModal = await fileCodeModal({ data, diff --git a/github/handlers/ExecuteViewSubmitHandler.ts b/github/handlers/ExecuteViewSubmitHandler.ts index da42679..b153a77 100644 --- a/github/handlers/ExecuteViewSubmitHandler.ts +++ b/github/handlers/ExecuteViewSubmitHandler.ts @@ -17,7 +17,7 @@ import { IGitHubSearchResultData } from '../definitions/searchResultData'; import { githubSearchErrorModal } from '../modals/githubSearchErrorModal'; import { GithubSearchResultStorage } from '../persistance/searchResults'; import { githubSearchResultShareModal } from '../modals/githubSearchResultsShareModal'; -import { addSubscribedEvents, createSubscription, updateSubscription, createNewIssue, getIssueTemplates,githubSearchIssuesPulls, mergePullRequest, addNewPullRequestComment, getPullRequestData, getPullRequestComments, getRepoData, getRepositoryIssues, updateGithubIssues } from '../helpers/githubSDK'; +import { addSubscribedEvents, createSubscription, updateSubscription, createNewIssue, getIssueTemplates,githubSearchIssuesPulls, mergePullRequest, addNewPullRequestComment, getPullRequestData, getPullRequestComments, getRepoData, getRepositoryIssues, updateGithubIssues, getBasicUserInfo } from '../helpers/githubSDK'; import { NewIssueModal } from '../modals/newIssueModal'; import { issueTemplateSelectionModal } from '../modals/issueTemplateSelectionModal'; import { githubIssuesListModal } from '../modals/githubIssuesListModal'; @@ -25,6 +25,8 @@ import { IGitHubIssue } from '../definitions/githubIssue'; import { GithubRepoIssuesStorage } from '../persistance/githubIssues'; import { IGitHubIssueData } from '../definitions/githubIssueData'; import { githubIssuesShareModal } from '../modals/githubIssuesShareModal'; +import { IAuthData } from '@rocket.chat/apps-engine/definition/oauth2/IOAuth2'; +import { RocketChatAssociationModel, RocketChatAssociationRecord } from '@rocket.chat/apps-engine/definition/metadata'; export class ExecuteViewSubmitHandler { constructor( @@ -547,6 +549,73 @@ export class ExecuteViewSubmitHandler { } } break; + } + case ModalsEnum.SHARE_PROFILE_VIEW : { + let {user, room} = context.getInteractionData(); + const block = this.modify.getCreator().getBlockBuilder(); + let accessToken = await getAccessTokenForUser(this.read, user ,this.app.oauth2Config) as IAuthData; + const userProfile = await getBasicUserInfo(this.http, accessToken.token); + + const idRecord = new RocketChatAssociationRecord(RocketChatAssociationModel.MISC, "ProfileShareParam") + + const profileData = await this.read.getPersistenceReader().readByAssociation(idRecord); + + let profileShareParams: string[] = []; + + if (profileData.length == 0){ + profileShareParams = ['username', 'avatar', 'email', 'bio', 'followers', 'following' , 'contributionGraph']; + } + else { + const dat = profileData[0] as {profileParams : string[]}; + profileShareParams = dat.profileParams; + } + + if (profileShareParams.includes('avatar')){ + block.addImageBlock({ + imageUrl : userProfile.avatar, + altText : "User Info" + }) + } + + profileShareParams.map((value) => { + if (value != 'contributionGraph' && value != 'avatar'){ + block.addSectionBlock({ + text : block.newPlainTextObject(value), + }) + block.addContextBlock({ + elements : [ + block.newPlainTextObject(userProfile[value], true), + ] + }); + block.addDividerBlock(); + } + }) + + if (profileShareParams.includes('contributionGraph')){ + block.addImageBlock({imageUrl : `https://activity-graph.herokuapp.com/graph?username=${userProfile.username}&bg_color=ffffff&color=708090&line=24292e&point=24292e`, altText: "Github Contribution Graph"}) + } + + + if(user?.id){ + if(room?.id){ + await sendMessage(this.modify, room!, user, `${userProfile.name}'s Github Profile`, block) + }else{ + let roomId = ( + await getInteractionRoomData( + this.read.getPersistenceReader(), + user.id + ) + ).roomId; + room = await this.read.getRoomReader().getById(roomId) as IRoom; + await sendMessage(this.modify, room, user, `${userProfile.name}'s Github Profile`, block) + } + + } + + this.persistence.removeByAssociation(idRecord); + + break; + } case ModalsEnum.ADD_ISSUE_ASSIGNEE_VIEW: { const { roomId } = await getInteractionRoomData(this.read.getPersistenceReader(), user.id); diff --git a/github/modals/profileShareModal.ts b/github/modals/profileShareModal.ts index 5efc163..4365b45 100644 --- a/github/modals/profileShareModal.ts +++ b/github/modals/profileShareModal.ts @@ -22,7 +22,7 @@ export async function shareProfileModal({ uikitcontext?: UIKitInteractionContext }) : Promise { - const viewId = "ProfileShareView"; + const viewId = ModalsEnum.SHARE_PROFILE_VIEW; const block = modify.getCreator().getBlockBuilder(); block.addActionsBlock({ @@ -90,25 +90,23 @@ export async function shareProfileModal({ text: 'Select Property to Share', }, }), - block.newButtonElement({ - actionId : ModalsEnum.SHARE_PROFILE_EXEC, - text : { - text : "Share to Chat", - type : TextObjectType.PLAINTEXT - }, - value : "shareChat" - - }) ] }) - return { + return { id: viewId, title: { type: TextObjectType.PLAINTEXT, - text: "Share Profile" + text: "Share Profile", }, - blocks: block.getBlocks() - } + blocks: block.getBlocks(), + submit: block.newButtonElement({ + text: { + text: "Share to Chat", + type: TextObjectType.PLAINTEXT, + }, + value: "shareChat", + }), + }; }