chat_sdk-linear 1.1.0 → 1.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0d0491ce8378e3f97fd5df84ee8d9c33ed93d8eafd9ef349336bb954eb6e40af
4
- data.tar.gz: 5dfcf8ba68473c04a906f47c1262045f8cfc2fbfe1c443ea7a06e6e3500de205
3
+ metadata.gz: 9be95d3a597df82103644afc1355e9709b60ff415eea342a9f9d13d74acb3271
4
+ data.tar.gz: 8974b645ccf302b9cf03319bc60a2ad42d3e5b94fec36664ff61072c79972bd4
5
5
  SHA512:
6
- metadata.gz: 3c1f81ee0e1ecbc4f79f05cb04fd6989667048a73b74652f0392d44b75696272dc6464a5e97a0f4cc7f25eb2dff2e14b0ba5149c06a43b0983f641df854d28a1
7
- data.tar.gz: b985a4d87dc592e18081bcd9f62d4f9618f030978fcf4608b52a998e02bf7b71616c535f2fbc748b7dadd56ce6b800edab4b232e8c3c5186c106dbb6cd568c30
6
+ metadata.gz: 8a88044be09c56867ba3ca1965a6631fc7f55256f8f6cf05e2458060317dbfa58c4f190a77b0e5b26ae88ff838d6a9e603f8ac56fd7d418b5d3c784ad98696d5
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:) # rubocop:disable Lint/UnusedMethodArgument
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:) # rubocop:disable Lint/UnusedMethodArgument
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
- parts = thread_id.split(":c:")
116
- parent_id = parts.last
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 = result.dig("data", "comments", "nodes") || []
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.1.0
4
+ version: 1.3.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: '0.1'
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: '0.1'
25
+ version: '1.2'
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: faraday
28
28
  requirement: !ruby/object:Gem::Requirement