Skip to content

Commit

Permalink
move last call computation to store getter
Browse files Browse the repository at this point in the history
Signed-off-by: Maksim Sukharev <antreesy.web@gmail.com>
  • Loading branch information
Antreesy committed Jan 10, 2024
1 parent 81ece88 commit db95ebb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 13 deletions.
15 changes: 2 additions & 13 deletions src/components/MessagesList/MessagesGroup/Message/Message.vue
Original file line number Diff line number Diff line change
Expand Up @@ -503,23 +503,12 @@ export default {
&& !this.isDeletedMessage
},

messagesList() {
return this.$store.getters.messagesList(this.token)
},

isLastCallStartedMessage() {
// FIXME: remove dependency to messages list and convert to property
const messages = this.messagesList
// FIXME: don't reverse the whole array as it would create a copy, just do an actual reverse search
const lastCallStartedMessage = messages.reverse().find((message) => message.systemMessage === 'call_started')
return lastCallStartedMessage ? (this.id === lastCallStartedMessage.id) : false
return this.systemMessage === 'call_started' && this.id === this.$store.getters.getLastCallStartedMessageId
},

showJoinCallButton() {
return this.systemMessage === 'call_started'
&& this.conversation.hasCall
&& this.isLastCallStartedMessage
&& !this.isInCall
return this.conversation.hasCall && !this.isInCall && this.isLastCallStartedMessage
},

showResultsButton() {
Expand Down
4 changes: 4 additions & 0 deletions src/store/messagesStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,10 @@ const getters = {
return null
},

getLastCallStartedMessageId: (state, getters, rootState, rootGetters) => {
return getters.messagesList(rootGetters.getToken()).findLast((message) => message.systemMessage === 'call_started')?.id
},

getFirstDisplayableMessageIdAfterReadMarker: (state, getters) => (token, readMessageId) => {
if (!state.messages[token]) {
return null
Expand Down

0 comments on commit db95ebb

Please sign in to comment.