From 32e20b2e025e20f38b4acdea55a13a647463a9f1 Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Sat, 29 Jul 2017 18:53:49 +0200 Subject: [PATCH] Only run through replies once. --- src/components/conversation/conversation.js | 27 ++++++++++++--------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/components/conversation/conversation.js b/src/components/conversation/conversation.js index 059028f9ec..4ee6c32e3b 100644 --- a/src/components/conversation/conversation.js +++ b/src/components/conversation/conversation.js @@ -1,4 +1,4 @@ -import { find, filter, sortBy } from 'lodash' +import { reduce, find, filter, sortBy } from 'lodash' import { statusType } from '../../modules/statuses.js' import Status from '../status/status.vue' @@ -33,6 +33,19 @@ const conversation = { const statuses = this.$store.state.statuses.allStatuses const conversation = filter(statuses, { statusnet_conversation_id: conversationId }) return sortAndFilterConversation(conversation) + }, + replies () { + return reduce(this.conversation, (result, {id, in_reply_to_status_id}) => { + const irid = Number(in_reply_to_status_id) + if (irid) { + result[irid] = result[irid] || [] + result[irid].push({ + name: `#${id}`, + id: id + }) + } + return result + }, {}) } }, components: { @@ -59,18 +72,8 @@ const conversation = { } }, getReplies (id) { - let res = [] id = Number(id) - let i - for (i = 0; i < this.conversation.length; i++) { - if (Number(this.conversation[i].in_reply_to_status_id) === id) { - res.push({ - name: `#${i}`, - id: this.conversation[i].id - }) - } - } - return res + return this.replies[id] || [] }, focused (id) { if (this.statusoid.retweeted_status) {