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 conversation switching lag #5084

Merged
merged 6 commits into from
Feb 24, 2021
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
11 changes: 4 additions & 7 deletions src/components/ChatView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,6 @@ export default {
NewMessageForm,
},

props: {
token: {
type: String,
required: true,
},
},

data: function() {
return {
isDraggingOver: false,
Expand Down Expand Up @@ -109,6 +102,10 @@ export default {
return undefined
}
},

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

methods: {
Expand Down
36 changes: 28 additions & 8 deletions src/components/NewMessageForm/NewMessageForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
<div
v-if="canUploadFiles || canShareFiles">
<Actions
ref="uploadMenu"
:disabled="disabled"
default-icon="icon-clip-add-file"
:aria-label="t('spreed', 'Share files to the conversation')"
:aria-haspopup="true">
Expand All @@ -59,11 +61,11 @@
</ActionButton>
</Actions>
</div>
<div
v-if="!isReadOnly">
<div>
<EmojiPicker @select="addEmoji">
<button
type="button"
:disabled="disabled"
class="nc-button nc-button__main"
:aria-label="t('spreed', 'Add emoji')"
:aria-haspopup="true">
Expand All @@ -86,15 +88,15 @@
ref="advancedInput"
v-model="text"
:token="token"
:active-input="!isReadOnly"
:active-input="!disabled"
:placeholder-text="placeholderText"
:aria-label="placeholderText"
@update:contentEditable="contentEditableToParsed"
@submit="handleSubmit"
@files-pasted="handlePastedFiles" />
</div>
<button
:disabled="isReadOnly"
:disabled="disabled"
type="submit"
:aria-label="t('spreed', 'Send message')"
class="nc-button nc-button__main"
Expand Down Expand Up @@ -179,10 +181,18 @@ export default {
return this.conversation.readOnly === CONVERSATION.STATE.READ_ONLY
},

disabled() {
return this.isReadOnly || !this.currentConversationIsJoined
},

placeholderText() {
return this.isReadOnly
? t('spreed', 'This conversation has been locked')
: t('spreed', 'Write message, @ to mention someone …')
if (this.isReadonly) {
return t('spreed', 'This conversation has been locked')
} else if (!this.currentConversationIsJoined) {
return t('spreed', 'Joining conversation …')
} else {
return t('spreed', 'Write message, @ to mention someone …')
}
},

messageToBeReplied() {
Expand All @@ -194,7 +204,7 @@ export default {
},

canShareFiles() {
return !this.currentUserIsGuest && !this.isReadOnly
return !this.currentUserIsGuest
},

canUploadFiles() {
Expand All @@ -207,6 +217,16 @@ export default {
attachmentFolderFreeSpace() {
return this.$store.getters.getAttachmentFolderFreeSpace()
},

currentConversationIsJoined() {
return this.$store.getters.currentConversationIsJoined
},
},

watch: {
disabled(newValue) {
this.$refs.uploadMenu.$refs.menuButton.disabled = newValue
},
},

mounted() {
Expand Down
5 changes: 5 additions & 0 deletions src/components/TopBar/CallButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ export default {
|| this.isBlockedByLobby
|| this.conversation.readOnly
|| this.isNextcloudTalkHashDirty
|| !this.currentConversationIsJoined
},

leaveCallLabel() {
Expand Down Expand Up @@ -164,6 +165,10 @@ export default {
return this.conversation.readOnly === CONVERSATION.STATE.READ_WRITE
&& this.isInCall
},

currentConversationIsJoined() {
return this.$store.getters.currentConversationIsJoined
},
},

methods: {
Expand Down
6 changes: 6 additions & 0 deletions src/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
// entry points

import store from './store'
import { EventBus } from './services/EventBus'

if (!window.OCA.Talk) {
window.OCA.Talk = {}
Expand All @@ -46,3 +47,8 @@ window.OCA.Talk.registerMessageAction = ({ label, callback, icon }) => {
}
store.dispatch('addMessageAction', messageAction)
}

EventBus.$on('Signaling::joinRoom', (payload) => {
const token = payload[0]
store.dispatch('updateLastJoinedConversationToken', token)
})
19 changes: 19 additions & 0 deletions src/store/tokenStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@
const state = {
token: '',
fileIdForToken: null,
/**
* The joining of a room with the signaling server always lags
* behind the "joining" of it in talk's UI. For this reason we
* might have a window of time in which we might be in
* conversation B in talk's UI while still leaving conversation
* A in the signaling server.
**/
lastJoinedConversationToken: '',
}

const getters = {
Expand All @@ -32,6 +40,9 @@ const getters = {
getFileIdForToken: (state) => () => {
return state.fileIdForToken
},
currentConversationIsJoined() {
return state.lastJoinedConversationToken === state.token
},
}

const mutations = {
Expand All @@ -56,6 +67,10 @@ const mutations = {
state.token = newToken
state.fileIdForToken = newFileId
},

updateLastJoinedConversationToken(state, { token }) {
state.lastJoinedConversationToken = token
},
}

const actions = {
Expand All @@ -80,6 +95,10 @@ const actions = {
updateTokenAndFileIdForToken(context, { newToken, newFileId }) {
context.commit('updateTokenAndFileIdForToken', { newToken, newFileId })
},

updateLastJoinedConversationToken({ commit }, token) {
commit('updateLastJoinedConversationToken', { token })
},
}

export default { state, mutations, getters, actions }