generated from discourse/discourse-plugin-skeleton
-
Notifications
You must be signed in to change notification settings - Fork 1
/
plugin.rb
30 lines (29 loc) · 978 Bytes
/
plugin.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# frozen_string_literal: true
# name: discourse-category-pin
# about: discourse-category-pin
# version: 0.0.1
# authors: Ghassan Maslamani
# url: discourse-category-pin
# required_version: 2.7.0
enabled_site_setting :category_pin_enabled
after_initialize do
# Code which should run after Rails has finished booting
DiscourseEvent.on(:topic_created) do |topic|
if SiteSetting.category_pin_id?
if topic.category_id?
if topic.category_id == SiteSetting.category_pin_id
# Check if there is exist topic
topics_pinned =
Topic.where(category: SiteSetting.category_pin_id).where.not(pinned_at: nil)
topics_pinned.each { |pinned_topic| pinned_topic.update_pinned(false) }
# Pinngin the current topic
topic.update_pinned(
true,
gloabl = true,
pinned_until = SiteSetting.category_pin_duration.minutes.from_now.to_s,
)
end
end
end
end
end