Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
mastodon
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
Pierre Boudes
mastodon
Commits
0eaf6d76
Unverified
Commit
0eaf6d76
authored
6 years ago
by
Eugen Rochko
Committed by
GitHub
6 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Sort self-replies to the top of descendants (#9320)
Fix #6463
parent
87a43274
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
app/models/concerns/status_threading_concern.rb
+24
-2
24 additions, 2 deletions
app/models/concerns/status_threading_concern.rb
spec/models/concerns/status_threading_concern_spec.rb
+10
-0
10 additions, 0 deletions
spec/models/concerns/status_threading_concern_spec.rb
with
34 additions
and
2 deletions
app/models/concerns/status_threading_concern.rb
+
24
−
2
View file @
0eaf6d76
...
...
@@ -8,7 +8,7 @@ module StatusThreadingConcern
end
def
descendants
(
limit
,
account
=
nil
,
max_child_id
=
nil
,
since_child_id
=
nil
,
depth
=
nil
)
find_statuses_from_tree_path
(
descendant_ids
(
limit
,
max_child_id
,
since_child_id
,
depth
),
account
)
find_statuses_from_tree_path
(
descendant_ids
(
limit
,
max_child_id
,
since_child_id
,
depth
),
account
,
promote:
true
)
end
private
...
...
@@ -76,7 +76,7 @@ module StatusThreadingConcern
descendants_with_self
-
[
self
]
end
def
find_statuses_from_tree_path
(
ids
,
account
)
def
find_statuses_from_tree_path
(
ids
,
account
,
promote:
false
)
statuses
=
statuses_with_accounts
(
ids
).
to_a
account_ids
=
statuses
.
map
(
&
:account_id
).
uniq
domains
=
statuses
.
map
(
&
:account_domain
).
compact
.
uniq
...
...
@@ -86,6 +86,28 @@ module StatusThreadingConcern
# Order ancestors/descendants by tree path
statuses
.
sort_by!
{
|
status
|
ids
.
index
(
status
.
id
)
}
# Bring self-replies to the top
if
promote
promote_by!
(
statuses
)
{
|
status
|
status
.
in_reply_to_account_id
==
status
.
account_id
}
else
statuses
end
end
def
promote_by!
(
arr
)
insert_at
=
arr
.
find_index
{
|
item
|
!
yield
(
item
)
}
return
arr
if
insert_at
.
nil?
arr
.
each_with_index
do
|
item
,
index
|
next
if
index
<=
insert_at
||
!
yield
(
item
)
arr
.
insert
(
insert_at
,
arr
.
delete_at
(
index
))
insert_at
+=
1
end
arr
end
def
relations_map_for_account
(
account
,
account_ids
,
domains
)
...
...
This diff is collapsed.
Click to expand it.
spec/models/concerns/status_threading_concern_spec.rb
+
10
−
0
View file @
0eaf6d76
...
...
@@ -118,5 +118,15 @@ describe StatusThreadingConcern do
viewer
.
block_domain!
(
'example.com'
)
expect
(
status
.
descendants
(
4
,
viewer
)).
to_not
include
(
reply2
)
end
it
'promotes self-replies to the top while leaving the rest in order'
do
a
=
Fabricate
(
:status
,
account:
alice
)
d
=
Fabricate
(
:status
,
account:
jeff
,
thread:
a
)
e
=
Fabricate
(
:status
,
account:
bob
,
thread:
d
)
c
=
Fabricate
(
:status
,
account:
alice
,
thread:
a
)
f
=
Fabricate
(
:status
,
account:
bob
,
thread:
c
)
expect
(
a
.
descendants
(
20
)).
to
eq
[
c
,
d
,
e
,
f
]
end
end
end
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