This repository has been archived by the owner on May 16, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
423 additions
and
39 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { RoomEvent } from "../matrix/events/room/room-event"; | ||
|
||
export interface RawEventBatch { | ||
id: number; | ||
roomId: string; | ||
startToken: string; | ||
endToken: string; | ||
events: RoomEvent[]; | ||
} | ||
|
||
export class PersistedEventBatch { | ||
constructor(public id: number, public roomId: string, public events: RoomEvent[], public startToken: string, public endToken: string) { | ||
} | ||
|
||
public toRaw(withId = true): RawEventBatch { | ||
const result = { | ||
id: this.id, | ||
roomId: this.roomId, | ||
startToken: this.startToken, | ||
endToken: this.endToken, | ||
events: this.events, | ||
}; | ||
if (!withId) delete result['id']; | ||
return result; | ||
} | ||
|
||
public static parseAll(batches: RawEventBatch[]): PersistedEventBatch[] { | ||
return batches.map(b => new PersistedEventBatch(b.id, b.roomId, b.events, b.startToken, b.endToken)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { RoomStateEvent } from "../matrix/events/room/state/room-state-event"; | ||
import { MatrixRoom } from "../matrix/dto/room"; | ||
|
||
export interface RawRoomState { | ||
id: number; | ||
roomId: string; | ||
events: RoomStateEvent[]; | ||
} | ||
|
||
export class PersistedRoomState { | ||
constructor(public id: number, public roomId: string, public events: RoomStateEvent[]) { | ||
} | ||
|
||
public toRaw(withId = true): RawRoomState { | ||
const result = { | ||
id: this.id, | ||
roomId: this.roomId, | ||
events: this.events, | ||
}; | ||
if (!withId) delete result['id']; | ||
return result; | ||
} | ||
|
||
public static parse(state: RawRoomState): PersistedRoomState { | ||
return new PersistedRoomState(state.id, state.roomId, state.events); | ||
} | ||
|
||
public static fromRoom(room: MatrixRoom): PersistedRoomState { | ||
console.log(room.id + " has " + room.state.length + " state events"); | ||
return new PersistedRoomState(null, room.id, room.state); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.