thread unreads and sync retrying

This commit is contained in:
tezlm 2024-01-15 02:18:45 -08:00
parent 5966e2cd9d
commit 51a50430a4
Signed by: tezlm
GPG key ID: 649733FCD94AFBBA
22 changed files with 81 additions and 11 deletions

1
dist/src/api.d.ts vendored
View file

@ -73,6 +73,7 @@ export interface SyncResponseRoom {
joined_count?: number;
invited_count?: number;
unreads?: Unreads;
unreads_threaded?: Record<EventId, Unreads>;
}
export interface SyncResponse {
pos: string;

2
dist/src/api.js.map vendored
View file

@ -1 +1 @@
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../src/api.ts"],"names":[],"mappings":"AAAA,4BAA4B;;AAyP5B,qCAAqC;AACrC,qBAAqB;AACrB,IAAI;AAEJ,kCAAkC;AAClC,kBAAkB;AAClB,mBAAmB;AACnB,oBAAoB;AACpB,qBAAqB;AACrB,oBAAoB;AACpB,OAAO;AACP,cAAc;AACd,oBAAoB;AACpB,uBAAuB;AACvB,mBAAmB;AACnB,OAAO;AACP,oBAAoB;AACpB,uBAAuB;AACvB,8BAA8B;AAC9B,kEAAkE;AAClE,QAAQ;AACR,IAAI"}
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../src/api.ts"],"names":[],"mappings":"AAAA,4BAA4B;;AA0P5B,qCAAqC;AACrC,qBAAqB;AACrB,IAAI;AAEJ,kCAAkC;AAClC,kBAAkB;AAClB,mBAAmB;AACnB,oBAAoB;AACpB,qBAAqB;AACrB,oBAAoB;AACpB,OAAO;AACP,cAAc;AACd,oBAAoB;AACpB,uBAAuB;AACvB,mBAAmB;AACnB,OAAO;AACP,oBAAoB;AACpB,uBAAuB;AACvB,8BAA8B;AAC9B,kEAAkE;AAClE,QAAQ;AACR,IAAI"}

View file

@ -83,6 +83,7 @@ export declare class Client extends Client_base {
media: Media;
constructor(config: ClientConfig);
private setState;
private retry;
start(): void;
stop(): void;
logout(): Promise<void>;

18
dist/src/client.js vendored
View file

@ -124,6 +124,20 @@ export class Client extends EventEmitter {
this.state = state;
this.emit("state", state);
}
retry() {
const backoff = this.state.state === "retry" ? this.state.backoff : 100;
setTimeout(async () => {
try {
await this.conn.sync();
this.start();
}
catch {
this.retry();
}
}, backoff);
// TODO: determine if something should be exponentially backed off or not
this.setState({ state: "retry", backoff: backoff * 2 });
}
// Start receiving events from /sync.
// WARN: if you lose the reference to Client, the poller will leak
start() {
@ -135,7 +149,9 @@ export class Client extends EventEmitter {
}
catch (err) {
console.error(err);
this.setState({ state: "error", reason: err });
// TODO: determine when something should or shouldn't be retried
// this.setState({ state: "error", reason: err });
this.retry();
}
}
})();

View file

@ -1 +1 @@
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AAAA,6DAA6D;AAG7D,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAEnC,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,YAAY,MAAM,QAAQ,CAAC;AAsDlC,MAAM,KAAM,SAAQ,GAAiB;IACnC,YAAmB,MAAc;QAC/B,KAAK,EAAE,CAAC;QADE;;;;mBAAO,MAAM;WAAQ;IAEjC,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,OAAmB;QAC9B,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC;YAChC,YAAY,EAAE,OAAO,CAAC,OAAO;YAC7B,aAAa,EAAE,OAAO,CAAC,YAAY,EAAE,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;gBAC9C,IAAI,EAAE,EAAE,CAAC,IAAI;gBACb,OAAO,EAAE,EAAE,CAAC,OAAO;gBACnB,SAAS,EAAE,EAAE,CAAC,QAAQ,IAAI,EAAE;aAC7B,CAAC,CAAC;YACH,gBAAgB,EAAE,OAAO,CAAC,eAAe;SAC1C,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,aAA8B,EAAE,MAAe;QACxD,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,a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QAAQ,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC;QAEjC,CAAC,KAAK,IAAI,EAAE;YACV,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,KAAK,MAAM,EAAE,CAAC;gBACnC,IAAI,CAAC;oBACH,MAAM,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;gBACzB,CAAC;gBAAC,OAAO,GAAG,EAAE,CAAC;oBACb,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;oBACnB,gEAAgE;oBAChE,kDAAkD;oBAClD,IAAI,CAAC,KAAK,EAAE,CAAC;gBACf,CAAC;YACH,CAAC;QACH,CAAC,CAAC,EAAE,CAAA;IACN,CAAC;IAED,oCAAoC;IACpC,IAAI;QACF,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;QAC7B,IAAI,CAAC,IAAI,GAAG,IAAI,UAAU,CAAC,IAAI,CAAC,CAAC;QACjC,IAAI,CAAC,QAAQ,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC;IACnC,CAAC;IAED,KAAK,CAAC,MAAM;QACV,IAAI,CAAC,IAAI,EAAE,CAAC;QACZ,MAAM,IAAI,CAAC,GAAG,CAAC,UAAU,EAAE,CAAC;QAC5B,IAAI,CAAC,QAAQ,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;IAClD,CAAC;CACF"}

