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:
parent
d29e2cbfe8
commit
632ac992ab
6
xC-proto
6
xC-proto
|
@ -19,7 +19,7 @@ struct CommandMessage {
|
|||
case HELLO:
|
||||
u32 version;
|
||||
// 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.
|
||||
case ACTIVE:
|
||||
void;
|
||||
|
@ -50,6 +50,7 @@ struct EventMessage {
|
|||
union EventData switch (enum Event {
|
||||
PING,
|
||||
BUFFER_UPDATE,
|
||||
BUFFER_STATS,
|
||||
BUFFER_RENAME,
|
||||
BUFFER_REMOVE,
|
||||
BUFFER_ACTIVATE,
|
||||
|
@ -62,12 +63,13 @@ struct EventMessage {
|
|||
void;
|
||||
case BUFFER_UPDATE:
|
||||
string buffer_name;
|
||||
case BUFFER_STATS:
|
||||
string buffer_name;
|
||||
// These are cumulative, even for lines flushed out from buffers.
|
||||
// Updates to these values aren't broadcasted, thus handle:
|
||||
// - BUFFER_LINE by bumping/setting them as appropriate,
|
||||
// - BUFFER_ACTIVATE by clearing them for the previous buffer
|
||||
// (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_unimportant_messages;
|
||||
bool highlighted;
|
||||
|
|
11
xC.c
11
xC.c
|
@ -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;
|
||||
e->event = RELAY_EVENT_BUFFER_UPDATE;
|
||||
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,
|
||||
buffer->new_messages_count - buffer->new_unimportant_count);
|
||||
e->new_unimportant_messages = MIN (UINT32_MAX,
|
||||
|
@ -15223,6 +15232,8 @@ client_resync (struct client *c)
|
|||
{
|
||||
relay_prepare_buffer_update (c->ctx, buffer);
|
||||
relay_send (c);
|
||||
relay_prepare_buffer_stats (c->ctx, buffer);
|
||||
relay_send (c);
|
||||
|
||||
LIST_FOR_EACH (struct buffer_line, line, buffer->lines)
|
||||
{
|
||||
|
|
|
@ -136,6 +136,12 @@ let bufferCurrent = undefined
|
|||
let bufferLog = undefined
|
||||
let bufferAutoscroll = true
|
||||
|
||||
function resetBufferStats(b) {
|
||||
b.newMessages = 0
|
||||
b.newUnimportantMessages = 0
|
||||
b.highlighted = false
|
||||
}
|
||||
|
||||
let connecting = true
|
||||
rpc.connect().then(result => {
|
||||
buffers.clear()
|
||||
|
@ -162,15 +168,21 @@ rpc.addEventListener('Ping', event => {
|
|||
rpc.addEventListener('BufferUpdate', event => {
|
||||
let e = event.detail, b = buffers.get(e.bufferName)
|
||||
if (b === undefined) {
|
||||
buffers.set(e.bufferName, {
|
||||
lines: [],
|
||||
newMessages: e.newMessages,
|
||||
newUnimportantMessages: e.newUnimportantMessages,
|
||||
highlighted: e.highlighted,
|
||||
})
|
||||
buffers.set(e.bufferName, (b = {lines: []}))
|
||||
resetBufferStats(b)
|
||||
}
|
||||
})
|
||||
|
||||
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 => {
|
||||
let e = event.detail
|
||||
buffers.set(e.new, buffers.get(e.bufferName))
|
||||
|
@ -184,11 +196,8 @@ rpc.addEventListener('BufferRemove', event => {
|
|||
|
||||
rpc.addEventListener('BufferActivate', event => {
|
||||
let old = buffers.get(bufferCurrent)
|
||||
if (old !== undefined) {
|
||||
old.newMessages = 0
|
||||
old.newUnimportantMessages = 0
|
||||
old.highlighted = false
|
||||
}
|
||||
if (old !== undefined)
|
||||
resetBufferStats(old)
|
||||
|
||||
let e = event.detail, b = buffers.get(e.bufferName)
|
||||
bufferCurrent = e.bufferName
|
||||
|
|
Loading…
Reference in New Issue