DEV: Make PresenceChannel timeout configurable per-channel (#14697)

This commit is contained in:
David Taylor 2021-10-22 16:24:55 +01:00 committed by GitHub
parent 76a9ca99a8
commit 00c6d16dce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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?