This commit is contained in:
payacom
2026-08-31 20:45:41 +03:30
parent fa9f23c61d
commit 3f416a7a60
367 changed files with 621895 additions and 6443 deletions

View File

@@ -44,6 +44,16 @@ const messageSchema = new Schema({
type: Number,
default: 0
},
/** Countdown length in seconds — timer starts when receiver views the message */
selfDestructSeconds: {
type: Number,
required: false
},
/** When the receiver opened the message and the self-destruct timer started */
selfDestructStartedAt: {
type: Date,
required: false
},
/** Auto-delete after this time (self-destruct messages) */
expiresAt: {
type: Date,
@@ -58,9 +68,27 @@ const messageSchema = new Schema({
viewOnceOpenedAt: {
type: Date,
required: false
}
},
reactions: [
{
userId: {
type: mongoose.Schema.Types.ObjectId,
ref: 'User',
required: true
},
emoji: { type: String, required: true, trim: true }
}
]
})
// GET /api/v1/chat فیلتر $or روی هر دو جهتِ {senderId,receiverId} می‌زنه و createdAt
// رو سورت می‌کنه؛ messageController.js هم شمارشِ نخونده‌ها رو با {receiverId,senderId,
// readStatus} و {receiverId,readStatus} می‌زنه — همه‌ی این‌ها روی هر بارِ باز کردنِ
// لیستِ چت/یه ترد اجرا می‌شن، بدونِ ایندکس یعنی scan کاملِ کالکشن
messageSchema.index({ senderId: 1, receiverId: 1, createdAt: -1 })
messageSchema.index({ receiverId: 1, senderId: 1, createdAt: -1 })
messageSchema.index({ receiverId: 1, readStatus: 1 })
const MessageModel = mongoose.model('Message', messageSchema)
module.exports = MessageModel