forked from CMU-313/cmu-313-f24-nodebb-f24-NodeBB
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
9 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,27 @@ | ||
'use strict'; | ||
|
||
const db = require('../database'); | ||
const plugins = require('../plugins'); | ||
|
||
module.exports = function (Posts) { | ||
Posts.answer = async function (pid, uid) { | ||
return await toggleAnswered('answer', pid, uid); | ||
}; | ||
|
||
Posts.unanswer = async function (pid, uid) { | ||
return await toggleAnswered('unanswer', pid, uid); | ||
}; | ||
Posts.unanswer = async function (pid, uid) { | ||
return await toggleAnswered('unanswer', pid, uid); | ||
}; | ||
|
||
async function toggleAnswered(type, pid, uid) { | ||
const isAnswering = type === 'answer'; | ||
await plugins.hooks.fire(`filter:post.${type}`, { pid: pid, uid: uid }); | ||
const isAnswering = type === 'answer'; | ||
await plugins.hooks.fire(`filter:post.${type}`, { pid: pid, uid: uid }); | ||
|
||
await Posts.setPostFields(pid, { | ||
await Posts.setPostFields(pid, { | ||
answered: isAnswering ? 1 : 0, | ||
answererUid: isAnswering ? uid : 0, | ||
}); | ||
|
||
const postData = await Posts.getPostFields(pid, ['pid', 'tid', 'uid', 'content', 'timestamp']); | ||
|
||
return postData; | ||
}; | ||
} | ||
} | ||
}; |