Skip to content

Commit

Permalink
sort messages within one group
Browse files Browse the repository at this point in the history
Signed-off-by: Maksim Sukharev <[email protected]>
  • Loading branch information
Antreesy committed Jul 3, 2023
1 parent 17312cf commit 0f7d991
Showing 1 changed file with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,22 @@ import NcButton from '@nextcloud/vue/dist/Components/NcButton.js'
import Message from './Message/Message.vue'
// List only sortable messages with order, in which they should be sorted
const MESSAGES = {
user_added: 1,
user_removed: 1,
moderator_promoted: 11,
guest_moderator_promoted: 11,
moderator_demoted: 11,
guest_moderator_demoted: 11,
call_started: 20,
recording_started: 21,
call_joined: 22,
call_left: 22,
call_ended: 23,
call_ended_everyone: 23,
}
export default {
name: 'MessagesSystemGroup',
Expand Down Expand Up @@ -133,7 +149,7 @@ export default {
messages: {
immediate: true,
handler(value) {
this.messagesGroupedBySystemMessage = this.groupMessages(value)
this.messagesGroupedBySystemMessage = this.groupMessages(this.sortMessages(value))
},
},
},
Expand Down Expand Up @@ -205,6 +221,18 @@ export default {
return ''
},
sortMessages(messages) {
return messages.sort((message1, message2) => {
// Don't sort messages if they're not intended to be sorted
if (!MESSAGES[message1.systemMessage] || !MESSAGES[message2.systemMessage]) {
return 0
}
// Don't sort related system messages (call join - call left) between each other
return MESSAGES[message1.systemMessage] - MESSAGES[message2.systemMessage]
})
},
groupMessages(messages) {
const groups = []
let lastMessage = null
Expand Down

0 comments on commit 0f7d991

Please sign in to comment.