grape-slack-bot 1.6.3 → 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: 1329dfec4d088344fdfec6196c57d74afb0da0b97c4366a5613d1d73f4a86137
4
- data.tar.gz: c55a6ac5ed4bbe4315e418f8fee85ae8c46725ebc1bb7e772d74dfb2caaf20a7
3
+ metadata.gz: 6dd62b47329ef32dcdcca944a6e92d61010e99c3521bdc10993a8d7495a5f664
4
+ data.tar.gz: 2c8a5746152b33a557567405079a14a9646e4ba7fcb1819a042128c9e2830f7d
5
5
  SHA512:
6
- metadata.gz: 67d60fcee908e3f81b56ccecd4698f709ea91a3873288a557c44b59a7c3b3c0005e39f3cb386110b7466266e8a5711cd2fc3d6b8b6315d57f422f5d6873f1da9
7
- data.tar.gz: 35ec83c38bf5072996657f701067d4e4efb6e271755cc1ada7affd77935c2cb8915a1cff0f123ece587b40cdb96cf5e5dcc8975190f5cd56a5c73e42db128379
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
@@ -71,8 +71,8 @@ module SlackBot
71
71
  view.send(view_name)
72
72
  end
73
73
 
74
- def open_modal(view_name, context: nil, callback: nil)
75
- callback ||= Callback.create(
74
+ def open_modal(view_name, context: nil)
75
+ self.callback ||= Callback.create(
76
76
  class_name: self.class.name,
77
77
  user: @current_user,
78
78
  config: config
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.3'.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.3
4
+ version: 1.6.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrei Makarov