chat_sdk-linear 1.0.1 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/chat_sdk/linear/adapter.rb +46 -7
- data/lib/chat_sdk/linear/api_client.rb +13 -0
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 77aa4875d970dfa4e431b23892814f6669807bdba9510d838f941e2ae8cd5b6d
|
|
4
|
+
data.tar.gz: 8974b645ccf302b9cf03319bc60a2ad42d3e5b94fec36664ff61072c79972bd4
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 6375a7623ca5db75473baf67e889c829927b8c4dd0f3bf7227b85065e0ca8f90cac8dadda5d3b39ec1bfc140e9618979cc168af262ea796cf1cadcbebe6508ea
|
|
7
|
+
data.tar.gz: 5686a9c75793d24afa7f45ef5efd9199b16ff0d952ce57f85f52091194f0978587b801abd8e9ad440f926307a28a484724fe867a8dfc6675bb1d0ff7c4d32037
|
|
@@ -89,21 +89,25 @@ module ChatSDK
|
|
|
89
89
|
)
|
|
90
90
|
end
|
|
91
91
|
|
|
92
|
-
def edit_message(channel_id:, message_id:, message:)
|
|
92
|
+
def edit_message(channel_id:, message_id:, message:, thread_id: nil)
|
|
93
|
+
validate_comment_ownership!(channel_id, message_id, thread_id)
|
|
93
94
|
msg = ChatSDK::PostableMessage.from(message)
|
|
94
95
|
text = msg.text || msg.card&.fallback_text || ""
|
|
95
96
|
@client.update_comment(comment_id: message_id, body: text)
|
|
96
97
|
end
|
|
97
98
|
|
|
98
|
-
def delete_message(channel_id:, message_id:)
|
|
99
|
+
def delete_message(channel_id:, message_id:, thread_id: nil)
|
|
100
|
+
validate_comment_ownership!(channel_id, message_id, thread_id)
|
|
99
101
|
@client.delete_comment(comment_id: message_id)
|
|
100
102
|
end
|
|
101
103
|
|
|
102
|
-
def add_reaction(channel_id:, message_id:, emoji
|
|
104
|
+
def add_reaction(channel_id:, message_id:, emoji:, thread_id: nil)
|
|
105
|
+
validate_comment_ownership!(channel_id, message_id, thread_id)
|
|
103
106
|
@client.create_reaction(comment_id: message_id, emoji: emoji)
|
|
104
107
|
end
|
|
105
108
|
|
|
106
|
-
def remove_reaction(channel_id:, message_id:, emoji
|
|
109
|
+
def remove_reaction(channel_id:, message_id:, emoji:, thread_id: nil)
|
|
110
|
+
validate_comment_ownership!(channel_id, message_id, thread_id)
|
|
107
111
|
@client.delete_reaction(comment_id: message_id, emoji: emoji)
|
|
108
112
|
end
|
|
109
113
|
|
|
@@ -112,12 +116,16 @@ module ChatSDK
|
|
|
112
116
|
parent_id = nil
|
|
113
117
|
|
|
114
118
|
if thread_id&.include?(":c:")
|
|
115
|
-
|
|
116
|
-
parent_id
|
|
119
|
+
parent_id = thread_id.split(":c:", 2).last
|
|
120
|
+
validate_comment_ownership!(issue_id, parent_id, nil)
|
|
117
121
|
end
|
|
118
122
|
|
|
119
123
|
result = @client.fetch_comments(issue_id: issue_id, parent_id: parent_id)
|
|
120
|
-
comments =
|
|
124
|
+
comments = if parent_id
|
|
125
|
+
result.dig("data", "comment", "children", "nodes") || []
|
|
126
|
+
else
|
|
127
|
+
result.dig("data", "comments", "nodes") || []
|
|
128
|
+
end
|
|
121
129
|
|
|
122
130
|
messages = comments.map do |comment|
|
|
123
131
|
user = comment["user"] || {}
|
|
@@ -142,6 +150,37 @@ module ChatSDK
|
|
|
142
150
|
def render(postable_message)
|
|
143
151
|
postable_message.text
|
|
144
152
|
end
|
|
153
|
+
|
|
154
|
+
private
|
|
155
|
+
|
|
156
|
+
def validate_comment_ownership!(channel_id, message_id, thread_id)
|
|
157
|
+
comment = @client.fetch_comment(comment_id: message_id)
|
|
158
|
+
issue_id = comment&.dig("issue", "id")
|
|
159
|
+
unless comment && same_identifier?(issue_id, channel_id)
|
|
160
|
+
raise ChatSDK::Error, "Linear comment does not belong to issue #{channel_id}"
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
root_id = thread_root_id(thread_id)
|
|
164
|
+
return unless root_id
|
|
165
|
+
return if same_identifier?(comment["id"], root_id)
|
|
166
|
+
|
|
167
|
+
root = @client.fetch_comment(comment_id: root_id)
|
|
168
|
+
root_issue_id = root&.dig("issue", "id")
|
|
169
|
+
unless root && same_identifier?(root_issue_id, channel_id) &&
|
|
170
|
+
same_identifier?(comment.dig("parent", "id"), root_id)
|
|
171
|
+
raise ChatSDK::Error, "Linear comment does not belong to thread #{thread_id}"
|
|
172
|
+
end
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
def thread_root_id(thread_id)
|
|
176
|
+
return unless thread_id.is_a?(String) && thread_id.include?(":c:")
|
|
177
|
+
|
|
178
|
+
thread_id.split(":c:", 2).last
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
def same_identifier?(left, right)
|
|
182
|
+
left.is_a?(String) && right.is_a?(String) && left.casecmp?(right)
|
|
183
|
+
end
|
|
145
184
|
end
|
|
146
185
|
end
|
|
147
186
|
end
|
|
@@ -90,6 +90,19 @@ module ChatSDK
|
|
|
90
90
|
end
|
|
91
91
|
end
|
|
92
92
|
|
|
93
|
+
def fetch_comment(comment_id:)
|
|
94
|
+
query = <<~GQL
|
|
95
|
+
query CommentOwnership($id: String!) {
|
|
96
|
+
comment(id: $id) {
|
|
97
|
+
id
|
|
98
|
+
issue { id }
|
|
99
|
+
parent { id }
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
GQL
|
|
103
|
+
graphql(query, {id: comment_id}).dig("data", "comment")
|
|
104
|
+
end
|
|
105
|
+
|
|
93
106
|
private
|
|
94
107
|
|
|
95
108
|
def base_url
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: chat_sdk-linear
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.0
|
|
4
|
+
version: 1.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Quentin Rousseau
|
|
@@ -15,14 +15,14 @@ dependencies:
|
|
|
15
15
|
requirements:
|
|
16
16
|
- - ">="
|
|
17
17
|
- !ruby/object:Gem::Version
|
|
18
|
-
version: '
|
|
18
|
+
version: '1.2'
|
|
19
19
|
type: :runtime
|
|
20
20
|
prerelease: false
|
|
21
21
|
version_requirements: !ruby/object:Gem::Requirement
|
|
22
22
|
requirements:
|
|
23
23
|
- - ">="
|
|
24
24
|
- !ruby/object:Gem::Version
|
|
25
|
-
version: '
|
|
25
|
+
version: '1.2'
|
|
26
26
|
- !ruby/object:Gem::Dependency
|
|
27
27
|
name: faraday
|
|
28
28
|
requirement: !ruby/object:Gem::Requirement
|