remove setTimeout

This commit is contained in:
Ulf Gebhardt 2023-07-13 11:33:45 +02:00
parent c21026e28a
commit ac6bbf1840
Signed by: ulfgebhardt
GPG Key ID: DA6B843E748679C9

View File

@ -146,7 +146,7 @@ export default {
}), }),
}, },
methods: { methods: {
fetchMessages({ room, options = {} }) { async fetchMessages({ room, options = {} }) {
if (this.lastRoom !== room.id) { if (this.lastRoom !== room.id) {
this.messages = [] this.messages = []
this.messagePage = 0 this.messagePage = 0
@ -154,35 +154,33 @@ export default {
} }
this.messagesLoaded = options.refetch ? this.messagesLoaded : false this.messagesLoaded = options.refetch ? this.messagesLoaded : false
const offset = (options.refetch ? 0 : this.messagePage) * this.messagePageSize const offset = (options.refetch ? 0 : this.messagePage) * this.messagePageSize
setTimeout(async () => { try {
try { const {
const { data: { Message },
data: { Message }, } = await this.$apollo.query({
} = await this.$apollo.query({ query: messageQuery(),
query: messageQuery(), variables: {
variables: { roomId: room.id,
roomId: room.id, first: this.messagePageSize,
first: this.messagePageSize, offset,
offset, },
}, fetchPolicy: 'no-cache',
fetchPolicy: 'no-cache', })
})
const msgs = [] const msgs = []
;[...this.messages, ...Message].forEach((m) => { ;[...this.messages, ...Message].forEach((m) => {
msgs[m.indexId] = m msgs[m.indexId] = m
}) })
this.messages = msgs.filter(Boolean) this.messages = msgs.filter(Boolean)
if (Message.length < this.messagePageSize) { if (Message.length < this.messagePageSize) {
this.messagesLoaded = true this.messagesLoaded = true
}
this.messagePage += 1
} catch (error) {
this.messages = []
this.$toast.error(error.message)
} }
}) this.messagePage += 1
} catch (error) {
this.messages = []
this.$toast.error(error.message)
}
}, },
refetchMessage(roomId) { refetchMessage(roomId) {