private async Task <(NotificationList, NotificationList)> GetNotificationListsAsync(string userId) { var notificationTransport = await feedRepo.GetUsersFeedNotificationTransportAsync(userId); var importantNotifications = new List <Notification>(); if (notificationTransport != null) { importantNotifications = (await feedRepo.GetFeedNotificationDeliveriesAsync(userId, n => n.Notification.InitiatedBy, transports: notificationTransport)) .Select(d => d.Notification) .ToList(); } var commentsNotifications = (await feedRepo.GetFeedNotificationDeliveriesAsync(userId, n => n.Notification.InitiatedBy, transports: commentsFeedNotificationTransport)) .Select(d => d.Notification) .ToList(); logger.Information($"[GetNotificationList] Step 1 done: found {importantNotifications.Count} important notifications and {commentsNotifications.Count} comment notifications"); importantNotifications = RemoveBlockedNotifications(importantNotifications).ToList(); commentsNotifications = RemoveBlockedNotifications(commentsNotifications, importantNotifications).ToList(); logger.Information($"[GetNotificationList] Step 2 done, removed blocked notifications: left {importantNotifications.Count} important notifications and {commentsNotifications.Count} comment notifications"); importantNotifications = RemoveNotActualNotifications(importantNotifications).ToList(); commentsNotifications = RemoveNotActualNotifications(commentsNotifications).ToList(); logger.Information($"[GetNotificationList] Step 3 done, removed not actual notifications: left {importantNotifications.Count} important notifications and {commentsNotifications.Count} comment notifications"); var importantLastViewTimestamp = await feedRepo.GetFeedViewTimestampAsync(userId, notificationTransport?.Id ?? -1); var commentsLastViewTimestamp = await feedRepo.GetFeedViewTimestampAsync(userId, commentsFeedNotificationTransport.Id); logger.Information("[GetNotificationList] Step 4, building models"); var allNotifications = importantNotifications.Concat(commentsNotifications).ToList(); var notificationsData = await notificationDataPreloader.LoadAsync(allNotifications); var importantNotificationList = new NotificationList { LastViewTimestamp = importantLastViewTimestamp, Notifications = importantNotifications.Select(notification => BuildNotificationInfo(notification, notificationsData)).ToList(), }; var commentsNotificationList = new NotificationList { LastViewTimestamp = commentsLastViewTimestamp, Notifications = commentsNotifications.Select(notification => BuildNotificationInfo(notification, notificationsData)).ToList(), }; return(importantNotificationList, commentsNotificationList); }