Fixes #9 and closes #8. This adds a way to mark servers as read.

Servers are also marked as read when joining them.
You can now also mark DMs as read.
This commit is contained in:
Paul
2021-08-07 12:30:19 +01:00
parent 2f06112921
commit 0ea80b5717
7 changed files with 54 additions and 11 deletions

View File

@@ -1,4 +1,5 @@
import type { ChannelUnread } from "revolt-api/types/Sync";
import { ulid } from "ulid";
export interface Unreads {
[key: string]: Partial<Omit<ChannelUnread, "_id">>;
@@ -11,6 +12,10 @@ export type UnreadsAction =
channel: string;
message: string;
}
| {
type: "UNREADS_MARK_MULTIPLE_READ";
channels: string[];
}
| {
type: "UNREADS_SET";
unreads: ChannelUnread[];
@@ -33,6 +38,17 @@ export function unreads(state = {} as Unreads, action: UnreadsAction): Unreads {
last_id: action.message,
},
};
case "UNREADS_MARK_MULTIPLE_READ": {
const newState = { ...state };
const last_id = ulid();
for (const channel of action.channels) {
newState[channel] = {
last_id,
};
}
return newState;
}
case "UNREADS_SET": {
const obj: Unreads = {};
for (const entry of action.unreads) {