diff --git a/Notesnook.API/Controllers/AnnouncementController.cs b/Notesnook.API/Controllers/AnnouncementController.cs
index 87eb8d9..8c08b5e 100644
--- a/Notesnook.API/Controllers/AnnouncementController.cs
+++ b/Notesnook.API/Controllers/AnnouncementController.cs
@@ -18,10 +18,12 @@ along with this program. If not, see .
*/
using System;
+using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
+using MongoDB.Driver;
using Notesnook.API.Models;
using Streetwriters.Data.Repositories;
@@ -42,9 +44,14 @@ namespace Notesnook.API.Controllers
[AllowAnonymous]
public async Task GetActiveAnnouncements([FromQuery] string userId)
{
- var announcements = await Announcements.FindAsync((a) => a.IsActive && (a.UserIds == null || a.UserIds.Length == 0 || a.UserIds.Contains(userId)));
+ var totalActive = await Announcements.Collection.CountDocumentsAsync(Builders.Filter.Eq("IsActive", true));
+ if (totalActive <= 0) return Ok(new Announcement[] { });
+
+ var announcements = (await Announcements.FindAsync((a) => a.IsActive)).Where((a) => a.UserIds == null || a.UserIds.Length == 0 || a.UserIds.Contains(userId));
foreach (var announcement in announcements)
{
+ if (announcement.UserIds != null && !announcement.UserIds.Contains(userId)) continue;
+
foreach (var item in announcement.Body)
{
if (item.Type != "callToActions") continue;