Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Sharkey
Manage
Activity
Members
Labels
Plan
Issues
336
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
23
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
TransFem.org
Sharkey
Commits
b7d056fb
Unverified
Commit
b7d056fb
authored
1 year ago
by
hutchisr
Committed by
GitHub
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
Use unique identifier for each follow request (#10600)
Co-authored-by:
anemone
<
anemoneya@icloud.com
>
parent
e3aeab81
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
packages/backend/src/core/UserFollowingService.ts
+5
-1
5 additions, 1 deletion
packages/backend/src/core/UserFollowingService.ts
packages/backend/src/server/ActivityPubServerService.ts
+63
-25
63 additions, 25 deletions
packages/backend/src/server/ActivityPubServerService.ts
with
68 additions
and
26 deletions
packages/backend/src/core/UserFollowingService.ts
+
5
−
1
View file @
b7d056fb
...
...
@@ -20,6 +20,7 @@ import { bindThis } from '@/decorators.js';
import
{
UserBlockingService
}
from
'
@/core/UserBlockingService.js
'
;
import
{
MetaService
}
from
'
@/core/MetaService.js
'
;
import
{
CacheService
}
from
'
@/core/CacheService.js
'
;
import
type
{
Config
}
from
'
@/config.js
'
;
import
Logger
from
'
../logger.js
'
;
const
logger
=
new
Logger
(
'
following/create
'
);
...
...
@@ -44,6 +45,9 @@ export class UserFollowingService implements OnModuleInit {
constructor
(
private
moduleRef
:
ModuleRef
,
@
Inject
(
DI
.
config
)
private
config
:
Config
,
@
Inject
(
DI
.
usersRepository
)
private
usersRepository
:
UsersRepository
,
...
...
@@ -411,7 +415,7 @@ export class UserFollowingService implements OnModuleInit {
}
if
(
this
.
userEntityService
.
isLocalUser
(
follower
)
&&
this
.
userEntityService
.
isRemoteUser
(
followee
))
{
const
content
=
this
.
apRendererService
.
addContext
(
this
.
apRendererService
.
renderFollow
(
follower
,
followee
));
const
content
=
this
.
apRendererService
.
addContext
(
this
.
apRendererService
.
renderFollow
(
follower
,
followee
,
requestId
??
`
${
this
.
config
.
url
}
/follows/
${
followRequest
.
id
}
`
));
this
.
queueService
.
deliver
(
follower
,
content
,
followee
.
inbox
,
false
);
}
}
...
...
This diff is collapsed.
Click to expand it.
packages/backend/src/server/ActivityPubServerService.ts
+
63
−
25
View file @
b7d056fb
...
...
@@ -6,7 +6,7 @@ import { Brackets, In, IsNull, LessThan, Not } from 'typeorm';
import
accepts
from
'
accepts
'
;
import
vary
from
'
vary
'
;
import
{
DI
}
from
'
@/di-symbols.js
'
;
import
type
{
FollowingsRepository
,
NotesRepository
,
EmojisRepository
,
NoteReactionsRepository
,
UserProfilesRepository
,
UserNotePiningsRepository
,
UsersRepository
}
from
'
@/models/index.js
'
;
import
type
{
FollowingsRepository
,
NotesRepository
,
EmojisRepository
,
NoteReactionsRepository
,
UserProfilesRepository
,
UserNotePiningsRepository
,
UsersRepository
,
FollowRequestsRepository
}
from
'
@/models/index.js
'
;
import
*
as
url
from
'
@/misc/prelude/url.js
'
;
import
type
{
Config
}
from
'
@/config.js
'
;
import
{
ApRendererService
}
from
'
@/core/activitypub/ApRendererService.js
'
;
...
...
@@ -54,6 +54,9 @@ export class ActivityPubServerService {
@
Inject
(
DI
.
followingsRepository
)
private
followingsRepository
:
FollowingsRepository
,
@
Inject
(
DI
.
followRequestsRepository
)
private
followRequestsRepository
:
FollowRequestsRepository
,
private
utilityService
:
UtilityService
,
private
userEntityService
:
UserEntityService
,
private
apRendererService
:
ApRendererService
,
...
...
@@ -205,22 +208,22 @@ export class ActivityPubServerService {
reply
.
code
(
400
);
return
;
}
const
page
=
request
.
query
.
page
===
'
true
'
;
const
user
=
await
this
.
usersRepository
.
findOneBy
({
id
:
userId
,
host
:
IsNull
(),
});
if
(
user
==
null
)
{
reply
.
code
(
404
);
return
;
}
//#region Check ff visibility
const
profile
=
await
this
.
userProfilesRepository
.
findOneByOrFail
({
userId
:
user
.
id
});
if
(
profile
.
ffVisibility
===
'
private
'
)
{
reply
.
code
(
403
);
reply
.
header
(
'
Cache-Control
'
,
'
public, max-age=30
'
);
...
...
@@ -231,31 +234,31 @@ export class ActivityPubServerService {
return
;
}
//#endregion
const
limit
=
10
;
const
partOf
=
`
${
this
.
config
.
url
}
/users/
${
userId
}
/following`
;
if
(
page
)
{
const
query
=
{
followerId
:
user
.
id
,
}
as
FindOptionsWhere
<
Following
>
;
// カーソルが指定されている場合
if
(
cursor
)
{
query
.
id
=
LessThan
(
cursor
);
}
// Get followings
const
followings
=
await
this
.
followingsRepository
.
find
({
where
:
query
,
take
:
limit
+
1
,
order
:
{
id
:
-
1
},
});
// 「次のページ」があるかどうか
const
inStock
=
followings
.
length
===
limit
+
1
;
if
(
inStock
)
followings
.
pop
();
const
renderedFollowees
=
await
Promise
.
all
(
followings
.
map
(
following
=>
this
.
apRendererService
.
renderFollowUser
(
following
.
followeeId
)));
const
rendered
=
this
.
apRendererService
.
renderOrderedCollectionPage
(
`
${
partOf
}
?
${
url
.
query
({
...
...
@@ -269,7 +272,7 @@ export class ActivityPubServerService {
cursor
:
followings
[
followings
.
length
-
1
].
id
,
})}
`
:
undefined
,
);
this
.
setResponseType
(
request
,
reply
);
return
(
this
.
apRendererService
.
addContext
(
rendered
));
}
else
{
...
...
@@ -330,33 +333,33 @@ export class ActivityPubServerService {
reply
.
code
(
400
);
return
;
}
const
untilId
=
request
.
query
.
until_id
;
if
(
untilId
!=
null
&&
typeof
untilId
!==
'
string
'
)
{
reply
.
code
(
400
);
return
;
}
const
page
=
request
.
query
.
page
===
'
true
'
;
if
(
countIf
(
x
=>
x
!=
null
,
[
sinceId
,
untilId
])
>
1
)
{
reply
.
code
(
400
);
return
;
}
const
user
=
await
this
.
usersRepository
.
findOneBy
({
id
:
userId
,
host
:
IsNull
(),
});
if
(
user
==
null
)
{
reply
.
code
(
404
);
return
;
}
const
limit
=
20
;
const
partOf
=
`
${
this
.
config
.
url
}
/users/
${
userId
}
/outbox`
;
if
(
page
)
{
const
query
=
this
.
queryService
.
makePaginationQuery
(
this
.
notesRepository
.
createQueryBuilder
(
'
note
'
),
sinceId
,
untilId
)
.
andWhere
(
'
note.userId = :userId
'
,
{
userId
:
user
.
id
})
...
...
@@ -365,11 +368,11 @@ export class ActivityPubServerService {
.
orWhere
(
'
note.visibility =
\'
home
\'
'
);
}))
.
andWhere
(
'
note.localOnly = FALSE
'
);
const
notes
=
await
query
.
take
(
limit
).
getMany
();
if
(
sinceId
)
notes
.
reverse
();
const
activities
=
await
Promise
.
all
(
notes
.
map
(
note
=>
this
.
packActivity
(
note
)));
const
rendered
=
this
.
apRendererService
.
renderOrderedCollectionPage
(
`
${
partOf
}
?
${
url
.
query
({
...
...
@@ -387,7 +390,7 @@ export class ActivityPubServerService {
until_id
:
notes
[
notes
.
length
-
1
].
id
,
})}
`
:
undefined
,
);
this
.
setResponseType
(
request
,
reply
);
return
(
this
.
apRendererService
.
addContext
(
rendered
));
}
else
{
...
...
@@ -457,7 +460,7 @@ export class ActivityPubServerService {
// note
fastify
.
get
<
{
Params
:
{
note
:
string
;
}
}
>
(
'
/notes/:note
'
,
{
constraints
:
{
apOrHtml
:
'
ap
'
}
},
async
(
request
,
reply
)
=>
{
vary
(
reply
.
raw
,
'
Accept
'
);
const
note
=
await
this
.
notesRepository
.
findOneBy
({
id
:
request
.
params
.
note
,
visibility
:
In
([
'
public
'
,
'
home
'
]),
...
...
@@ -639,6 +642,41 @@ export class ActivityPubServerService {
return
(
this
.
apRendererService
.
addContext
(
this
.
apRendererService
.
renderFollow
(
follower
,
followee
)));
});
// follow
fastify
.
get
<
{
Params
:
{
followRequestId
:
string
;
}
}
>
(
'
/follows/:followRequestId
'
,
async
(
request
,
reply
)
=>
{
// This may be used before the follow is completed, so we do not
// check if the following exists and only check if the follow request exists.
const
followRequest
=
await
this
.
followRequestsRepository
.
findOneBy
({
id
:
request
.
params
.
followRequestId
,
});
if
(
followRequest
==
null
)
{
reply
.
code
(
404
);
return
;
}
const
[
follower
,
followee
]
=
await
Promise
.
all
([
this
.
usersRepository
.
findOneBy
({
id
:
followRequest
.
followerId
,
host
:
IsNull
(),
}),
this
.
usersRepository
.
findOneBy
({
id
:
followRequest
.
followeeId
,
host
:
Not
(
IsNull
()),
}),
]);
if
(
follower
==
null
||
followee
==
null
)
{
reply
.
code
(
404
);
return
;
}
reply
.
header
(
'
Cache-Control
'
,
'
public, max-age=180
'
);
this
.
setResponseType
(
request
,
reply
);
return
(
this
.
apRendererService
.
addContext
(
this
.
apRendererService
.
renderFollow
(
follower
,
followee
)));
});
done
();
}
}
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