Skip to content

Commit a7491b3

Browse files
committed
refactor waiting_since logic
1 parent 099c733 commit a7491b3

File tree

2 files changed

+34
-12
lines changed

2 files changed

+34
-12
lines changed

.vscode/settings.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"files.exclude": {
3+
"**/.git": true,
4+
"**/.svn": true,
5+
"**/.hg": true,
6+
"**/.DS_Store": true,
7+
"**/Thumbs.db": true,
8+
"**/.retool_types/**": true,
9+
"**/*tsconfig.json": true,
10+
".cache": true,
11+
"retool.config.json": true
12+
}
13+
}

plugin.rb

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,16 @@ module ::CommunityCustomFields
1313
CUSTOM_FIELDS = {
1414
assignee_id: :integer,
1515
first_assigned_to_id: :integer,
16-
first_assigned_at: :datetime,
16+
first_assigned_at: :datetime,
17+
last_assigned_to_id: :integer,
1718
last_assigned_at: :datetime,
18-
last_action_by_assignee_at: :datetime,
1919
priority: :string,
2020
product_area: :string,
2121
status: :string,
22+
outcome: :string,
2223
snoozed_until: :datetime,
23-
waiting_since: :datetime
24+
waiting_since: :datetime,
25+
waiting_id: :integer
2426
}
2527
end
2628

@@ -43,23 +45,30 @@ module ::CommunityCustomFields
4345
topic.custom_fields[:assignee_id] = 0
4446
topic.custom_fields[:status] = "new"
4547
topic.custom_fields[:waiting_since] = Time.now.utc
48+
topic.custom_fields[:waiting_id] = user.id
4649
topic.save_custom_fields
4750
end
4851

4952
on(:post_created) do |post, _opts, user|
50-
next unless post.archetype == "regular" && post.post_type == 1 && user.id > 0
53+
next unless post.archetype == "regular" && user.id > 0 && post.post_type == 1
5154

5255
topic = post.topic
5356

5457
if user.admin
55-
# check if user is an admin and update the `waiting_since` field, if so
56-
topic.custom_fields[:waiting_since] = Time.now.utc
57-
topic.save_custom_fields
58-
elsif topic.custom_fields[:status] == "snoozed"
59-
# check if new post belongs to a snoozed topic and update status
60-
topic.custom_fields[:status] = "open"
61-
topic.custom_fields[:snoozed_until] = nil
62-
topic.save_custom_fields
58+
topic.custom_fields[:waiting_since] = nil
59+
topic.custom_fields[:waiting_id] = nil
60+
else
61+
if user.id != topic.custom_fields[:waiting_id]
62+
topic.custom_fields[:waiting_since] = Time.now.utc
63+
topic.custom_fields[:waiting_id] = user.id
64+
end
65+
66+
if topic.custom_fields[:status] == "snoozed"
67+
topic.custom_fields[:status] = "open"
68+
topic.custom_fields[:snoozed_until] = nil
69+
end
6370
end
71+
72+
topic.save_custom_fields
6473
end
6574
end

0 commit comments

Comments
 (0)