1
0
mirror of https://github.com/jiriks74/presence.nvim synced 2024-11-23 20:37:50 +01:00

Skip debounce on activity across different buffers

This commit is contained in:
Andrew Kwon 2021-03-18 19:53:35 -07:00
parent a325d154fc
commit c8ba01782e

@ -7,6 +7,7 @@
-- -- -- --
-- Discord Rich Presence plugin for Neovim. -- -- Discord Rich Presence plugin for Neovim. --
-------------------------------------------------- --------------------------------------------------
--
-- Nvim peer-to-peer runtime state shape example: -- Nvim peer-to-peer runtime state shape example:
-- --
-- Presence = { -- Presence = {
@ -18,6 +19,7 @@
-- last_activity = { -- last_activity = {
-- file = "/Users/user/Code/presence.nvim/README.md", -- file = "/Users/user/Code/presence.nvim/README.md",
-- workspace = "/Users/user/Code/presence.nvim", -- workspace = "/Users/user/Code/presence.nvim",
-- set_at = 1616033523,
-- }, -- },
-- --
-- -- Other remote Neovim instances (peers) -- -- Other remote Neovim instances (peers)
@ -46,6 +48,7 @@
-- --
-- ... other methods and member variables -- ... other methods and member variables
-- } -- }
--
local Presence = {} local Presence = {}
Presence.is_authorized = false Presence.is_authorized = false
Presence.is_connected = false Presence.is_connected = false
@ -496,7 +499,10 @@ Presence.update = Presence.discord_event(function(self, buffer, should_debounce)
-- https://discord.com/developers/docs/rich-presence/how-to#updating-presence -- https://discord.com/developers/docs/rich-presence/how-to#updating-presence
local last_updated_at = self.last_activity.set_at local last_updated_at = self.last_activity.set_at
local debounce_timeout = self.options.debounce_timeout local debounce_timeout = self.options.debounce_timeout
local should_skip = should_debounce and debounce_timeout and local should_skip =
should_debounce and
debounce_timeout and
self.last_activity.file == buffer and
last_updated_at and os.time() - last_updated_at <= debounce_timeout last_updated_at and os.time() - last_updated_at <= debounce_timeout
if should_skip then if should_skip then