From a471f19f043d4e7a412d2a407f0d2b6c5b4d2f2d Mon Sep 17 00:00:00 2001 From: Akif9748 Date: Sun, 9 Oct 2022 20:58:55 +0300 Subject: [PATCH] message&thread search user profile --- models/Message.js | 11 +++++++++-- models/Thread.js | 11 +++++++++-- models/cache.js | 11 ++++++++--- public/css/user.css | 24 ++++++++++++------------ views/user.ejs | 6 +++--- 5 files changed, 41 insertions(+), 22 deletions(-) diff --git a/models/Message.js b/models/Message.js index 356ffcc..35ae4df 100644 --- a/models/Message.js +++ b/models/Message.js @@ -4,9 +4,16 @@ const { limits } = require("../config.json"); const schema = new mongoose.Schema({ id: { type: String, unique: true }, - author: Object, + authorID: { + type: String, get(v) { return v || this.author?.id } + }, + author: { + type: Object, set(v) { + this.authorID = v.id; + return v; + } + }, threadID: String, - authorID: String, content: { type: String, maxlength: limits.message }, oldContents: [String], time: { type: Date, default: Date.now }, diff --git a/models/Thread.js b/models/Thread.js index 4525a71..89eb0b1 100644 --- a/models/Thread.js +++ b/models/Thread.js @@ -7,8 +7,15 @@ const schema = new mongoose.Schema({ id: { type: String, unique: true }, categoryID: String, - authorID: String, - author: Object, + authorID: { + type: String, get(v) { return v || this.author?.id } + }, + author: { + type: Object, set(v) { + this.authorID = v.id; + return v; + } + }, title: { type: String, maxlength: limits.title }, oldTitles: [String], diff --git a/models/cache.js b/models/cache.js index 9ffc90a..a2322c4 100644 --- a/models/cache.js +++ b/models/cache.js @@ -4,10 +4,15 @@ const UserCache = []; module.exports.getAuthor = async function () { const id = this.authorID || this.author?.id; let user = UserCache.find(user => user?.id == id) - if (!user) { - user = await UserModel.findOne({ id }) - UserCache.push(user) + if (!user) + UserCache.push(user = await UserModel.findOne({ id })) + + if (!this.get('authorID', null, { getters: false })) { + this.authorID = user.id; + await this.save(); } + this.author = user; + return this; } \ No newline at end of file diff --git a/public/css/user.css b/public/css/user.css index 76f0b03..dc498a5 100644 --- a/public/css/user.css +++ b/public/css/user.css @@ -22,18 +22,18 @@ width: 100%; } -.box-title{ +.box-title { font-weight: 400; + color: var(--anti); } + .box-value { -font-weight: 300; -background-color: var(--main); -color: white; -font-size: 14px; -padding: 4px; -border-radius: 5px; -min-width: 50px; -text-align: center; -} - - + font-weight: 300; + background-color: var(--main); + color: white; + font-size: 14px; + padding: 4px; + border-radius: 5px; + min-width: 50px; + text-align: center; +} \ No newline at end of file diff --git a/views/user.ejs b/views/user.ejs index 79c5b30..ff4caab 100644 --- a/views/user.ejs +++ b/views/user.ejs @@ -148,11 +148,11 @@ color: var(--anti); <% } %>
-

Message:

-

<%= counts.message %>

+ Message: + <%= counts.message %>
-

Thread:

+ Thread:

<%= counts.thread %>