grape-slack-bot 1.6.4 → 1.6.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d67c8a3223c22c71a6c65df3779ec80008a06534d389eefa56fb1758fd91f352
4
- data.tar.gz: 1e220f3dc13b1dd5a0ade887bd13bd0e86612f08433897efd0a4cd84cb96c354
3
+ metadata.gz: ae374ea5f4698b8505bde66baa7a67eaf75764e130d2f40e9de6fd29848966a8
4
+ data.tar.gz: 01ec55f539994166f4d3b90cf70953c5b4e2f421a9622affa5a44d7d0adcf888
5
5
  SHA512:
6
- metadata.gz: 3a731d872905dcc3da371323195b7c3efae2a4fc92a0174453e64f2815b82117d7dbd54f5b29e60077bdb5ea55716e17fd4882de7fc559d2c601bc01d447ca83
7
- data.tar.gz: bd4409a17bbbb6191d4fd424fdf6502a06b4283bdcc7890e33c0052caa45b2a6ff23bb6870107b8ec802fbffac19859ac51f6d211ebb59cc3473e8ccac37fa03
6
+ metadata.gz: 7a0223855ad9173023eb667115a6e2137212164c06069ca78db6289a813b9ea92da38c062577b6ab18642a4e3f1689326f353b159e21c05672e2447573e248e7
7
+ data.tar.gz: b44baf6641e68b2815afaf915485e9052d2594a1d43e92ae56d7e9a25463de0395253819627349ec8257814c0372bef1fb1fd72bb7b3ed91b436e7c2e84a5aba
@@ -15,6 +15,14 @@ module SlackBot
15
15
  nil
16
16
  end
17
17
 
18
+ def self.find_by_view_id(view_id, user: nil, config: nil)
19
+ callback = new(view_id: view_id, user: user, config: config)
20
+ callback_id = callback.read_view_callback_id
21
+ return if callback_id.blank?
22
+
23
+ find(callback_id, user: user, config: config)
24
+ end
25
+
18
26
  def self.create(id: nil, class_name:, user:, channel_id: nil, config: nil, payload: nil, expires_in: nil, user_scope: nil)
19
27
  callback =
20
28
  new(id: id, class_name: class_name, user: user, channel_id: channel_id, payload: payload, config: config, expires_in: expires_in, user_scope: user_scope)
@@ -30,12 +38,13 @@ module SlackBot
30
38
  end
31
39
 
32
40
  attr_reader :id, :data, :args, :config, :expires_in, :user_scope
33
- def initialize(id: nil, class_name: nil, user: nil, channel_id: nil, payload: nil, config: nil, expires_in: nil, user_scope: nil)
41
+ def initialize(id: nil, class_name: nil, user: nil, channel_id: nil, payload: nil, config: nil, expires_in: nil, user_scope: nil, view_id: nil)
34
42
  @id = id
35
43
  @data = {
36
44
  class_name: class_name,
37
45
  user_id: user&.id,
38
46
  channel_id: channel_id,
47
+ view_id: view_id,
39
48
  payload: payload
40
49
  }
41
50
  @args = SlackBot::Args.new
@@ -105,6 +114,10 @@ module SlackBot
105
114
  @data[:payload] = payload
106
115
  end
107
116
 
117
+ def view_id=(view_id)
118
+ @data[:view_id] = view_id
119
+ end
120
+
108
121
  def handler_class=(handler_class)
109
122
  new_class_name = handler_class&.name
110
123
  config.find_handler_class(class_name)
@@ -125,6 +138,12 @@ module SlackBot
125
138
  super
126
139
  end
127
140
 
141
+ def read_view_callback_id
142
+ return if view_id.blank?
143
+
144
+ config.callback_storage_instance.read(view_storage_key)
145
+ end
146
+
128
147
  private
129
148
 
130
149
  def parse_args
@@ -140,13 +159,15 @@ module SlackBot
140
159
  end
141
160
 
142
161
  def storage_key
143
- if user_scope
144
- raise "User is required for scoped callback" if user.blank?
162
+ raise "User is required for scoped callback" if user.blank?
145
163
 
146
- "#{CALLBACK_KEY_PREFIX}:u#{user.id}:#{id}"
147
- else
148
- "#{CALLBACK_KEY_PREFIX}:#{id}"
149
- end
164
+ "#{CALLBACK_KEY_PREFIX}:u#{user.id}:#{id}"
165
+ end
166
+
167
+ def view_storage_key
168
+ raise "User is required for scoped callback" if user.blank?
169
+
170
+ "#{CALLBACK_KEY_PREFIX}:u#{user.id}:#{view_id}"
150
171
  end
151
172
 
152
173
  def read_data
@@ -155,10 +176,12 @@ module SlackBot
155
176
 
156
177
  def write_data(data, expires_in: nil)
157
178
  expires_in ||= CALLBACK_RECORD_EXPIRES_IN
179
+ config.callback_storage_instance.write(view_storage_key, id, expires_in: expires_in) if view_id.present?
158
180
  config.callback_storage_instance.write(storage_key, data, expires_in: expires_in)
159
181
  end
160
182
 
161
183
  def delete_data
184
+ config.callback_storage_instance.delete(view_storage_key) if view_id.present?
162
185
  config.callback_storage_instance.delete(storage_key)
163
186
  end
164
187
  end
@@ -18,7 +18,7 @@ module SlackBot
18
18
  end
19
19
 
20
20
  view_id = response.data.dig("view", "id")
21
- callback.update(view_id: view_id) if view_id.present?
21
+ callback.view_id = view_id if view_id.present?
22
22
 
23
23
  SlackViewsReply.new(callback.id, view_id)
24
24
  end
@@ -33,7 +33,7 @@ module SlackBot
33
33
  end
34
34
 
35
35
  view_id = response.data.dig("view", "id")
36
- callback.update(view_id: view_id) if view_id.present?
36
+ callback.view_id = view_id if view_id.present?
37
37
 
38
38
  SlackViewsReply.new(callback.id, view_id)
39
39
  end
data/lib/slack_bot.rb CHANGED
@@ -22,5 +22,5 @@ require 'slack_bot/pager'
22
22
  require 'slack_bot/grape_extension'
23
23
 
24
24
  module SlackBot
25
- VERSION = '1.6.4'.freeze
25
+ VERSION = '1.6.6'.freeze
26
26
  end
@@ -78,7 +78,8 @@ describe SlackBot::Callback do
78
78
  user_id: user.id,
79
79
  channel_id: "test_channel_id",
80
80
  payload: { test: "test" },
81
- args: ""
81
+ args: "",
82
+ view_id: nil
82
83
  }
83
84
  }
84
85
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grape-slack-bot
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.4
4
+ version: 1.6.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrei Makarov