Skip to content

Commit

Permalink
Merge pull request #129 from VipinDevelops/fix-share-profile-modal
Browse files Browse the repository at this point in the history
[FIX]: Share profile modal No closing and Empty Contirbution graph
  • Loading branch information
samad-yar-khan authored Mar 3, 2024
2 parents 35a7a88 + 723dc14 commit 5d12e48
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 102 deletions.
73 changes: 4 additions & 69 deletions github/handlers/ExecuteBlockActionHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,77 +288,12 @@ export class ExecuteBlockActionHandler {
}
case ModalsEnum.SHARE_PROFILE_PARAMS : {
const profileInteractionData = context.getInteractionData().value;
const datAny = profileInteractionData as any;
const storeData = {
profileParams : datAny as string[]
}

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)
if(Array.isArray(profileInteractionData)) {
const storeData = {
profileParams: profileInteractionData as string[]
}
await this.persistence.updateByAssociation(new RocketChatAssociationRecord(RocketChatAssociationModel.MISC, "ProfileShareParam"), storeData);
}

this.persistence.removeByAssociation(idRecord);

break;
}
case ModalsEnum.VIEW_FILE_ACTION: {
Expand Down
65 changes: 62 additions & 3 deletions github/handlers/ExecuteViewSubmitHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, addNewIssueComment, getIssuesComments, getIssueData } from '../helpers/githubSDK';
import { addSubscribedEvents, createSubscription, updateSubscription, createNewIssue, getIssueTemplates,githubSearchIssuesPulls, mergePullRequest, addNewPullRequestComment, getPullRequestData, getPullRequestComments, getRepoData, getRepositoryIssues, updateGithubIssues, addNewIssueComment, getIssuesComments, getIssueData, getBasicUserInfo } from '../helpers/githubSDK';
import { NewIssueModal } from '../modals/newIssueModal';
import { issueTemplateSelectionModal } from '../modals/issueTemplateSelectionModal';
import { githubIssuesListModal } from '../modals/githubIssuesListModal';
Expand All @@ -27,7 +27,8 @@ import { IGitHubIssueData } from '../definitions/githubIssueData';
import { githubIssuesShareModal } from '../modals/githubIssuesShareModal';
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';
export class ExecuteViewSubmitHandler {
constructor(
private readonly app: GithubApp,
Expand Down Expand Up @@ -745,7 +746,65 @@ 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'];
}else {
const data = profileData[0] as {profileParams : string[]};
profileShareParams = data.profileParams;
}

if (profileShareParams.includes('avatar')){
block.addImageBlock({
imageUrl : userProfile.avatar,
altText : "User Info"
})
}

profileShareParams.map((value) => {
if (value != 'avatar'){
block.addSectionBlock({
text : block.newPlainTextObject(value),
})
block.addContextBlock({
elements : [
block.newPlainTextObject(userProfile[value], true),
]
});
block.addDividerBlock();
}
})

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 Down
4 changes: 0 additions & 4 deletions github/helpers/githubActivityGraphURL.ts

This file was deleted.

7 changes: 0 additions & 7 deletions github/modals/UserProfileModal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { ModalsEnum } from "../enum/Modals";
import { getBasicUserInfo } from "../helpers/githubSDK";
import { getInteractionRoomData, storeInteractionRoomData } from "../persistance/roomInteraction";
import {} from "@rocket.chat/apps-engine/definition/uikit/"
import { githubActivityGraphUrl } from "../helpers/githubActivityGraphURL";

export async function userProfileModal({
access_token,
Expand Down Expand Up @@ -67,12 +66,6 @@ export async function userProfileModal({
]
});

block.addDividerBlock();

block.addImageBlock({imageUrl : githubActivityGraphUrl(userInfo.username), altText: "Github Contribution Graph"});



block.addDividerBlock();

block.addSectionBlock({
Expand Down
29 changes: 10 additions & 19 deletions github/modals/profileShareModal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ export async function shareProfileModal({
uikitcontext?: UIKitInteractionContext
}) : Promise<IUIKitModalViewParam> {

const viewId = "ProfileShareView";
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' , 'contributionGraph'],
initialValue: ['username', 'avatar', 'email', 'bio', 'followers', 'following'],
options: [
{
value: 'followers',
Expand Down Expand Up @@ -77,28 +77,12 @@ export async function shareProfileModal({
text: 'bio'
}
},
{
value : 'contributionGraph',
text : {
text: 'Contribution',
type : TextObjectType.PLAINTEXT
}
}
],
placeholder: {
type: TextObjectType.PLAINTEXT,
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 +92,14 @@ 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"
})
}

}

0 comments on commit 5d12e48

Please sign in to comment.