Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
# Conflicts:
#	assets/vue/components/layout/TopbarLoggedIn.vue
  • Loading branch information
AngelFQC committed Jun 19, 2024
2 parents 38754b0 + ad0fe4f commit 1df925b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 15 deletions.
13 changes: 7 additions & 6 deletions assets/vue/components/layout/TopbarLoggedIn.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

<PrimeButton
:badge="btnInboxBadge"
:class="{ 'item-button--unread': btnInboxBadge }"
:class="{ 'item-button--unread': !!btnInboxBadge }"
:icon="chamiloIconToClass['inbox']"
badge-class="item-button__badge"
class="item-button"
Expand All @@ -32,7 +32,7 @@
class="user-avatar"
shape="circle"
unstyled
@click="toogleUserMenu"
@click="toggleUserMenu"
/>
</div>
</div>
Expand Down Expand Up @@ -115,13 +115,14 @@ const userSubmenuItems = computed(() => [
},
])
function toogleUserMenu(event) {
function toggleUserMenu(event) {
elUserSubmenu.value.toggle(event)
}
const btnInboxBadge = computed(() =>
messageRelUserStore.countUnread > 9 ? "9+" : messageRelUserStore.countUnread.toString(),
)
const btnInboxBadge = computed(() => {
const unreadCount = messageRelUserStore.countUnread
return unreadCount > 20 ? "9+" : unreadCount > 0 ? unreadCount.toString() : null
})
messageRelUserStore.findUnreadCount().catch((e) => notification.showErrorNotification(e))
</script>
6 changes: 6 additions & 0 deletions assets/vue/services/message.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ async function create(message) {
return await baseService.post("/api/messages", message)
}

async function countUnreadMessages(params) {
const queryParams = new URLSearchParams(params).toString()
return await baseService.get(`/api/messages?${queryParams}`)
}

export const messageService = {
create,
countUnreadMessages,
}
28 changes: 19 additions & 9 deletions assets/vue/store/messageRelUserStore.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { defineStore } from "pinia"
import { useSecurityStore } from "./securityStore"
import messageRelUSerService from "../services/messagereluser"
import { messageService } from "../services/message"
import { MESSAGE_TYPE_INBOX } from "../components/message/constants"

export const useMessageRelUserStore = defineStore("messageRelUser", {
state: () => ({
Expand All @@ -10,16 +11,25 @@ export const useMessageRelUserStore = defineStore("messageRelUser", {
async findUnreadCount() {
const securityStore = useSecurityStore()

const response = await messageRelUSerService.findAll({
params: {
read: false,
receiver: securityStore.user["@id"],
try {
const params = {
"order[sendDate]": "desc",
"receivers.read": false,
"receivers.receiver": securityStore.user["@id"],
itemsPerPage: 1,
},
})
const json = await response.json()
msgType: MESSAGE_TYPE_INBOX,
}
const response = await messageService.countUnreadMessages(params)

this.countUnread = json["hydra:totalItems"]
if (response && response["hydra:totalItems"] !== undefined) {
this.countUnread = response["hydra:totalItems"]
} else {
this.countUnread = 0
}
} catch (error) {
console.error("Error fetching unread count:", error)
this.countUnread = 0
}
},
},
})

0 comments on commit 1df925b

Please sign in to comment.