TS errors
This commit is contained in:
parent
c685c8e856
commit
769fd4a786
5 changed files with 46 additions and 30 deletions
|
@ -231,7 +231,7 @@ export class SlidingSyncManager {
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
logger.debug("ensureListRegistered: update failed txn_id=", err);
|
logger.debug("ensureListRegistered: update failed txn_id=", err);
|
||||||
}
|
}
|
||||||
return this.slidingSync.getListParams(listKey);
|
return this.slidingSync.getListParams(listKey)!;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async setRoomVisible(roomId: string, visible: boolean): Promise<string> {
|
public async setRoomVisible(roomId: string, visible: boolean): Promise<string> {
|
||||||
|
@ -315,13 +315,19 @@ export class SlidingSyncManager {
|
||||||
} else {
|
} else {
|
||||||
await this.slidingSync.setListRanges(SlidingSyncManager.ListSearch, ranges);
|
await this.slidingSync.setListRanges(SlidingSyncManager.ListSearch, ranges);
|
||||||
}
|
}
|
||||||
// gradually request more over time
|
|
||||||
await sleep(gapBetweenRequestsMs);
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
// do nothing, as we reject only when we get interrupted but that's fine as the next
|
// do nothing, as we reject only when we get interrupted but that's fine as the next
|
||||||
// request will include our data
|
// request will include our data
|
||||||
|
} finally {
|
||||||
|
// gradually request more over time, even on errors.
|
||||||
|
await sleep(gapBetweenRequestsMs);
|
||||||
}
|
}
|
||||||
hasMore = endIndex + 1 < this.slidingSync.getListData(SlidingSyncManager.ListSearch)?.joinedCount;
|
const listData = this.slidingSync.getListData(SlidingSyncManager.ListSearch);
|
||||||
|
if (!listData) {
|
||||||
|
// we failed to do the first request, keep trying
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
hasMore = endIndex + 1 < listData.joinedCount;
|
||||||
startIndex += batchSize;
|
startIndex += batchSize;
|
||||||
firstTime = false;
|
firstTime = false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -566,8 +566,8 @@ export default class RoomSublist extends React.Component<IProps, IState> {
|
||||||
let isUnreadFirst = RoomListStore.instance.getListOrder(this.props.tagId) === ListAlgorithm.Importance;
|
let isUnreadFirst = RoomListStore.instance.getListOrder(this.props.tagId) === ListAlgorithm.Importance;
|
||||||
if (this.slidingSyncMode) {
|
if (this.slidingSyncMode) {
|
||||||
const slidingList = SlidingSyncManager.instance.slidingSync.getListParams(this.props.tagId);
|
const slidingList = SlidingSyncManager.instance.slidingSync.getListParams(this.props.tagId);
|
||||||
isAlphabetical = slidingList.sort[0] === "by_name";
|
isAlphabetical = (slidingList?.sort || [])[0] === "by_name";
|
||||||
isUnreadFirst = slidingList.sort[0] === "by_notification_level";
|
isUnreadFirst = (slidingList?.sort || [])[0] === "by_notification_level";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Invites don't get some nonsense options, so only add them if we have to.
|
// Invites don't get some nonsense options, so only add them if we have to.
|
||||||
|
|
|
@ -58,7 +58,7 @@ export const useSlidingSyncRoomSearch = (): {
|
||||||
const rooms = [];
|
const rooms = [];
|
||||||
const { roomIndexToRoomId } = SlidingSyncManager.instance.slidingSync.getListData(
|
const { roomIndexToRoomId } = SlidingSyncManager.instance.slidingSync.getListData(
|
||||||
SlidingSyncManager.ListSearch,
|
SlidingSyncManager.ListSearch,
|
||||||
);
|
)!;
|
||||||
let i = 0;
|
let i = 0;
|
||||||
while (roomIndexToRoomId[i]) {
|
while (roomIndexToRoomId[i]) {
|
||||||
const roomId = roomIndexToRoomId[i];
|
const roomId = roomIndexToRoomId[i];
|
||||||
|
|
|
@ -29,6 +29,7 @@ import { MetaSpace, SpaceKey, UPDATE_SELECTED_SPACE } from "../spaces";
|
||||||
import { LISTS_LOADING_EVENT } from "./RoomListStore";
|
import { LISTS_LOADING_EVENT } from "./RoomListStore";
|
||||||
import { UPDATE_EVENT } from "../AsyncStore";
|
import { UPDATE_EVENT } from "../AsyncStore";
|
||||||
import { SdkContextClass } from "../../contexts/SDKContext";
|
import { SdkContextClass } from "../../contexts/SDKContext";
|
||||||
|
import { filter } from "lodash";
|
||||||
|
|
||||||
interface IState {
|
interface IState {
|
||||||
// state is tracked in underlying classes
|
// state is tracked in underlying classes
|
||||||
|
@ -84,6 +85,7 @@ export class SlidingRoomListStoreClass extends AsyncStoreWithClient<IState> impl
|
||||||
public constructor(dis: MatrixDispatcher, private readonly context: SdkContextClass) {
|
public constructor(dis: MatrixDispatcher, private readonly context: SdkContextClass) {
|
||||||
super(dis);
|
super(dis);
|
||||||
this.setMaxListeners(20); // RoomList + LeftPanel + 8xRoomSubList + spares
|
this.setMaxListeners(20); // RoomList + LeftPanel + 8xRoomSubList + spares
|
||||||
|
this.stickyRoomId = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async setTagSorting(tagId: TagID, sort: SortAlgorithm): Promise<void> {
|
public async setTagSorting(tagId: TagID, sort: SortAlgorithm): Promise<void> {
|
||||||
|
@ -249,9 +251,14 @@ export class SlidingRoomListStoreClass extends AsyncStoreWithClient<IState> impl
|
||||||
}
|
}
|
||||||
|
|
||||||
// now set the rooms
|
// now set the rooms
|
||||||
const rooms = orderedRoomIds.map((roomId) => {
|
const rooms: Room[] = [];
|
||||||
return this.matrixClient.getRoom(roomId);
|
orderedRoomIds.forEach((roomId) => {
|
||||||
});
|
const room = this.matrixClient.getRoom(roomId);
|
||||||
|
if (!room) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
rooms.push(room);
|
||||||
|
})
|
||||||
tagMap[tagId] = rooms;
|
tagMap[tagId] = rooms;
|
||||||
this.tagMap = tagMap;
|
this.tagMap = tagMap;
|
||||||
}
|
}
|
||||||
|
@ -352,6 +359,9 @@ export class SlidingRoomListStoreClass extends AsyncStoreWithClient<IState> impl
|
||||||
if (roomId === activeSpace) {
|
if (roomId === activeSpace) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (!filters.spaces) {
|
||||||
|
filters.spaces = [];
|
||||||
|
}
|
||||||
filters.spaces.push(roomId); // add subspace
|
filters.spaces.push(roomId); // add subspace
|
||||||
},
|
},
|
||||||
false,
|
false,
|
||||||
|
|
|
@ -82,10 +82,10 @@ describe("SlidingRoomListStore", () => {
|
||||||
|
|
||||||
// change the active space
|
// change the active space
|
||||||
activeSpace = spaceRoomId;
|
activeSpace = spaceRoomId;
|
||||||
context._SpaceStore.emit(UPDATE_SELECTED_SPACE, spaceRoomId, false);
|
context._SpaceStore!.emit(UPDATE_SELECTED_SPACE, spaceRoomId, false);
|
||||||
await p;
|
await p;
|
||||||
|
|
||||||
expect(context._SlidingSyncManager.ensureListRegistered).toHaveBeenCalledWith(DefaultTagID.Untagged, {
|
expect(context._SlidingSyncManager!.ensureListRegistered).toHaveBeenCalledWith(DefaultTagID.Untagged, {
|
||||||
filters: expect.objectContaining({
|
filters: expect.objectContaining({
|
||||||
spaces: [spaceRoomId],
|
spaces: [spaceRoomId],
|
||||||
}),
|
}),
|
||||||
|
@ -101,7 +101,7 @@ describe("SlidingRoomListStore", () => {
|
||||||
});
|
});
|
||||||
await store.start(); // call onReady
|
await store.start(); // call onReady
|
||||||
await p;
|
await p;
|
||||||
expect(context._SlidingSyncManager.ensureListRegistered).toHaveBeenCalledWith(
|
expect(context._SlidingSyncManager!.ensureListRegistered).toHaveBeenCalledWith(
|
||||||
DefaultTagID.Untagged,
|
DefaultTagID.Untagged,
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
filters: expect.objectContaining({
|
filters: expect.objectContaining({
|
||||||
|
@ -121,7 +121,7 @@ describe("SlidingRoomListStore", () => {
|
||||||
return listName === DefaultTagID.Untagged && !isLoading;
|
return listName === DefaultTagID.Untagged && !isLoading;
|
||||||
});
|
});
|
||||||
|
|
||||||
mocked(context._SpaceStore.traverseSpace).mockImplementation(
|
mocked(context._SpaceStore!.traverseSpace).mockImplementation(
|
||||||
(spaceId: string, fn: (roomId: string) => void) => {
|
(spaceId: string, fn: (roomId: string) => void) => {
|
||||||
if (spaceId === spaceRoomId) {
|
if (spaceId === spaceRoomId) {
|
||||||
fn(subSpace1);
|
fn(subSpace1);
|
||||||
|
@ -132,10 +132,10 @@ describe("SlidingRoomListStore", () => {
|
||||||
|
|
||||||
// change the active space
|
// change the active space
|
||||||
activeSpace = spaceRoomId;
|
activeSpace = spaceRoomId;
|
||||||
context._SpaceStore.emit(UPDATE_SELECTED_SPACE, spaceRoomId, false);
|
context._SpaceStore!.emit(UPDATE_SELECTED_SPACE, spaceRoomId, false);
|
||||||
await p;
|
await p;
|
||||||
|
|
||||||
expect(context._SlidingSyncManager.ensureListRegistered).toHaveBeenCalledWith(DefaultTagID.Untagged, {
|
expect(context._SlidingSyncManager!.ensureListRegistered).toHaveBeenCalledWith(DefaultTagID.Untagged, {
|
||||||
filters: expect.objectContaining({
|
filters: expect.objectContaining({
|
||||||
spaces: [spaceRoomId, subSpace1, subSpace2],
|
spaces: [spaceRoomId, subSpace1, subSpace2],
|
||||||
}),
|
}),
|
||||||
|
@ -146,13 +146,13 @@ describe("SlidingRoomListStore", () => {
|
||||||
it("setTagSorting alters the 'sort' option in the list", async () => {
|
it("setTagSorting alters the 'sort' option in the list", async () => {
|
||||||
const tagId: TagID = "foo";
|
const tagId: TagID = "foo";
|
||||||
await store.setTagSorting(tagId, SortAlgorithm.Alphabetic);
|
await store.setTagSorting(tagId, SortAlgorithm.Alphabetic);
|
||||||
expect(context._SlidingSyncManager.ensureListRegistered).toBeCalledWith(tagId, {
|
expect(context._SlidingSyncManager!.ensureListRegistered).toBeCalledWith(tagId, {
|
||||||
sort: SlidingSyncSortToFilter[SortAlgorithm.Alphabetic],
|
sort: SlidingSyncSortToFilter[SortAlgorithm.Alphabetic],
|
||||||
});
|
});
|
||||||
expect(store.getTagSorting(tagId)).toEqual(SortAlgorithm.Alphabetic);
|
expect(store.getTagSorting(tagId)).toEqual(SortAlgorithm.Alphabetic);
|
||||||
|
|
||||||
await store.setTagSorting(tagId, SortAlgorithm.Recent);
|
await store.setTagSorting(tagId, SortAlgorithm.Recent);
|
||||||
expect(context._SlidingSyncManager.ensureListRegistered).toBeCalledWith(tagId, {
|
expect(context._SlidingSyncManager!.ensureListRegistered).toBeCalledWith(tagId, {
|
||||||
sort: SlidingSyncSortToFilter[SortAlgorithm.Recent],
|
sort: SlidingSyncSortToFilter[SortAlgorithm.Recent],
|
||||||
});
|
});
|
||||||
expect(store.getTagSorting(tagId)).toEqual(SortAlgorithm.Recent);
|
expect(store.getTagSorting(tagId)).toEqual(SortAlgorithm.Recent);
|
||||||
|
@ -177,14 +177,14 @@ describe("SlidingRoomListStore", () => {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
mocked(context._SlidingSyncManager.slidingSync.getListData).mockImplementation((key: string) => {
|
mocked(context._SlidingSyncManager!.slidingSync.getListData).mockImplementation((key: string) => {
|
||||||
return keyToListData[key] || null;
|
return keyToListData[key] || null;
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(store.getTagsForRoom(new Room(roomA, context.client, context.client.getUserId()))).toEqual([
|
expect(store.getTagsForRoom(new Room(roomA, context.client!, context.client!.getUserId()))).toEqual([
|
||||||
DefaultTagID.Untagged,
|
DefaultTagID.Untagged,
|
||||||
]);
|
]);
|
||||||
expect(store.getTagsForRoom(new Room(roomB, context.client, context.client.getUserId()))).toEqual([
|
expect(store.getTagsForRoom(new Room(roomB, context.client!, context.client!.getUserId()))).toEqual([
|
||||||
DefaultTagID.Favourite,
|
DefaultTagID.Favourite,
|
||||||
DefaultTagID.Untagged,
|
DefaultTagID.Untagged,
|
||||||
]);
|
]);
|
||||||
|
@ -204,11 +204,11 @@ describe("SlidingRoomListStore", () => {
|
||||||
0: roomA,
|
0: roomA,
|
||||||
};
|
};
|
||||||
const rooms = [
|
const rooms = [
|
||||||
new Room(roomA, context.client, context.client.getUserId()),
|
new Room(roomA, context.client!, context.client!.getUserId()),
|
||||||
new Room(roomB, context.client, context.client.getUserId()),
|
new Room(roomB, context.client!, context.client!.getUserId()),
|
||||||
new Room(roomC, context.client, context.client.getUserId()),
|
new Room(roomC, context.client!, context.client!.getUserId()),
|
||||||
];
|
];
|
||||||
mocked(context.client.getRoom).mockImplementation((roomId: string) => {
|
mocked(context.client!.getRoom).mockImplementation((roomId: string) => {
|
||||||
switch (roomId) {
|
switch (roomId) {
|
||||||
case roomA:
|
case roomA:
|
||||||
return rooms[0];
|
return rooms[0];
|
||||||
|
@ -240,10 +240,10 @@ describe("SlidingRoomListStore", () => {
|
||||||
2: roomIdC,
|
2: roomIdC,
|
||||||
0: roomIdA,
|
0: roomIdA,
|
||||||
};
|
};
|
||||||
const roomA = new Room(roomIdA, context.client, context.client.getUserId());
|
const roomA = new Room(roomIdA, context.client!, context.client!.getUserId());
|
||||||
const roomB = new Room(roomIdB, context.client, context.client.getUserId());
|
const roomB = new Room(roomIdB, context.client!, context.client!.getUserId());
|
||||||
const roomC = new Room(roomIdC, context.client, context.client.getUserId());
|
const roomC = new Room(roomIdC, context.client!, context.client!.getUserId());
|
||||||
mocked(context.client.getRoom).mockImplementation((roomId: string) => {
|
mocked(context.client!.getRoom).mockImplementation((roomId: string) => {
|
||||||
switch (roomId) {
|
switch (roomId) {
|
||||||
case roomIdA:
|
case roomIdA:
|
||||||
return roomA;
|
return roomA;
|
||||||
|
@ -254,7 +254,7 @@ describe("SlidingRoomListStore", () => {
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
mocked(context._SlidingSyncManager.slidingSync.getListData).mockImplementation((key: string) => {
|
mocked(context._SlidingSyncManager!.slidingSync.getListData).mockImplementation((key: string) => {
|
||||||
if (key !== tagId) {
|
if (key !== tagId) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue