Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] Share profile not closing the modal #100

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion github/enum/Modals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
65 changes: 0 additions & 65 deletions github/handlers/ExecuteBlockActionHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
71 changes: 70 additions & 1 deletion github/handlers/ExecuteViewSubmitHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@ 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';
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(
Expand Down Expand Up @@ -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);
Expand Down
26 changes: 12 additions & 14 deletions github/modals/profileShareModal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export async function shareProfileModal({
uikitcontext?: UIKitInteractionContext
}) : Promise<IUIKitModalViewParam> {

const viewId = "ProfileShareView";
const viewId = ModalsEnum.SHARE_PROFILE_VIEW;
const block = modify.getCreator().getBlockBuilder();

block.addActionsBlock({
Expand Down Expand Up @@ -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",
}),
};

}