Include attachments in message selection dropdowns (#13)
* Include attachments in message selection dropdowns * DRY up message attachment string generation * Add specs for attachments in UI
This commit is contained in:
parent
6ed0deedf8
commit
b69abe3913
|
@ -24,7 +24,7 @@ module DiscourseChat::Provider::SlackProvider
|
|||
end
|
||||
|
||||
def text
|
||||
text = @raw["text"]
|
||||
text = @raw['text'].nil? ? "" : @raw['text']
|
||||
|
||||
# Format links (don't worry about special cases @ # !)
|
||||
text = text.gsub(/<(.*?)>/) do |match|
|
||||
|
@ -49,8 +49,23 @@ module DiscourseChat::Provider::SlackProvider
|
|||
text
|
||||
end
|
||||
|
||||
def attachments_string
|
||||
string = ""
|
||||
string += "\n" if !attachments.empty?
|
||||
attachments.each do |attachment|
|
||||
string += " - #{attachment}\n"
|
||||
end
|
||||
string
|
||||
end
|
||||
|
||||
def processed_text_with_attachments
|
||||
self.text + attachments_string
|
||||
end
|
||||
|
||||
def raw_text
|
||||
@raw['text']
|
||||
raw_text = @raw['text'].nil? ? "" : @raw['text']
|
||||
raw_text += attachments_string
|
||||
raw_text
|
||||
end
|
||||
|
||||
def attachments
|
||||
|
|
|
@ -148,7 +148,7 @@ module DiscourseChat::Provider::SlackProvider
|
|||
),
|
||||
type: "select",
|
||||
options: first_message_options = @messages[ [(first_message_number - 20), 0].max .. last_message_number]
|
||||
.map { |m| { text: "#{m.username}: #{m.text}", value: m.ts } }
|
||||
.map { |m| { text: "#{m.username}: #{m.processed_text_with_attachments}", value: m.ts } }
|
||||
}
|
||||
],
|
||||
},
|
||||
|
@ -176,7 +176,7 @@ module DiscourseChat::Provider::SlackProvider
|
|||
),
|
||||
type: "select",
|
||||
options: @messages[first_message_number..(last_message_number + 20)]
|
||||
.map { |m| { text: "#{m.username}: #{m.text}", value: m.ts } }
|
||||
.map { |m| { text: "#{m.username}: #{m.processed_text_with_attachments}", value: m.ts } }
|
||||
}
|
||||
],
|
||||
}
|
||||
|
|
|
@ -159,6 +159,11 @@ RSpec.describe DiscourseChat::Provider::SlackProvider::SlackTranscript do
|
|||
expect(transcript.messages.first.url).to eq("https://slack.com/archives/G1234/p1501093331439776")
|
||||
end
|
||||
|
||||
it 'includes attachments in raw text' do
|
||||
transcript.set_first_message_by_ts('1501615820.949638')
|
||||
expect(transcript.first_message.raw_text).to eq("\n - Discourse can now be integrated with Mattermost! - @david\n")
|
||||
end
|
||||
|
||||
it 'gives correct first and last messages' do
|
||||
expect(transcript.first_message_number).to eq(0)
|
||||
expect(transcript.last_message_number).to eq(transcript.messages.length - 1)
|
||||
|
@ -242,6 +247,9 @@ RSpec.describe DiscourseChat::Provider::SlackProvider::SlackTranscript do
|
|||
# The timestamps should match up to the actual messages
|
||||
expect(first_ui[:ts]).to eq(transcript.first_message.ts)
|
||||
expect(last_ui[:ts]).to eq(transcript.last_message.ts)
|
||||
|
||||
# Raw text should be used
|
||||
expect(first_ui[:text]).to eq(transcript.first_message.raw_text)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue