Skip to content

Commit

Permalink
Merge pull request #558 from Adamant-im/feat/show-unread-count-over-t…
Browse files Browse the repository at this point in the history
…he-back-button

feat:show unread count over the back button
  • Loading branch information
bludnic authored Nov 13, 2023
2 parents 613580a + 62af83b commit 4e1e687
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/components/Chat/ChatToolbar.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
<template>
<v-toolbar flat height="56" :class="`${className}`" color="transparent">
<v-btn icon @click="goBack">
<v-badge
v-if="numOfNewMessages > 0"
:value="numOfNewMessages"
color="primary"
:class="`${className}__messages-counter`"
:content="numOfNewMessages > 99 ? '99+' : numOfNewMessages"
>
</v-badge>
<v-icon icon="mdi-arrow-left" />
</v-btn>
<div v-if="!isWelcomeChat(partnerId)">
Expand Down Expand Up @@ -61,6 +69,9 @@ export default {
displayName: value
})
}
},
numOfNewMessages() {
return this.$store.getters['chat/numWithoutTheCurrentChat'](this.partnerId)
}
},
data: () => ({
Expand Down Expand Up @@ -95,6 +106,11 @@ export default {
flex-grow: 0;
flex-shrink: 0;
&__messages-counter {
position: relative;
top: -14px;
left: -2px;
}
&__textfield-container {
width: 100%;
}
Expand Down
6 changes: 6 additions & 0 deletions src/store/modules/chat/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,12 @@ const getters = {
return senderIds.reduce((acc, senderId) => state.chats[senderId].numOfNewMessages + acc, 0)
},

numWithoutTheCurrentChat: (state, getters) => (senderId) => {
const totalNumOfNewMessages = getters.totalNumOfNewMessages
const numOfNewMessages = getters.numOfNewMessages(senderId)
return totalNumOfNewMessages - numOfNewMessages
},

/**
* Get unread messages from all chats.
* @returns {Message[]}
Expand Down

0 comments on commit 4e1e687

Please sign in to comment.