Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Message): optimize getters and provided props #11349

Merged
merged 4 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/components/MediaSettings/MediaSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ export default {
},

hasCall() {
return this.conversation.hasCall || this.conversation.hasCallOverwrittenByChat
return this.conversation.hasCall
},

isCurrentlyRecording() {
Expand Down
10 changes: 0 additions & 10 deletions src/components/MessagesList/MessagesGroup/Message/Message.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,6 @@ describe('Message.vue', () => {
}

injected = {
scrollerBoundingClientRect: {
x: 0,
y: 0,
width: 0,
height: 0,
top: 0,
right: 0,
bottom: 0,
left: 0,
},
getMessagesListScroller: jest.fn(),
}

Expand Down
20 changes: 2 additions & 18 deletions src/components/MessagesList/MessagesGroup/Message/Message.vue
Original file line number Diff line number Diff line change
Expand Up @@ -247,9 +247,6 @@ const isTranslationAvailable = getCapabilities()?.spreed?.config?.chat?.['has-tr
// Fallback for the desktop client when connecting to Talk 17
?? getCapabilities()?.spreed?.config?.chat?.translations?.length > 0

/**
* @property {object} scrollerBoundingClientRect provided by MessageList.vue
*/
export default {
name: 'Message',

Expand All @@ -272,8 +269,6 @@ export default {
UnfoldMore,
},

inject: ['scrollerBoundingClientRect'],

inheritAttrs: false,

props: {
Expand Down Expand Up @@ -508,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
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,6 @@ describe('MessageButtonsBar.vue', () => {
store = new Store(testStoreConfig)

injected = {
scrollerBoundingClientRect: {
x: 0,
y: 0,
width: 0,
height: 0,
top: 0,
right: 0,
bottom: 0,
left: 0,
},
getMessagesListScroller: jest.fn(),
}
})
Expand Down
2 changes: 0 additions & 2 deletions src/components/MessagesList/MessagesList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ get the messagesList array and loop through the list to generate the messages.
<script>
import debounce from 'debounce'
import uniqueId from 'lodash/uniqueId.js'
import { computed } from 'vue'

import Message from 'vue-material-design-icons/Message.vue'

Expand Down Expand Up @@ -98,7 +97,6 @@ export default {

provide() {
return {
scrollerBoundingClientRect: computed(() => this.$refs.scroller.getBoundingClientRect()),
getMessagesListScroller: () => this.$refs.scroller,
}
},
Expand Down
2 changes: 1 addition & 1 deletion src/components/TopBar/CallButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ export default {
},

hasCall() {
return this.conversation.hasCall || this.conversation.hasCallOverwrittenByChat
return this.conversation.hasCall
},

startCallButtonDisabled() {
Expand Down
25 changes: 15 additions & 10 deletions src/store/conversationsStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
import { talkBroadcastChannel } from '../services/talkBroadcastChannel.js'
import { useChatExtrasStore } from '../stores/chatExtras.js'
import { useTalkHashStore } from '../stores/talkHash.js'
import { useReactionsStore } from '../stores/reactions.js'

Check warning on line 70 in src/store/conversationsStore.js

View workflow job for this annotation

GitHub Actions / NPM lint

`../stores/reactions.js` import should occur before import of `../stores/talkHash.js`

const DUMMY_CONVERSATION = {
token: '',
Expand Down Expand Up @@ -215,14 +215,6 @@
}
},

overwriteHasCallByChat(state, { token, hasCall }) {
if (hasCall) {
Vue.set(state.conversations[token], 'hasCallOverwrittenByChat', hasCall)
} else {
Vue.delete(state.conversations[token], 'hasCallOverwrittenByChat')
}
},

setNotificationLevel(state, { token, notificationLevel }) {
Vue.set(state.conversations[token], 'notificationLevel', notificationLevel)
},
Expand Down Expand Up @@ -758,6 +750,11 @@

const activeSince = (new Date(notification.datetime)).getTime() / 1000

// Check if notification information is older than in known conversation object
if (activeSince < getters.conversations[token].lastActivity) {
return
}

const conversation = Object.assign({}, getters.conversations[token], {
hasCall: true,
callFlag: PARTICIPANT.CALL_FLAG.WITH_VIDEO,
Expand Down Expand Up @@ -792,8 +789,16 @@
commit('updateConversationLastReadMessage', { token, lastReadMessage })
},

async overwriteHasCallByChat({ commit }, { token, hasCall }) {
commit('overwriteHasCallByChat', { token, hasCall })
async overwriteHasCallByChat({ commit, dispatch }, { token, hasCall, lastActivity }) {
dispatch('setConversationProperties', {
token,
properties: {
hasCall,
callFlag: hasCall ? PARTICIPANT.CALL_FLAG.IN_CALL : PARTICIPANT.CALL_FLAG.DISCONNECTED,
lastActivity,
callStartTime: hasCall ? lastActivity : 0,
}
})
},

async fetchConversation({ dispatch }, { token }) {
Expand Down
24 changes: 7 additions & 17 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 Expand Up @@ -1086,25 +1090,11 @@ const actions = {
// Overwrite the conversation.hasCall property so people can join
// after seeing the message in the chat.
if (conversation && conversation.lastMessage && message.id > conversation.lastMessage.id) {
if (message.systemMessage === 'call_started') {
if (['call_started', 'call_ended', 'call_ended_everyone', 'call_missed'].includes(message.systemMessage)) {
context.dispatch('overwriteHasCallByChat', {
token,
hasCall: true,
})
context.dispatch('setConversationProperties', {
token: message.token,
properties: { callStartTime: message.timestamp },
})
} else if (message.systemMessage === 'call_ended'
|| message.systemMessage === 'call_ended_everyone'
|| message.systemMessage === 'call_missed') {
context.dispatch('overwriteHasCallByChat', {
token,
hasCall: false,
})
context.dispatch('setConversationProperties', {
token: message.token,
properties: { callStartTime: 0 },
hasCall: message.systemMessage === 'call_started',
lastActivity: message.timestamp,
})
}
}
Expand Down
Loading