From 2cfe7034e8d2f873cffb74e96dc745de8ce42536 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Tue, 4 May 2021 13:33:30 +0200 Subject: [PATCH] extract fn --- src/matrix/room/RoomSummary.js | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/matrix/room/RoomSummary.js b/src/matrix/room/RoomSummary.js index 13d06ee5..5cdc24a6 100644 --- a/src/matrix/room/RoomSummary.js +++ b/src/matrix/room/RoomSummary.js @@ -68,21 +68,26 @@ function applySyncResponse(data, roomResponse, membership, ownUserId) { } const unreadNotifications = roomResponse.unread_notifications; if (unreadNotifications) { - const highlightCount = unreadNotifications.highlight_count || 0; - if (highlightCount !== data.highlightCount) { - data = data.cloneIfNeeded(); - data.highlightCount = highlightCount; - } - const notificationCount = unreadNotifications.notification_count; - if (notificationCount !== data.notificationCount) { - data = data.cloneIfNeeded(); - data.notificationCount = notificationCount; - } + data = processNotificationCounts(data, unreadNotifications); } return data; } +function processNotificationCounts(data, unreadNotifications) { + const highlightCount = unreadNotifications.highlight_count || 0; + if (highlightCount !== data.highlightCount) { + data = data.cloneIfNeeded(); + data.highlightCount = highlightCount; + } + const notificationCount = unreadNotifications.notification_count; + if (notificationCount !== data.notificationCount) { + data = data.cloneIfNeeded(); + data.notificationCount = notificationCount; + } + return data; +} + function processRoomAccountData(data, event) { if (event?.type === "m.tag") { let tags = event?.content?.tags;