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 Jun 30, 2023
1 parent 4bc962a commit 1d53c0f
Showing 1 changed file with 41 additions and 7 deletions.
48 changes: 41 additions & 7 deletions src/components/MessagesList/MessagesGroup/MessagesSystemGroup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,18 @@ 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: 2,
moderator_promoted: 11,
guest_moderator_promoted: 11,
moderator_demoted: 12,
guest_moderator_demoted: 12,
call_joined: 21,
call_left: 22,
}
export default {
name: 'MessagesSystemGroup',
Expand Down Expand Up @@ -133,7 +145,7 @@ export default {
messages: {
immediate: true,
handler(value) {
this.messagesGroupedBySystemMessage = this.groupMessages(value)
this.messagesGroupedBySystemMessage = this.groupMessages(this.sortMessages(value))
},
},
},
Expand Down Expand Up @@ -191,24 +203,46 @@ export default {
}
// Group users promoted one by one
if (message1.systemMessage === 'moderator_promoted'
&& message1.systemMessage === message2.systemMessage) {
if ((message1.systemMessage === 'moderator_promoted' || message1.systemMessage === 'guest_moderator_promoted')
&& (message2.systemMessage === 'moderator_promoted' || message2.systemMessage === 'guest_moderator_promoted')) {
return 'moderator_promoted'
}
// Group users demoted one by one
if (message1.systemMessage === 'moderator_demoted'
&& message1.systemMessage === message2.systemMessage) {
if ((message1.systemMessage === 'moderator_demoted' || message1.systemMessage === 'guest_moderator_demoted')
&& (message2.systemMessage === 'moderator_demoted' || message2.systemMessage === 'guest_moderator_demoted')) {
return 'moderator_demoted'
}
return ''
},
groupMessages() {
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 same system messages between each other
if (MESSAGES[message1.systemMessage] === MESSAGES[message2.systemMessage]) {
return 0
}
// Don't sort related system messages from one actor between each other
if (message1.actorId === message2.actorId && message1.actorType === message2.actorType
&& Math.abs(MESSAGES[message1.systemMessage] - MESSAGES[message2.systemMessage]) === 1) {
return 0
}
return MESSAGES[message1.systemMessage] > MESSAGES[message2.systemMessage] ? 1 : -1
})
},
groupMessages(messages) {
const groups = []
let lastMessage = null
for (const message of this.messages) {
for (const message of messages) {
const groupingType = this.messagesShouldBeGrouped(message, lastMessage)
if (!groupingType) {
groups.push({ messages: [message], type: '', collapsed: true })
Expand Down

0 comments on commit 1d53c0f

Please sign in to comment.