summaryrefslogtreecommitdiff
path: root/src/models
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2018-09-10 02:43:16 +0900
committersyuilo <syuilotan@yahoo.co.jp>2018-09-10 02:43:16 +0900
commit6ac92ac4b86a2e9aeac55b7e1259a9dedcb7e379 (patch)
tree82cd5e475384863b3625684a3b366c93731f3fd1 /src/models
parent#2623 (diff)
downloadsharkey-6ac92ac4b86a2e9aeac55b7e1259a9dedcb7e379.tar.gz
sharkey-6ac92ac4b86a2e9aeac55b7e1259a9dedcb7e379.tar.bz2
sharkey-6ac92ac4b86a2e9aeac55b7e1259a9dedcb7e379.zip
Fix #2321
Diffstat (limited to 'src/models')
-rw-r--r--src/models/note.ts127
1 files changed, 68 insertions, 59 deletions
diff --git a/src/models/note.ts b/src/models/note.ts
index 181ebecf24..624bdbdfe8 100644
--- a/src/models/note.ts
+++ b/src/models/note.ts
@@ -162,6 +162,66 @@ export async function deleteNote(note: string | mongo.ObjectID | INote) {
console.log(`Note: deleted ${n._id}`);
}
+export const hideNote = async (packedNote: any, meId: mongo.ObjectID) => {
+ let hide = false;
+
+ // visibility が private かつ投稿者のIDが自分のIDではなかったら非表示
+ if (packedNote.visibility == 'private' && (meId == null || !meId.equals(packedNote.userId))) {
+ hide = true;
+ }
+
+ // visibility が specified かつ自分が指定されていなかったら非表示
+ if (packedNote.visibility == 'specified') {
+ if (meId == null) {
+ hide = true;
+ } else if (meId.equals(packedNote.userId)) {
+ hide = false;
+ } else {
+ // 指定されているかどうか
+ const specified = packedNote.visibleUserIds.some((id: mongo.ObjectID) => id.equals(meId));
+
+ if (specified) {
+ hide = false;
+ } else {
+ hide = true;
+ }
+ }
+ }
+
+ // visibility が followers かつ自分が投稿者のフォロワーでなかったら非表示
+ if (packedNote.visibility == 'followers') {
+ if (meId == null) {
+ hide = true;
+ } else if (meId.equals(packedNote.userId)) {
+ hide = false;
+ } else {
+ // フォロワーかどうか
+ const following = await Following.findOne({
+ followeeId: packedNote.userId,
+ followerId: meId
+ });
+
+ if (following == null) {
+ hide = true;
+ } else {
+ hide = false;
+ }
+ }
+ }
+
+ if (hide) {
+ packedNote.fileIds = [];
+ packedNote.files = [];
+ packedNote.text = null;
+ packedNote.poll = null;
+ packedNote.cw = null;
+ packedNote.tags = [];
+ packedNote.tagsLower = [];
+ packedNote.geo = null;
+ packedNote.isHidden = true;
+ }
+};
+
/**
* Pack a note for API response
*
@@ -174,11 +234,13 @@ export const pack = async (
note: string | mongo.ObjectID | INote,
me?: string | mongo.ObjectID | IUser,
options?: {
- detail: boolean
+ detail?: boolean;
+ skipHide?: boolean;
}
) => {
const opts = Object.assign({
- detail: true
+ detail: true,
+ skipHide: false
}, options);
// Me
@@ -207,52 +269,6 @@ export const pack = async (
if (!_note) throw `invalid note arg ${note}`;
- let hide = false;
-
- // visibility が private かつ投稿者のIDが自分のIDではなかったら非表示
- if (_note.visibility == 'private' && (meId == null || !meId.equals(_note.userId))) {
- hide = true;
- }
-
- // visibility が specified かつ自分が指定されていなかったら非表示
- if (_note.visibility == 'specified') {
- if (meId == null) {
- hide = true;
- } else if (meId.equals(_note.userId)) {
- hide = false;
- } else {
- // 指定されているかどうか
- const specified = _note.visibleUserIds.some((id: mongo.ObjectID) => id.equals(meId));
-
- if (specified) {
- hide = false;
- } else {
- hide = true;
- }
- }
- }
-
- // visibility が followers かつ自分が投稿者のフォロワーでなかったら非表示
- if (_note.visibility == 'followers') {
- if (meId == null) {
- hide = true;
- } else if (meId.equals(_note.userId)) {
- hide = false;
- } else {
- // フォロワーかどうか
- const following = await Following.findOne({
- followeeId: _note.userId,
- followerId: meId
- });
-
- if (following == null) {
- hide = true;
- } else {
- hide = false;
- }
- }
- }
-
const id = _note._id;
// Rename _id to id
@@ -274,7 +290,7 @@ export const pack = async (
}
// Populate files
- _note.files = hide ? [] : Promise.all(_note.fileIds.map((fileId: mongo.ObjectID) =>
+ _note.files = Promise.all(_note.fileIds.map((fileId: mongo.ObjectID) =>
packFile(fileId)
));
@@ -304,7 +320,7 @@ export const pack = async (
}
// Poll
- if (meId && _note.poll && !hide) {
+ if (meId && _note.poll) {
_note.poll = (async poll => {
const vote = await PollVote
.findOne({
@@ -349,15 +365,8 @@ export const pack = async (
_note.text = _note.text.replace(/な/g, 'にゃ').replace(/ナ/g, 'ニャ').replace(/ナ/g, 'ニャ');
}
- if (hide) {
- _note.fileIds = [];
- _note.text = null;
- _note.poll = null;
- _note.cw = null;
- _note.tags = [];
- _note.tagsLower = [];
- _note.geo = null;
- _note.isHidden = true;
+ if (!opts.skipHide) {
+ await hideNote(_note, meId);
}
return _note;