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
Wiki
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
Matrix-Sasuke
pleroma-fe
Commits
281c71b1
Commit
281c71b1
authored
8 years ago
by
lain
Browse files
Options
Downloads
Patches
Plain Diff
Move addNewStatuses code around.
parent
47ddf8c3
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/modules/statuses.js
+82
-80
82 additions, 80 deletions
src/modules/statuses.js
with
82 additions
and
80 deletions
src/modules/statuses.js
+
82
−
80
View file @
281c71b1
...
...
@@ -99,101 +99,103 @@ const mergeOrAdd = (arr, item) => {
}
}
export
const
mutations
=
{
addNewStatuses
(
state
,
{
statuses
,
showImmediately
=
false
,
timeline
,
user
=
{}
})
{
const
allStatuses
=
state
.
allStatuses
const
timelineObject
=
state
.
timelines
[
timeline
]
// Set the maxId to the new id if it's larger.
const
updateMaxId
=
({
id
})
=>
{
timelineObject
.
maxId
=
max
([
id
,
timelineObject
.
maxId
])
}
const
addStatus
=
(
status
,
showImmediately
,
addToTimeline
=
true
)
=>
{
const
result
=
mergeOrAdd
(
allStatuses
,
status
)
status
=
result
.
item
const
addNewStatuses
=
(
state
,
{
statuses
,
showImmediately
=
false
,
timeline
,
user
=
{}
})
=>
{
const
allStatuses
=
state
.
allStatuses
const
timelineObject
=
state
.
timelines
[
timeline
]
if
(
result
.
new
)
{
updateMaxId
(
status
)
}
// Set the maxId to the new id if it's larger.
const
updateMaxId
=
({
id
})
=>
{
timelineObject
.
maxId
=
max
([
id
,
timelineObject
.
maxId
])
}
// Some statuses should only be added to the global status repository.
if
(
addToTimeline
)
{
mergeOrAdd
(
timelineObject
.
statuses
,
status
)
}
const
addStatus
=
(
status
,
showImmediately
,
addToTimeline
=
true
)
=>
{
const
result
=
mergeOrAdd
(
allStatuses
,
status
)
status
=
result
.
item
if
(
showImmediately
)
{
// Add it directly to the visibleStatuses, don't change
// newStatusCount
mergeOrAdd
(
timelineObject
.
visibleStatuses
,
status
)
}
else
if
(
addToTimeline
&&
result
.
new
)
{
// Just change newStatuscount
timelineObject
.
newStatusCount
+=
1
}
if
(
result
.
new
)
{
updateMaxId
(
status
)
}
return
status
// Some statuses should only be added to the global status repository.
if
(
addToTimeline
)
{
mergeOrAdd
(
timelineObject
.
statuses
,
status
)
}
const
addNotification
=
({
type
,
status
,
action
})
=>
{
state
.
notifications
.
push
({
type
,
status
,
action
})
if
(
showImmediately
)
{
// Add it directly to the visibleStatuses, don't change
// newStatusCount
mergeOrAdd
(
timelineObject
.
visibleStatuses
,
status
)
}
else
if
(
addToTimeline
&&
result
.
new
)
{
// Just change newStatuscount
timelineObject
.
newStatusCount
+=
1
}
const
favoriteStatus
=
(
favorite
)
=>
{
const
status
=
find
(
allStatuses
,
{
id
:
toInteger
(
favorite
.
in_reply_to_status_id
)
})
if
(
status
)
{
status
.
fave_num
+=
1
if
(
status
.
user
.
id
===
user
.
id
)
{
addNotification
({
type
:
'
favorite
'
,
status
,
action
:
favorite
})
}
return
status
}
const
addNotification
=
({
type
,
status
,
action
})
=>
{
state
.
notifications
.
push
({
type
,
status
,
action
})
}
const
favoriteStatus
=
(
favorite
)
=>
{
const
status
=
find
(
allStatuses
,
{
id
:
toInteger
(
favorite
.
in_reply_to_status_id
)
})
if
(
status
)
{
status
.
fave_num
+=
1
if
(
status
.
user
.
id
===
user
.
id
)
{
addNotification
({
type
:
'
favorite
'
,
status
,
action
:
favorite
})
}
return
status
}
return
status
}
const
processors
=
{
'
status
'
:
(
status
)
=>
{
addStatus
(
status
,
showImmediately
)
},
'
retweet
'
:
(
status
)
=>
{
// RetweetedStatuses are never shown immediately
const
retweetedStatus
=
addStatus
(
status
.
retweeted_status
,
false
,
false
)
let
retweet
// If the retweeted status is already there, don't add the retweet
// to the timeline.
if
(
find
(
timelineObject
.
visibleStatuses
,
{
id
:
retweetedStatus
.
id
}))
{
// Already have it visible, don't add to timeline, don't show.
retweet
=
addStatus
(
status
,
false
,
false
)
}
else
{
retweet
=
addStatus
(
status
,
showImmediately
)
}
retweet
.
retweeted_status
=
retweetedStatus
},
'
favorite
'
:
(
favorite
)
=>
{
updateMaxId
(
favorite
)
favoriteStatus
(
favorite
)
},
'
deletion
'
:
({
uri
})
=>
{
remove
(
allStatuses
,
{
tag
:
uri
})
remove
(
timelineObject
.
statuses
,
{
tag
:
uri
})
remove
(
timelineObject
.
visibleStatuses
,
{
tag
:
uri
})
},
'
default
'
:
(
unknown
)
=>
{
console
.
log
(
unknown
)
const
processors
=
{
'
status
'
:
(
status
)
=>
{
addStatus
(
status
,
showImmediately
)
},
'
retweet
'
:
(
status
)
=>
{
// RetweetedStatuses are never shown immediately
const
retweetedStatus
=
addStatus
(
status
.
retweeted_status
,
false
,
false
)
let
retweet
// If the retweeted status is already there, don't add the retweet
// to the timeline.
if
(
find
(
timelineObject
.
visibleStatuses
,
{
id
:
retweetedStatus
.
id
}))
{
// Already have it visible, don't add to timeline, don't show.
retweet
=
addStatus
(
status
,
false
,
false
)
}
else
{
retweet
=
addStatus
(
status
,
showImmediately
)
}
retweet
.
retweeted_status
=
retweetedStatus
},
'
favorite
'
:
(
favorite
)
=>
{
updateMaxId
(
favorite
)
favoriteStatus
(
favorite
)
},
'
deletion
'
:
({
uri
})
=>
{
remove
(
allStatuses
,
{
tag
:
uri
})
remove
(
timelineObject
.
statuses
,
{
tag
:
uri
})
remove
(
timelineObject
.
visibleStatuses
,
{
tag
:
uri
})
},
'
default
'
:
(
unknown
)
=>
{
console
.
log
(
unknown
)
}
}
each
(
statuses
,
(
status
)
=>
{
const
type
=
statusType
(
status
)
const
processor
=
processors
[
type
]
||
processors
[
'
default
'
]
processor
(
status
)
})
each
(
statuses
,
(
status
)
=>
{
const
type
=
statusType
(
status
)
const
processor
=
processors
[
type
]
||
processors
[
'
default
'
]
processor
(
status
)
})
// 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
},
// 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
}
export
const
mutations
=
{
addNewStatuses
,
showNewStatuses
(
state
,
{
timeline
})
{
const
oldTimeline
=
(
state
.
timelines
[
timeline
])
...
...
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