diff --git a/src/components/timeline/timeline.js b/src/components/timeline/timeline.js
index 5e24bd15..aac3869f 100644
--- a/src/components/timeline/timeline.js
+++ b/src/components/timeline/timeline.js
@@ -1,7 +1,20 @@
import Status from '../status/status.vue'
import timelineFetcher from '../../services/timeline_fetcher/timeline_fetcher.service.js'
import Conversation from '../conversation/conversation.vue'
-import { throttle } from 'lodash'
+import { throttle, keyBy } from 'lodash'
+
+export const getExcludedStatusIdsByPinning = (statuses, pinnedStatusIds) => {
+ const ids = []
+ if (pinnedStatusIds && pinnedStatusIds.length > 0) {
+ for (let status of statuses) {
+ if (!pinnedStatusIds.includes(status.id)) {
+ break
+ }
+ ids.push(status.id)
+ }
+ }
+ return ids
+}
const Timeline = {
props: [
@@ -11,7 +24,8 @@ const Timeline = {
'userId',
'tag',
'embedded',
- 'count'
+ 'count',
+ 'pinnedStatusIds'
],
data () {
return {
@@ -39,6 +53,12 @@ const Timeline = {
body: ['timeline-body'].concat(!this.embedded ? ['panel-body'] : []),
footer: ['timeline-footer'].concat(!this.embedded ? ['panel-footer'] : [])
}
+ },
+ // id map of statuses which need to be hidden in the main list due to pinning logic
+ excludedStatusIdsObject () {
+ const ids = getExcludedStatusIdsByPinning(this.timeline.visibleStatuses, this.pinnedStatusIds)
+ // Convert id array to object
+ return keyBy(ids, id => id)
}
},
components: {
diff --git a/src/components/timeline/timeline.vue b/src/components/timeline/timeline.vue
index 1fc52083..0cb4b3ef 100644
--- a/src/components/timeline/timeline.vue
+++ b/src/components/timeline/timeline.vue
@@ -28,13 +28,25 @@
diff --git a/src/components/user_profile/user_profile.vue b/src/components/user_profile/user_profile.vue
index 4ea0a869..e862440e 100644
--- a/src/components/user_profile/user_profile.vue
+++ b/src/components/user_profile/user_profile.vue
@@ -15,25 +15,14 @@
:render-only-focused="true"
>
{
output.statuses_count = data.statuses_count
output.friendIds = []
output.followerIds = []
- output.pinnedStatuseIds = []
+ output.pinnedStatusIds = []
if (data.pleroma) {
output.follow_request_count = data.pleroma.follow_request_count
diff --git a/test/unit/specs/components/timeline.spec.js b/test/unit/specs/components/timeline.spec.js
new file mode 100644
index 00000000..0c8674a8
--- /dev/null
+++ b/test/unit/specs/components/timeline.spec.js
@@ -0,0 +1,27 @@
+import { getExcludedStatusIdsByPinning } from 'src/components/timeline/timeline.js'
+
+describe('Timeline', () => {
+ describe('getExcludedStatusIdsByPinning', () => {
+ const mockStatuses = (ids) => ids.map(id => ({ id }))
+
+ it('should return only members of both pinnedStatusIds and ids of the given statuses', () => {
+ const statusIds = [1, 2, 3, 4]
+ const statuses = mockStatuses(statusIds)
+ const pinnedStatusIds = [1, 3, 5]
+ const result = getExcludedStatusIdsByPinning(statuses, pinnedStatusIds)
+ result.forEach(item => {
+ expect(item).to.be.oneOf(statusIds)
+ expect(item).to.be.oneOf(pinnedStatusIds)
+ })
+ })
+
+ it('should return ids of pinned statuses not posted before any unpinned status', () => {
+ const pinnedStatusIdSet1 = ['PINNED1', 'PINNED2']
+ const pinnedStatusIdSet2 = ['PINNED3', 'PINNED4']
+ const pinnedStatusIds = [...pinnedStatusIdSet1, ...pinnedStatusIdSet2]
+ const statusIds = [...pinnedStatusIdSet1, 'UNPINNED1', ...pinnedStatusIdSet2]
+ const statuses = mockStatuses(statusIds)
+ expect(getExcludedStatusIdsByPinning(statuses, pinnedStatusIds)).to.eql(pinnedStatusIdSet1)
+ })
+ })
+})