feat(communication): add chat reactions emojis and images
This commit is contained in:
22
backend/db/migrations/0081_chat_media_reactions.sql
Normal file
22
backend/db/migrations/0081_chat_media_reactions.sql
Normal file
@@ -0,0 +1,22 @@
|
||||
ALTER TABLE communication_messages ADD COLUMN image jsonb;
|
||||
--> statement-breakpoint
|
||||
ALTER TABLE collaboration_messages ADD COLUMN image jsonb;
|
||||
--> statement-breakpoint
|
||||
ALTER TABLE collaboration_messages DROP CONSTRAINT collaboration_messages_body_check;
|
||||
--> statement-breakpoint
|
||||
ALTER TABLE collaboration_messages ADD CONSTRAINT collaboration_messages_body_check
|
||||
CHECK (length(body) <= 10000 AND (length(body) > 0 OR image IS NOT NULL));
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE communication_message_reactions (
|
||||
message_id bigint NOT NULL REFERENCES communication_messages(id) ON DELETE CASCADE,
|
||||
actor_id uuid NOT NULL REFERENCES auth_users(id) ON DELETE CASCADE,
|
||||
emoji text NOT NULL CHECK (length(emoji) BETWEEN 1 AND 16),
|
||||
PRIMARY KEY (message_id, actor_id, emoji)
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE collaboration_message_reactions (
|
||||
message_id uuid NOT NULL REFERENCES collaboration_messages(id) ON DELETE CASCADE,
|
||||
actor_id uuid NOT NULL REFERENCES collaboration_principals(id) ON DELETE CASCADE,
|
||||
emoji text NOT NULL CHECK (length(emoji) BETWEEN 1 AND 16),
|
||||
PRIMARY KEY (message_id, actor_id, emoji)
|
||||
);
|
||||
@@ -547,6 +547,13 @@
|
||||
"when": 1791158400000,
|
||||
"tag": "0080_staff_time_spans",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 78,
|
||||
"version": "7",
|
||||
"when": 1791244800000,
|
||||
"tag": "0081_chat_media_reactions",
|
||||
"breakpoints": true
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
19
backend/db/schema/chat_reactions.ts
Normal file
19
backend/db/schema/chat_reactions.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import { sql } from "drizzle-orm"
|
||||
import { bigint, check, pgTable, primaryKey, text, uuid } from "drizzle-orm/pg-core"
|
||||
import { authUsers } from "./auth_users"
|
||||
import { collaborationMessages, collaborationPrincipals } from "./collaboration"
|
||||
import { communicationMessages } from "./communication_messages"
|
||||
|
||||
export const communicationMessageReactions = pgTable("communication_message_reactions", {
|
||||
messageId: bigint("message_id", { mode: "number" }).notNull().references(() => communicationMessages.id, { onDelete: "cascade" }),
|
||||
actorId: uuid("actor_id").notNull().references(() => authUsers.id, { onDelete: "cascade" }),
|
||||
emoji: text("emoji").notNull(),
|
||||
}, t => ({ pk: primaryKey({ columns: [t.messageId, t.actorId, t.emoji] }),
|
||||
emoji: check("communication_message_reactions_emoji_check", sql`length(${t.emoji}) BETWEEN 1 AND 16`) }))
|
||||
|
||||
export const collaborationMessageReactions = pgTable("collaboration_message_reactions", {
|
||||
messageId: uuid("message_id").notNull().references(() => collaborationMessages.id, { onDelete: "cascade" }),
|
||||
actorId: uuid("actor_id").notNull().references(() => collaborationPrincipals.id, { onDelete: "cascade" }),
|
||||
emoji: text("emoji").notNull(),
|
||||
}, t => ({ pk: primaryKey({ columns: [t.messageId, t.actorId, t.emoji] }),
|
||||
emoji: check("collaboration_message_reactions_emoji_check", sql`length(${t.emoji}) BETWEEN 1 AND 16`) }))
|
||||
@@ -50,10 +50,10 @@ export const collaborationMembers = pgTable("collaboration_members", {
|
||||
export const collaborationMessages = pgTable("collaboration_messages", {
|
||||
id: uuid("id").primaryKey().defaultRandom(), roomId: uuid("room_id").notNull().references(() => collaborationRooms.id, { onDelete: "cascade" }),
|
||||
seq: bigint("seq", { mode: "number" }).notNull(), principalId: uuid("principal_id").notNull().references(() => collaborationPrincipals.id),
|
||||
clientId: uuid("client_id").notNull(), body: text("body").notNull(), createdAt: time("created_at").notNull().defaultNow(),
|
||||
clientId: uuid("client_id").notNull(), body: text("body").notNull(), image: jsonb("image"), createdAt: time("created_at").notNull().defaultNow(),
|
||||
}, t => ({ seq: uniqueIndex("collaboration_messages_room_id_seq_key").on(t.roomId, t.seq),
|
||||
command: uniqueIndex("collaboration_messages_room_id_principal_id_client_id_key").on(t.roomId, t.principalId, t.clientId),
|
||||
body: check("collaboration_messages_body_check", sql`length(${t.body}) BETWEEN 1 AND 10000`) }))
|
||||
body: check("collaboration_messages_body_check", sql`length(${t.body}) <= 10000 AND (length(${t.body}) > 0 OR ${t.image} IS NOT NULL)`) }))
|
||||
export const collaborationInvitations = pgTable("collaboration_invitations", {
|
||||
id: uuid("id").primaryKey().defaultRandom(), roomId: uuid("room_id").notNull().references(() => collaborationRooms.id, { onDelete: "cascade" }),
|
||||
targetPrincipalId: uuid("target_principal_id").notNull().references(() => collaborationPrincipals.id), tokenHash: text("token_hash").notNull().unique(),
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { bigint, index, pgTable, text, timestamp, uuid } from "drizzle-orm/pg-core"
|
||||
import { bigint, index, jsonb, pgTable, text, timestamp, uuid } from "drizzle-orm/pg-core"
|
||||
|
||||
import { authUsers } from "./auth_users"
|
||||
import { communicationRooms } from "./communication_rooms"
|
||||
@@ -20,6 +20,7 @@ export const communicationMessages = pgTable(
|
||||
.notNull()
|
||||
.references(() => authUsers.id),
|
||||
body: text("body").notNull(),
|
||||
image: jsonb("image"),
|
||||
createdAt: timestamp("created_at", { withTimezone: true })
|
||||
.notNull()
|
||||
.defaultNow(),
|
||||
|
||||
@@ -106,3 +106,5 @@ export * from "./collaboration";
|
||||
|
||||
export * from "./collaboration_federation"
|
||||
export * from './staff_time_spans'
|
||||
|
||||
export * from "./chat_reactions"
|
||||
|
||||
Reference in New Issue
Block a user