Skip to content

Commit

Permalink
没有订阅到未读通知时需要额外单独触发重新请求通知列表及未读数量
Browse files Browse the repository at this point in the history
  • Loading branch information
yinlianghui committed May 29, 2024
1 parent 44cfcb1 commit b533489
Showing 1 changed file with 24 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @Author: [email protected]
* @Date: 2022-09-01 14:44:57
* @LastEditors: 殷亮辉 [email protected]
* @LastEditTime: 2024-05-24 19:37:30
* @LastEditTime: 2024-05-29 11:45:57
* @Description:
*/

Expand Down Expand Up @@ -33,6 +33,13 @@ const notificationReadAdaptor = `
return payload;
`;

const beforeMarkReadAllScript = `
var hasUnRead = !!db.notifications.find({'$or':[{'is_read': null},{'is_read': false}]}).count();
// 没有订阅到未读通知时需要额外单独触发重新请求通知列表及未读数量
// 如果有订阅到的话,因为监听订阅到的通知记录变化,有变化会触发@data.changed.notifications事件,从而会自动触发重新请求通知列表及未读数量
event.data.needToReload = !hasUnRead;
`;

const getNotificationBadgeButton = () => {
const isMobile = window.innerWidth < 768;
const listContent = {
Expand Down Expand Up @@ -130,6 +137,10 @@ const getNotificationBadgeButton = () => {
"onEvent": {
"click": {
"actions": [
{
"actionType": "custom",
"script": beforeMarkReadAllScript
},
{
"componentId": "",
"args": {
Expand All @@ -145,6 +156,16 @@ const getNotificationBadgeButton = () => {
}
},
"actionType": "ajax"
},
{
"componentId": "service_global_header_notifications_unread_count",
"actionType": "reload",
"expression": "${needToReload}"
},
{
"componentId": "service_global_header_notifications_list",
"actionType": "reload",
"expression": "${needToReload}"
}
],
"weight": 0
Expand All @@ -155,7 +176,7 @@ const getNotificationBadgeButton = () => {
},

],
"id": "u:aba521eed5b7",
"id": "service_global_header_notifications_list",
"onEvent": {
"@data.changed.notifications": {
"actions": [
Expand Down Expand Up @@ -200,7 +221,7 @@ const getNotificationBadgeButton = () => {
"count": "${unReadCount}"
},
],
"id": "u:aba521eed5b7",
"id": "service_global_header_notifications_unread_count",
"messages": {
},
"api": {
Expand Down

0 comments on commit b533489

Please sign in to comment.