forked from misskey-dev/misskey
-
Notifications
You must be signed in to change notification settings - Fork 12
/
locao-timeline.ts
196 lines (161 loc) · 3.85 KB
/
locao-timeline.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
import $ from 'cafy';
import ID, { transform } from '../../../../misc/cafy-id';
import define from '../../define';
import fetchMeta from '../../../../misc/fetch-meta';
import activeUsersChart from '../../../../services/chart/active-users';
import { getHideUserIds } from '../../common/get-hide-users';
import { ApiError } from '../../error';
import { getPackedTimeline } from '../../common/get-timeline';
export const meta = {
desc: {
'ja-JP': 'ローカオタイムラインを取得します。'
},
tags: ['notes'],
params: {
withFiles: {
validator: $.optional.bool,
desc: {
'ja-JP': 'ファイルが添付された投稿に限定するか否か'
}
},
mediaOnly: {
validator: $.optional.bool,
deprecated: true,
desc: {
'ja-JP': 'ファイルが添付された投稿に限定するか否か (このパラメータは廃止予定です。代わりに withFiles を使ってください。)'
}
},
fileType: {
validator: $.optional.arr($.str),
desc: {
'ja-JP': '指定された種類のファイルが添付された投稿のみを取得します'
}
},
excludeNsfw: {
validator: $.optional.bool,
default: false,
desc: {
'ja-JP': 'true にすると、NSFW指定されたファイルを除外します(fileTypeが指定されている場合のみ有効)'
}
},
excludeSfw: {
validator: $.optional.bool,
default: false,
desc: {
'ja-JP': 'true にすると、NSFW指定されてないファイルを除外します(fileTypeが指定されている場合のみ有効)'
}
},
limit: {
validator: $.optional.num.range(1, 100),
default: 10
},
sinceId: {
validator: $.optional.type(ID),
transform: transform,
},
untilId: {
validator: $.optional.type(ID),
transform: transform,
},
sinceDate: {
validator: $.optional.num,
},
untilDate: {
validator: $.optional.num,
},
},
res: {
type: 'array',
items: {
type: 'Note',
},
},
errors: {
ltlDisabled: {
message: 'Local timeline has been disabled.',
code: 'LTL_DISABLED',
id: '45a6eb02-7695-4393-b023-dd3be9aaaefd'
},
}
};
export default define(meta, async (ps, user) => {
const m = await fetchMeta();
if (m.disableLocalTimeline) {
throw new ApiError(meta.errors.ltlDisabled);
}
// 隠すユーザーを取得
const hideUserIds = await getHideUserIds(user);
//#region Construct query
const sort = {
_id: -1
};
const query = {
// local
'_user.host': null,
// public only
visibility: 'public',
localOnly: true,
deletedAt: null,
$and: [ {} ]
} as any;
if (!m.showReplayInPublicTimeline) {
query.replyId = null;
}
if (hideUserIds && hideUserIds.length > 0) {
query.userId = {
$nin: hideUserIds
};
// リプライを表示する設定じゃなければリプライ先のミュートは不要
if (m.showReplayInPublicTimeline) {
query['_reply.userId'] = {
$nin: hideUserIds
};
}
query['_renote.userId'] = {
$nin: hideUserIds
};
}
const withFiles = ps.withFiles != null ? ps.withFiles : ps.mediaOnly;
if (withFiles) {
query.fileIds = { $exists: true, $ne: [] };
}
if (ps.fileType) {
query.fileIds = { $exists: true, $ne: [] };
query['_files.contentType'] = {
$in: ps.fileType
};
if (ps.excludeNsfw) {
query['_files.metadata.isSensitive'] = {
$ne: true
};
query['cw'] = null;
}
if (ps.excludeSfw) {
query['_files.metadata.isSensitive'] = true;
}
}
if (ps.sinceId) {
sort._id = 1;
query._id = {
$gt: ps.sinceId
};
} else if (ps.untilId) {
query._id = {
$lt: ps.untilId
};
} else if (ps.sinceDate) {
sort._id = 1;
query.createdAt = {
$gt: new Date(ps.sinceDate)
};
} else if (ps.untilDate) {
query.createdAt = {
$lt: new Date(ps.untilDate)
};
}
//#endregion
if (user) {
activeUsersChart.update(user);
}
return await getPackedTimeline(user, query, sort, ps.limit!);
});