mirror of
https://github.com/Akif9748/akf-forum.git
synced 2024-11-29 22:20:41 +03:00
45 lines
No EOL
1.3 KiB
JavaScript
45 lines
No EOL
1.3 KiB
JavaScript
|
|
const User = require("./user")
|
|
const Thread = require("./thread")
|
|
const db = require("quick.db");
|
|
module.exports = class Message {
|
|
|
|
|
|
constructor(content, author = new User(), thread = new Thread(), time = new Date().getTime(), deleted = false, edited = false, react = {}) {
|
|
|
|
|
|
this.content = content;
|
|
this.author = author;
|
|
this.time = time;
|
|
this.thread = thread;
|
|
this.deleted = deleted;
|
|
this.edited = edited;
|
|
this.react = react;
|
|
}
|
|
getId(id = this.id) {
|
|
const message = db.get("messages").find(msg => msg.id == id);
|
|
if (!message) return null;
|
|
|
|
this.id = Number(id);
|
|
const { content, author, thread = new Thread(), time = new Date().getTime(), deleted = false, edited = false, react = {} } = message;
|
|
this.content = content;
|
|
this.thread = thread;
|
|
this.author = author;
|
|
this.time = time;
|
|
this.deleted = deleted;
|
|
this.edited = edited;
|
|
this.react = react;
|
|
return this
|
|
}
|
|
takeId() {
|
|
this.id = db.get("messages").length || 0;
|
|
return this;
|
|
}
|
|
write(id = this.id) {
|
|
db.set("messages." + id, this)
|
|
return this;
|
|
}
|
|
getLink(id = this.id) {
|
|
return "/messages/" + id;
|
|
}
|
|
} |