@@ -119,7 +117,7 @@
-
- Connected: {{ connected }}
-
\ No newline at end of file
+
+
+
+
\ No newline at end of file
diff --git a/prisma/schema.prisma b/prisma/schema.prisma
index 7857486..5a07b0b 100644
--- a/prisma/schema.prisma
+++ b/prisma/schema.prisma
@@ -8,18 +8,17 @@ generator client {
}
model User {
- id String @id @default(cuid())
- email String @unique
- username String @unique
+ id String @id @default(cuid())
+ email String @unique
+ username String @unique
passwordhash String
servers Server[]
messages Message[]
session Session[]
channels Channel[]
roles Role[]
- createdAt DateTime @default(now())
- Reaction Reaction? @relation(fields: [reactionId], references: [id])
- reactionId String?
+ createdAt DateTime @default(now())
+ Reactions Reaction[]
}
model Server {
diff --git a/public/32.png b/public/32.png
new file mode 100644
index 0000000..8bfbd06
Binary files /dev/null and b/public/32.png differ
diff --git a/server/api/channels/[id]/messages/[messageId]/reactions/[name].post.ts b/server/api/channels/[id]/messages/[messageId]/reactions/[name].post.ts
index 80c15cd..fc2b97c 100644
--- a/server/api/channels/[id]/messages/[messageId]/reactions/[name].post.ts
+++ b/server/api/channels/[id]/messages/[messageId]/reactions/[name].post.ts
@@ -1,6 +1,6 @@
import { IChannel, IServer, SafeUser } from '~/types'
+import emojiRegex from 'emoji-regex'
import { PrismaClient } from '@prisma/client'
-import { node } from 'unenv'
const prisma = new PrismaClient()
export default defineEventHandler(async (event) => {
@@ -12,23 +12,14 @@ export default defineEventHandler(async (event) => {
}
const emoji = decodeURIComponent(event.context.params.name)
-
- if (emoji.length !== 2) {
+ const match = emoji.match(emojiRegex());
+ if (!match || match.length !== 1) {
event.node.res.statusCode = 400;
return {
message: 'reaction is not an emoji or more than one emoji.'
}
}
-
- const first = emoji.charCodeAt(0);
- const second = emoji.charCodeAt(1);
- if (!((first >= 0xD800 && first <= 0xDBFF) && (second >= 0xDC00 && second <= 0xDFFF))) {
- event.node.res.statusCode = 400;
- return {
- message: 'reaction is not an emoji or more than one emoji.'
- }
- }
const messageSelect = {
id: true,
diff --git a/utils/parseMessageBody.ts b/utils/parseMessageBody.ts
new file mode 100644
index 0000000..41a7f50
--- /dev/null
+++ b/utils/parseMessageBody.ts
@@ -0,0 +1,44 @@
+import { IChannel } from "~/types";
+
+export default function parseBody(body: string, activeChannel: IChannel) {
+ body = escape(body);
+ const rules = [
+ //bold, italics and paragragh rules
+ [/\*\*\s?([^\n]+)\*\*/g, "$1"],
+ [/\*\s?([^\n]+)\*/g, "$1"],
+ [/\_\_\s?([^\n]+)\_\_/g, "$1"],
+ [/\~\~\s?([^\n]+)\~\~/g, "$1"],
+
+ // code lines and blocks
+ [/```(.+?)```/g, "$1
"],
+ [/(?$1"],
+ ];
+
+ rules.forEach(([rule, template]) => {
+ body = body.replace(rule, template);
+ })
+
+ const mentions = body.match(/<@([a-z]|[0-9]){25}>/g);
+
+ if (mentions) {
+ const participants = (activeChannel.DM) ? activeChannel.dmParticipants : activeChannel.server.participants;
+ if (!participants) throw new Error(`participants in channel "${activeChannel.id}" not found"`)
+ mentions.forEach((e: string) => {
+ if (!e) return
+ const id = e.split('<@')[1]?.split('>')[0];
+ if (!id) return;
+ const user = participants.find((e) => e.id === id)
+ if (!user) return;
+ body = body.split(e).join(`@${user.username}`)
+ });
+ }
+
+ return body
+}
+
+function escape(s: string) {
+ return s.replace(
+ /[^0-9A-Za-z ]/g,
+ c => "" + c.charCodeAt(0) + ";"
+ );
+}
\ No newline at end of file