Skip to content

Commit d215a04

Browse files
authored
Merge pull request #95 from erdnaxeli/readBuffer
Mark a room as read when leaving the corresponding buffer
2 parents 39ff618 + e8bae3a commit d215a04

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

matrix.lua

+12-4
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.
@@ -2711,7 +2713,7 @@ function Room:ParseChunk(chunk, backlog, chunktype)
27112713
-- luacheck: ignore 542
27122714
elseif chunk['type'] == 'm.receipt' then
27132715
-- TODO: figure out if we can do something sensible with read receipts
2714-
elseif chunk['type'] == 'm.fully_read' and self.buffer ~= w.current_buffer() then
2716+
elseif chunk['type'] == 'm.fully_read' and self.buffer ~= current_buffer then
27152717
-- we don't want to update read line for the current buffer
27162718
-- TODO: check if read marker correspond to the last event in the room
27172719
w.buffer_set(self.buffer, "unread", "")
@@ -3303,10 +3305,17 @@ function typing_notification_cb(signal, sig_type, data)
33033305
return w.WEECHAT_RC_OK
33043306
end
33053307

3306-
function buffer_switch_cb(signal, sig_type, data)
3308+
function buffer_switch_cb(data, signal, sig_type)
33073309
-- Update bar item
33083310
w.bar_item_update('matrix_typing_notice')
3309-
local current_buffer = w.current_buffer()
3311+
if current_buffer then
3312+
local room = SERVER:findRoom(current_buffer)
3313+
if room then
3314+
room:MarkAsRead()
3315+
end
3316+
end
3317+
3318+
current_buffer = w.current_buffer()
33103319
local room = SERVER:findRoom(current_buffer)
33113320
if room then
33123321
room:MarkAsRead()
@@ -3315,7 +3324,6 @@ function buffer_switch_cb(signal, sig_type, data)
33153324
end
33163325

33173326
function typing_bar_item_cb(data, buffer, args)
3318-
local current_buffer = w.current_buffer()
33193327
local room = SERVER:findRoom(current_buffer)
33203328
if not room then return '' end
33213329
local typing_ids = table.concat(room.typing_ids, ' ')

0 commit comments

Comments
 (0)