Skip to content

Commit e8bae3a

Browse files
committed
Mark a room as read when leaving it
This replicate the behavior of the weechat's read marker, and is useful when you use differents clients.
1 parent 37aae25 commit e8bae3a

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

matrix.lua

+11-3
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ local POLL_INTERVAL = 55
7373
-- Floating values like 0.4 should work too.
7474
local timeout = 5*1000 -- overriden by w.config_get_plugin later
7575

76+
local current_buffer
77+
7678
local default_color = w.color('default')
7779
-- Cache error variables so we don't have to look them up for every error
7880
-- message, a normal user will not change these ever anyway.
@@ -2695,7 +2697,7 @@ function Room:ParseChunk(chunk, backlog, chunktype)
26952697
-- luacheck: ignore 542
26962698
elseif chunk['type'] == 'm.receipt' then
26972699
-- TODO: figure out if we can do something sensible with read receipts
2698-
elseif chunk['type'] == 'm.fully_read' and self.buffer ~= w.current_buffer() then
2700+
elseif chunk['type'] == 'm.fully_read' and self.buffer ~= current_buffer then
26992701
-- we don't want to update read line for the current buffer
27002702
-- TODO: check if read marker correspond to the last event in the room
27012703
w.buffer_set(self.buffer, "unread", "")
@@ -3290,7 +3292,14 @@ end
32903292
function buffer_switch_cb(data, signal, sig_type)
32913293
-- Update bar item
32923294
w.bar_item_update('matrix_typing_notice')
3293-
local current_buffer = w.current_buffer()
3295+
if current_buffer then
3296+
local room = SERVER:findRoom(current_buffer)
3297+
if room then
3298+
room:MarkAsRead()
3299+
end
3300+
end
3301+
3302+
current_buffer = w.current_buffer()
32943303
local room = SERVER:findRoom(current_buffer)
32953304
if room then
32963305
room:MarkAsRead()
@@ -3299,7 +3308,6 @@ function buffer_switch_cb(data, signal, sig_type)
32993308
end
33003309

33013310
function typing_bar_item_cb(data, buffer, args)
3302-
local current_buffer = w.current_buffer()
33033311
local room = SERVER:findRoom(current_buffer)
33043312
if not room then return '' end
33053313
local typing_ids = table.concat(room.typing_ids, ' ')

0 commit comments

Comments
 (0)