fix: pretend channels are read until we get the actual data

This commit is contained in:
Paul Makles
2022-05-27 22:25:27 +01:00
parent 52c7bfdcd6
commit 866ec618dd
3 changed files with 10 additions and 2 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "revolt.js",
"version": "6.0.1",
"version": "6.0.2",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"module": "esm/index.js",
+1 -1
View File
@@ -1,4 +1,4 @@
export const LIBRARY_VERSION = "6.0.1";
export const LIBRARY_VERSION = "6.0.2";
export const defaultConfig = {
apiURL: "https://api.revolt.chat",
+8
View File
@@ -20,6 +20,7 @@ export interface INotificationChecker {
*/
export default class Unreads {
private client: Client;
private loaded: boolean;
private channels: ObservableMap<string, Omit<ChannelUnread, "_id">>;
/**
@@ -27,6 +28,7 @@ export default class Unreads {
*/
constructor(client: Client) {
this.channels = new ObservableMap();
this.loaded = false;
makeAutoObservable(this);
this.client = client;
}
@@ -37,6 +39,7 @@ export default class Unreads {
async sync() {
const unreads = await this.client.syncFetchUnreads();
runInAction(() => {
this.loaded = true;
for (const unread of unreads) {
const { _id, ...data } = unread;
this.channels.set(_id.channel, data);
@@ -50,6 +53,11 @@ export default class Unreads {
* @returns Partial channel unread object
*/
@computed getUnread(channel_id: string) {
if (!this.loaded)
return {
last_id: "40000000000000000000000000",
};
return this.channels.get(channel_id);
}