( groupId: string )
| 7 | * @param groupId 群组id |
| 8 | */ |
| 9 | export function useGroupUnreadState( |
| 10 | groupId: string |
| 11 | ): 'none' | 'muted' | 'unread' { |
| 12 | const group = useGroupInfo(groupId); |
| 13 | const groupTextPanelIds = (group?.panels ?? []) |
| 14 | .filter((panel) => isGroupAckPanel(panel)) |
| 15 | .map((p) => p.id); |
| 16 | |
| 17 | const { mutedList } = useUserNotifyMute(); |
| 18 | |
| 19 | const unreadList = useUnread(groupTextPanelIds); |
| 20 | const unreadEntires = _zip(groupTextPanelIds, unreadList); |
| 21 | let hasUnread = false; |
| 22 | let hasUnmutedUnread = false; |
| 23 | const isGroupMuted = mutedList.includes(groupId); // 群组自身是否被禁用 |
| 24 | |
| 25 | for (const [panelId, isUnread] of unreadEntires) { |
| 26 | if (isUnread === true) { |
| 27 | hasUnread = true; |
| 28 | |
| 29 | if (isGroupMuted) { |
| 30 | // 如果群组已经被静音,则无需做后续判断,跳出循环 |
| 31 | break; |
| 32 | } |
| 33 | |
| 34 | if (panelId && !mutedList.includes(panelId)) { |
| 35 | // 如果面板没有并禁言,且有未读消息 |
| 36 | hasUnmutedUnread = true; |
| 37 | break; |
| 38 | } |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | if (hasUnread) { |
| 43 | if (hasUnmutedUnread) { |
| 44 | return 'unread'; // 有未读消息,显示红点 |
| 45 | } else { |
| 46 | return 'muted'; // 有未读消息,但是未读消息均被静音,显示灰点 |
| 47 | } |
| 48 | } else { |
| 49 | return 'none'; // 没有未读消息,不显示任何状态 |
| 50 | } |
| 51 | } |
no test coverage detected