From 7ed9d17ce745abc38a27d4994452a136357aba46 Mon Sep 17 00:00:00 2001 From: shpuld Date: Sun, 7 Jul 2019 23:02:09 +0300 Subject: [PATCH 01/33] Add thread muting to context menu of status --- src/components/extra_buttons/extra_buttons.js | 15 ++++++++++++--- src/components/extra_buttons/extra_buttons.vue | 16 +++++++++++++++- src/i18n/en.json | 4 +++- src/i18n/fi.json | 9 ++++++++- src/modules/statuses.js | 12 ++++++++++++ src/services/api/api.service.js | 14 ++++++++++++++ .../backend_interactor_service.js | 4 ++++ .../entity_normalizer.service.js | 1 + 8 files changed, 69 insertions(+), 6 deletions(-) diff --git a/src/components/extra_buttons/extra_buttons.js b/src/components/extra_buttons/extra_buttons.js index 528da301f..56b2c41ef 100644 --- a/src/components/extra_buttons/extra_buttons.js +++ b/src/components/extra_buttons/extra_buttons.js @@ -34,6 +34,18 @@ const ExtraButtons = { .then(() => this.$emit('onSuccess')) .catch(err => this.$emit('onError', err.error.error)) }, + muteConversation () { + this.refreshPopper() + this.$store.dispatch('muteConversation', this.status.id) + .then(() => this.$emit('onSuccess')) + .catch(err => this.$emit('onError', err.error.error)) + }, + unmuteConversation () { + this.refreshPopper() + this.$store.dispatch('unmuteConversation', this.status.id) + .then(() => this.$emit('onSuccess')) + .catch(err => this.$emit('onError', err.error.error)) + }, refreshPopper () { this.showPopper = false this.showDropDown = false @@ -54,9 +66,6 @@ const ExtraButtons = { }, canPin () { return this.ownStatus && (this.status.visibility === 'public' || this.status.visibility === 'unlisted') - }, - enabled () { - return this.canPin || this.canDelete } } } diff --git a/src/components/extra_buttons/extra_buttons.vue b/src/components/extra_buttons/extra_buttons.vue index 8e24e9a53..5027be1be 100644 --- a/src/components/extra_buttons/extra_buttons.vue +++ b/src/components/extra_buttons/extra_buttons.vue @@ -1,6 +1,6 @@ - +
From 53c9517a4aeae1158a95e3b9c6d6d89e3a7e0ee9 Mon Sep 17 00:00:00 2001 From: taehoon Date: Wed, 24 Jul 2019 22:42:06 -0400 Subject: [PATCH 10/33] use array.includes instead of array.indexOf --- src/components/timeline/timeline.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/timeline/timeline.js b/src/components/timeline/timeline.js index b14135914..a5c6418b2 100644 --- a/src/components/timeline/timeline.js +++ b/src/components/timeline/timeline.js @@ -46,7 +46,7 @@ const Timeline = { const result = {} if (this.pinnedStatusIds && this.pinnedStatusIds.length > 0) { for (let status of this.timeline.visibleStatuses) { - if (this.pinnedStatusIds.indexOf(status.id) === -1) { + if (!this.pinnedStatusIds.includes(status.id)) { break } result[status.id] = true From 65ef03931661561db0791ee7d560292dda6b7d48 Mon Sep 17 00:00:00 2001 From: taehoon Date: Thu, 25 Jul 2019 08:03:41 -0400 Subject: [PATCH 11/33] add unit test for elimination logic --- src/components/timeline/timeline.js | 28 +++++++++++++-------- test/unit/specs/components/timeline.spec.js | 17 +++++++++++++ 2 files changed, 34 insertions(+), 11 deletions(-) create mode 100644 test/unit/specs/components/timeline.spec.js diff --git a/src/components/timeline/timeline.js b/src/components/timeline/timeline.js index a5c6418b2..aac3869f5 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: [ @@ -43,16 +56,9 @@ const Timeline = { }, // id map of statuses which need to be hidden in the main list due to pinning logic excludedStatusIdsObject () { - const result = {} - if (this.pinnedStatusIds && this.pinnedStatusIds.length > 0) { - for (let status of this.timeline.visibleStatuses) { - if (!this.pinnedStatusIds.includes(status.id)) { - break - } - result[status.id] = true - } - } - return result + const ids = getExcludedStatusIdsByPinning(this.timeline.visibleStatuses, this.pinnedStatusIds) + // Convert id array to object + return keyBy(ids, id => id) } }, components: { diff --git a/test/unit/specs/components/timeline.spec.js b/test/unit/specs/components/timeline.spec.js new file mode 100644 index 000000000..b13d3e207 --- /dev/null +++ b/test/unit/specs/components/timeline.spec.js @@ -0,0 +1,17 @@ +import { getExcludedStatusIdsByPinning } from 'src/components/timeline/timeline.js' +import { difference } from 'lodash' + +describe('Timeline', () => { + describe('getExcludedStatusIdsByPinning', () => { + it('should not return unpinned status ids', () => { + const statuses = [ + { id: 1 }, + { id: 2 }, + { id: 3 }, + { id: 4 } + ] + const pinnedStatusIds = [1, 3] + expect(difference(getExcludedStatusIdsByPinning(statuses, pinnedStatusIds), pinnedStatusIds)).to.eql([]) + }) + }) +}) \ No newline at end of file From a443a5203e19eb43cdff76b1e3e6502a5b917bc9 Mon Sep 17 00:00:00 2001 From: taehoon Date: Thu, 25 Jul 2019 14:17:48 -0400 Subject: [PATCH 12/33] add more unit tests for elimination logic --- test/unit/specs/components/timeline.spec.js | 31 +++++++++++++++------ 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/test/unit/specs/components/timeline.spec.js b/test/unit/specs/components/timeline.spec.js index b13d3e207..48796cd39 100644 --- a/test/unit/specs/components/timeline.spec.js +++ b/test/unit/specs/components/timeline.spec.js @@ -3,15 +3,28 @@ import { difference } from 'lodash' describe('Timeline', () => { describe('getExcludedStatusIdsByPinning', () => { - it('should not return unpinned status ids', () => { - const statuses = [ - { id: 1 }, - { id: 2 }, - { id: 3 }, - { id: 4 } - ] - const pinnedStatusIds = [1, 3] + const mockStatuses = (ids) => ids.map(id => ({ id })) + + it('should not return any unpinned status ids', () => { + const statuses = mockStatuses([1, 2, 3, 4]) + const pinnedStatusIds = [1, 3, 5] expect(difference(getExcludedStatusIdsByPinning(statuses, pinnedStatusIds), pinnedStatusIds)).to.eql([]) }) + + it('should not return any status ids not listed in the given statuses', () => { + const statusIds = [1, 2, 3, 4] + const statuses = mockStatuses(statusIds) + const pinnedStatusIds = [1, 3, 5] + expect(difference(getExcludedStatusIdsByPinning(statuses, pinnedStatusIds), statusIds)).to.eql([]) + }) + + 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) + }) }) -}) \ No newline at end of file +}) From d785ed5a05b3123d95e8627a0f82f0f9cddec33f Mon Sep 17 00:00:00 2001 From: taehoon Date: Thu, 25 Jul 2019 23:34:56 -0400 Subject: [PATCH 13/33] rewrite unit tests --- test/unit/specs/components/timeline.spec.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/test/unit/specs/components/timeline.spec.js b/test/unit/specs/components/timeline.spec.js index 48796cd39..c1fdd0dd9 100644 --- a/test/unit/specs/components/timeline.spec.js +++ b/test/unit/specs/components/timeline.spec.js @@ -1,5 +1,4 @@ import { getExcludedStatusIdsByPinning } from 'src/components/timeline/timeline.js' -import { difference } from 'lodash' describe('Timeline', () => { describe('getExcludedStatusIdsByPinning', () => { @@ -8,14 +7,14 @@ describe('Timeline', () => { it('should not return any unpinned status ids', () => { const statuses = mockStatuses([1, 2, 3, 4]) const pinnedStatusIds = [1, 3, 5] - expect(difference(getExcludedStatusIdsByPinning(statuses, pinnedStatusIds), pinnedStatusIds)).to.eql([]) + expect(pinnedStatusIds).to.include.members(getExcludedStatusIdsByPinning(statuses, pinnedStatusIds)) }) it('should not return any status ids not listed in the given statuses', () => { const statusIds = [1, 2, 3, 4] const statuses = mockStatuses(statusIds) const pinnedStatusIds = [1, 3, 5] - expect(difference(getExcludedStatusIdsByPinning(statuses, pinnedStatusIds), statusIds)).to.eql([]) + expect(statusIds).to.include.members(getExcludedStatusIdsByPinning(statuses, pinnedStatusIds)) }) it('should return ids of pinned statuses not posted before any unpinned status', () => { From 18a41e785ed85531f032a0aa1b6bfdce5a892fa9 Mon Sep 17 00:00:00 2001 From: taehoon Date: Sun, 28 Jul 2019 16:55:34 -0400 Subject: [PATCH 14/33] update unit test --- test/unit/specs/components/timeline.spec.js | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/test/unit/specs/components/timeline.spec.js b/test/unit/specs/components/timeline.spec.js index c1fdd0dd9..0c8674a84 100644 --- a/test/unit/specs/components/timeline.spec.js +++ b/test/unit/specs/components/timeline.spec.js @@ -4,17 +4,15 @@ describe('Timeline', () => { describe('getExcludedStatusIdsByPinning', () => { const mockStatuses = (ids) => ids.map(id => ({ id })) - it('should not return any unpinned status ids', () => { - const statuses = mockStatuses([1, 2, 3, 4]) - const pinnedStatusIds = [1, 3, 5] - expect(pinnedStatusIds).to.include.members(getExcludedStatusIdsByPinning(statuses, pinnedStatusIds)) - }) - - it('should not return any status ids not listed in the given statuses', () => { + 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] - expect(statusIds).to.include.members(getExcludedStatusIdsByPinning(statuses, pinnedStatusIds)) + 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', () => { From 7c2982064e6faf60c95e909e7722d6110310055a Mon Sep 17 00:00:00 2001 From: taehoon Date: Mon, 22 Jul 2019 16:58:20 -0400 Subject: [PATCH 15/33] enlarge avatar in profile page --- src/components/user_card/user_card.js | 14 ++++++++++++++ src/components/user_card/user_card.vue | 19 ++++++++++++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/components/user_card/user_card.js b/src/components/user_card/user_card.js index e019ebbdb..a3c962fb8 100644 --- a/src/components/user_card/user_card.js +++ b/src/components/user_card/user_card.js @@ -5,6 +5,7 @@ import ModerationTools from '../moderation_tools/moderation_tools.vue' import { hex2rgb } from '../../services/color_convert/color_convert.js' import { requestFollow, requestUnfollow } from '../../services/follow_manipulate/follow_manipulate' import generateProfileLink from 'src/services/user_profile_link_generator/user_profile_link_generator' +import { isEqual } from 'lodash' export default { props: [ 'user', 'switcher', 'selected', 'hideBio', 'rounded', 'bordered' ], @@ -100,6 +101,11 @@ export default { const validRole = rights.admin || rights.moderator const roleTitle = rights.admin ? 'admin' : 'moderator' return validRole && roleTitle + }, + isActiveRoute () { + const profileRoute = this.userProfileLink(this.user) + const currentRoute = this.$router.currentRoute + return profileRoute.name === currentRoute.name && isEqual(profileRoute.params, currentRoute.params) } }, components: { @@ -162,6 +168,14 @@ export default { }, reportUser () { this.$store.dispatch('openUserReportingModal', this.user.id) + }, + enlargeAvatar () { + const attachment = { + url: this.user.profile_image_url_original, + mimetype: 'image' + } + this.$store.dispatch('setMedia', [attachment]) + this.$store.dispatch('setCurrent', attachment) } } } diff --git a/src/components/user_card/user_card.vue b/src/components/user_card/user_card.vue index 9e1424801..3c0bf0d4e 100644 --- a/src/components/user_card/user_card.vue +++ b/src/components/user_card/user_card.vue @@ -7,7 +7,20 @@