forked from mystiq/hydrogen-web
Add sync3 API call
With some manual tests in the HTML test jig.
This commit is contained in:
parent
201ca20646
commit
737d37326a
2 changed files with 43 additions and 0 deletions
|
@ -110,6 +110,10 @@ export class HomeServerApi {
|
|||
return this._get("/sync", {since, timeout, filter}, null, options);
|
||||
}
|
||||
|
||||
sync3(body, pos, timeout, options = null) {
|
||||
return this._authedRequest("POST", this._url("/sync", "/_matrix/client/v3"), {timeout, pos}, body, options);
|
||||
}
|
||||
|
||||
// params is from, dir and optionally to, limit, filter.
|
||||
messages(roomId, params, options = null) {
|
||||
return this._get(`/rooms/${encodeURIComponent(roomId)}/messages`, params, null, options);
|
||||
|
|
|
@ -11,6 +11,8 @@
|
|||
</style>
|
||||
</head>
|
||||
<body class="not-ie11">
|
||||
<input id="tokeninput" type="password" placeholder="access_token"/>
|
||||
<input id="tokensubmit" type="button" value="Start" />
|
||||
<div id="session-status" class="hydrogen" style="height: 500px;"></div>
|
||||
<script id="main" type="module">
|
||||
import {LeftPanelView} from "./platform/web/ui/session/leftpanel/LeftPanelView.js";
|
||||
|
@ -20,6 +22,8 @@
|
|||
import {parseUrlPath, stringifyPath} from "./domain/navigation/index.js";
|
||||
import {ObservableMap} from "./observable/index.js";
|
||||
import {History} from "./platform/web/dom/History.js";
|
||||
import {HomeServerApi} from "./matrix/net/HomeServerApi.js";
|
||||
import {xhrRequest} from "./platform/web/dom/request/xhr.js";
|
||||
const navigation = new Navigation(() => false);
|
||||
const rooms = new ObservableMap();
|
||||
for (let i = 0; i < 1000; i++) {
|
||||
|
@ -65,6 +69,41 @@
|
|||
};
|
||||
const view = new LeftPanelView(leftPanel);
|
||||
document.getElementById("session-status").appendChild(view.mount());
|
||||
|
||||
|
||||
document.getElementById("tokensubmit").addEventListener("click", () => {
|
||||
const accessToken = document.getElementById("tokeninput").value;
|
||||
const sessionId = new Date().getTime() + "";
|
||||
const hs = new HomeServerApi({
|
||||
homeserver: "http://localhost:8008",
|
||||
accessToken: accessToken,
|
||||
request: xhrRequest,
|
||||
});
|
||||
|
||||
const loop = async () => {
|
||||
let pos;
|
||||
while (true) {
|
||||
let req = hs.sync3({
|
||||
session_id: sessionId,
|
||||
lists: [{
|
||||
rooms: [ [0,99] ],
|
||||
// TODO: only send these the first time.
|
||||
sort: ["by_highlight_count", "by_notification_count", "by_recency"],
|
||||
timeline_limit: 20,
|
||||
required_state: [
|
||||
["m.room.avatar", ""],
|
||||
]
|
||||
}],
|
||||
}, pos, 10);
|
||||
const resp = await req.response();
|
||||
console.log(resp);
|
||||
pos = resp.pos;
|
||||
await sleep(100);
|
||||
}
|
||||
}
|
||||
loop();
|
||||
});
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
Loading…
Reference in a new issue