akf-forum/models/Message.js
Akif9748 db61361a95 Major update named as minor!
Forum Setup page,
edit forum config w/api
ban user's all ips,
secretmodel deleted,
/undelete is disabled
and better themes
if user reacted a message, view it
fixs for reactions of messages
discord auth in config.json
2022-09-23 23:10:13 +03:00

39 lines
No EOL
989 B
JavaScript

const mongoose = require("mongoose");
const cache = require("./cache");
const { limits } = require("../config.json");
const schema = new mongoose.Schema({
id: { type: String, unique: true },
author: Object,
threadID: String,
authorID: String,
content: { type: String, maxlength: limits.message },
oldContents: [String],
time: { type: Date, default: Date.now },
deleted: { type: Boolean, default: false },
edited: { type: Boolean, default: false },
react: {
like: [String],
dislike: [String]
}
})
schema.methods.get_author = cache.getAuthor
schema.methods.takeId = async function () {
this.id = String(await model.count() || 0);
return this;
}
schema.methods.getLink = function (id = this.id) {
return "/messages/" + id;
}
const model = mongoose.model('message', schema);
model.get = async id => {
const message = await model.findOne({ id })
return await message.get_author();
};
module.exports = model;