mirror of
https://github.com/discourse/discourse-chat-integration.git
synced 2025-02-17 17:04:54 +00:00
FIX: An error would be raised if fewer than "skip_messages" existed
This commit is contained in:
parent
0b85c2a0e5
commit
82351a790c
@ -34,6 +34,7 @@ module DiscourseChat::Provider::SlackProvider
|
|||||||
# Apply a heuristic to decide which is the first message in the current conversation
|
# Apply a heuristic to decide which is the first message in the current conversation
|
||||||
def guess_first_message(skip_messages: 5) # Can skip the last n messages
|
def guess_first_message(skip_messages: 5) # Can skip the last n messages
|
||||||
return true if @requested_thread_ts # Always start thread on first message
|
return true if @requested_thread_ts # Always start thread on first message
|
||||||
|
return false if @messages.blank? || @messages.size < skip_messages
|
||||||
|
|
||||||
possible_first_messages = @messages[0..-skip_messages]
|
possible_first_messages = @messages[0..-skip_messages]
|
||||||
|
|
||||||
|
@ -96,6 +96,11 @@ RSpec.describe DiscourseChat::Provider::SlackProvider::SlackTranscript do
|
|||||||
SiteSetting.chat_integration_slack_access_token = "abcde"
|
SiteSetting.chat_integration_slack_access_token = "abcde"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "doesn't raise an error when there are no messages to guess" do
|
||||||
|
transcript.instance_variable_set(:@messages, [])
|
||||||
|
expect(transcript.guess_first_message(skip_messages: 1)).to eq(false)
|
||||||
|
end
|
||||||
|
|
||||||
describe 'loading users' do
|
describe 'loading users' do
|
||||||
it 'loads users correctly' do
|
it 'loads users correctly' do
|
||||||
stub_request(:post, "https://slack.com/api/users.list")
|
stub_request(:post, "https://slack.com/api/users.list")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user