mirror of
https://github.com/discourse/discourse.git
synced 2025-02-20 11:48:26 -06: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 [])
|
# count_only: boolean. If true, user identities are never revealed to clients. (default [])
|
||||||
class Config
|
class Config
|
||||||
NOT_FOUND ||= "notfound"
|
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
|
@public = public
|
||||||
@allowed_user_ids = allowed_user_ids
|
@allowed_user_ids = allowed_user_ids
|
||||||
@allowed_group_ids = allowed_group_ids
|
@allowed_group_ids = allowed_group_ids
|
||||||
@count_only = count_only
|
@count_only = count_only
|
||||||
|
@timeout = timeout
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.from_json(json)
|
def self.from_json(json)
|
||||||
data = JSON.parse(json, symbolize_names: true)
|
data = JSON.parse(json, symbolize_names: true)
|
||||||
data = {} if !data.is_a? Hash
|
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
|
end
|
||||||
|
|
||||||
def to_json
|
def to_json
|
||||||
@ -56,6 +58,7 @@ class PresenceChannel
|
|||||||
data[:allowed_user_ids] = allowed_user_ids if allowed_user_ids
|
data[:allowed_user_ids] = allowed_user_ids if allowed_user_ids
|
||||||
data[:allowed_group_ids] = allowed_group_ids if allowed_group_ids
|
data[:allowed_group_ids] = allowed_group_ids if allowed_group_ids
|
||||||
data[:count_only] = count_only if count_only
|
data[:count_only] = count_only if count_only
|
||||||
|
data[:timeout] = timeout if timeout
|
||||||
data.to_json
|
data.to_json
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -72,7 +75,6 @@ class PresenceChannel
|
|||||||
|
|
||||||
def initialize(name, raise_not_found: true, use_cache: true)
|
def initialize(name, raise_not_found: true, use_cache: true)
|
||||||
@name = name
|
@name = name
|
||||||
@timeout = DEFAULT_TIMEOUT
|
|
||||||
@message_bus_channel_name = "/presence#{name}"
|
@message_bus_channel_name = "/presence#{name}"
|
||||||
|
|
||||||
begin
|
begin
|
||||||
@ -81,6 +83,8 @@ class PresenceChannel
|
|||||||
raise if raise_not_found
|
raise if raise_not_found
|
||||||
@config = Config.new
|
@config = Config.new
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@timeout = config.timeout || DEFAULT_TIMEOUT
|
||||||
end
|
end
|
||||||
|
|
||||||
# Is this user allowed to view this channel?
|
# Is this user allowed to view this channel?
|
||||||
|
Loading…
Reference in New Issue
Block a user