Messing with timeline stuff a bit
This commit is contained in:
parent
b0cf2ad840
commit
b72a379d79
16 changed files with 311 additions and 41 deletions
4
dist/src/client.js
vendored
4
dist/src/client.js
vendored
|
@ -13,7 +13,7 @@ class Rooms extends Map {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
async create(options) {
|
async create(options) {
|
||||||
return this.client.net.createRoom({
|
return this.client.net.roomCreate({
|
||||||
room_version: options.version,
|
room_version: options.version,
|
||||||
initial_state: options.initialState?.map(ev => ({
|
initial_state: options.initialState?.map(ev => ({
|
||||||
type: ev.type,
|
type: ev.type,
|
||||||
|
@ -24,7 +24,7 @@ class Rooms extends Map {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
async join(roomIdOrAlias, reason) {
|
async join(roomIdOrAlias, reason) {
|
||||||
return this.client.net.joinRoom(roomIdOrAlias, reason);
|
return this.client.net.roomJoin(roomIdOrAlias, reason);
|
||||||
}
|
}
|
||||||
subscribe(roomId, subscription) {
|
subscribe(roomId, subscription) {
|
||||||
this.client.conn.roomSubscribe(roomId, subscription);
|
this.client.conn.roomSubscribe(roomId, subscription);
|
||||||
|
|
7
dist/src/net.d.ts
vendored
7
dist/src/net.d.ts
vendored
|
@ -11,9 +11,10 @@ export declare class Network {
|
||||||
private fetch;
|
private fetch;
|
||||||
private fetchSkipQueue;
|
private fetchSkipQueue;
|
||||||
sync(options: t.SyncRequest, signal: AbortSignal): Promise<t.SyncResponse>;
|
sync(options: t.SyncRequest, signal: AbortSignal): Promise<t.SyncResponse>;
|
||||||
createRoom(options: t.CreateRoomRequest): Promise<t.CreateRoomResponse>;
|
roomCreate(options: t.CreateRoomRequest): Promise<t.CreateRoomResponse>;
|
||||||
leaveRoom(roomId: t.RoomId, reason?: string): Promise<void>;
|
roomLeave(roomId: t.RoomId, reason?: string): Promise<void>;
|
||||||
joinRoom(roomIdOrAlias: t.RoomId | string, reason?: string): Promise<void>;
|
roomJoin(roomIdOrAlias: t.RoomId | string, reason?: string): Promise<void>;
|
||||||
|
roomInvite(roomId: t.RoomId, userId: t.UserId, reason?: string): Promise<void>;
|
||||||
fetchEvent(roomId: t.RoomId, eventId: t.EventId): Promise<t.ApiEvent>;
|
fetchEvent(roomId: t.RoomId, eventId: t.EventId): Promise<t.ApiEvent>;
|
||||||
fetchContext(roomId: t.RoomId, eventId: t.EventId, limit?: number): Promise<t.ContextResponse>;
|
fetchContext(roomId: t.RoomId, eventId: t.EventId, limit?: number): Promise<t.ContextResponse>;
|
||||||
fetchMessages(opts: {
|
fetchMessages(opts: {
|
||||||
|
|
32
dist/src/net.js
vendored
32
dist/src/net.js
vendored
|
@ -101,27 +101,34 @@ export class Network {
|
||||||
extra: { signal },
|
extra: { signal },
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
async createRoom(options) {
|
async roomCreate(options) {
|
||||||
return this.fetch({
|
return this.fetch({
|
||||||
method: "POST",
|
method: "POST",
|
||||||
path: `/_matrix/client/v3/createRoom`,
|
path: `/_matrix/client/v3/createRoom`,
|
||||||
body: options,
|
body: options,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
async leaveRoom(roomId, reason) {
|
async roomLeave(roomId, reason) {
|
||||||
return this.fetch({
|
return this.fetch({
|
||||||
method: "POST",
|
method: "POST",
|
||||||
path: `/_matrix/client/v3/rooms/${e(roomId)}/leave`,
|
path: `/_matrix/client/v3/rooms/${e(roomId)}/leave`,
|
||||||
body: { reason },
|
body: { reason },
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
async joinRoom(roomIdOrAlias, reason) {
|
async roomJoin(roomIdOrAlias, reason) {
|
||||||
return this.fetch({
|
return this.fetch({
|
||||||
method: "POST",
|
method: "POST",
|
||||||
path: `/_matrix/client/v3/join/${e(roomIdOrAlias)}`,
|
path: `/_matrix/client/v3/join/${e(roomIdOrAlias)}`,
|
||||||
body: { reason },
|
body: { reason },
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
async roomInvite(roomId, userId, reason) {
|
||||||
|
return this.fetch({
|
||||||
|
method: "POST",
|
||||||
|
path: `/_matrix/client/v3/rooms/${e(roomId)}/invite`,
|
||||||
|
body: { reason, user_id: userId },
|
||||||
|
});
|
||||||
|
}
|
||||||
async fetchEvent(roomId, eventId) {
|
async fetchEvent(roomId, eventId) {
|
||||||
return this.fetch({
|
return this.fetch({
|
||||||
method: "GET",
|
method: "GET",
|
||||||
|
@ -231,4 +238,23 @@ export class Network {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
|
new apis?
|
||||||
|
|
||||||
|
POST /rooms/{roomId}/relations/{eventId}
|
||||||
|
|
||||||
|
{
|
||||||
|
limit: uint,
|
||||||
|
from: Option<String>,
|
||||||
|
to: Option<String>,
|
||||||
|
dir: "b" | "f",
|
||||||
|
event_types: Vec<String>,
|
||||||
|
rel_types: Vec<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
chunk: Vec<Event>,
|
||||||
|
next_batch: Option<String>,
|
||||||
|
}
|
||||||
|
*/
|
||||||
//# sourceMappingURL=net.js.map
|
//# sourceMappingURL=net.js.map
|
2
dist/src/net.js.map
vendored
2
dist/src/net.js.map
vendored
File diff suppressed because one or more lines are too long
2
dist/src/room.js
vendored
2
dist/src/room.js
vendored
|
@ -118,7 +118,7 @@ export class Room extends EventEmitter {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
async leave(reason) {
|
async leave(reason) {
|
||||||
await this.client.net.leaveRoom(this.id, reason);
|
await this.client.net.roomLeave(this.id, reason);
|
||||||
}
|
}
|
||||||
async ack(eventId) {
|
async ack(eventId) {
|
||||||
await this.client.net.ack({
|
await this.client.net.ack({
|
||||||
|
|
2
dist/src/sync.js
vendored
2
dist/src/sync.js
vendored
|
@ -78,7 +78,7 @@ export class Connection {
|
||||||
if (!list)
|
if (!list)
|
||||||
continue;
|
continue;
|
||||||
list.count = json.lists[listId].count;
|
list.count = json.lists[listId].count;
|
||||||
for (const op of json.lists[listId].ops) {
|
for (const op of json.lists[listId].ops || []) {
|
||||||
switch (op.op) {
|
switch (op.op) {
|
||||||
case "SYNC":
|
case "SYNC":
|
||||||
list.rooms.splice(op.range[0], op.range[1] - op.range[0] + 1, ...op.room_ids.map(id => rooms.get(id)));
|
list.rooms.splice(op.range[0], op.range[1] - op.range[0] + 1, ...op.room_ids.map(id => rooms.get(id)));
|
||||||
|
|
2
dist/src/sync.js.map
vendored
2
dist/src/sync.js.map
vendored
|
@ -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,IAAI,SAAS;YACpC,OAAO;YACP,GAAG,IAAI,CAAC,KAAK;SACd,EAAE,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,CAAC,MAAM,EAAE,EAAE;YAC1C,IAAI,MAAM,KAAK,cAAc;gBAAE,OAAO,IAAI,CAAC;YAC3C,IAAI,MAAM,KAAK,WAAW;gBAAE,OAAO,IAAI,CAAC;Y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C;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"}
|
6
dist/src/timeline.d.ts
vendored
6
dist/src/timeline.d.ts
vendored
|
@ -17,19 +17,19 @@ declare abstract class Timeline extends Timeline_base {
|
||||||
prevBatch: string | undefined;
|
prevBatch: string | undefined;
|
||||||
nextBatch: string | undefined;
|
nextBatch: string | undefined;
|
||||||
getEvents(): Array<Event>;
|
getEvents(): Array<Event>;
|
||||||
abstract paginate(dir: "f" | "b", limit: number): Promise<boolean>;
|
abstract paginate(dir: "f" | "b", limit: number): Promise<number>;
|
||||||
}
|
}
|
||||||
export declare class RoomTimeline extends Timeline implements TypedEmitter<TimelineEvents<RoomTimeline>> {
|
export declare class RoomTimeline extends Timeline implements TypedEmitter<TimelineEvents<RoomTimeline>> {
|
||||||
private timelineSet;
|
private timelineSet;
|
||||||
room: Room;
|
room: Room;
|
||||||
constructor(timelineSet: RoomTimelineSet, room: Room);
|
constructor(timelineSet: RoomTimelineSet, room: Room);
|
||||||
paginate(dir: "f" | "b", limit?: number): Promise<boolean>;
|
paginate(dir: "f" | "b", limit?: number): Promise<number>;
|
||||||
}
|
}
|
||||||
export declare class ThreadTimeline extends Timeline implements TypedEmitter<TimelineEvents<ThreadTimeline>> {
|
export declare class ThreadTimeline extends Timeline implements TypedEmitter<TimelineEvents<ThreadTimeline>> {
|
||||||
private timelineSet;
|
private timelineSet;
|
||||||
thread: Thread;
|
thread: Thread;
|
||||||
constructor(timelineSet: ThreadTimelineSet, thread: Thread);
|
constructor(timelineSet: ThreadTimelineSet, thread: Thread);
|
||||||
paginate(dir: "f" | "b", limit?: number): Promise<boolean>;
|
paginate(dir: "f" | "b", limit?: number): Promise<number>;
|
||||||
}
|
}
|
||||||
declare abstract class TimelineSet {
|
declare abstract class TimelineSet {
|
||||||
abstract timelines: Set<Timeline>;
|
abstract timelines: Set<Timeline>;
|
||||||
|
|
111
dist/src/timeline.js
vendored
111
dist/src/timeline.js
vendored
|
@ -66,9 +66,9 @@ export class RoomTimeline extends Timeline {
|
||||||
}
|
}
|
||||||
async paginate(dir, limit = 50) {
|
async paginate(dir, limit = 50) {
|
||||||
if (dir === "b" && this.isAtBeginning)
|
if (dir === "b" && this.isAtBeginning)
|
||||||
return false;
|
return 0;
|
||||||
if (dir === "f" && this.isAtEnd)
|
if (dir === "f" && this.isAtEnd)
|
||||||
return false;
|
return 0;
|
||||||
const from = dir === "f" ? this.nextBatch : this.prevBatch;
|
const from = dir === "f" ? this.nextBatch : this.prevBatch;
|
||||||
const data = await this.room.client.net.fetchMessages({
|
const data = await this.room.client.net.fetchMessages({
|
||||||
roomId: this.room.id,
|
roomId: this.room.id,
|
||||||
|
@ -88,6 +88,7 @@ export class RoomTimeline extends Timeline {
|
||||||
for (const event of events)
|
for (const event of events)
|
||||||
this.room.events.set(event.id, event);
|
this.room.events.set(event.id, event);
|
||||||
this.emit("timelineUpdate", events, false);
|
this.emit("timelineUpdate", events, false);
|
||||||
|
return events.length;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
const events = data.chunk.reverse().map(intoEvent(this.room));
|
const events = data.chunk.reverse().map(intoEvent(this.room));
|
||||||
|
@ -111,8 +112,8 @@ export class RoomTimeline extends Timeline {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.emit("timelineUpdate", events, true);
|
this.emit("timelineUpdate", events, true);
|
||||||
|
return events.length;
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
export class ThreadTimeline extends Timeline {
|
export class ThreadTimeline extends Timeline {
|
||||||
|
@ -133,9 +134,9 @@ export class ThreadTimeline extends Timeline {
|
||||||
}
|
}
|
||||||
async paginate(dir, limit = 50) {
|
async paginate(dir, limit = 50) {
|
||||||
if (dir === "b" && this.isAtBeginning)
|
if (dir === "b" && this.isAtBeginning)
|
||||||
return false;
|
return 0;
|
||||||
if (dir === "f" && this.isAtEnd)
|
if (dir === "f" && this.isAtEnd)
|
||||||
return false;
|
return 0;
|
||||||
const { room } = this.thread;
|
const { room } = this.thread;
|
||||||
const from = dir === "f" ? this.nextBatch : this.prevBatch;
|
const from = dir === "f" ? this.nextBatch : this.prevBatch;
|
||||||
const data = await room.client.net.fetchRelations(room.id, this.thread.baseEvent.id, {
|
const data = await room.client.net.fetchRelations(room.id, this.thread.baseEvent.id, {
|
||||||
|
@ -156,7 +157,7 @@ export class ThreadTimeline extends Timeline {
|
||||||
for (const event of events)
|
for (const event of events)
|
||||||
room.events.set(event.id, event);
|
room.events.set(event.id, event);
|
||||||
this.emit("timelineUpdate", events, false);
|
this.emit("timelineUpdate", events, false);
|
||||||
return !!data.next_batch;
|
return events.length;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
const events = data.chunk.map(intoEvent(room));
|
const events = data.chunk.map(intoEvent(room));
|
||||||
|
@ -180,7 +181,7 @@ export class ThreadTimeline extends Timeline {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.emit("timelineUpdate", events, true);
|
this.emit("timelineUpdate", events, true);
|
||||||
return !!data.prev_batch;
|
return events.length;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -195,6 +196,93 @@ class TimelineSet {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
function merge2(timelines, tl) {
|
||||||
|
// [_, _, 2, 3, 4, 5, _, _, _] (current)
|
||||||
|
// [_, _, _, 3, 4, 5, 6, 7, 8] (other1)
|
||||||
|
// [0, 1, 2, 3, 4, _, _, _, _] (other2)
|
||||||
|
// [0, 1, 2, 3, 4, 5, 6, 7, 8] (other3)
|
||||||
|
// [_, _, 2, 3, 4, 5, 6, 7, 8] (other4)
|
||||||
|
// event = 3, thisIdx = 3, otherIdx1 = 0
|
||||||
|
// event = 2, thisIdx = 0, otherIdx2 = 2
|
||||||
|
// event = 2, thisIdx = 0, otherIdx3 = 2
|
||||||
|
// event = 2, thisIdx = 0, otherIdx4 = 0
|
||||||
|
// [1, 2] + [4, 5] (events = [2, 3, 4])
|
||||||
|
const events = tl._eventList;
|
||||||
|
// let otherTl;
|
||||||
|
for (const event of events) {
|
||||||
|
const other = timelines.timelineMap.get(event.id);
|
||||||
|
if (!other)
|
||||||
|
continue;
|
||||||
|
if (tl === other)
|
||||||
|
continue;
|
||||||
|
// console.log("merge ", tl, other);
|
||||||
|
const idx = other._eventList.indexOf(event);
|
||||||
|
other._eventList.unshift(...events.slice(0, idx));
|
||||||
|
other.isAtBeginning = tl.isAtBeginning;
|
||||||
|
for (const event of events.slice(0, idx)) {
|
||||||
|
timelines.timelineMap.set(event.id, other);
|
||||||
|
}
|
||||||
|
timelines.timelines.delete(tl);
|
||||||
|
tl = other;
|
||||||
|
}
|
||||||
|
// for (const event of events) {
|
||||||
|
// const other = timelines.timelineMap.get(event.id);
|
||||||
|
// if (!other) continue;
|
||||||
|
// if (tl === other) continue;
|
||||||
|
// console.log("merge ", tl, other);
|
||||||
|
// // const idx = other._eventList.indexOf(event);
|
||||||
|
// // other._eventList.splice(idx, other._eventList.length - idx);
|
||||||
|
// // other._eventList.push(...events.slice(idx));
|
||||||
|
// other.isAtEnd = tl.isAtEnd;
|
||||||
|
// tl = other;
|
||||||
|
// }
|
||||||
|
// for (let i = events.length - 1; i >= 0; i--) {
|
||||||
|
// const event = events[i];
|
||||||
|
// const other = timelines.timelineMap.get(event.id);
|
||||||
|
// if (!other) continue;
|
||||||
|
// if (tl === other) continue;
|
||||||
|
// const idx = other._eventList.lastIndexOf(event);
|
||||||
|
// other._eventList.push(...events.slice(idx));
|
||||||
|
// for (const event of events.slice(0, idx)) {
|
||||||
|
// timelines.timelineMap.set(event.id, other);
|
||||||
|
// }
|
||||||
|
// timelines.timelines.delete(tl);
|
||||||
|
// tl = other;
|
||||||
|
// }
|
||||||
|
return tl;
|
||||||
|
}
|
||||||
|
// function merge(timelines: ThreadTimelineSet, events: Array<Event>): ThreadTimeline | null {
|
||||||
|
// for (const event of events) {
|
||||||
|
// const other = timelines.timelineMap.get(event.id);
|
||||||
|
// if (!other) continue;
|
||||||
|
// if (tl === other) continue;
|
||||||
|
// console.log("merge earliest with ", other);
|
||||||
|
// const idx = other._eventList.indexOf(event);
|
||||||
|
// other._eventList.unshift(...events.slice(0, idx));
|
||||||
|
// other.isAtBeginning = true;
|
||||||
|
// return other;
|
||||||
|
// }
|
||||||
|
// return null;
|
||||||
|
// }
|
||||||
|
// const realTimeline = merge(this, tl._eventList) ?? tl;
|
||||||
|
// function merge(timelines: ThreadTimelineSet, events: Array<Event>): ThreadTimeline | null {
|
||||||
|
// // [_, _, _, _, (4), 5, 6, 7]
|
||||||
|
// // [0, 1, 2, 3, 4 , 5]
|
||||||
|
// // ^
|
||||||
|
// for (const event of events) {
|
||||||
|
// const other = timelines.timelineMap.get(event.id);
|
||||||
|
// if (!other) continue;
|
||||||
|
// if (tl === other) continue;
|
||||||
|
// console.log("merge live with ", other);
|
||||||
|
// const idx = other._eventList.indexOf(event);
|
||||||
|
// other._eventList.splice(idx, other._eventList.length - idx); // delete 4, 5
|
||||||
|
// other._eventList.push(...events.slice(idx)); // push 4, 5, 6, 7
|
||||||
|
// other.isAtEnd = true;
|
||||||
|
// return other;
|
||||||
|
// }
|
||||||
|
// return null;
|
||||||
|
// }
|
||||||
|
// const realTimeline = merge(this, tl._eventList);
|
||||||
export class ThreadTimelineSet extends TimelineSet {
|
export class ThreadTimelineSet extends TimelineSet {
|
||||||
constructor(thread) {
|
constructor(thread) {
|
||||||
super();
|
super();
|
||||||
|
@ -239,6 +327,13 @@ export class ThreadTimelineSet extends TimelineSet {
|
||||||
if (fetchCount > 0)
|
if (fetchCount > 0)
|
||||||
await this.live.paginate("b", fetchCount);
|
await this.live.paginate("b", fetchCount);
|
||||||
return this.live;
|
return this.live;
|
||||||
|
const tl = this.live;
|
||||||
|
const realTimeline = merge2(this, tl);
|
||||||
|
if (realTimeline) {
|
||||||
|
this.timelines.delete(tl);
|
||||||
|
this.live = realTimeline;
|
||||||
|
}
|
||||||
|
return realTimeline ?? tl;
|
||||||
}
|
}
|
||||||
else if (at === "start") {
|
else if (at === "start") {
|
||||||
const existing = [...this.timelines].find(i => i.isAtBeginning);
|
const existing = [...this.timelines].find(i => i.isAtBeginning);
|
||||||
|
@ -253,6 +348,8 @@ export class ThreadTimelineSet extends TimelineSet {
|
||||||
await tl.paginate("b", limit);
|
await tl.paginate("b", limit);
|
||||||
this.timelines.add(tl);
|
this.timelines.add(tl);
|
||||||
return tl;
|
return tl;
|
||||||
|
const realTimeline = merge2(this, tl) ?? tl;
|
||||||
|
return realTimeline;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
2
dist/src/timeline.js.map
vendored
2
dist/src/timeline.js.map
vendored
File diff suppressed because one or more lines are too long
2
dist/tsconfig.tsbuildinfo
vendored
2
dist/tsconfig.tsbuildinfo
vendored
File diff suppressed because one or more lines are too long
|
@ -64,7 +64,7 @@ class Rooms extends Map<string, Room> {
|
||||||
}
|
}
|
||||||
|
|
||||||
async create(options: CreateRoom): Promise<unknown> {
|
async create(options: CreateRoom): Promise<unknown> {
|
||||||
return this.client.net.createRoom({
|
return this.client.net.roomCreate({
|
||||||
room_version: options.version,
|
room_version: options.version,
|
||||||
initial_state: options.initialState?.map(ev => ({
|
initial_state: options.initialState?.map(ev => ({
|
||||||
type: ev.type,
|
type: ev.type,
|
||||||
|
@ -76,7 +76,7 @@ class Rooms extends Map<string, Room> {
|
||||||
}
|
}
|
||||||
|
|
||||||
async join(roomIdOrAlias: RoomId | string, reason?: string): Promise<unknown> {
|
async join(roomIdOrAlias: RoomId | string, reason?: string): Promise<unknown> {
|
||||||
return this.client.net.joinRoom(roomIdOrAlias, reason);
|
return this.client.net.roomJoin(roomIdOrAlias, reason);
|
||||||
}
|
}
|
||||||
|
|
||||||
subscribe(roomId: RoomId, subscription: RoomSubscription) {
|
subscribe(roomId: RoomId, subscription: RoomSubscription) {
|
||||||
|
|
34
src/net.ts
34
src/net.ts
|
@ -116,7 +116,7 @@ export class Network {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public async createRoom(options: t.CreateRoomRequest): Promise<t.CreateRoomResponse> {
|
public async roomCreate(options: t.CreateRoomRequest): Promise<t.CreateRoomResponse> {
|
||||||
return this.fetch({
|
return this.fetch({
|
||||||
method: "POST",
|
method: "POST",
|
||||||
path: `/_matrix/client/v3/createRoom`,
|
path: `/_matrix/client/v3/createRoom`,
|
||||||
|
@ -124,7 +124,7 @@ export class Network {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public async leaveRoom(roomId: t.RoomId, reason?: string): Promise<void> {
|
public async roomLeave(roomId: t.RoomId, reason?: string): Promise<void> {
|
||||||
return this.fetch({
|
return this.fetch({
|
||||||
method: "POST",
|
method: "POST",
|
||||||
path: `/_matrix/client/v3/rooms/${e(roomId)}/leave`,
|
path: `/_matrix/client/v3/rooms/${e(roomId)}/leave`,
|
||||||
|
@ -132,7 +132,7 @@ export class Network {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public async joinRoom(roomIdOrAlias: t.RoomId | string, reason?: string): Promise<void> {
|
public async roomJoin(roomIdOrAlias: t.RoomId | string, reason?: string): Promise<void> {
|
||||||
return this.fetch({
|
return this.fetch({
|
||||||
method: "POST",
|
method: "POST",
|
||||||
path: `/_matrix/client/v3/join/${e(roomIdOrAlias)}`,
|
path: `/_matrix/client/v3/join/${e(roomIdOrAlias)}`,
|
||||||
|
@ -140,6 +140,14 @@ export class Network {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async roomInvite(roomId: t.RoomId, userId: t.UserId, reason?: string): Promise<void> {
|
||||||
|
return this.fetch({
|
||||||
|
method: "POST",
|
||||||
|
path: `/_matrix/client/v3/rooms/${e(roomId)}/invite`,
|
||||||
|
body: { reason, user_id: userId },
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public async fetchEvent(roomId: t.RoomId, eventId: t.EventId): Promise<t.ApiEvent> {
|
public async fetchEvent(roomId: t.RoomId, eventId: t.EventId): Promise<t.ApiEvent> {
|
||||||
return this.fetch({
|
return this.fetch({
|
||||||
method: "GET",
|
method: "GET",
|
||||||
|
@ -264,3 +272,23 @@ export class Network {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
new apis?
|
||||||
|
|
||||||
|
POST /rooms/{roomId}/relations/{eventId}
|
||||||
|
|
||||||
|
{
|
||||||
|
limit: uint,
|
||||||
|
from: Option<String>,
|
||||||
|
to: Option<String>,
|
||||||
|
dir: "b" | "f",
|
||||||
|
event_types: Vec<String>,
|
||||||
|
rel_types: Vec<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
chunk: Vec<Event>,
|
||||||
|
next_batch: Option<String>,
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
|
@ -121,7 +121,7 @@ room.unban(userid)
|
||||||
}
|
}
|
||||||
|
|
||||||
async leave(reason?: string) {
|
async leave(reason?: string) {
|
||||||
await this.client.net.leaveRoom(this.id, reason);
|
await this.client.net.roomLeave(this.id, reason);
|
||||||
}
|
}
|
||||||
|
|
||||||
async ack(eventId?: EventId) {
|
async ack(eventId?: EventId) {
|
||||||
|
|
|
@ -53,7 +53,7 @@ export class Connection {
|
||||||
|
|
||||||
list.count = json.lists[listId].count;
|
list.count = json.lists[listId].count;
|
||||||
|
|
||||||
for (const op of json.lists[listId].ops) {
|
for (const op of json.lists[listId].ops || []) {
|
||||||
switch (op.op) {
|
switch (op.op) {
|
||||||
case "SYNC":
|
case "SYNC":
|
||||||
list.rooms.splice(op.range[0], op.range[1] - op.range[0] + 1, ...op.room_ids.map(id => rooms.get(id)!));
|
list.rooms.splice(op.range[0], op.range[1] - op.range[0] + 1, ...op.room_ids.map(id => rooms.get(id)!));
|
||||||
|
|
138
src/timeline.ts
138
src/timeline.ts
|
@ -44,7 +44,7 @@ abstract class Timeline extends (EventEmitter as unknown as new () => TypedEmitt
|
||||||
return this._eventList;
|
return this._eventList;
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract paginate(dir: "f" | "b", limit: number): Promise<boolean>;
|
public abstract paginate(dir: "f" | "b", limit: number): Promise<number>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class RoomTimeline extends Timeline implements TypedEmitter<TimelineEvents<RoomTimeline>> {
|
export class RoomTimeline extends Timeline implements TypedEmitter<TimelineEvents<RoomTimeline>> {
|
||||||
|
@ -55,9 +55,9 @@ export class RoomTimeline extends Timeline implements TypedEmitter<TimelineEvent
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async paginate(dir: "f" | "b", limit: number = 50): Promise<boolean> {
|
public async paginate(dir: "f" | "b", limit: number = 50): Promise<number> {
|
||||||
if (dir === "b" && this.isAtBeginning) return false;
|
if (dir === "b" && this.isAtBeginning) return 0;
|
||||||
if (dir === "f" && this.isAtEnd) return false;
|
if (dir === "f" && this.isAtEnd) return 0;
|
||||||
|
|
||||||
const from = dir === "f" ? this.nextBatch : this.prevBatch;
|
const from = dir === "f" ? this.nextBatch : this.prevBatch;
|
||||||
const data = await this.room.client.net.fetchMessages({
|
const data = await this.room.client.net.fetchMessages({
|
||||||
|
@ -76,6 +76,7 @@ export class RoomTimeline extends Timeline implements TypedEmitter<TimelineEvent
|
||||||
this._eventList.push(...events);
|
this._eventList.push(...events);
|
||||||
for (const event of events) this.room.events.set(event.id, event);
|
for (const event of events) this.room.events.set(event.id, event);
|
||||||
this.emit("timelineUpdate", events, false);
|
this.emit("timelineUpdate", events, false);
|
||||||
|
return events.length;
|
||||||
} else {
|
} else {
|
||||||
const events = data.chunk.reverse().map(intoEvent(this.room));
|
const events = data.chunk.reverse().map(intoEvent(this.room));
|
||||||
if (data.end) {
|
if (data.end) {
|
||||||
|
@ -95,8 +96,8 @@ export class RoomTimeline extends Timeline implements TypedEmitter<TimelineEvent
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.emit("timelineUpdate", events, true);
|
this.emit("timelineUpdate", events, true);
|
||||||
|
return events.length;
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,9 +109,9 @@ export class ThreadTimeline extends Timeline implements TypedEmitter<TimelineEve
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async paginate(dir: "f" | "b", limit: number = 50): Promise<boolean> {
|
public async paginate(dir: "f" | "b", limit: number = 50): Promise<number> {
|
||||||
if (dir === "b" && this.isAtBeginning) return false;
|
if (dir === "b" && this.isAtBeginning) return 0;
|
||||||
if (dir === "f" && this.isAtEnd) return false;
|
if (dir === "f" && this.isAtEnd) return 0;
|
||||||
|
|
||||||
const { room } = this.thread;
|
const { room } = this.thread;
|
||||||
const from = dir === "f" ? this.nextBatch : this.prevBatch;
|
const from = dir === "f" ? this.nextBatch : this.prevBatch;
|
||||||
|
@ -130,7 +131,7 @@ export class ThreadTimeline extends Timeline implements TypedEmitter<TimelineEve
|
||||||
this._eventList.push(...events);
|
this._eventList.push(...events);
|
||||||
for (const event of events) room.events.set(event.id, event);
|
for (const event of events) room.events.set(event.id, event);
|
||||||
this.emit("timelineUpdate", events, false);
|
this.emit("timelineUpdate", events, false);
|
||||||
return !!data.next_batch;
|
return events.length;
|
||||||
} else {
|
} else {
|
||||||
const events = data.chunk.map(intoEvent(room));
|
const events = data.chunk.map(intoEvent(room));
|
||||||
if (data.prev_batch) {
|
if (data.prev_batch) {
|
||||||
|
@ -150,7 +151,7 @@ export class ThreadTimeline extends Timeline implements TypedEmitter<TimelineEve
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.emit("timelineUpdate", events, true);
|
this.emit("timelineUpdate", events, true);
|
||||||
return !!data.prev_batch;
|
return events.length;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -169,6 +170,112 @@ abstract class TimelineSet {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function merge2(timelines: ThreadTimelineSet, tl: ThreadTimeline): ThreadTimeline {
|
||||||
|
// [_, _, 2, 3, 4, 5, _, _, _] (current)
|
||||||
|
// [_, _, _, 3, 4, 5, 6, 7, 8] (other1)
|
||||||
|
// [0, 1, 2, 3, 4, _, _, _, _] (other2)
|
||||||
|
// [0, 1, 2, 3, 4, 5, 6, 7, 8] (other3)
|
||||||
|
// [_, _, 2, 3, 4, 5, 6, 7, 8] (other4)
|
||||||
|
// event = 3, thisIdx = 3, otherIdx1 = 0
|
||||||
|
// event = 2, thisIdx = 0, otherIdx2 = 2
|
||||||
|
// event = 2, thisIdx = 0, otherIdx3 = 2
|
||||||
|
// event = 2, thisIdx = 0, otherIdx4 = 0
|
||||||
|
|
||||||
|
// [1, 2] + [4, 5] (events = [2, 3, 4])
|
||||||
|
|
||||||
|
const events = tl._eventList;
|
||||||
|
|
||||||
|
// let otherTl;
|
||||||
|
for (const event of events) {
|
||||||
|
const other = timelines.timelineMap.get(event.id);
|
||||||
|
if (!other) continue;
|
||||||
|
if (tl === other) continue;
|
||||||
|
|
||||||
|
// console.log("merge ", tl, other);
|
||||||
|
const idx = other._eventList.indexOf(event);
|
||||||
|
other._eventList.unshift(...events.slice(0, idx));
|
||||||
|
other.isAtBeginning = tl.isAtBeginning;
|
||||||
|
|
||||||
|
for (const event of events.slice(0, idx)) {
|
||||||
|
timelines.timelineMap.set(event.id, other);
|
||||||
|
}
|
||||||
|
timelines.timelines.delete(tl);
|
||||||
|
tl = other;
|
||||||
|
}
|
||||||
|
|
||||||
|
// for (const event of events) {
|
||||||
|
// const other = timelines.timelineMap.get(event.id);
|
||||||
|
// if (!other) continue;
|
||||||
|
// if (tl === other) continue;
|
||||||
|
|
||||||
|
// console.log("merge ", tl, other);
|
||||||
|
// // const idx = other._eventList.indexOf(event);
|
||||||
|
// // other._eventList.splice(idx, other._eventList.length - idx);
|
||||||
|
// // other._eventList.push(...events.slice(idx));
|
||||||
|
// other.isAtEnd = tl.isAtEnd;
|
||||||
|
|
||||||
|
// tl = other;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// for (let i = events.length - 1; i >= 0; i--) {
|
||||||
|
// const event = events[i];
|
||||||
|
// const other = timelines.timelineMap.get(event.id);
|
||||||
|
// if (!other) continue;
|
||||||
|
// if (tl === other) continue;
|
||||||
|
|
||||||
|
// const idx = other._eventList.lastIndexOf(event);
|
||||||
|
// other._eventList.push(...events.slice(idx));
|
||||||
|
|
||||||
|
// for (const event of events.slice(0, idx)) {
|
||||||
|
// timelines.timelineMap.set(event.id, other);
|
||||||
|
// }
|
||||||
|
// timelines.timelines.delete(tl);
|
||||||
|
// tl = other;
|
||||||
|
// }
|
||||||
|
|
||||||
|
return tl;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// function merge(timelines: ThreadTimelineSet, events: Array<Event>): ThreadTimeline | null {
|
||||||
|
// for (const event of events) {
|
||||||
|
// const other = timelines.timelineMap.get(event.id);
|
||||||
|
// if (!other) continue;
|
||||||
|
// if (tl === other) continue;
|
||||||
|
// console.log("merge earliest with ", other);
|
||||||
|
// const idx = other._eventList.indexOf(event);
|
||||||
|
// other._eventList.unshift(...events.slice(0, idx));
|
||||||
|
// other.isAtBeginning = true;
|
||||||
|
// return other;
|
||||||
|
// }
|
||||||
|
// return null;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// const realTimeline = merge(this, tl._eventList) ?? tl;
|
||||||
|
|
||||||
|
// function merge(timelines: ThreadTimelineSet, events: Array<Event>): ThreadTimeline | null {
|
||||||
|
// // [_, _, _, _, (4), 5, 6, 7]
|
||||||
|
// // [0, 1, 2, 3, 4 , 5]
|
||||||
|
// // ^
|
||||||
|
|
||||||
|
// for (const event of events) {
|
||||||
|
// const other = timelines.timelineMap.get(event.id);
|
||||||
|
// if (!other) continue;
|
||||||
|
// if (tl === other) continue;
|
||||||
|
// console.log("merge live with ", other);
|
||||||
|
|
||||||
|
// const idx = other._eventList.indexOf(event);
|
||||||
|
// other._eventList.splice(idx, other._eventList.length - idx); // delete 4, 5
|
||||||
|
// other._eventList.push(...events.slice(idx)); // push 4, 5, 6, 7
|
||||||
|
|
||||||
|
// other.isAtEnd = true;
|
||||||
|
// return other;
|
||||||
|
// }
|
||||||
|
// return null;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// const realTimeline = merge(this, tl._eventList);
|
||||||
|
|
||||||
export class ThreadTimelineSet extends TimelineSet {
|
export class ThreadTimelineSet extends TimelineSet {
|
||||||
// This is the one live timeline
|
// This is the one live timeline
|
||||||
public client = this.thread.room.client;
|
public client = this.thread.room.client;
|
||||||
|
@ -188,6 +295,15 @@ export class ThreadTimelineSet extends TimelineSet {
|
||||||
const fetchCount = limit - this.live.getEvents().length;
|
const fetchCount = limit - this.live.getEvents().length;
|
||||||
if (fetchCount > 0) await this.live.paginate("b", fetchCount);
|
if (fetchCount > 0) await this.live.paginate("b", fetchCount);
|
||||||
return this.live;
|
return this.live;
|
||||||
|
|
||||||
|
const tl = this.live;
|
||||||
|
|
||||||
|
const realTimeline = merge2(this, tl);
|
||||||
|
if (realTimeline) {
|
||||||
|
this.timelines.delete(tl);
|
||||||
|
this.live = realTimeline;
|
||||||
|
}
|
||||||
|
return realTimeline ?? tl;
|
||||||
} else if (at === "start") {
|
} else if (at === "start") {
|
||||||
const existing = [...this.timelines].find(i => i.isAtBeginning);
|
const existing = [...this.timelines].find(i => i.isAtBeginning);
|
||||||
if (existing) {
|
if (existing) {
|
||||||
|
@ -199,6 +315,8 @@ export class ThreadTimelineSet extends TimelineSet {
|
||||||
await tl.paginate("b", limit);
|
await tl.paginate("b", limit);
|
||||||
this.timelines.add(tl);
|
this.timelines.add(tl);
|
||||||
return tl;
|
return tl;
|
||||||
|
const realTimeline = merge2(this, tl) ?? tl;
|
||||||
|
return realTimeline;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// TODO: respect limit?
|
// TODO: respect limit?
|
||||||
|
|
Loading…
Reference in a new issue