mirror of
https://github.com/discourse/discourse.git
synced 2024-11-25 18:03:43 +08:00
DEV: Make PresenceChannel timeout configurable per-channel (#14697)
This commit is contained in:
parent
76a9ca99a8
commit
00c6d16dce
|
@ -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?
|
||||
|
|
Loading…
Reference in New Issue
Block a user