Skip to content

Commit cbf8251

Browse files
committed
add waiting_since field and logic
1 parent dadc2a5 commit cbf8251

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

plugin.rb

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ module ::CommunityCustomFields
1919
priority: :string,
2020
product_area: :string,
2121
status: :string,
22-
snoozed_until: :datetime
22+
snoozed_until: :datetime,
23+
waiting_since: :datetime
2324
}
2425
end
2526

@@ -36,16 +37,22 @@ module ::CommunityCustomFields
3637
object.topic.custom_fields.slice(*CommunityCustomFields::CUSTOM_FIELDS.keys)
3738
end
3839

39-
on(:topic_created) do |topic, params, user|
40-
topic.custom_fields[:status] = "new"
40+
on(:topic_created) do |topic, _opts, _user|
4141
topic.custom_fields[:assignee_id] = 0
42+
topic.custom_fields[:status] = "new"
43+
topic.custom_fields[:waiting_since] = Time.now.utc
4244
topic.save_custom_fields
4345
end
4446

4547
on(:post_created) do |post, _opts, user|
4648
topic = post.topic
47-
48-
if (topic.custom_fields[:status] == "snoozed") && !user.admin
49+
50+
if user.admin
51+
# check if user is an admin and update the `waiting_since` field, if so
52+
topic.custom_fields[:waiting_since] = Time.now.utc
53+
topic.save_custom_fields
54+
elsif topic.custom_fields[:status] == "snoozed"
55+
# check if new post belongs to a snoozed topic and update status
4956
topic.custom_fields[:status] = "open"
5057
topic.custom_fields[:snoozed_until] = nil
5158
topic.save_custom_fields

0 commit comments

Comments
 (0)