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
Dima Krasner
Sharkey
Commits
84fcf9ef
Verified
Commit
84fcf9ef
authored
1 year ago
by
Mar0xy
Browse files
Options
Downloads
Patches
Plain Diff
upd: change way of fetching descendants
parent
73b086b6
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
packages/megalodon/src/misskey.ts
+43
-1
43 additions, 1 deletion
packages/megalodon/src/misskey.ts
with
43 additions
and
1 deletion
packages/megalodon/src/misskey.ts
+
43
−
1
View file @
84fcf9ef
...
...
@@ -1203,7 +1203,7 @@ export default class Misskey implements MegalodonInterface {
);
const
context
:
Entity
.
Context
=
{
ancestors
:
parents
.
reverse
(),
descendants
:
res
.
data
.
map
(
n
=>
MisskeyAPI
.
Converter
.
note
(
n
,
this
.
baseUrl
))
descendants
:
this
.
dfs
(
await
Promise
.
all
(
res
.
data
.
map
(
n
=>
MisskeyAPI
.
Converter
.
note
(
n
,
this
.
baseUrl
))
))
}
return
{
...
res
,
...
...
@@ -1212,6 +1212,48 @@ export default class Misskey implements MegalodonInterface {
})
}
private
dfs
(
graph
:
Entity
.
Status
[])
{
// we don't need to run dfs if we have zero or one elements
if
(
graph
.
length
<=
1
)
{
return
graph
;
}
// sort the graph first, so we can grab the correct starting point
graph
=
graph
.
sort
((
a
,
b
)
=>
{
if
(
a
.
id
<
b
.
id
)
return
-
1
;
if
(
a
.
id
>
b
.
id
)
return
1
;
return
0
;
});
const
initialPostId
=
graph
[
0
].
in_reply_to_id
;
// populate stack with all top level replies
const
stack
=
graph
.
filter
((
reply
)
=>
reply
.
in_reply_to_id
===
initialPostId
)
.
reverse
();
const
visited
=
new
Set
();
const
result
=
[];
while
(
stack
.
length
)
{
const
currentPost
=
stack
.
pop
();
if
(
currentPost
===
undefined
)
return
result
;
if
(
!
visited
.
has
(
currentPost
))
{
visited
.
add
(
currentPost
);
result
.
push
(
currentPost
);
for
(
const
reply
of
graph
.
filter
((
reply
)
=>
reply
.
in_reply_to_id
===
currentPost
.
id
)
.
reverse
())
{
stack
.
push
(
reply
);
}
}
}
return
result
;
}
public
async
getStatusSource
(
_id
:
string
):
Promise
<
Response
<
Entity
.
StatusSource
>>
{
return
new
Promise
((
_
,
reject
)
=>
{
const
err
=
new
NoImplementedError
(
'
misskey does not support
'
)
...
...
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