Some twitter to/from fixes.
This commit is contained in:
parent
7a56b48d42
commit
6e926250a5
4 changed files with 64 additions and 57 deletions
|
@ -312,6 +312,7 @@ class App.TicketZoomArticleNew extends App.Controller
|
|||
@textarea.focus()
|
||||
|
||||
openTextarea: (event, withoutAnimation) =>
|
||||
if event
|
||||
event.stopPropagation()
|
||||
if @articleNewEdit.hasClass('is-open')
|
||||
return
|
||||
|
|
|
@ -30,7 +30,15 @@ class Observer::Ticket::Article::CommunicateTwitter < ActiveRecord::Observer
|
|||
)
|
||||
|
||||
# fill article with tweet info
|
||||
record.from = tweet.user.screen_name
|
||||
|
||||
# direct message
|
||||
if tweet.class == Twitter::DirectMessage
|
||||
record.from = "@#{tweet.sender.screen_name}"
|
||||
record.to = "@#{tweet.recipient.screen_name}"
|
||||
|
||||
# regular tweet
|
||||
elsif tweet.class == Twitter::Tweet
|
||||
record.from = "@#{tweet.user.screen_name}"
|
||||
if tweet.user_mentions
|
||||
to = ''
|
||||
twitter_mention_ids = []
|
||||
|
@ -44,6 +52,9 @@ class Observer::Ticket::Article::CommunicateTwitter < ActiveRecord::Observer
|
|||
record.to = to
|
||||
record.preferences[:twitter_mention_ids] = twitter_mention_ids
|
||||
end
|
||||
else
|
||||
fail "Unknown tweet type '#{tweet.class}'"
|
||||
end
|
||||
|
||||
record.message_id = tweet.id
|
||||
record.save
|
||||
|
|
18
lib/tweet.rb
18
lib/tweet.rb
|
@ -110,13 +110,8 @@ class Tweet
|
|||
Rails.logger.debug group_id.inspect
|
||||
|
||||
if tweet.class == Twitter::DirectMessage
|
||||
article = Ticket::Article.find_by(
|
||||
from: tweet.sender.screen_name,
|
||||
type_id: Ticket::Article::Type.find_by(name: 'twitter direct-message').id,
|
||||
)
|
||||
if article
|
||||
ticket = Ticket.find_by(
|
||||
id: article.ticket_id,
|
||||
create_article_type: Ticket::Article::Type.lookup(name: 'twitter direct-message'),
|
||||
customer_id: user.id,
|
||||
state: Ticket::State.where.not(
|
||||
state_type_id: Ticket::StateType.where(
|
||||
|
@ -126,7 +121,6 @@ class Tweet
|
|||
)
|
||||
return ticket if ticket
|
||||
end
|
||||
end
|
||||
|
||||
UserInfo.current_user_id = user.id
|
||||
|
||||
|
@ -134,8 +128,8 @@ class Tweet
|
|||
customer_id: user.id,
|
||||
title: "#{tweet.text[0, 37]}...",
|
||||
group_id: group_id,
|
||||
state_id: Ticket::State.find_by(name: 'new').id,
|
||||
priority_id: Ticket::Priority.find_by(name: '2 normal').id,
|
||||
state: Ticket::State.find_by(name: 'new'),
|
||||
priority: Ticket::Priority.find_by(name: '2 normal'),
|
||||
preferences: {
|
||||
channel_id: channel.id
|
||||
},
|
||||
|
@ -162,11 +156,11 @@ class Tweet
|
|||
in_reply_to = nil
|
||||
if tweet.class == Twitter::DirectMessage
|
||||
article_type = 'twitter direct-message'
|
||||
to = tweet.recipient.screen_name
|
||||
from = tweet.sender.screen_name
|
||||
to = "@#{tweet.recipient.screen_name}"
|
||||
from = "@#{tweet.sender.screen_name}"
|
||||
elsif tweet.class == Twitter::Tweet
|
||||
article_type = 'twitter status'
|
||||
from = tweet.user.screen_name
|
||||
from = "@#{tweet.user.screen_name}"
|
||||
in_reply_to = tweet.in_reply_to_status_id
|
||||
else
|
||||
fail "Unknown tweet type '#{tweet.class}'"
|
||||
|
|
|
@ -100,7 +100,6 @@ class TwitterTest < ActiveSupport::TestCase
|
|||
created_by_id: 1,
|
||||
)
|
||||
assert(ticket, "outbound ticket created, text: #{text}")
|
||||
|
||||
article = Ticket::Article.create(
|
||||
ticket_id: ticket.id,
|
||||
body: text,
|
||||
|
@ -111,6 +110,8 @@ class TwitterTest < ActiveSupport::TestCase
|
|||
created_by_id: 1,
|
||||
)
|
||||
assert(article, "outbound article created, text: #{text}")
|
||||
assert_equal('@armin_theo', article.from, 'ticket article from')
|
||||
assert_equal('', article.to, 'ticket article to')
|
||||
|
||||
# reply by me_bauer
|
||||
client = Twitter::REST::Client.new do |config|
|
||||
|
@ -139,23 +140,20 @@ class TwitterTest < ActiveSupport::TestCase
|
|||
|
||||
# fetch check system account
|
||||
sleep 10
|
||||
|
||||
# fetch check system account
|
||||
article = nil
|
||||
(1..2).each {
|
||||
Channel.fetch
|
||||
|
||||
# check if follow up article has been created
|
||||
article = Ticket::Article.find_by(message_id: tweet.id)
|
||||
|
||||
break if article
|
||||
|
||||
sleep 10
|
||||
}
|
||||
|
||||
assert(article, "article tweet '#{tweet.id}' imported")
|
||||
assert_equal('armin_theo', article.from, 'ticket article inbound from')
|
||||
assert_equal(nil, article.to, 'ticket article inbound to')
|
||||
assert_equal('@me_bauer', article.from, 'ticket article from')
|
||||
#assert_equal('@armin_theo', article.to, 'ticket article to')
|
||||
assert_equal(nil, article.to, 'ticket article to')
|
||||
assert_equal(tweet.id.to_s, article.message_id, 'ticket article inbound message_id')
|
||||
assert_equal(2, article.ticket.articles.count, 'ticket article inbound count')
|
||||
assert_equal(reply_text.utf8_to_3bytesutf8, ticket.articles.last.body, 'ticket article inbound body')
|
||||
|
@ -176,25 +174,25 @@ class TwitterTest < ActiveSupport::TestCase
|
|||
tweet = client.update(
|
||||
text,
|
||||
)
|
||||
sleep 15
|
||||
|
||||
# fetch check system account
|
||||
sleep 15
|
||||
article = nil
|
||||
(1..2).each {
|
||||
Channel.fetch
|
||||
|
||||
# check if ticket and article has been created
|
||||
article = Ticket::Article.find_by(message_id: tweet.id)
|
||||
|
||||
break if article
|
||||
|
||||
sleep 10
|
||||
}
|
||||
assert(article)
|
||||
assert_equal('@me_bauer', article.from, 'ticket article from')
|
||||
assert_equal(nil, article.to, 'ticket article to')
|
||||
ticket = article.ticket
|
||||
|
||||
# send reply
|
||||
reply_text = '@armin_theo on my side #weather' + rand(9999).to_s
|
||||
reply_text = '@me_bauer on my side #weather' + rand(9999).to_s
|
||||
article = Ticket::Article.create(
|
||||
ticket_id: ticket.id,
|
||||
body: reply_text,
|
||||
|
@ -205,10 +203,12 @@ class TwitterTest < ActiveSupport::TestCase
|
|||
created_by_id: 1,
|
||||
)
|
||||
assert(article, "outbound article created, text: #{reply_text}")
|
||||
assert_equal(nil, article.to, 'ticket article outbound to')
|
||||
assert_equal('@armin_theo', article.from, 'ticket article from')
|
||||
assert_equal('@me_bauer', article.to, 'ticket article to')
|
||||
sleep 5
|
||||
tweet_found = false
|
||||
client.user_timeline('armin_theo').each { |local_tweet|
|
||||
sleep 10
|
||||
next if local_tweet.id.to_s != article.message_id.to_s
|
||||
tweet_found = true
|
||||
break
|
||||
|
@ -246,22 +246,22 @@ class TwitterTest < ActiveSupport::TestCase
|
|||
text,
|
||||
)
|
||||
assert(dm, "dm with ##{hash} created")
|
||||
sleep 15
|
||||
|
||||
# fetch check system account
|
||||
sleep 15
|
||||
article = nil
|
||||
(1..2).each {
|
||||
Channel.fetch
|
||||
|
||||
# check if ticket and article has been created
|
||||
article = Ticket::Article.find_by(message_id: dm.id)
|
||||
|
||||
break if article
|
||||
|
||||
sleep 10
|
||||
}
|
||||
|
||||
assert(article, "inbound article '#{text}' created")
|
||||
assert_equal('@me_bauer', article.from, 'ticket article from')
|
||||
assert_equal('@armin_theo', article.to, 'ticket article to')
|
||||
ticket = article.ticket
|
||||
assert(ticket, 'ticket of inbound article exists')
|
||||
assert(ticket.articles, 'ticket.articles exists')
|
||||
|
@ -279,11 +279,12 @@ class TwitterTest < ActiveSupport::TestCase
|
|||
updated_by_id: 1,
|
||||
created_by_id: 1,
|
||||
)
|
||||
ticket.state = Ticket::State.find_by(name: 'pending reminder')
|
||||
ticket.save
|
||||
|
||||
assert(outbound_article, 'outbound article created')
|
||||
assert_equal(2, outbound_article.ticket.articles.count, 'ticket article outbound count')
|
||||
assert_equal('@armin_theo', outbound_article.from, 'ticket article from')
|
||||
assert_equal('@me_bauer', outbound_article.to, 'ticket article to')
|
||||
ticket.state = Ticket::State.find_by(name: 'pending reminder')
|
||||
ticket.save
|
||||
|
||||
text = 'Ok. ' + hash
|
||||
dm = client.create_direct_message(
|
||||
|
@ -291,22 +292,22 @@ class TwitterTest < ActiveSupport::TestCase
|
|||
text,
|
||||
)
|
||||
assert(dm, "second dm with ##{hash} created")
|
||||
sleep 15
|
||||
|
||||
# fetch check system account
|
||||
sleep 15
|
||||
article = nil
|
||||
(1..2).each {
|
||||
Channel.fetch
|
||||
|
||||
# check if ticket and article has been created
|
||||
article = Ticket::Article.find_by(message_id: dm.id)
|
||||
|
||||
break if article
|
||||
|
||||
sleep 10
|
||||
}
|
||||
|
||||
assert(article, "inbound article '#{text}' created")
|
||||
assert_equal('@me_bauer', article.from, 'ticket article inbound from')
|
||||
assert_equal('@armin_theo', article.to, 'ticket article inbound to')
|
||||
assert_equal(article.ticket.id, ticket.id, 'still the same ticket')
|
||||
ticket = article.ticket
|
||||
assert(ticket, 'ticket of inbound article exists')
|
||||
|
@ -324,22 +325,22 @@ class TwitterTest < ActiveSupport::TestCase
|
|||
text,
|
||||
)
|
||||
assert(dm, "third dm with ##{hash} created")
|
||||
sleep 15
|
||||
|
||||
# fetch check system account
|
||||
sleep 15
|
||||
article = nil
|
||||
(1..2).each {
|
||||
Channel.fetch
|
||||
|
||||
# check if ticket and article has been created
|
||||
article = Ticket::Article.find_by(message_id: dm.id)
|
||||
|
||||
break if article
|
||||
|
||||
sleep 10
|
||||
}
|
||||
|
||||
assert(article, "inbound article '#{text}' created")
|
||||
assert_equal('@me_bauer', article.from, 'ticket article inbound from')
|
||||
assert_equal('@armin_theo', article.to, 'ticket article inbound to')
|
||||
ticket = article.ticket
|
||||
assert(ticket, 'ticket of inbound article exists')
|
||||
assert(ticket.articles, 'ticket.articles exists')
|
||||
|
|
Loading…
Reference in a new issue