Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 0 additions & 64 deletions github/handlers/ExecuteBlockActionHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,71 +289,7 @@ 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
89 changes: 78 additions & 11 deletions 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 { RocketChatAssociationModel, RocketChatAssociationRecord } from '@rocket.chat/apps-engine/definition/metadata';
import { IAuthData } from '@rocket.chat/apps-engine/definition/oauth2/IOAuth2';

export class ExecuteViewSubmitHandler {
constructor(
Expand Down Expand Up @@ -151,20 +153,20 @@ 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;
let accessToken = await getAccessTokenForUser(this.read, user, this.app.oauth2Config);
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){
Expand All @@ -182,7 +184,7 @@ export class ExecuteViewSubmitHandler {
.openModalViewResponse(createNewIssue);
}
}
}
}
break;
}
case ModalsEnum.SEARCH_VIEW: {
Expand Down Expand Up @@ -224,7 +226,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 !*");
Expand Down Expand Up @@ -401,7 +403,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){
Expand Down Expand Up @@ -545,7 +547,7 @@ export class ExecuteViewSubmitHandler {
.getInteractionResponder()
.openModalViewResponse(issuesListModal);
}
}
}
break;
}
case ModalsEnum.ADD_ISSUE_ASSIGNEE_VIEW: {
Expand Down Expand Up @@ -615,7 +617,7 @@ export class ExecuteViewSubmitHandler {
}
}
}
}
}
break;
}
case ModalsEnum.ISSUE_LIST_VIEW:{
Expand Down Expand Up @@ -653,7 +655,72 @@ export class ExecuteViewSubmitHandler {
}
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;
}

default:
break;
}
Expand All @@ -665,4 +732,4 @@ export class ExecuteViewSubmitHandler {
success: true,
};
}
}
}
21 changes: 10 additions & 11 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_EXEC;
const block = modify.getCreator().getBlockBuilder();

block.addActionsBlock({
Expand Down Expand Up @@ -90,15 +90,6 @@ 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"

})
]
})

Expand All @@ -108,7 +99,15 @@ export async function shareProfileModal({
type: TextObjectType.PLAINTEXT,
text: "Share Profile"
},
blocks: block.getBlocks()
blocks: block.getBlocks(),
submit:block.newButtonElement({
text : {
text : "Share to Chat",
type : TextObjectType.PLAINTEXT
},
value : "shareChat"

})
}

}