Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
pleroma-fe
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
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
Pleroma
pleroma-fe
Commits
a5f52392
Commit
a5f52392
authored
8 years ago
by
lain
Browse files
Options
Downloads
Patches
Plain Diff
Make timelineless status adding possible.
parent
81c6f6e2
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
src/modules/statuses.js
+21
-11
21 additions, 11 deletions
src/modules/statuses.js
test/unit/specs/modules/statuses.spec.js
+12
-0
12 additions, 0 deletions
test/unit/specs/modules/statuses.spec.js
with
33 additions
and
11 deletions
src/modules/statuses.js
+
21
−
11
View file @
a5f52392
import
{
remove
,
map
,
slice
,
sortBy
,
toInteger
,
each
,
find
,
flatten
,
maxBy
,
last
,
merge
,
max
}
from
'
lodash
'
import
{
remove
,
map
,
slice
,
sortBy
,
toInteger
,
each
,
find
,
flatten
,
maxBy
,
last
,
merge
,
max
,
isArray
}
from
'
lodash
'
import
moment
from
'
moment
'
import
apiService
from
'
../services/api/api.service.js
'
// import parse from '../services/status_parser/status_parser.js'
...
...
@@ -100,11 +100,17 @@ const mergeOrAdd = (arr, item) => {
}
const
addNewStatuses
=
(
state
,
{
statuses
,
showImmediately
=
false
,
timeline
,
user
=
{}
})
=>
{
// Sanity check
if
(
!
isArray
(
statuses
))
{
return
false
}
const
allStatuses
=
state
.
allStatuses
const
timelineObject
=
state
.
timelines
[
timeline
]
// Set the maxId to the new id if it's larger.
const
updateMaxId
=
({
id
})
=>
{
if
(
!
timeline
)
{
return
false
}
timelineObject
.
maxId
=
max
([
id
,
timelineObject
.
maxId
])
}
...
...
@@ -117,15 +123,15 @@ const addNewStatuses = (state, { statuses, showImmediately = false, timeline, us
}
// Some statuses should only be added to the global status repository.
if
(
addToTimeline
)
{
if
(
timeline
&&
addToTimeline
)
{
mergeOrAdd
(
timelineObject
.
statuses
,
status
)
}
if
(
showImmediately
)
{
if
(
timeline
&&
showImmediately
)
{
// Add it directly to the visibleStatuses, don't change
// newStatusCount
mergeOrAdd
(
timelineObject
.
visibleStatuses
,
status
)
}
else
if
(
addToTimeline
&&
result
.
new
)
{
}
else
if
(
timeline
&&
addToTimeline
&&
result
.
new
)
{
// Just change newStatuscount
timelineObject
.
newStatusCount
+=
1
}
...
...
@@ -159,7 +165,7 @@ const addNewStatuses = (state, { statuses, showImmediately = false, timeline, us
let
retweet
// If the retweeted status is already there, don't add the retweet
// to the timeline.
if
(
find
(
timelineObject
.
visibleStatuses
,
{
id
:
retweetedStatus
.
id
}))
{
if
(
timeline
&&
find
(
timelineObject
.
visibleStatuses
,
{
id
:
retweetedStatus
.
id
}))
{
// Already have it visible, don't add to timeline, don't show.
retweet
=
addStatus
(
status
,
false
,
false
)
}
else
{
...
...
@@ -177,8 +183,10 @@ const addNewStatuses = (state, { statuses, showImmediately = false, timeline, us
updateMaxId
(
deletion
)
remove
(
allStatuses
,
{
uri
})
remove
(
timelineObject
.
statuses
,
{
uri
})
remove
(
timelineObject
.
visibleStatuses
,
{
uri
})
if
(
timeline
)
{
remove
(
timelineObject
.
statuses
,
{
uri
})
remove
(
timelineObject
.
visibleStatuses
,
{
uri
})
}
},
'
default
'
:
(
unknown
)
=>
{
console
.
log
(
unknown
)
...
...
@@ -192,9 +200,11 @@ const addNewStatuses = (state, { statuses, showImmediately = false, timeline, us
})
// Keep the visible statuses sorted
timelineObject
.
visibleStatuses
=
sortBy
(
timelineObject
.
visibleStatuses
,
({
id
})
=>
-
id
)
timelineObject
.
statuses
=
sortBy
(
timelineObject
.
statuses
,
({
id
})
=>
-
id
)
timelineObject
.
minVisibleId
=
(
last
(
timelineObject
.
statuses
)
||
{}).
id
if
(
timeline
)
{
timelineObject
.
visibleStatuses
=
sortBy
(
timelineObject
.
visibleStatuses
,
({
id
})
=>
-
id
)
timelineObject
.
statuses
=
sortBy
(
timelineObject
.
statuses
,
({
id
})
=>
-
id
)
timelineObject
.
minVisibleId
=
(
last
(
timelineObject
.
statuses
)
||
{}).
id
}
}
export
const
mutations
=
{
...
...
@@ -228,7 +238,7 @@ export const mutations = {
const
statuses
=
{
state
:
defaultState
,
actions
:
{
addNewStatuses
({
rootState
,
commit
},
{
statuses
,
showImmediately
=
false
,
timeline
})
{
addNewStatuses
({
rootState
,
commit
},
{
statuses
,
showImmediately
=
false
,
timeline
=
false
})
{
commit
(
'
addNewStatuses
'
,
{
statuses
,
showImmediately
,
timeline
,
user
:
rootState
.
users
.
currentUser
})
},
favorite
({
rootState
,
commit
},
status
)
{
...
...
This diff is collapsed.
Click to expand it.
test/unit/specs/modules/statuses.spec.js
+
12
−
0
View file @
a5f52392
...
...
@@ -67,6 +67,18 @@ describe('The Statuses module', () => {
expect
(
state
.
timelines
.
public
.
newStatusCount
).
to
.
equal
(
1
)
})
it
(
'
add the statuses to allStatuses if no timeline is given
'
,
()
=>
{
const
state
=
cloneDeep
(
defaultState
)
const
status
=
makeMockStatus
({
id
:
1
})
mutations
.
addNewStatuses
(
state
,
{
statuses
:
[
status
]
})
expect
(
state
.
allStatuses
).
to
.
eql
([
status
])
expect
(
state
.
timelines
.
public
.
statuses
).
to
.
eql
([])
expect
(
state
.
timelines
.
public
.
visibleStatuses
).
to
.
eql
([])
expect
(
state
.
timelines
.
public
.
newStatusCount
).
to
.
equal
(
0
)
})
it
(
'
adds the status to allStatuses and to the given timeline, directly visible
'
,
()
=>
{
const
state
=
cloneDeep
(
defaultState
)
const
status
=
makeMockStatus
({
id
:
1
})
...
...
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