mirror of
https://github.com/discourse/discourse-chat-integration.git
synced 2025-02-16 16:34:50 +00:00
Don’t load responses to threads (#14)
* Don’t load responses to threads * Add test case for ignoring threaded messages * Appease rubocop
This commit is contained in:
parent
e22a7e38b8
commit
6ed0deedf8
@ -220,7 +220,11 @@ module DiscourseChat::Provider::SlackProvider
|
|||||||
# Build some message objects
|
# Build some message objects
|
||||||
@messages = []
|
@messages = []
|
||||||
raw_messages.each_with_index do |message, index|
|
raw_messages.each_with_index do |message, index|
|
||||||
|
# Only load messages
|
||||||
next unless message["type"] == "message"
|
next unless message["type"] == "message"
|
||||||
|
# Don't load responses to threads (if ts==thread_ts then it's the thread parent)
|
||||||
|
next if message["thread_ts"] && message["thread_ts"] != message["ts"]
|
||||||
|
|
||||||
this_message = SlackMessage.new(message, self)
|
this_message = SlackMessage.new(message, self)
|
||||||
@messages << this_message
|
@messages << this_message
|
||||||
end
|
end
|
||||||
|
@ -28,6 +28,13 @@ RSpec.describe DiscourseChat::Provider::SlackProvider::SlackTranscript do
|
|||||||
"text": "So, who's interested in the new <https://meta.discourse.org|discourse plugin>?",
|
"text": "So, who's interested in the new <https://meta.discourse.org|discourse plugin>?",
|
||||||
"ts": "1501801629.052212"
|
"ts": "1501801629.052212"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"type": "message",
|
||||||
|
"user": "U6E2W7R8C",
|
||||||
|
"text": "I'm interested!!",
|
||||||
|
"ts": "1501801634.053761",
|
||||||
|
"thread_ts": "1501801629.052212"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"text": "",
|
"text": "",
|
||||||
"username": "Test Community",
|
"username": "Test Community",
|
||||||
@ -128,6 +135,10 @@ RSpec.describe DiscourseChat::Provider::SlackProvider::SlackTranscript do
|
|||||||
transcript.load_chat_history
|
transcript.load_chat_history
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'ignores messages in a thread' do
|
||||||
|
expect(transcript.messages.length).to eq(6)
|
||||||
|
end
|
||||||
|
|
||||||
it 'loads in chronological order' do # API presents in reverse chronological
|
it 'loads in chronological order' do # API presents in reverse chronological
|
||||||
expect(transcript.messages.first.ts).to eq('1501093331.439776')
|
expect(transcript.messages.first.ts).to eq('1501093331.439776')
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user