Skip to content

Commit 95924e4

Browse files
committed
update logic to handle whisper posts
1 parent e7d052f commit 95924e4

File tree

1 file changed

+31
-13
lines changed

1 file changed

+31
-13
lines changed

plugin.rb

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ module ::CommunityCustomFields
4444
end
4545

4646
on(:topic_created) do |topic, _opts, user|
47-
next if topic.archetype != "regular"
48-
next if user.id < 0
47+
next unless topic.archetype == "regular"
48+
next unless user.id > 0
4949

5050
topic.custom_fields[:status] = "new"
5151

@@ -58,16 +58,38 @@ module ::CommunityCustomFields
5858
end
5959

6060
on(:post_created) do |post, _opts, user|
61-
next if post.archetype != "regular"
62-
next if user.id < 0
63-
next if post.post_type != 1
61+
next unless post.archetype == "regular"
62+
next unless user.id > 0
63+
next unless post.post_type == 1 || post.post_type == 4
6464
next if post.post_number == 1
65-
65+
6666
topic = post.topic
67+
topic.custom_fields[:status] ||= "new"
6768

68-
if user.admin
69+
if user.admin && post.post_type == 1
6970
topic.custom_fields[:waiting_since] = nil
7071
topic.custom_fields[:waiting_id] = nil
72+
elsif user.admin && post.post_type == 4
73+
if topic.custom_fields[:status] == "snoozed"
74+
topic.custom_fields[:status] = "open"
75+
topic.custom_fields[:snoozed_until] = nil
76+
end
77+
78+
if topic.custom_fields[:status] == "closed"
79+
# this handles an edge case where `closed_at` was never set
80+
topic.custom_fields[:closed_at] ||= Time.current.iso8601
81+
82+
if topic.custom_fields[:last_assigned_to_id].nil?
83+
topic.custom_fields[:status] = "new"
84+
else
85+
topic.custom_fields[:status] = "open"
86+
topic.custom_fields[:assignee_id] = topic.custom_fields[:last_assigned_to_id]
87+
topic.custom_fields[:last_assigned_at] = Time.current.iso8601
88+
end
89+
90+
topic.custom_fields[:outcome] = nil
91+
topic.custom_fields[:closed_at] = nil
92+
end
7193
else
7294
if user.id != topic.custom_fields[:waiting_id].to_i
7395
topic.custom_fields[:waiting_since] = Time.current.iso8601
@@ -80,7 +102,7 @@ module ::CommunityCustomFields
80102
end
81103

82104
if topic.custom_fields[:status] == "closed"
83-
# this handles an edge case where `closed_at` was never assigned
105+
# this handles an edge case where `closed_at` was never set
84106
topic.custom_fields[:closed_at] ||= Time.current.iso8601
85107

86108
if topic.custom_fields[:last_assigned_to_id].nil? || Time.iso8601(topic.custom_fields[:closed_at]) < 1.month.ago.iso8601
@@ -93,12 +115,8 @@ module ::CommunityCustomFields
93115
topic.custom_fields[:outcome] = nil
94116
topic.custom_fields[:closed_at] = nil
95117
end
96-
97-
if topic.custom_fields[:status].nil?
98-
topic.custom_fields[:status] = "new"
99-
end
100118
end
101-
119+
102120
topic.save_custom_fields
103121
end
104122
end

0 commit comments

Comments
 (0)