Display canonical alias if no room name is set; display errors on UI

This commit is contained in:
Kegan Dougal 2021-09-30 17:28:36 +01:00
parent 02003cb31e
commit 852d3b4ae0
3 changed files with 25 additions and 1 deletions

View File

@ -15,6 +15,12 @@ $ ./syncv3 -server "https://matrix-client.matrix.org" -db "user=$(whoami) dbname
Then visit http://localhost:8008/client/ (with trailing slash) and paste in the `access_token` for any account on `-server`.
When you hit the Sync button nothing will happen initially, but you should see:
```
INF Poller: v2 poll loop started ip=::1 since= user_id=@kegan:matrix.org
```
Wait for the first initial v2 sync to be processed (this can take minutes!) and then v3 APIs will be responsive.
## API
API is under active development and is not stable.

View File

@ -2,6 +2,7 @@
<head>
<title>Sync v3 experiments</title>
<script>
let lastError = null;
let activeAbortController = new AbortController();
let activeSessionId;
let activeRanges = [[0,20]];
@ -140,6 +141,7 @@
const doSyncLoop = async(accessToken, sessionId) => {
console.log("Starting sync loop. Active: ", activeSessionId, " this:", sessionId);
let currentPos;
let currentError = null;
while (sessionId === activeSessionId) {
let resp;
try {
@ -154,6 +156,12 @@
} catch (err) {
if (err.name !== "AbortError") {
console.error("/sync failed:",err);
console.log("current", currentError, "last", lastError);
if (currentError != lastError) {
console.log("set!");
document.getElementById("errorMsg").textContent = lastError ? lastError : "";
}
currentError = lastError;
await sleep(1000);
}
}
@ -236,6 +244,13 @@
if (respBody.ops) {
console.log(respBody);
}
if (resp.status != 200) {
if (respBody.error) {
lastError = respBody.error;
}
throw new Error("/sync returned HTTP " + resp.status + " " + respBody.error);
}
lastError = null;
return respBody;
}
@ -285,6 +300,7 @@
<input id="accessToken" type="password" placeholder="matrix.org access token" />
<input id="syncButton" type="button" value="Sync" />
<input id="resetButton" type="button" value="New Session" />
<span id="errorMsg"></span>
<div id="listContainer" style="background: #f7f7f7;" ></div>
<template id="roomCellTemplate">
<div style="padding: 5px; display: flex; align-items: center; cursor: pointer; border-bottom: 1px solid #8d99a5; height: 40px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;">

View File

@ -218,7 +218,9 @@ func (m *ConnMap) onNewEvent(
}
}
if eventType == "m.room.name" && stateKey != nil && *stateKey == "" {
globalRoom.Name = gjson.ParseBytes(event).Get("content.name").Str
globalRoom.Name = ev.Get("content.name").Str
} else if eventType == "m.room.canonical_alias" && stateKey != nil && *stateKey == "" && globalRoom.Name == "" {
globalRoom.Name = ev.Get("content.alias").Str
}
eventTimestamp := ev.Get("origin_server_ts").Int()
globalRoom.LastMessageTimestamp = eventTimestamp