chat_sdk-linear 0.4.0 → 0.5.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: 610c576e330ed052f595520e180085ee02ee57ff6f38beef2d3a5de4ad078d44
4
- data.tar.gz: e52b81ffe0a6eb62ae36f503f04812b54be7dcd381ef8182edec126fe580faf3
3
+ metadata.gz: 0605e52949de13bad1133aa060393a1e2ac98c41bc92a5a768f5de8595728fc0
4
+ data.tar.gz: 1bcaefeb23df84aedb1389d94be52449ed23136846ed552535c7f4f39db17483
5
5
  SHA512:
6
- metadata.gz: 02bb007d06f983ec8ba7b354e029dd40fa66bcf943087804663d0c9d25115f12a2c8791544713924dfd29d32d7e92a7051ddd357e903286cb7033c912838d7cf
7
- data.tar.gz: 9fa10d981d2c67703271b34ffe2a898fd5a7559f1ff20eb9d012f04f74b0d9934f00836a08d797dad9ab1cf40f00d16983c66e8c4e5c136ed6b89f872d7a6e76
6
+ metadata.gz: 8bf4bfbf8fdb8a76fc640d26bf0738d92698b274a6c2ab1f3127e215daa7c94be5db1f2c83981e747ff295deb0f1ea1c55a6b4784f35c2bda83a8a7dff06893d
7
+ data.tar.gz: 06df724cf8098ebb1ba55587d1130f8b8737517e1028885d0082052814cb5d2ac29c094a37525b7558fc56af21b6032eec9e1164600800bcd9eadd61258b05bb
@@ -6,7 +6,7 @@ require "rack/utils"
6
6
  module ChatSDK
7
7
  module Linear
8
8
  class Adapter < ChatSDK::Adapter::Base
9
- capabilities :reactions
9
+ capabilities :threads, :edit_messages, :delete_messages, :reactions, :message_history, :streaming_edit
10
10
 
11
11
  attr_reader :client
12
12
 
@@ -89,6 +89,16 @@ module ChatSDK
89
89
  )
90
90
  end
91
91
 
92
+ def edit_message(channel_id:, message_id:, message:)
93
+ msg = ChatSDK::PostableMessage.from(message)
94
+ text = msg.text || msg.card&.fallback_text || ""
95
+ @client.update_comment(comment_id: message_id, body: text)
96
+ end
97
+
98
+ def delete_message(channel_id:, message_id:)
99
+ @client.delete_comment(comment_id: message_id)
100
+ end
101
+
92
102
  def add_reaction(channel_id:, message_id:, emoji:) # rubocop:disable Lint/UnusedMethodArgument
93
103
  @client.create_reaction(comment_id: message_id, emoji: emoji)
94
104
  end
@@ -97,6 +107,34 @@ module ChatSDK
97
107
  @client.delete_reaction(comment_id: message_id, emoji: emoji)
98
108
  end
99
109
 
110
+ def fetch_messages(channel_id:, thread_id: nil, limit: 50) # rubocop:disable Lint/UnusedMethodArgument
111
+ issue_id = channel_id
112
+ parent_id = nil
113
+
114
+ if thread_id&.include?(":c:")
115
+ parts = thread_id.split(":c:")
116
+ parent_id = parts.last
117
+ end
118
+
119
+ result = @client.fetch_comments(issue_id: issue_id, parent_id: parent_id)
120
+ comments = result.dig("data", "comments", "nodes") || []
121
+
122
+ messages = comments.map do |comment|
123
+ user = comment["user"] || {}
124
+ ChatSDK::Message.new(
125
+ id: comment["id"],
126
+ text: comment["body"] || "",
127
+ author: ChatSDK::Author.new(id: user["id"] || "unknown", name: user["name"] || "unknown", platform: :linear, bot: false),
128
+ thread_id: "linear:#{issue_id}:c:#{comment["id"]}",
129
+ channel_id: channel_id,
130
+ platform: :linear,
131
+ raw: comment
132
+ )
133
+ end
134
+
135
+ [messages, nil]
136
+ end
137
+
100
138
  def mention(user_id)
101
139
  "@#{user_id}"
102
140
  end
@@ -27,28 +27,69 @@ module ChatSDK
27
27
  graphql(query, {input: input})
28
28
  end
29
29
 
30
- def create_reaction(comment_id:, emoji:)
30
+ def update_comment(comment_id:, body:)
31
31
  query = <<~GQL
32
- mutation($input: ReactionCreateInput!) {
33
- reactionCreate(input: $input) {
32
+ mutation CommentUpdate($id: String!, $input: CommentUpdateInput!) {
33
+ commentUpdate(id: $id, input: $input) {
34
34
  success
35
+ comment { id body }
35
36
  }
36
37
  }
37
38
  GQL
39
+ graphql(query, {id: comment_id, input: {body: body}})
40
+ end
41
+
42
+ def delete_comment(comment_id:)
43
+ query = <<~GQL
44
+ mutation CommentDelete($id: String!) {
45
+ commentDelete(id: $id) { success }
46
+ }
47
+ GQL
48
+ graphql(query, {id: comment_id})
49
+ end
50
+
51
+ def create_reaction(comment_id:, emoji:)
52
+ query = <<~GQL
53
+ mutation ReactionCreate($input: ReactionCreateInput!) {
54
+ reactionCreate(input: $input) { success }
55
+ }
56
+ GQL
38
57
  graphql(query, {input: {commentId: comment_id, emoji: emoji}})
39
58
  end
40
59
 
41
60
  def delete_reaction(comment_id:, emoji:)
42
61
  query = <<~GQL
43
- mutation($input: ReactionCreateInput!) {
44
- reactionDelete(input: $input) {
45
- success
46
- }
62
+ mutation ReactionDelete($input: ReactionCreateInput!) {
63
+ reactionDelete(input: $input) { success }
47
64
  }
48
65
  GQL
49
66
  graphql(query, {input: {commentId: comment_id, emoji: emoji}})
50
67
  end
51
68
 
69
+ def fetch_comments(issue_id:, parent_id: nil)
70
+ if parent_id
71
+ query = <<~GQL
72
+ query CommentThread($id: String!) {
73
+ comment(id: $id) {
74
+ id body user { id name }
75
+ children { nodes { id body user { id name } } }
76
+ }
77
+ }
78
+ GQL
79
+ graphql(query, {id: parent_id})
80
+ else
81
+ query = <<~GQL
82
+ query IssueComments($id: String!) {
83
+ issue(id: $id) {
84
+ comments { nodes { id body user { id name } } }
85
+ }
86
+ }
87
+ GQL
88
+ result = graphql(query, {id: issue_id})
89
+ {"data" => {"comments" => result.dig("data", "issue", "comments") || {"nodes" => []}}}
90
+ end
91
+ end
92
+
52
93
  private
53
94
 
54
95
  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: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Quentin Rousseau