You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
1.2 KiB
34 lines
1.2 KiB
// chat-message.js
|
|
// Copyright (C) 2024 DTP Technologies, LLC
|
|
// All Rights Reserved
|
|
|
|
'use strict';
|
|
|
|
import mongoose from 'mongoose';
|
|
const Schema = mongoose.Schema;
|
|
|
|
const CHANNEL_TYPE_LIST = ['User', 'ChatRoom'];
|
|
|
|
const ReactionSchema = new Schema({
|
|
emoji: { type: String },
|
|
users: { type: [Schema.ObjectId], ref: 'User' },
|
|
});
|
|
|
|
const ChatMessageSchema = new Schema({
|
|
created: { type: Date, default: Date.now, required: true, index: -1, expires: '30d' },
|
|
expires: { type: Date, index: -1 },
|
|
channelType: { type: String, enum: CHANNEL_TYPE_LIST, required: true },
|
|
channel: { type: Schema.ObjectId, required: true, index: 1, refPath: 'channelType' },
|
|
author: { type: Schema.ObjectId, required: true, index: 1, ref: 'User' },
|
|
content: { type: String },
|
|
mentions: { type: [Schema.ObjectId], select: false, ref: 'User' },
|
|
hashtags: { type: [String], select: false },
|
|
links: { type: [Schema.ObjectId], ref: 'Link' },
|
|
attachments: {
|
|
images: { type: [Schema.ObjectId], ref: 'Image' },
|
|
videos: { type: [Schema.ObjectId], ref: 'Video' },
|
|
},
|
|
reactions: { type: [ReactionSchema], default: [ ] },
|
|
});
|
|
|
|
export default mongoose.model('ChatMessage', ChatMessageSchema);
|