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(desktop): fix loss messages issue #1835

Merged
merged 4 commits into from
Dec 13, 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
8 changes: 4 additions & 4 deletions src/components/MessageList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { Component, Vue, Prop, Watch } from 'vue-property-decorator'
import MsgRightItem from '@/components/MsgRightItem.vue'
import MsgLeftItem from '@/components/MsgLeftItem.vue'
import { matchTopicMethod } from '@/utils/topicMatch'
import { SCROLL_OFFSET_MAX_NUM } from '@/utils/constant'

@Component({
components: {
Expand All @@ -48,11 +49,10 @@ export default class MessageList extends Vue {
offset: Number.MAX_SAFE_INTEGER,
mode: 'before',
}
private scrollOffsetMaxNum: number = 100
private isScrolling = false
private timeout: undefined | number = undefined

@Watch('messages')
@Watch('messages', { deep: true })
private handleMessagesChanged(val: MessageModel[]) {
this.showMessages = this.getMessageMatchColor(val)
}
Expand Down Expand Up @@ -95,9 +95,9 @@ export default class MessageList extends Vue {
this.timeout = undefined
const { scrollTop, scrollHeight, clientHeight } = this.getScrollBox()
const scrollBottom = scrollHeight - scrollTop - clientHeight
if (scrollTop <= this.scrollOffsetMaxNum) {
if (scrollTop <= SCROLL_OFFSET_MAX_NUM) {
this.scrollOffset = { offset: scrollTop, mode: 'before' }
} else if (scrollBottom <= this.scrollOffsetMaxNum) {
} else if (scrollBottom <= SCROLL_OFFSET_MAX_NUM) {
this.scrollOffset = { offset: scrollBottom, mode: 'after' }
this.$emit('hideNewMsgsTip')
}
Expand Down
17 changes: 17 additions & 0 deletions src/utils/constant.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Message rate threshold (messages/second) for enabling buffering
export const MESSAGE_RATE_THRESHOLD = 30

// Threshold in pixels from bottom to determine if scrolled to bottom
export const SCROLL_BOTTOM_THRESHOLD = 500

// Height compensation in pixels for scroll container
export const SCROLL_HEIGHT_COMPENSATION = 160

// Maximum number of messages to keep in memory
export const MAX_MESSAGES_COUNT = 40

// Maximum scroll offset in pixels to trigger loading more messages
export const SCROLL_OFFSET_MAX_NUM = 100

// Messages buffer time in milliseconds
export const MESSAGES_BUFFER_TIME = 1000
2 changes: 1 addition & 1 deletion src/utils/messageQueue.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Subject, Observable } from 'rxjs'
import { bufferTime, filter, mergeMap, map, share } from 'rxjs/operators'
import { bufferTime, filter, share } from 'rxjs/operators'

/**
* A generic MessageQueue class for buffering and processing messages.
Expand Down
Loading