Skip to content

Commit

Permalink
Merge pull request #753 from ganta/fix-mention-in-guest-space
Browse files Browse the repository at this point in the history
fix: fix the mention of a guest that is not working properly
  • Loading branch information
ganta authored Oct 5, 2024
2 parents ee78faa + 1b6cd7c commit ffcfc8b
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 30 deletions.
2 changes: 1 addition & 1 deletion src/app/components/marktone.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ interface MarktoneProps {

interface MentionCandidateItem {
type: DirectoryEntityType;
id: number;
id: string;
code: string;
name: string;
avatar: string;
Expand Down
2 changes: 1 addition & 1 deletion src/app/kintone/directory-entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class DirectoryEntityTypeUtil {

export interface DirectoryEntity {
type: DirectoryEntityType;
id: number;
id: string;
code: string;
name: string;
avatar: string;
Expand Down
58 changes: 32 additions & 26 deletions src/app/kintone/kintone-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,12 +236,12 @@ export default class KintoneClient {
requestBody,
);

return response.result.entities.map((entity) => {
return response.result.entities.map(({ entityType, id, code, name }) => {
return {
type: DirectoryEntityTypeUtil.valueOf(entity.entityType),
id: parseInt(entity.id, 10),
code: entity.code,
name: entity.name,
type: DirectoryEntityTypeUtil.valueOf(entityType),
id,
code,
name,
avatar: "",
};
});
Expand All @@ -259,27 +259,33 @@ export default class KintoneClient {
requestBody,
);

const users = response.result.users.map<DirectoryEntity>((u) => ({
type: DirectoryEntityType.USER,
id: parseInt(u.id, 10),
code: u.code,
name: u.name,
avatar: u.photo.size_24,
}));
const orgs = response.result.orgs.map<DirectoryEntity>((o) => ({
type: DirectoryEntityType.ORGANIZATION,
id: parseInt(o.id, 10),
code: o.code,
name: o.name,
avatar: KintoneClient.presetOrganizationImageURL,
}));
const groups = response.result.groups.map<DirectoryEntity>((g) => ({
type: DirectoryEntityType.GROUP,
id: parseInt(g.id, 10),
code: g.code,
name: g.name,
avatar: KintoneClient.presetGroupImageURL,
}));
const users = response.result.users.map<DirectoryEntity>(
({ id, code, name, photo }) => ({
type: DirectoryEntityType.USER,
id,
code,
name,
avatar: photo.size_24,
}),
);
const orgs = response.result.orgs.map<DirectoryEntity>(
({ id, code, name }) => ({
type: DirectoryEntityType.ORGANIZATION,
id,
code,
name,
avatar: KintoneClient.presetOrganizationImageURL,
}),
);
const groups = response.result.groups.map<DirectoryEntity>(
({ id, code, name }) => ({
type: DirectoryEntityType.GROUP,
id,
code,
name,
avatar: KintoneClient.presetGroupImageURL,
}),
);

return new DirectoryEntityCollection({ users, orgs, groups });
}
Expand Down
8 changes: 6 additions & 2 deletions src/app/markdown/replacer/mention-replacer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class MentionReplacer {
};
return (
code
.replace(/[ @%&'"<>*]/g, replacer)
.replace(/[ @%&'"<>*+]/g, replacer)
// Escape Markdown syntax characters following a multi-bytes character.
.replace(/(?<!\w)[ _~![\]|\\-]/g, replacer)
);
Expand Down Expand Up @@ -107,7 +107,11 @@ class MentionReplacer {
if (!entity) return match;

const attrName = type ? `${type}-mention-id` : "mention-id";
const href = type ? "#" : `/k/#/people/user/${code}`;
const href = type
? "#"
: code.includes("@")
? `/k/guest/#/people/guest/${escapedCode}`
: `/k/#/people/user/${escapedCode}`;
// LRO/RLO may be included in `name`. Therefore, it is surrounded by bdi element.
return `<a class="${className}" href="${href}" data-${attrName}="${entity.id}" tabindex="-1" style="${style}">@<bdi>${entity.name}</bdi></a>`;
};
Expand Down

0 comments on commit ffcfc8b

Please sign in to comment.