You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-11-25 05:23:13 +03:00
Loading threads with server-side assistance (#2735)
* Fix bug where undefined vs null in pagination tokens wasn't correctly handled * Fix bug where thread list results were sorted incorrectly * Allow removing the relationship of an event to a thread * Implement feature detection for new threads MSCs and specs * Prefix dir parameter for threads pagination if necessary * Make threads conform to the same timeline APIs as any other timeline * Extract thread timeline loading out of thread class * fix thread roots not being updated correctly * fix jumping to events by link * implement new thread timeline loading * Fix fetchRoomEvent incorrect return type Co-authored-by: Germain <germains@element.io> Co-authored-by: Germain <germain@souquet.com>
This commit is contained in:
committed by
GitHub
parent
b44787192d
commit
068fbb7660
28
src/utils.ts
28
src/utils.ts
@@ -22,6 +22,7 @@ limitations under the License.
|
||||
|
||||
import unhomoglyph from "unhomoglyph";
|
||||
import promiseRetry from "p-retry";
|
||||
import { Optional } from "matrix-events-sdk";
|
||||
|
||||
import { MatrixEvent } from "./models/event";
|
||||
import { M_TIMESTAMP } from "./@types/location";
|
||||
@@ -76,6 +77,25 @@ export function encodeParams(params: QueryDict, urlSearchParams?: URLSearchParam
|
||||
|
||||
export type QueryDict = Record<string, string[] | string | number | boolean | undefined>;
|
||||
|
||||
/**
|
||||
* Replace a stable parameter with the unstable naming for params
|
||||
* @param stable
|
||||
* @param unstable
|
||||
* @param dict
|
||||
*/
|
||||
export function replaceParam(
|
||||
stable: string,
|
||||
unstable: string,
|
||||
dict: QueryDict,
|
||||
): QueryDict {
|
||||
const result = {
|
||||
...dict,
|
||||
[unstable]: dict[stable],
|
||||
};
|
||||
delete result[stable];
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode a query string in `application/x-www-form-urlencoded` format.
|
||||
* @param {string} query A query string to decode e.g.
|
||||
@@ -103,13 +123,17 @@ export function decodeParams(query: string): Record<string, string | string[]> {
|
||||
* variables with. E.g. { "$bar": "baz" }.
|
||||
* @return {string} The result of replacing all template variables e.g. '/foo/baz'.
|
||||
*/
|
||||
export function encodeUri(pathTemplate: string, variables: Record<string, string>): string {
|
||||
export function encodeUri(pathTemplate: string, variables: Record<string, Optional<string>>): string {
|
||||
for (const key in variables) {
|
||||
if (!variables.hasOwnProperty(key)) {
|
||||
continue;
|
||||
}
|
||||
const value = variables[key];
|
||||
if (value === undefined || value === null) {
|
||||
continue;
|
||||
}
|
||||
pathTemplate = pathTemplate.replace(
|
||||
key, encodeURIComponent(variables[key]),
|
||||
key, encodeURIComponent(value),
|
||||
);
|
||||
}
|
||||
return pathTemplate;
|
||||
|
||||
Reference in New Issue
Block a user