grape-slack-bot 1.6.4 → 1.6.5

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: 6dd62b47329ef32dcdcca944a6e92d61010e99c3521bdc10993a8d7495a5f664
4
+ data.tar.gz: 2c8a5746152b33a557567405079a14a9646e4ba7fcb1819a042128c9e2830f7d
5
5
  SHA512:
6
- metadata.gz: 3a731d872905dcc3da371323195b7c3efae2a4fc92a0174453e64f2815b82117d7dbd54f5b29e60077bdb5ea55716e17fd4882de7fc559d2c601bc01d447ca83
7
- data.tar.gz: bd4409a17bbbb6191d4fd424fdf6502a06b4283bdcc7890e33c0052caa45b2a6ff23bb6870107b8ec802fbffac19859ac51f6d211ebb59cc3473e8ccac37fa03
6
+ metadata.gz: 5b2faa38f309c0851235d6528eda0b110f219eed374c7791999f8b3ded2063ca050360d5a312fa1f9cafd56d3e44041c0b1c08e40f9200637007f8350f84c77c
7
+ data.tar.gz: 681ebb8c167698b46c8f300491d3097a85809da8584796688f305a783ea64f3d6e5be56cee798338474f081aa25e51241e4a98f4b9de41a3ab7082205c84eaf1
@@ -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
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.5'.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.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrei Makarov