1
dist/src/room.d.ts vendored
View file

@ -22,6 +22,7 @@ export declare class Room extends Room_base {
timelines: RoomTimelineSet;
events: Map<EventId, Event>;
threads: RoomThreads;
unreads: Unreads;
constructor(client: Client, id: string, data: SyncResponseRoom);
_merge(data: SyncResponseRoom): void;
getState(type: string, stateKey?: string): StateEvent | null;

13
dist/src/room.js vendored
View file

@ -57,6 +57,12 @@ export class Room extends EventEmitter {
writable: true,
value: new RoomThreads(this)
});
Object.defineProperty(this, "unreads", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
this.timelines.live.prevBatch = data.prev_batch;
this._merge(data);
}
@ -91,6 +97,13 @@ export class Room extends EventEmitter {
}
}
}
if (data.unreads)
this.unreads = data.unreads;
for (const key in data.unreads_threaded) {
const thread = this.threads.get(key);
if (thread)
thread.unreads = data.unreads_threaded[key];
}
}
getState(type, stateKey = "") {
return this.state.get(type)?.get(stateKey) || null;

File diff suppressed because one or more lines are too long

3
dist/src/sync.js vendored
View file

@ -50,6 +50,7 @@ export class Connection {
timeout,
...this.query,
}, this.controller.signal).catch((reason) => {
console.log({ reason });
if (reason === "update query")
return null;
if (reason === "stop sync")
@ -68,6 +69,8 @@ export class Connection {
rooms.get(roomId)._merge(data);
}
else {
if (rooms.has(roomId))
console.warn("recreating room");
const room = new Room(this.client, roomId, data);
rooms.set(roomId, room);
this.client.emit("roomInit", room);

View file

@ -1 +1 @@
{"version":3,"file":"sync.js","sourceRoot":"","sources":["../../src/sync.ts"],"names":[],"mappings":"AAAA,gEAAgE;AAChE,6DAA6D;AAG7D,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,MAAM,OAAO,UAAU;IAOrB,YAAoB,MAAc;QAAtB;;;;mBAAQ,MAAM;WAAQ;QAN1B;;;;mBAAS,MAAM,EAAE;WAAC;QAClB;;;;mBAAa,IAAI,eAAe,EAAE;WAAC;QACnC;;;;mBAAc,GAAG;WAAC;QAClB;;;;;WAA0B;QAC1B;;;;mBAAqB,EAAE;WAAC;IAEK,CAAC;IAEtC,gBAAgB;IAChB,KAAK,CAAC,IAAI,CAAC,UAAkB,KAAK;QAChC,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC;YACtC,OAAO,EAAE,IAAI,CAAC,MAAM;YACpB,GAAG,EAAE,IAAI,CAAC,GAAG;YACb,WAAW,EAAE,IAAI,CAAC,KAAK,IAA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K,CAAC,IAAI,CAAC,GAAG,YAAY,CAAC;QACtC,IAAI,CAAC,OAAO,EAAE,CAAC;IACjB,CAAC;IAED,eAAe,CAAC,IAAY;QAC1B,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK;YAAE,OAAO;QAC9B,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAC9B,IAAI,CAAC,OAAO,EAAE,CAAC;IACjB,CAAC;IAED,aAAa,CAAC,MAAc,EAAE,YAA8B;QAC1D,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK;YAAE,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,EAAE,CAAC;QAC7C,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,YAAY,CAAC;QACxC,IAAI,CAAC,OAAO,EAAE,CAAC;IACjB,CAAC;IAED,eAAe,CAAC,MAAc;QAC5B,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK;YAAE,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,EAAE,CAAC;QAC7C,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC;QAChC,IAAI,CAAC,OAAO,EAAE,CAAC;IACjB,CAAC;IAED,KAAK,CAAC,MAAe;QACnB,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IAChC,CAAC;CACF"}

View file

@ -16,6 +16,7 @@ export declare class Thread extends Thread_base {
participation: string;
messageCount: number;
latestEvent: Event;
unreads: Unreads;
constructor(baseEvent: Event);
ack(eventId?: EventId): Promise<void>;
}

7
dist/src/thread.js vendored
View file

@ -49,6 +49,12 @@ export class Thread extends EventEmitter {
writable: true,
value: void 0
});
Object.defineProperty(this, "unreads", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
const latestRaw = threadRel.latest_event;
const latestCached = this.room.events.get(latestRaw.event_id);
const latestEvent = latestCached ?? new Event(this.room, latestRaw);
@ -56,6 +62,7 @@ export class Thread extends EventEmitter {
this.room.events.set(latestEvent.id, latestEvent);
this.latestEvent = latestEvent;
this.messageCount = threadRel.count;
this.unreads = baseEvent.unsigned["m.unreads"];
}
// // TODO: local echo(?), return event
// async sendEvent(type: string, content: any) {

View file

@ -1 +1 @@
{"version":3,"file":"thread.js","sourceRoot":"","sources":["../../src/thread.ts"],"names":[],"mappings":"AAAA,OAAO,YAAY,MAAM,QAAQ,CAAC;AAIlC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAUlD,MAAM,OAAO,MAAO,SAAS,YAAgE;IAS3F,YAAmB,SAAgB;QACjC,MAAM,SAAS,GAAG,SAAS,CAAC,QAAQ,CAAC,aAAa,CAAC,EAAE,CAAC,UAAU,CAAC,CAAC;QAClE,IAAI,CAAC,SAAS;YAAE,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAC;QAErF,KAAK,EAAE,CAAC;QAJE;;;;mBAAO,SAAS;WAAO;QAR5B;;;;mBAAa,IAAI,CAAC,SAAS,CAAC,IAAI;WAAC;QACjC;;;;mBAAK,IAAI,CAAC,SAAS,CAAC,EAAE;WAAC;QACvB;;;;mBAAY,IAAI,iBAAiB,CAAC,IAAI,CAAC;WAAC;QAExC;;;;mBAAgB,eAAe;WAAC;QAChC;;;;;WAAqB;QACrB;;;;;WAAmB;QAQxB,MAAM,SAAS,GAAG,SAAS,CAAC,YAAY,CAAC;QACzC,MAAM,YAAY,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;QAC9D,MAAM,WAAW,GAAG,YAAY,IAAI,IAAI,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;QACpE,IAAI,CAAC,YAAY;YAAE,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,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;WAAqB;QACrB;;;;;WAAmB;QACnB;;;;;WAAiB;QAQtB,MAAM,SAAS,GAAG,SAAS,CAAC,YAAY,CAAC;QACzC,MAAM,YAAY,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;QAC9D,MAAM,WAAW,GAAG,YAAY,IAAI,IAAI,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;QACpE,IAAI,CAAC,YAAY;YAAE,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE,EAAE,WAAW,CAAC,CAAC;QACrE,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,YAAY,GAAG,SAAS,CAAC,KAAK,CAAC;QACpC,IAAI,CAAC,OAAO,GAAG,SAAS,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;IACjD,CAAC;IAED,uCAAuC;IACvC,gDAAgD;IAChD,uEAAuE;IACvE,IAAI;IAEJ,sDAAsD;IACtD,sDAAsD;IACtD,IAAI;IAEJ,KAAK,CAAC,GAAG,CAAC,OAAiB;QACzB,MAAM,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC;YAC7B,IAAI,EAAE,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,IAAI,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC;SACnF,CAAC,CAAC;IACL,CAAC;CACF"}

View file

@ -199,6 +199,7 @@ class TimelineSet {
return null;
}
}
// FIXME: this has some kind of bug
function merge(timelines, tl) {
// [_, _, 2, 3, 4, 5, _, _, _] (current)
// [_, _, _, 3, 4, 5, 6, 7, 8] (other1)
@ -285,7 +286,6 @@ export class ThreadTimelineSet extends TimelineSet {
this.timelines.add(this.live);
}
async fetch(at, limit = 50) {
console.log("FETCH");
if (at === "end") {
const fetchCount = limit - this.live.getEvents().length;
if (fetchCount > 0)

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -119,6 +119,7 @@ export interface SyncResponseRoom {
joined_count?: number,
invited_count?: number,
unreads?: Unreads,
unreads_threaded?: Record<EventId, Unreads>,
}
export interface SyncResponse {

View file

@ -149,6 +149,20 @@ export class Client extends (EventEmitter as unknown as new () => TypedEmitter<C
this.emit("state", state);
}
private retry() {
const backoff = this.state.state === "retry" ? this.state.backoff : 100;
setTimeout(async () => {
try {
await this.conn.sync();
this.start();
} catch {
this.retry();
}
}, backoff);
// TODO: determine if something should be exponentially backed off or not
this.setState({ state: "retry", backoff: backoff * 2 });
}
// Start receiving events from /sync.
// WARN: if you lose the reference to Client, the poller will leak
start() {
@ -160,7 +174,9 @@ export class Client extends (EventEmitter as unknown as new () => TypedEmitter<C
await this.conn.sync();
} catch (err) {
console.error(err);
this.setState({ state: "error", reason: err });
// TODO: determine when something should or shouldn't be retried
// this.setState({ state: "error", reason: err });
this.retry();
}
}
})()

View file

@ -31,6 +31,7 @@ export class Room extends (EventEmitter as unknown as new () => TypedEmitter<Roo
public timelines = new RoomTimelineSet(this);
public events: Map<EventId, Event> = new Map();
public threads = new RoomThreads(this);
public unreads!: Unreads;
// public members: Members;
/*
@ -88,6 +89,11 @@ room.unban(userid)
}
}
}
if (data.unreads) this.unreads = data.unreads;
for (const key in data.unreads_threaded) {
const thread = this.threads.get(key);
if (thread) thread.unreads = data.unreads_threaded[key];
}
}
getState(type: string, stateKey: string = ""): StateEvent | null {

View file

@ -24,6 +24,7 @@ export class Connection {
timeout,
...this.query,
}, this.controller.signal).catch((reason) => {
console.log({ reason });
if (reason === "update query") return null;
if (reason === "stop sync") return null;
throw reason;
@ -41,6 +42,7 @@ export class Connection {
if (rooms.has(roomId) && !data.initial) {
rooms.get(roomId)!._merge(data);
} else {
if (rooms.has(roomId)) console.warn("recreating room");
const room = new Room(this.client, roomId, data);
rooms.set(roomId, room);
this.client.emit("roomInit", room);

View file

@ -21,6 +21,7 @@ export class Thread extends (EventEmitter as unknown as new () => TypedEmitter<T
public participation = "participating";
public messageCount: number;
public latestEvent: Event;
public unreads: Unreads;
constructor(public baseEvent: Event) {
const threadRel = baseEvent.unsigned["m.relations"]?.["m.thread"];
@ -34,6 +35,7 @@ export class Thread extends (EventEmitter as unknown as new () => TypedEmitter<T
if (!latestCached) this.room.events.set(latestEvent.id, latestEvent);
this.latestEvent = latestEvent;
this.messageCount = threadRel.count;
this.unreads = baseEvent.unsigned["m.unreads"];
}
// // TODO: local echo(?), return event

View file

@ -174,6 +174,7 @@ abstract class TimelineSet {
}
}
// FIXME: this has some kind of bug
function merge(timelines: ThreadTimelineSet, tl: ThreadTimeline): ThreadTimeline {
// [_, _, 2, 3, 4, 5, _, _, _] (current)
// [_, _, _, 3, 4, 5, 6, 7, 8] (other1)
@ -241,7 +242,6 @@ export class ThreadTimelineSet extends TimelineSet {
}
public async fetch(at: EventId | "start" | "end", limit = 50): Promise<ThreadTimeline> {
console.log("FETCH");
if (at === "end") {
const fetchCount = limit - this.live.getEvents().length;
if (fetchCount > 0) await this.live.paginate("b", fetchCount);