diff --git a/apps/backend/src/api/routes/integrations.controller.ts b/apps/backend/src/api/routes/integrations.controller.ts
index 1f90e65f..fb3eee3b 100644
--- a/apps/backend/src/api/routes/integrations.controller.ts
+++ b/apps/backend/src/api/routes/integrations.controller.ts
@@ -263,8 +263,10 @@ export class IntegrationsController {
let newList: any[] | {none: true} = [];
try {
- newList = await this.functionIntegration(org, body);
- } catch (err) {}
+ newList = (await this.functionIntegration(org, body)) || [];
+ } catch (err) {
+ console.log(err);
+ }
if (!Array.isArray(newList) && newList?.none) {
return newList;
@@ -283,8 +285,9 @@ export class IntegrationsController {
name: p.label || '',
username: p.id || '',
image: p.image || '',
+ doNotCache: p.doNotCache || false,
}))
- .filter((f: any) => f.name)
+ .filter((f: any) => f.name && !f.doNotCache)
);
}
@@ -298,7 +301,7 @@ export class IntegrationsController {
...newList as any[],
],
(p) => p.id
- ).filter((f) => f.label && f.image && f.id);
+ ).filter((f) => f.label && f.id);
}
@Post('/function')
diff --git a/apps/frontend/src/components/new-launch/mention.component.tsx b/apps/frontend/src/components/new-launch/mention.component.tsx
index 3f93caeb..8e1ddca7 100644
--- a/apps/frontend/src/components/new-launch/mention.component.tsx
+++ b/apps/frontend/src/components/new-launch/mention.component.tsx
@@ -100,7 +100,7 @@ const MentionList: FC = (props: any) => {
onClick={() => selectItem(index)}
>
diff --git a/libraries/helpers/src/utils/strip.html.validation.ts b/libraries/helpers/src/utils/strip.html.validation.ts
index 97e4eb66..870494d1 100644
--- a/libraries/helpers/src/utils/strip.html.validation.ts
+++ b/libraries/helpers/src/utils/strip.html.validation.ts
@@ -161,6 +161,8 @@ export const stripHtmlValidation = (
.replace(/
([.\s\S]*?)<\/h1>/g, (match, p1) => {
return `# ${p1}
\n`;
})
+ .replace(/&/gi, '&')
+ .replace(/ /gi, ' ')
.replace(/([.\s\S]*?)<\/h2>/g, (match, p1) => {
return `## ${p1}
\n`;
})
diff --git a/libraries/nestjs-libraries/src/integrations/social.abstract.ts b/libraries/nestjs-libraries/src/integrations/social.abstract.ts
index 193c3ee9..cd14c6e8 100644
--- a/libraries/nestjs-libraries/src/integrations/social.abstract.ts
+++ b/libraries/nestjs-libraries/src/integrations/social.abstract.ts
@@ -37,7 +37,7 @@ export abstract class SocialAbstract {
d: { query: string },
id: string,
integration: Integration
- ): Promise<{ id: string; label: string; image: string }[] | { none: true }> {
+ ): Promise<{ id: string; label: string; image: string, doNotCache?: boolean }[] | { none: true }> {
return { none: true };
}
diff --git a/libraries/nestjs-libraries/src/integrations/social/discord.provider.ts b/libraries/nestjs-libraries/src/integrations/social/discord.provider.ts
index 74da1f99..4c685d5e 100644
--- a/libraries/nestjs-libraries/src/integrations/social/discord.provider.ts
+++ b/libraries/nestjs-libraries/src/integrations/social/discord.provider.ts
@@ -159,7 +159,7 @@ export class DiscordProvider extends SocialAbstract implements SocialProvider {
form.append(
'payload_json',
JSON.stringify({
- content: post.message.replace(/\[\[\[(@\d.*?)]]]/g, (match, p1) => {
+ content: post.message.replace(/\[\[\[(@.*?)]]]/g, (match, p1) => {
return `<${p1}>`;
}),
attachments: post.media?.map((p, index) => ({
@@ -228,6 +228,21 @@ export class DiscordProvider extends SocialAbstract implements SocialProvider {
id: string,
integration: Integration
) {
+ const allRoles = await (
+ await fetch(`https://discord.com/api/guilds/${id}/roles`, {
+ headers: {
+ Authorization: `Bot ${process.env.DISCORD_BOT_TOKEN_ID}`,
+ 'Content-Type': 'application/json',
+ },
+ })
+ ).json();
+
+ const matching = allRoles
+ .filter((role: any) =>
+ role.name.toLowerCase().includes(data.query.toLowerCase())
+ )
+ .filter((f) => f.name !== '@everyone' && f.name !== '@here');
+
const list = await (
await fetch(
`https://discord.com/api/guilds/${id}/members/search?query=${data.query}`,
@@ -240,14 +255,41 @@ export class DiscordProvider extends SocialAbstract implements SocialProvider {
)
).json();
- return list.map((p: any) => ({
- id: String(p.user.id),
- label: p.user.global_name || p.user.username,
- image: `https://cdn.discordapp.com/avatars/${p.user.id}/${p.user.avatar}.png`,
- }));
+ return [
+ ...[
+ {
+ id: String('here'),
+ label: 'here',
+ image: '',
+ doNotCache: true,
+ },
+ {
+ id: String('everyone'),
+ label: 'everyone',
+ image: '',
+ doNotCache: true,
+ },
+ ].filter((role: any) => {
+ return role.label.toLowerCase().includes(data.query.toLowerCase());
+ }),
+ ...matching.map((p: any) => ({
+ id: String('&' + p.id),
+ label: p.name.split('@')[1],
+ image: '',
+ doNotCache: true,
+ })),
+ ...list.map((p: any) => ({
+ id: String(p.user.id),
+ label: p.user.global_name || p.user.username,
+ image: `https://cdn.discordapp.com/avatars/${p.user.id}/${p.user.avatar}.png`,
+ })),
+ ];
}
mentionFormat(idOrHandle: string, name: string) {
- return `[[[@${idOrHandle}]]]`;
+ if (name === '@here' || name === '@everyone') {
+ return name;
+ }
+ return `[[[@${idOrHandle.replace('@', '')}]]]`;
}
}
diff --git a/libraries/nestjs-libraries/src/integrations/social/social.integrations.interface.ts b/libraries/nestjs-libraries/src/integrations/social/social.integrations.interface.ts
index 20add654..79f9da3a 100644
--- a/libraries/nestjs-libraries/src/integrations/social/social.integrations.interface.ts
+++ b/libraries/nestjs-libraries/src/integrations/social/social.integrations.interface.ts
@@ -134,6 +134,6 @@ export interface SocialProvider
) => Promise<{ client_id: string; client_secret: string }>;
mention?: (
token: string, data: { query: string }, id: string, integration: Integration
- ) => Promise<{ id: string; label: string; image: string }[] | {none: true}>;
+ ) => Promise<{ id: string; label: string; image: string, doNotCache?: boolean }[] | {none: true}>;
mentionFormat?(idOrHandle: string, name: string): string;
}