From 00c6d16dcec314459d605b3d672ce1f469d3048e Mon Sep 17 00:00:00 2001 From: David Taylor Date: Fri, 22 Oct 2021 16:24:55 +0100 Subject: [PATCH] DEV: Make PresenceChannel timeout configurable per-channel (#14697) --- lib/presence_channel.rb | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/presence_channel.rb b/lib/presence_channel.rb index a84853465b8..f2e8031c4cb 100644 --- a/lib/presence_channel.rb +++ b/lib/presence_channel.rb @@ -36,19 +36,21 @@ class PresenceChannel # count_only: boolean. If true, user identities are never revealed to clients. (default []) class Config NOT_FOUND ||= "notfound" - attr_accessor :public, :allowed_user_ids, :allowed_group_ids, :count_only - def initialize(public: false, allowed_user_ids: nil, allowed_group_ids: nil, count_only: false) + attr_accessor :public, :allowed_user_ids, :allowed_group_ids, :count_only, :timeout + + def initialize(public: false, allowed_user_ids: nil, allowed_group_ids: nil, count_only: false, timeout: nil) @public = public @allowed_user_ids = allowed_user_ids @allowed_group_ids = allowed_group_ids @count_only = count_only + @timeout = timeout end def self.from_json(json) data = JSON.parse(json, symbolize_names: true) data = {} if !data.is_a? Hash - new(**data.slice(:public, :allowed_user_ids, :allowed_group_ids, :count_only)) + new(**data.slice(:public, :allowed_user_ids, :allowed_group_ids, :count_only, :timeout)) end def to_json @@ -56,6 +58,7 @@ class PresenceChannel data[:allowed_user_ids] = allowed_user_ids if allowed_user_ids data[:allowed_group_ids] = allowed_group_ids if allowed_group_ids data[:count_only] = count_only if count_only + data[:timeout] = timeout if timeout data.to_json end end @@ -72,7 +75,6 @@ class PresenceChannel def initialize(name, raise_not_found: true, use_cache: true) @name = name - @timeout = DEFAULT_TIMEOUT @message_bus_channel_name = "/presence#{name}" begin @@ -81,6 +83,8 @@ class PresenceChannel raise if raise_not_found @config = Config.new end + + @timeout = config.timeout || DEFAULT_TIMEOUT end # Is this user allowed to view this channel?