Add persistent Inbox and RFC 8291/8292 Web Push notification system
This commit is contained in:
parent
4714d25724
commit
7cc9ba7f4d
27 changed files with 3573 additions and 17 deletions
|
|
@ -45,6 +45,9 @@ public class ClientState
|
|||
public HashSet<string> LoadingHistoryChannels { get; } = new(StringComparer.OrdinalIgnoreCase);
|
||||
public List<UserSummary> Users { get; } = new();
|
||||
public List<FileSummary> Files { get; } = new();
|
||||
public List<InboxItem> InboxItems { get; } = new();
|
||||
public int UnreadInboxCount { get; set; } = 0;
|
||||
public InboxPreferences InboxPreferences { get; set; } = new();
|
||||
public List<string> SystemNotices { get; } = new();
|
||||
|
||||
public int ChatScrollOffset { get; set; } = 0;
|
||||
|
|
@ -440,4 +443,57 @@ public class ClientState
|
|||
NeedsRedraw = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void SetInboxSync(List<InboxItem> items, int unreadCount, InboxPreferences? preferences = null)
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
InboxItems.Clear();
|
||||
InboxItems.AddRange(items);
|
||||
UnreadInboxCount = unreadCount;
|
||||
if (preferences != null)
|
||||
{
|
||||
InboxPreferences = preferences;
|
||||
}
|
||||
NeedsRedraw = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void AddOrUpdateInboxItem(InboxItem item, int unreadCount)
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
int idx = InboxItems.FindIndex(x => string.Equals(x.Id, item.Id, StringComparison.OrdinalIgnoreCase));
|
||||
if (idx >= 0)
|
||||
{
|
||||
InboxItems[idx] = item;
|
||||
}
|
||||
else
|
||||
{
|
||||
InboxItems.Insert(0, item);
|
||||
}
|
||||
UnreadInboxCount = unreadCount;
|
||||
NeedsRedraw = true;
|
||||
}
|
||||
}
|
||||
|
||||
public List<InboxItem> GetInboxItems()
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
return new List<InboxItem>(InboxItems);
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsConversationFollowed(Channel ch)
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
if (ch.Type == ChannelTypes.Channel)
|
||||
{
|
||||
return InboxPreferences.FollowedChannelIds.Contains(ch.Id, StringComparer.OrdinalIgnoreCase);
|
||||
}
|
||||
return !InboxPreferences.MutedChannelIds.Contains(ch.Id, StringComparer.OrdinalIgnoreCase);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue