feat: add message attachments (wip)
This commit is contained in:
@@ -218,6 +218,9 @@ export const schema = S.Collections({
|
||||
topic: S.RelationOne('topics', {
|
||||
where: [['id', '=', '$topicId']],
|
||||
}),
|
||||
attachments: S.RelationMany('attachments', {
|
||||
where: [['messageId', '=', '$id']],
|
||||
}),
|
||||
parts: S.RelationMany('message_parts', {
|
||||
where: [['messageId', '=', '$id']],
|
||||
}),
|
||||
@@ -259,6 +262,80 @@ export const schema = S.Collections({
|
||||
},
|
||||
},
|
||||
},
|
||||
// we split up the files and attachments table because we want to be able to
|
||||
// store files on their own so they can be used in multiple messages at once
|
||||
files: {
|
||||
schema: S.Schema({
|
||||
id: S.Id(),
|
||||
userId: S.String(),
|
||||
name: S.String(),
|
||||
mimeType: S.String(),
|
||||
url: S.String(),
|
||||
createdAt: S.Date({ default: S.Default.now() }),
|
||||
}),
|
||||
permissions: {
|
||||
authenticated: {
|
||||
read: {
|
||||
filter: [['userId', '=', '$token.sub']],
|
||||
},
|
||||
insert: {
|
||||
filter: [['userId', '=', '$token.sub']],
|
||||
},
|
||||
update: {
|
||||
filter: [['userId', '=', '$token.sub']],
|
||||
},
|
||||
postUpdate: {
|
||||
filter: [['userId', '=', '$prev.userId']],
|
||||
},
|
||||
delete: {
|
||||
filter: [['userId', '=', '$token.sub']],
|
||||
},
|
||||
},
|
||||
}
|
||||
},
|
||||
attachments: {
|
||||
schema: S.Schema({
|
||||
id: S.Id(),
|
||||
userId: S.String(),
|
||||
topicId: S.String(),
|
||||
messageId: S.String(),
|
||||
fileId: S.String(),
|
||||
// Denormalized for zero-subquery rendering. However, this can be
|
||||
// dangerous. It is absolutely PARAMOUNT that whenver a file is
|
||||
// modified, it's children attachments are modified as well.
|
||||
name: S.String(),
|
||||
mimeType: S.String(),
|
||||
url: S.String(),
|
||||
createdAt: S.Date({ default: S.Default.now() }),
|
||||
}),
|
||||
relationships: {
|
||||
topic: S.RelationOne('topics', {
|
||||
where: [['id', '=', '$topicId']],
|
||||
}),
|
||||
message: S.RelationOne('messages', {
|
||||
where: [['id', '=', '$messageId']],
|
||||
}),
|
||||
},
|
||||
permissions: {
|
||||
authenticated: {
|
||||
read: {
|
||||
filter: [['userId', '=', '$token.sub']],
|
||||
},
|
||||
insert: {
|
||||
filter: [['userId', '=', '$token.sub']],
|
||||
},
|
||||
update: {
|
||||
filter: [['userId', '=', '$token.sub']],
|
||||
},
|
||||
postUpdate: {
|
||||
filter: [['userId', '=', '$prev.userId']],
|
||||
},
|
||||
delete: {
|
||||
filter: [['userId', '=', '$token.sub']],
|
||||
},
|
||||
}
|
||||
}
|
||||
},
|
||||
generations: {
|
||||
schema: S.Schema({
|
||||
id: S.Id(),
|
||||
|
||||
Reference in New Issue
Block a user