typing indicator, mentions + bug fixes

This commit is contained in:
Zoe
2023-01-14 06:37:13 -06:00
parent c39da0678d
commit f1c5537697
23 changed files with 629 additions and 190 deletions

View File

@@ -26,7 +26,14 @@ export default defineEventHandler(async (event) => {
name: true,
server: {
select: {
id: true
id: true,
name: true,
participants: {
select: {
id: true,
username: true
}
}
}
},
messages: {
@@ -41,12 +48,16 @@ export default defineEventHandler(async (event) => {
},
invites: {
select: {
id: true,
id: true,
server: {
select: {
id: true,
name: true,
participants: true
participants: {
select: {
id: true
}
}
}
}
}

View File

@@ -55,12 +55,37 @@ export default defineEventHandler(async (event) => {
]
}
},
include: {
channels: true,
participants: true,
roles: true
select: {
id: true,
name: true,
channels: {
select: {
id: true,
DM: true,
name: true
}
},
participants: {
select: {
id: true,
username: true
}
},
roles: {
select: {
id: true,
name: true,
administrator: true,
owner: true,
users: {
select: {
id: true
}
}
}
}
}
}) as IServer;
}) as unknown as IServer;
return server
})

View File

@@ -62,8 +62,17 @@ export default defineEventHandler(async (event) => {
dmParticipants: { connect: [{ id: event.context.user.id }, { id: partner.id }] },
DM: true
},
include: {
dmParticipants: true
select: {
id: true,
name: true,
messages: false,
DM: true,
dmParticipants: {
select: {
id: true,
username: true
}
}
}
}) as IChannel

View File

@@ -1,6 +1,7 @@
import { IChannel, IServer, SafeUser, IMessage } from '~/types'
import { Server } from 'socket.io'
import { PrismaClient } from '@prisma/client'
import { registerRuntimeHelpers } from '@vue/compiler-core'
const prisma = new PrismaClient()
declare global {
@@ -28,20 +29,67 @@ export default defineEventHandler(async (event) => {
where: {
id: channelId
},
include: {
dmParticipants: true
select: {
id: true,
name: true,
messages: false,
DM: true,
dmParticipants: {
select: {
id: true,
username: true
}
}
}
}) as IChannel
}) as IChannel | null;
if (!channel) {
event.node.res.statusCode = 404;
return {
message: `Channel with id "${channelId}" not found.`
}
}
if (!channel.DM) {
const server = await prisma.server.findFirst({
where: {
id: channel.serverId
},
include: {
participants: true
select: {
id: true,
name: true,
channels: {
select: {
id: true,
DM: true,
name: true
}
},
participants: {
select: {
id: true,
username: true
}
},
roles: {
select: {
id: true,
name: true,
administrator: true,
owner: true,
users: {
select: {
id: true
}
}
}
}
}
}) as IServer
}) as IServer | null;
if (!server) {
throw new Error(`server with id "${channel.serverId}" is not found but channel with id "${channel.id}" is not a dm?`)
}
const userInServer: SafeUser | undefined = server.participants.find((e: SafeUser) => e.id === event.context.user.id)
@@ -69,11 +117,11 @@ export default defineEventHandler(async (event) => {
}
}
const matches = body.match(/<&([a-z]|[0-9]){25}>/g);
const inviteCodes = body.match(/<&([a-z]|[0-9]){25}>/g);
let invites: { id: string; }[] = [];
if (matches) {
matches.forEach((e: string) => {
if (inviteCodes) {
inviteCodes.forEach((e: string) => {
if (!e) return
const opBody = body;
body = body.split(e).join('')