Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Sharkey
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Essem
Sharkey
Commits
a81a34cd
Commit
a81a34cd
authored
6 years ago
by
syuilo
Browse files
Options
Downloads
Patches
Plain Diff
新形式に移行
parent
118db9b2
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/server/api/endpoints/notes/timeline.ts
+77
-44
77 additions, 44 deletions
src/server/api/endpoints/notes/timeline.ts
with
77 additions
and
44 deletions
src/server/api/endpoints/notes/timeline.ts
+
77
−
44
View file @
a81a34cd
...
...
@@ -4,47 +4,80 @@ import Mute from '../../../../models/mute';
import
{
getFriends
}
from
'
../../common/get-friends
'
;
import
{
pack
}
from
'
../../../../models/note
'
;
import
{
ILocalUser
}
from
'
../../../../models/user
'
;
import
getParams
from
'
../../get-params
'
;
/**
* Get timeline of myself
*/
export
default
async
(
params
:
any
,
user
:
ILocalUser
)
=>
{
// Get 'limit' parameter
const
[
limit
=
10
,
limitErr
]
=
$
.
num
.
optional
.
range
(
1
,
100
).
get
(
params
.
limit
);
if
(
limitErr
)
throw
'
invalid limit param
'
;
export
const
meta
=
{
name
:
'
notes/timeline
'
,
// Get 'sinceId' parameter
const
[
sinceId
,
sinceIdErr
]
=
$
.
type
(
ID
).
optional
.
get
(
params
.
sinceId
);
if
(
sinceIdErr
)
throw
'
invalid sinceId param
'
;
desc
:
{
ja
:
'
タイムラインを取得します。
'
},
// Get 'untilId' parameter
const
[
untilId
,
untilIdErr
]
=
$
.
type
(
ID
).
optional
.
get
(
params
.
untilId
);
if
(
untilIdErr
)
throw
'
invalid untilId param
'
;
params
:
{
limit
:
$
.
num
.
optional
.
range
(
1
,
100
).
note
({
default
:
10
,
desc
:
{
ja
:
'
最大数
'
}
}),
// Get 'sinceDate' parameter
const
[
sinceDate
,
sinceDateErr
]
=
$
.
num
.
optional
.
get
(
params
.
sinceDate
);
if
(
sinceDateErr
)
throw
'
invalid sinceDate param
'
;
sinceId
:
$
.
type
(
ID
).
optional
.
note
({
desc
:
{
ja
:
'
指定すると、この投稿を基点としてより新しい投稿を取得します
'
}
}),
// Get 'untilDate' parameter
const
[
untilDate
,
untilDateErr
]
=
$
.
num
.
optional
.
get
(
params
.
untilDate
);
if
(
untilDateErr
)
throw
'
invalid untilDate param
'
;
untilId
:
$
.
type
(
ID
).
optional
.
note
({
desc
:
{
ja
:
'
指定すると、この投稿を基点としてより古い投稿を取得します
'
}
}),
// Check if only one of sinceId, untilId, sinceDate, untilDate specified
if
([
sinceId
,
untilId
,
sinceDate
,
untilDate
].
filter
(
x
=>
x
!=
null
).
length
>
1
)
{
throw
'
only one of sinceId, untilId, sinceDate, untilDate can be specified
'
;
}
sinceDate
:
$
.
num
.
optional
.
note
({
desc
:
{
ja
:
'
指定した時間を基点としてより新しい投稿を取得します。数値は、1970 年 1 月 1 日 00:00:00 UTC から指定した日時までの経過時間をミリ秒単位で表します。
'
}
}),
// Get 'includeMyRenotes' parameter
const
[
includeMyRenotes
=
true
,
includeMyRenotesErr
]
=
$
.
bool
.
optional
.
get
(
params
.
includeMyRenotes
);
if
(
includeMyRenotesErr
)
throw
'
invalid includeMyRenotes param
'
;
untilDate
:
$
.
num
.
optional
.
note
({
desc
:
{
ja
:
'
指定した時間を基点としてより古い投稿を取得します。数値は、1970 年 1 月 1 日 00:00:00 UTC から指定した日時までの経過時間をミリ秒単位で表します。
'
}
}),
// Get 'includeRenotedMyNotes' parameter
const
[
includeRenotedMyNotes
=
true
,
includeRenotedMyNotesErr
]
=
$
.
bool
.
optional
.
get
(
params
.
includeRenotedMyNotes
);
if
(
includeRenotedMyNotesErr
)
throw
'
invalid includeRenotedMyNotes param
'
;
includeMyRenotes
:
$
.
bool
.
optional
.
note
({
default
:
true
,
desc
:
{
ja
:
'
自分の行ったRenoteを含めるかどうか
'
}
}),
// Get 'mediaOnly' parameter
const
[
mediaOnly
,
mediaOnlyErr
]
=
$
.
bool
.
optional
.
get
(
params
.
mediaOnly
);
if
(
mediaOnlyErr
)
throw
'
invalid mediaOnly param
'
;
includeRenotedMyNotes
:
$
.
bool
.
optional
.
note
({
default
:
true
,
desc
:
{
ja
:
'
Renoteされた自分の投稿を含めるかどうか
'
}
}),
mediaOnly
:
$
.
bool
.
optional
.
note
({
desc
:
{
ja
:
'
true にすると、メディアが添付された投稿だけ取得します
'
}
}),
}
};
/**
* Get timeline of myself
*/
export
default
async
(
params
:
any
,
user
:
ILocalUser
)
=>
{
const
[
ps
,
psErr
]
=
getParams
(
meta
,
params
);
if
(
psErr
)
throw
psErr
;
// Check if only one of sinceId, untilId, sinceDate, untilDate specified
if
([
ps
.
sinceId
,
ps
.
untilId
,
ps
.
sinceDate
,
ps
.
untilDate
].
filter
(
x
=>
x
!=
null
).
length
>
1
)
{
throw
'
only one of sinceId, untilId, sinceDate, untilDate can be specified
'
;
}
const
[
followings
,
mutedUserIds
]
=
await
Promise
.
all
([
// フォローを取得
...
...
@@ -107,7 +140,7 @@ export default async (params: any, user: ILocalUser) => {
// つまり、「『自分の投稿かつRenote』ではない」を「『自分の投稿ではない』または『Renoteではない』」と表現します。
// for details: https://en.wikipedia.org/wiki/De_Morgan%27s_laws
if
(
includeMyRenotes
===
false
)
{
if
(
ps
.
includeMyRenotes
===
false
)
{
query
.
$and
.
push
({
$or
:
[{
userId
:
{
$ne
:
user
.
_id
}
...
...
@@ -123,7 +156,7 @@ export default async (params: any, user: ILocalUser) => {
});
}
if
(
includeRenotedMyNotes
===
false
)
{
if
(
ps
.
includeRenotedMyNotes
===
false
)
{
query
.
$and
.
push
({
$or
:
[{
'
_renote.userId
'
:
{
$ne
:
user
.
_id
}
...
...
@@ -139,29 +172,29 @@ export default async (params: any, user: ILocalUser) => {
});
}
if
(
mediaOnly
)
{
if
(
ps
.
mediaOnly
)
{
query
.
$and
.
push
({
mediaIds
:
{
$exists
:
true
,
$ne
:
[]
}
});
}
if
(
sinceId
)
{
if
(
ps
.
sinceId
)
{
sort
.
_id
=
1
;
query
.
_id
=
{
$gt
:
sinceId
$gt
:
ps
.
sinceId
};
}
else
if
(
untilId
)
{
}
else
if
(
ps
.
untilId
)
{
query
.
_id
=
{
$lt
:
untilId
$lt
:
ps
.
untilId
};
}
else
if
(
sinceDate
)
{
}
else
if
(
ps
.
sinceDate
)
{
sort
.
_id
=
1
;
query
.
createdAt
=
{
$gt
:
new
Date
(
sinceDate
)
$gt
:
new
Date
(
ps
.
sinceDate
)
};
}
else
if
(
untilDate
)
{
}
else
if
(
ps
.
untilDate
)
{
query
.
createdAt
=
{
$lt
:
new
Date
(
untilDate
)
$lt
:
new
Date
(
ps
.
untilDate
)
};
}
//#endregion
...
...
@@ -169,7 +202,7 @@ export default async (params: any, user: ILocalUser) => {
// Issue query
const
timeline
=
await
Note
.
find
(
query
,
{
limit
:
limit
,
limit
:
ps
.
limit
,
sort
:
sort
});
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment