Enable @typescript-eslint/explicit-function-return-type
in /src (#9788)
* Enable `@typescript-eslint/explicit-member-accessibility` on /src * Prettier * Enable `@typescript-eslint/explicit-function-return-type` in /src * Fix types * tsc strict fixes * Delint * Fix test * Fix bad merge
This commit is contained in:
parent
7a36ba0fde
commit
030b7e90bf
683 changed files with 3459 additions and 3013 deletions
|
@ -23,7 +23,7 @@ import { EventTimelineSet, IRoomTimelineData } from "matrix-js-sdk/src/models/ev
|
|||
import { RoomState, RoomStateEvent } from "matrix-js-sdk/src/models/room-state";
|
||||
import { TimelineIndex, TimelineWindow } from "matrix-js-sdk/src/timeline-window";
|
||||
import { sleep } from "matrix-js-sdk/src/utils";
|
||||
import { IResultRoomEvents } from "matrix-js-sdk/src/@types/search";
|
||||
import { IEventWithRoomId, IMatrixProfile, IResultRoomEvents } from "matrix-js-sdk/src/@types/search";
|
||||
import { logger } from "matrix-js-sdk/src/logger";
|
||||
import { EventType } from "matrix-js-sdk/src/@types/event";
|
||||
import { ClientEvent, MatrixClient } from "matrix-js-sdk/src/client";
|
||||
|
@ -32,7 +32,7 @@ import PlatformPeg from "../PlatformPeg";
|
|||
import { MatrixClientPeg } from "../MatrixClientPeg";
|
||||
import SettingsStore from "../settings/SettingsStore";
|
||||
import { SettingLevel } from "../settings/SettingLevel";
|
||||
import { ICrawlerCheckpoint, ILoadArgs, ISearchArgs } from "./BaseEventIndexManager";
|
||||
import { ICrawlerCheckpoint, IEventAndProfile, IIndexStats, ILoadArgs, ISearchArgs } from "./BaseEventIndexManager";
|
||||
|
||||
// The time in ms that the crawler will wait loop iterations if there
|
||||
// have not been any checkpoints to consume in the last iteration.
|
||||
|
@ -53,7 +53,7 @@ export default class EventIndex extends EventEmitter {
|
|||
private crawler: ICrawler = null;
|
||||
private currentCheckpoint: ICrawlerCheckpoint = null;
|
||||
|
||||
public async init() {
|
||||
public async init(): Promise<void> {
|
||||
const indexManager = PlatformPeg.get().getEventIndexingManager();
|
||||
|
||||
this.crawlerCheckpoints = await indexManager.loadCheckpoints();
|
||||
|
@ -65,7 +65,7 @@ export default class EventIndex extends EventEmitter {
|
|||
/**
|
||||
* Register event listeners that are necessary for the event index to work.
|
||||
*/
|
||||
public registerListeners() {
|
||||
public registerListeners(): void {
|
||||
const client = MatrixClientPeg.get();
|
||||
|
||||
client.on(ClientEvent.Sync, this.onSync);
|
||||
|
@ -77,7 +77,7 @@ export default class EventIndex extends EventEmitter {
|
|||
/**
|
||||
* Remove the event index specific event listeners.
|
||||
*/
|
||||
public removeListeners() {
|
||||
public removeListeners(): void {
|
||||
const client = MatrixClientPeg.get();
|
||||
if (client === null) return;
|
||||
|
||||
|
@ -90,12 +90,12 @@ export default class EventIndex extends EventEmitter {
|
|||
/**
|
||||
* Get crawler checkpoints for the encrypted rooms and store them in the index.
|
||||
*/
|
||||
public async addInitialCheckpoints() {
|
||||
public async addInitialCheckpoints(): Promise<void> {
|
||||
const indexManager = PlatformPeg.get().getEventIndexingManager();
|
||||
const client = MatrixClientPeg.get();
|
||||
const rooms = client.getRooms();
|
||||
|
||||
const isRoomEncrypted = (room) => {
|
||||
const isRoomEncrypted = (room): boolean => {
|
||||
return client.isRoomEncrypted(room.roomId);
|
||||
};
|
||||
|
||||
|
@ -108,7 +108,7 @@ export default class EventIndex extends EventEmitter {
|
|||
// Gather the prev_batch tokens and create checkpoints for
|
||||
// our message crawler.
|
||||
await Promise.all(
|
||||
encryptedRooms.map(async (room) => {
|
||||
encryptedRooms.map(async (room): Promise<void> => {
|
||||
const timeline = room.getLiveTimeline();
|
||||
const token = timeline.getPaginationToken(Direction.Backward);
|
||||
|
||||
|
@ -157,7 +157,7 @@ export default class EventIndex extends EventEmitter {
|
|||
* - Every other sync, tell the event index to commit all the queued up
|
||||
* live events
|
||||
*/
|
||||
private onSync = async (state: string, prevState: string, data: object) => {
|
||||
private onSync = async (state: string, prevState: string, data: object): Promise<void> => {
|
||||
const indexManager = PlatformPeg.get().getEventIndexingManager();
|
||||
|
||||
if (prevState === "PREPARED" && state === "SYNCING") {
|
||||
|
@ -192,7 +192,7 @@ export default class EventIndex extends EventEmitter {
|
|||
toStartOfTimeline: boolean,
|
||||
removed: boolean,
|
||||
data: IRoomTimelineData,
|
||||
) => {
|
||||
): Promise<void> => {
|
||||
if (!room) return; // notification timeline, we'll get this event again with a room specific timeline
|
||||
|
||||
const client = MatrixClientPeg.get();
|
||||
|
@ -214,7 +214,7 @@ export default class EventIndex extends EventEmitter {
|
|||
await this.addLiveEventToIndex(ev);
|
||||
};
|
||||
|
||||
private onRoomStateEvent = async (ev: MatrixEvent, state: RoomState) => {
|
||||
private onRoomStateEvent = async (ev: MatrixEvent, state: RoomState): Promise<void> => {
|
||||
if (!MatrixClientPeg.get().isRoomEncrypted(state.roomId)) return;
|
||||
|
||||
if (ev.getType() === EventType.RoomEncryption && !(await this.isRoomIndexed(state.roomId))) {
|
||||
|
@ -227,7 +227,7 @@ export default class EventIndex extends EventEmitter {
|
|||
* Removes a redacted event from our event index.
|
||||
* We cannot rely on Room.redaction as this only fires if the redaction applied to an event the js-sdk has loaded.
|
||||
*/
|
||||
private redactEvent = async (ev: MatrixEvent) => {
|
||||
private redactEvent = async (ev: MatrixEvent): Promise<void> => {
|
||||
const indexManager = PlatformPeg.get().getEventIndexingManager();
|
||||
|
||||
try {
|
||||
|
@ -243,7 +243,7 @@ export default class EventIndex extends EventEmitter {
|
|||
* Listens for timeline resets that are caused by a limited timeline to
|
||||
* re-add checkpoints for rooms that need to be crawled again.
|
||||
*/
|
||||
private onTimelineReset = async (room: Room | undefined) => {
|
||||
private onTimelineReset = async (room: Room | undefined): Promise<void> => {
|
||||
if (!room) return;
|
||||
if (!MatrixClientPeg.get().isRoomEncrypted(room.roomId)) return;
|
||||
|
||||
|
@ -288,7 +288,7 @@ export default class EventIndex extends EventEmitter {
|
|||
return validEventType && validMsgType && hasContentValue;
|
||||
}
|
||||
|
||||
private eventToJson(ev: MatrixEvent) {
|
||||
private eventToJson(ev: MatrixEvent): IEventWithRoomId {
|
||||
const jsonEvent: any = ev.toJSON();
|
||||
const e = ev.isEncrypted() ? jsonEvent.decrypted : jsonEvent;
|
||||
|
||||
|
@ -320,7 +320,7 @@ export default class EventIndex extends EventEmitter {
|
|||
*
|
||||
* @param {MatrixEvent} ev The event that should be added to the index.
|
||||
*/
|
||||
private async addLiveEventToIndex(ev: MatrixEvent) {
|
||||
private async addLiveEventToIndex(ev: MatrixEvent): Promise<void> {
|
||||
const indexManager = PlatformPeg.get().getEventIndexingManager();
|
||||
|
||||
if (!this.isValidEvent(ev)) return;
|
||||
|
@ -339,11 +339,11 @@ export default class EventIndex extends EventEmitter {
|
|||
* Emmit that the crawler has changed the checkpoint that it's currently
|
||||
* handling.
|
||||
*/
|
||||
private emitNewCheckpoint() {
|
||||
private emitNewCheckpoint(): void {
|
||||
this.emit("changedCheckpoint", this.currentRoom());
|
||||
}
|
||||
|
||||
private async addEventsFromLiveTimeline(timeline: EventTimeline) {
|
||||
private async addEventsFromLiveTimeline(timeline: EventTimeline): Promise<void> {
|
||||
const events = timeline.getEvents();
|
||||
|
||||
for (let i = 0; i < events.length; i++) {
|
||||
|
@ -352,7 +352,7 @@ export default class EventIndex extends EventEmitter {
|
|||
}
|
||||
}
|
||||
|
||||
private async addRoomCheckpoint(roomId: string, fullCrawl = false) {
|
||||
private async addRoomCheckpoint(roomId: string, fullCrawl = false): Promise<void> {
|
||||
const indexManager = PlatformPeg.get().getEventIndexingManager();
|
||||
const client = MatrixClientPeg.get();
|
||||
const room = client.getRoom(roomId);
|
||||
|
@ -397,7 +397,7 @@ export default class EventIndex extends EventEmitter {
|
|||
* crawl, otherwise create a new checkpoint and push it to the
|
||||
* crawlerCheckpoints queue, so we go through them in a round-robin way.
|
||||
*/
|
||||
private async crawlerFunc() {
|
||||
private async crawlerFunc(): Promise<void> {
|
||||
let cancelled = false;
|
||||
|
||||
const client = MatrixClientPeg.get();
|
||||
|
@ -504,12 +504,12 @@ export default class EventIndex extends EventEmitter {
|
|||
// Convert the plain JSON events into Matrix events so they get
|
||||
// decrypted if necessary.
|
||||
const matrixEvents = res.chunk.map(eventMapper);
|
||||
let stateEvents = [];
|
||||
let stateEvents: MatrixEvent[] = [];
|
||||
if (res.state !== undefined) {
|
||||
stateEvents = res.state.map(eventMapper);
|
||||
}
|
||||
|
||||
const profiles = {};
|
||||
const profiles: Record<string, IMatrixProfile> = {};
|
||||
|
||||
stateEvents.forEach((ev) => {
|
||||
if (ev.event.content && ev.event.content.membership === "join") {
|
||||
|
@ -545,7 +545,7 @@ export default class EventIndex extends EventEmitter {
|
|||
const events = filteredEvents.map((ev) => {
|
||||
const e = this.eventToJson(ev);
|
||||
|
||||
let profile = {};
|
||||
let profile: IMatrixProfile = {};
|
||||
if (e.sender in profiles) profile = profiles[e.sender];
|
||||
const object = {
|
||||
event: e,
|
||||
|
@ -629,7 +629,7 @@ export default class EventIndex extends EventEmitter {
|
|||
/**
|
||||
* Start the crawler background task.
|
||||
*/
|
||||
public startCrawler() {
|
||||
public startCrawler(): void {
|
||||
if (this.crawler !== null) return;
|
||||
this.crawlerFunc();
|
||||
}
|
||||
|
@ -637,7 +637,7 @@ export default class EventIndex extends EventEmitter {
|
|||
/**
|
||||
* Stop the crawler background task.
|
||||
*/
|
||||
public stopCrawler() {
|
||||
public stopCrawler(): void {
|
||||
if (this.crawler === null) return;
|
||||
this.crawler.cancel();
|
||||
}
|
||||
|
@ -648,7 +648,7 @@ export default class EventIndex extends EventEmitter {
|
|||
* This removes all the MatrixClient event listeners, stops the crawler
|
||||
* task, and closes the index.
|
||||
*/
|
||||
public async close() {
|
||||
public async close(): Promise<void> {
|
||||
const indexManager = PlatformPeg.get().getEventIndexingManager();
|
||||
this.removeListeners();
|
||||
this.stopCrawler();
|
||||
|
@ -695,7 +695,7 @@ export default class EventIndex extends EventEmitter {
|
|||
limit = 10,
|
||||
fromEvent: string = null,
|
||||
direction: string = EventTimeline.BACKWARDS,
|
||||
) {
|
||||
): Promise<MatrixEvent[]> {
|
||||
const client = MatrixClientPeg.get();
|
||||
const indexManager = PlatformPeg.get().getEventIndexingManager();
|
||||
|
||||
|
@ -709,7 +709,7 @@ export default class EventIndex extends EventEmitter {
|
|||
loadArgs.direction = direction;
|
||||
}
|
||||
|
||||
let events;
|
||||
let events: IEventAndProfile[];
|
||||
|
||||
// Get our events from the event index.
|
||||
try {
|
||||
|
@ -792,7 +792,7 @@ export default class EventIndex extends EventEmitter {
|
|||
limit = 10,
|
||||
fromEvent: string = null,
|
||||
direction: string = EventTimeline.BACKWARDS,
|
||||
) {
|
||||
): Promise<boolean> {
|
||||
const matrixEvents = await this.loadFileEvents(room, limit, fromEvent, direction);
|
||||
|
||||
// If this is a normal fill request, not a pagination request, we need
|
||||
|
@ -854,7 +854,12 @@ export default class EventIndex extends EventEmitter {
|
|||
* @returns {Promise<boolean>} Resolves to a boolean which is true if more
|
||||
* events were successfully retrieved.
|
||||
*/
|
||||
public paginateTimelineWindow(room: Room, timelineWindow: TimelineWindow, direction: Direction, limit: number) {
|
||||
public paginateTimelineWindow(
|
||||
room: Room,
|
||||
timelineWindow: TimelineWindow,
|
||||
direction: Direction,
|
||||
limit: number,
|
||||
): Promise<boolean> {
|
||||
const tl = timelineWindow.getTimelineIndex(direction);
|
||||
|
||||
if (!tl) return Promise.resolve(false);
|
||||
|
@ -870,7 +875,7 @@ export default class EventIndex extends EventEmitter {
|
|||
room: Room,
|
||||
direction: Direction,
|
||||
limit: number,
|
||||
) => {
|
||||
): Promise<boolean> => {
|
||||
const timeline = timelineIndex.timeline;
|
||||
const timelineSet = timeline.getTimelineSet();
|
||||
const token = timeline.getPaginationToken(direction);
|
||||
|
@ -892,10 +897,10 @@ export default class EventIndex extends EventEmitter {
|
|||
/**
|
||||
* Get statistical information of the index.
|
||||
*
|
||||
* @return {Promise<IndexStats>} A promise that will resolve to the index
|
||||
* @return {Promise<IIndexStats>} A promise that will resolve to the index
|
||||
* statistics.
|
||||
*/
|
||||
public async getStats() {
|
||||
public async getStats(): Promise<IIndexStats> {
|
||||
const indexManager = PlatformPeg.get().getEventIndexingManager();
|
||||
return indexManager.getStats();
|
||||
}
|
||||
|
@ -909,7 +914,7 @@ export default class EventIndex extends EventEmitter {
|
|||
* @return {Promise<boolean>} Returns true if the index contains events for
|
||||
* the given room, false otherwise.
|
||||
*/
|
||||
public async isRoomIndexed(roomId) {
|
||||
public async isRoomIndexed(roomId: string): Promise<boolean> {
|
||||
const indexManager = PlatformPeg.get().getEventIndexingManager();
|
||||
return indexManager.isRoomIndexed(roomId);
|
||||
}
|
||||
|
@ -920,7 +925,7 @@ export default class EventIndex extends EventEmitter {
|
|||
* @returns {Room} A MatrixRoom that is being currently crawled, null
|
||||
* if no room is currently being crawled.
|
||||
*/
|
||||
public currentRoom() {
|
||||
public currentRoom(): Room | null {
|
||||
if (this.currentCheckpoint === null && this.crawlerCheckpoints.length === 0) {
|
||||
return null;
|
||||
}
|
||||
|
@ -934,9 +939,12 @@ export default class EventIndex extends EventEmitter {
|
|||
}
|
||||
}
|
||||
|
||||
public crawlingRooms() {
|
||||
const totalRooms = new Set();
|
||||
const crawlingRooms = new Set();
|
||||
public crawlingRooms(): {
|
||||
crawlingRooms: Set<string>;
|
||||
totalRooms: Set<string>;
|
||||
} {
|
||||
const totalRooms = new Set<string>();
|
||||
const crawlingRooms = new Set<string>();
|
||||
|
||||
this.crawlerCheckpoints.forEach((checkpoint, index) => {
|
||||
crawlingRooms.add(checkpoint.roomId);
|
||||
|
@ -949,7 +957,7 @@ export default class EventIndex extends EventEmitter {
|
|||
const client = MatrixClientPeg.get();
|
||||
const rooms = client.getRooms();
|
||||
|
||||
const isRoomEncrypted = (room: Room) => {
|
||||
const isRoomEncrypted = (room: Room): boolean => {
|
||||
return client.isRoomEncrypted(room.roomId);
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue