Compare commits
3 Commits
ab49c32148
...
20317226b7
| Author | SHA1 | Date | |
|---|---|---|---|
| 20317226b7 | |||
|
|
122968d7c4 | ||
|
|
785e557b87 |
@@ -1036,7 +1036,7 @@ Return the current user's session state.
|
||||
|
||||
| Parameter | Type | Default | Description |
|
||||
|-----------|--------|---------|-------------|
|
||||
| `initChannelState` | string | (none) | When set to `1`, enqueues synthetic JOIN + TOPIC + NAMES messages for every channel the session belongs to into the calling client's queue. Used by the SPA on reconnect to restore channel tabs without re-sending JOIN commands. |
|
||||
| `replay` | string | (none) | When set to `1`, enqueues synthetic JOIN + TOPIC + NAMES messages for every channel the session belongs to into the calling client's queue. Used by the SPA on reconnect to restore channel tabs without re-sending JOIN commands. |
|
||||
|
||||
**Response:** `200 OK`
|
||||
```json
|
||||
@@ -1070,9 +1070,9 @@ curl -s http://localhost:8080/api/v1/state \
|
||||
-H "Authorization: Bearer $TOKEN" | jq .
|
||||
```
|
||||
|
||||
**Reconnect with channel state init:**
|
||||
**Reconnect with channel replay:**
|
||||
```bash
|
||||
curl -s "http://localhost:8080/api/v1/state?initChannelState=1" \
|
||||
curl -s "http://localhost:8080/api/v1/state?replay=1" \
|
||||
-H "Authorization: Bearer $TOKEN" | jq .
|
||||
```
|
||||
|
||||
|
||||
@@ -444,11 +444,10 @@ func (hdlr *Handlers) enqueueNumeric(
|
||||
}
|
||||
|
||||
// HandleState returns the current session's info and
|
||||
// channels. When called with ?initChannelState=1, it also
|
||||
// enqueues synthetic JOIN + TOPIC + NAMES messages for every
|
||||
// channel the session belongs to so that a reconnecting
|
||||
// client can rebuild its channel tabs from the message
|
||||
// stream.
|
||||
// channels. When called with ?replay=1, it also enqueues
|
||||
// synthetic JOIN + TOPIC + NAMES messages for every channel
|
||||
// the session belongs to so that a reconnecting client can
|
||||
// rebuild its channel tabs from the message stream.
|
||||
func (hdlr *Handlers) HandleState() http.HandlerFunc {
|
||||
return func(
|
||||
writer http.ResponseWriter,
|
||||
@@ -476,8 +475,8 @@ func (hdlr *Handlers) HandleState() http.HandlerFunc {
|
||||
return
|
||||
}
|
||||
|
||||
if request.URL.Query().Get("initChannelState") == "1" {
|
||||
hdlr.initChannelState(
|
||||
if request.URL.Query().Get("replay") == "1" {
|
||||
hdlr.replayChannelState(
|
||||
request, clientID, sessionID, nick,
|
||||
)
|
||||
}
|
||||
@@ -490,12 +489,12 @@ func (hdlr *Handlers) HandleState() http.HandlerFunc {
|
||||
}
|
||||
}
|
||||
|
||||
// initChannelState enqueues synthetic JOIN messages and
|
||||
// replayChannelState enqueues synthetic JOIN messages and
|
||||
// join-numerics (TOPIC, NAMES) for every channel the
|
||||
// session belongs to. Messages are enqueued only to the
|
||||
// specified client so other clients/sessions are not
|
||||
// affected.
|
||||
func (hdlr *Handlers) initChannelState(
|
||||
func (hdlr *Handlers) replayChannelState(
|
||||
request *http.Request,
|
||||
clientID, sessionID int64,
|
||||
nick string,
|
||||
@@ -517,7 +516,7 @@ func (hdlr *Handlers) initChannelState(
|
||||
)
|
||||
if insErr != nil {
|
||||
hdlr.log.Error(
|
||||
"initChannelState: insert JOIN",
|
||||
"replay: insert JOIN",
|
||||
"error", insErr,
|
||||
)
|
||||
|
||||
|
||||
@@ -182,9 +182,9 @@ func (hdlr *Handlers) handleLogin(
|
||||
request, clientID, sessionID, payload.Nick,
|
||||
)
|
||||
|
||||
// Init channel state so the new client knows which
|
||||
// Replay channel state so the new client knows which
|
||||
// channels the session already belongs to.
|
||||
hdlr.initChannelState(
|
||||
hdlr.replayChannelState(
|
||||
request, clientID, sessionID, payload.Nick,
|
||||
)
|
||||
|
||||
|
||||
4
web/dist/app.js
vendored
4
web/dist/app.js
vendored
File diff suppressed because one or more lines are too long
@@ -70,7 +70,7 @@ function LoginScreen({ onLogin }) {
|
||||
.catch(() => {});
|
||||
const saved = localStorage.getItem("neoirc_token");
|
||||
if (saved) {
|
||||
api("/state?initChannelState=1")
|
||||
api("/state?replay=1")
|
||||
.then((u) => onLogin(u.nick, true))
|
||||
.catch(() => localStorage.removeItem("neoirc_token"));
|
||||
}
|
||||
@@ -335,7 +335,7 @@ function App() {
|
||||
if (msg.to) addMessage(msg.to, { ...base, text, system: true });
|
||||
if (msg.to && msg.to.startsWith("#")) {
|
||||
// Create a tab when the current user joins a channel
|
||||
// (including initial JOINs on reconnect).
|
||||
// (including replayed JOINs on reconnect).
|
||||
if (msg.from === nickRef.current) {
|
||||
setTabs((prev) => {
|
||||
if (
|
||||
@@ -656,8 +656,8 @@ function App() {
|
||||
if (isResumed) {
|
||||
// Request MOTD on resumed sessions (new sessions
|
||||
// get it automatically from the server during
|
||||
// creation). Channel state is initialised by the
|
||||
// server via the message queue (?initChannelState=1), so we
|
||||
// creation). Channel state is replayed by the
|
||||
// server via the message queue (?replay=1), so we
|
||||
// do not need to re-JOIN channels here.
|
||||
try {
|
||||
await api("/messages", {
|
||||
|
||||
Reference in New Issue
Block a user