diff options
Diffstat (limited to 'app/models/broadcast_message.rb')
-rw-r--r-- | app/models/broadcast_message.rb | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/app/models/broadcast_message.rb b/app/models/broadcast_message.rb index dfcf28763ee..9c2ae92071d 100644 --- a/app/models/broadcast_message.rb +++ b/app/models/broadcast_message.rb @@ -20,7 +20,7 @@ class BroadcastMessage < ApplicationRecord after_commit :flush_redis_cache - def self.current + def self.current(current_path = nil) messages = cache.fetch(CACHE_KEY, as: BroadcastMessage, expires_in: cache_expires_in) do current_and_future_messages end @@ -33,7 +33,7 @@ class BroadcastMessage < ApplicationRecord # cache so we don't keep running this code all the time. cache.expire(CACHE_KEY) if now_or_future.empty? - now_or_future.select(&:now?) + now_or_future.select(&:now?).select { |message| message.matches_current_path(current_path) } end def self.current_and_future_messages @@ -72,6 +72,12 @@ class BroadcastMessage < ApplicationRecord now? || future? end + def matches_current_path(current_path) + return true if current_path.blank? || target_path.blank? + + current_path.match(Regexp.escape(target_path).gsub('\\*', '.*')) + end + def flush_redis_cache self.class.cache.expire(CACHE_KEY) end |