xC/xP: only send buffer stats in the initial sync

The client and frontends track these separately,
there is no need for hard synchronization.
This commit is contained in:
Přemysl Eric Janouch 2022-09-10 17:37:19 +02:00
parent d29e2cbfe8
commit 632ac992ab
Signed by: p
GPG Key ID: A0420B94F92B9493
3 changed files with 35 additions and 13 deletions

View File

@ -19,7 +19,7 @@ struct CommandMessage {
case HELLO: case HELLO:
u32 version; u32 version;
// If the version check succeeds, the client will receive // If the version check succeeds, the client will receive
// an initial stream of BUFFER_UPDATE, BUFFER_LINE, // an initial stream of BUFFER_UPDATE, BUFFER_STATS, BUFFER_LINE,
// and finally a BUFFER_ACTIVATE message. // and finally a BUFFER_ACTIVATE message.
case ACTIVE: case ACTIVE:
void; void;
@ -50,6 +50,7 @@ struct EventMessage {
union EventData switch (enum Event { union EventData switch (enum Event {
PING, PING,
BUFFER_UPDATE, BUFFER_UPDATE,
BUFFER_STATS,
BUFFER_RENAME, BUFFER_RENAME,
BUFFER_REMOVE, BUFFER_REMOVE,
BUFFER_ACTIVATE, BUFFER_ACTIVATE,
@ -62,12 +63,13 @@ struct EventMessage {
void; void;
case BUFFER_UPDATE: case BUFFER_UPDATE:
string buffer_name; string buffer_name;
case BUFFER_STATS:
string buffer_name;
// These are cumulative, even for lines flushed out from buffers. // These are cumulative, even for lines flushed out from buffers.
// Updates to these values aren't broadcasted, thus handle: // Updates to these values aren't broadcasted, thus handle:
// - BUFFER_LINE by bumping/setting them as appropriate, // - BUFFER_LINE by bumping/setting them as appropriate,
// - BUFFER_ACTIVATE by clearing them for the previous buffer // - BUFFER_ACTIVATE by clearing them for the previous buffer
// (this way, they can be used to mark unread messages). // (this way, they can be used to mark unread messages).
// Any updates received after the initial sync should be ignored.
u32 new_messages; u32 new_messages;
u32 new_unimportant_messages; u32 new_unimportant_messages;
bool highlighted; bool highlighted;

11
xC.c
View File

@ -3068,6 +3068,15 @@ relay_prepare_buffer_update (struct app_context *ctx, struct buffer *buffer)
struct relay_event_data_buffer_update *e = &m->data.buffer_update; struct relay_event_data_buffer_update *e = &m->data.buffer_update;
e->event = RELAY_EVENT_BUFFER_UPDATE; e->event = RELAY_EVENT_BUFFER_UPDATE;
e->buffer_name = str_from_cstr (buffer->name); e->buffer_name = str_from_cstr (buffer->name);
}
static void
relay_prepare_buffer_stats (struct app_context *ctx, struct buffer *buffer)
{
struct relay_event_message *m = relay_prepare (ctx);
struct relay_event_data_buffer_stats *e = &m->data.buffer_stats;
e->event = RELAY_EVENT_BUFFER_STATS;
e->buffer_name = str_from_cstr (buffer->name);
e->new_messages = MIN (UINT32_MAX, e->new_messages = MIN (UINT32_MAX,
buffer->new_messages_count - buffer->new_unimportant_count); buffer->new_messages_count - buffer->new_unimportant_count);
e->new_unimportant_messages = MIN (UINT32_MAX, e->new_unimportant_messages = MIN (UINT32_MAX,
@ -15223,6 +15232,8 @@ client_resync (struct client *c)
{ {
relay_prepare_buffer_update (c->ctx, buffer); relay_prepare_buffer_update (c->ctx, buffer);
relay_send (c); relay_send (c);
relay_prepare_buffer_stats (c->ctx, buffer);
relay_send (c);
LIST_FOR_EACH (struct buffer_line, line, buffer->lines) LIST_FOR_EACH (struct buffer_line, line, buffer->lines)
{ {

View File

@ -136,6 +136,12 @@ let bufferCurrent = undefined
let bufferLog = undefined let bufferLog = undefined
let bufferAutoscroll = true let bufferAutoscroll = true
function resetBufferStats(b) {
b.newMessages = 0
b.newUnimportantMessages = 0
b.highlighted = false
}
let connecting = true let connecting = true
rpc.connect().then(result => { rpc.connect().then(result => {
buffers.clear() buffers.clear()
@ -162,15 +168,21 @@ rpc.addEventListener('Ping', event => {
rpc.addEventListener('BufferUpdate', event => { rpc.addEventListener('BufferUpdate', event => {
let e = event.detail, b = buffers.get(e.bufferName) let e = event.detail, b = buffers.get(e.bufferName)
if (b === undefined) { if (b === undefined) {
buffers.set(e.bufferName, { buffers.set(e.bufferName, (b = {lines: []}))
lines: [], resetBufferStats(b)
newMessages: e.newMessages,
newUnimportantMessages: e.newUnimportantMessages,
highlighted: e.highlighted,
})
} }
}) })
rpc.addEventListener('BufferStats', event => {
let e = event.detail, b = buffers.get(e.bufferName)
if (b === undefined)
return
b.newMessages = e.newMessages,
b.newUnimportantMessages = e.newUnimportantMessages
b.highlighted = e.highlighted
})
rpc.addEventListener('BufferRename', event => { rpc.addEventListener('BufferRename', event => {
let e = event.detail let e = event.detail
buffers.set(e.new, buffers.get(e.bufferName)) buffers.set(e.new, buffers.get(e.bufferName))
@ -184,11 +196,8 @@ rpc.addEventListener('BufferRemove', event => {
rpc.addEventListener('BufferActivate', event => { rpc.addEventListener('BufferActivate', event => {
let old = buffers.get(bufferCurrent) let old = buffers.get(bufferCurrent)
if (old !== undefined) { if (old !== undefined)
old.newMessages = 0 resetBufferStats(old)
old.newUnimportantMessages = 0
old.highlighted = false
}
let e = event.detail, b = buffers.get(e.bufferName) let e = event.detail, b = buffers.get(e.bufferName)
bufferCurrent = e.bufferName bufferCurrent = e.bufferName