Some twitter to/from fixes.

This commit is contained in:
Martin Edenhofer 2015-12-14 23:46:02 +01:00
parent 7a56b48d42
commit 6e926250a5
4 changed files with 64 additions and 57 deletions

View file

@ -312,6 +312,7 @@ class App.TicketZoomArticleNew extends App.Controller
@textarea.focus() @textarea.focus()
openTextarea: (event, withoutAnimation) => openTextarea: (event, withoutAnimation) =>
if event
event.stopPropagation() event.stopPropagation()
if @articleNewEdit.hasClass('is-open') if @articleNewEdit.hasClass('is-open')
return return

View file

@ -30,7 +30,15 @@ class Observer::Ticket::Article::CommunicateTwitter < ActiveRecord::Observer
) )
# fill article with tweet info # 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 if tweet.user_mentions
to = '' to = ''
twitter_mention_ids = [] twitter_mention_ids = []
@ -44,6 +52,9 @@ class Observer::Ticket::Article::CommunicateTwitter < ActiveRecord::Observer
record.to = to record.to = to
record.preferences[:twitter_mention_ids] = twitter_mention_ids record.preferences[:twitter_mention_ids] = twitter_mention_ids
end end
else
fail "Unknown tweet type '#{tweet.class}'"
end
record.message_id = tweet.id record.message_id = tweet.id
record.save record.save

View file

@ -110,13 +110,8 @@ class Tweet
Rails.logger.debug group_id.inspect Rails.logger.debug group_id.inspect
if tweet.class == Twitter::DirectMessage 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( ticket = Ticket.find_by(
id: article.ticket_id, create_article_type: Ticket::Article::Type.lookup(name: 'twitter direct-message'),
customer_id: user.id, customer_id: user.id,
state: Ticket::State.where.not( state: Ticket::State.where.not(
state_type_id: Ticket::StateType.where( state_type_id: Ticket::StateType.where(
@ -126,7 +121,6 @@ class Tweet
) )
return ticket if ticket return ticket if ticket
end end
end
UserInfo.current_user_id = user.id UserInfo.current_user_id = user.id
@ -134,8 +128,8 @@ class Tweet
customer_id: user.id, customer_id: user.id,
title: "#{tweet.text[0, 37]}...", title: "#{tweet.text[0, 37]}...",
group_id: group_id, group_id: group_id,
state_id: Ticket::State.find_by(name: 'new').id, state: Ticket::State.find_by(name: 'new'),
priority_id: Ticket::Priority.find_by(name: '2 normal').id, priority: Ticket::Priority.find_by(name: '2 normal'),
preferences: { preferences: {
channel_id: channel.id channel_id: channel.id
}, },
@ -162,11 +156,11 @@ class Tweet
in_reply_to = nil in_reply_to = nil
if tweet.class == Twitter::DirectMessage if tweet.class == Twitter::DirectMessage
article_type = 'twitter direct-message' article_type = 'twitter direct-message'
to = tweet.recipient.screen_name to = "@#{tweet.recipient.screen_name}"
from = tweet.sender.screen_name from = "@#{tweet.sender.screen_name}"
elsif tweet.class == Twitter::Tweet elsif tweet.class == Twitter::Tweet
article_type = 'twitter status' article_type = 'twitter status'
from = tweet.user.screen_name from = "@#{tweet.user.screen_name}"
in_reply_to = tweet.in_reply_to_status_id in_reply_to = tweet.in_reply_to_status_id
else else
fail "Unknown tweet type '#{tweet.class}'" fail "Unknown tweet type '#{tweet.class}'"

View file

@ -100,7 +100,6 @@ class TwitterTest < ActiveSupport::TestCase
created_by_id: 1, created_by_id: 1,
) )
assert(ticket, "outbound ticket created, text: #{text}") assert(ticket, "outbound ticket created, text: #{text}")
article = Ticket::Article.create( article = Ticket::Article.create(
ticket_id: ticket.id, ticket_id: ticket.id,
body: text, body: text,
@ -111,6 +110,8 @@ class TwitterTest < ActiveSupport::TestCase
created_by_id: 1, created_by_id: 1,
) )
assert(article, "outbound article created, text: #{text}") 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 # reply by me_bauer
client = Twitter::REST::Client.new do |config| client = Twitter::REST::Client.new do |config|
@ -139,23 +140,20 @@ class TwitterTest < ActiveSupport::TestCase
# fetch check system account # fetch check system account
sleep 10 sleep 10
# fetch check system account
article = nil article = nil
(1..2).each { (1..2).each {
Channel.fetch Channel.fetch
# check if follow up article has been created # check if follow up article has been created
article = Ticket::Article.find_by(message_id: tweet.id) article = Ticket::Article.find_by(message_id: tweet.id)
break if article break if article
sleep 10 sleep 10
} }
assert(article, "article tweet '#{tweet.id}' imported") assert(article, "article tweet '#{tweet.id}' imported")
assert_equal('armin_theo', article.from, 'ticket article inbound from') assert_equal('@me_bauer', article.from, 'ticket article from')
assert_equal(nil, article.to, 'ticket article inbound to') #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(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(2, article.ticket.articles.count, 'ticket article inbound count')
assert_equal(reply_text.utf8_to_3bytesutf8, ticket.articles.last.body, 'ticket article inbound body') 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( tweet = client.update(
text, text,
) )
sleep 15
# fetch check system account # fetch check system account
sleep 15
article = nil article = nil
(1..2).each { (1..2).each {
Channel.fetch Channel.fetch
# check if ticket and article has been created # check if ticket and article has been created
article = Ticket::Article.find_by(message_id: tweet.id) article = Ticket::Article.find_by(message_id: tweet.id)
break if article break if article
sleep 10 sleep 10
} }
assert(article) assert(article)
assert_equal('@me_bauer', article.from, 'ticket article from')
assert_equal(nil, article.to, 'ticket article to')
ticket = article.ticket ticket = article.ticket
# send reply # 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( article = Ticket::Article.create(
ticket_id: ticket.id, ticket_id: ticket.id,
body: reply_text, body: reply_text,
@ -205,10 +203,12 @@ class TwitterTest < ActiveSupport::TestCase
created_by_id: 1, created_by_id: 1,
) )
assert(article, "outbound article created, text: #{reply_text}") 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 sleep 5
tweet_found = false tweet_found = false
client.user_timeline('armin_theo').each { |local_tweet| client.user_timeline('armin_theo').each { |local_tweet|
sleep 10
next if local_tweet.id.to_s != article.message_id.to_s next if local_tweet.id.to_s != article.message_id.to_s
tweet_found = true tweet_found = true
break break
@ -246,22 +246,22 @@ class TwitterTest < ActiveSupport::TestCase
text, text,
) )
assert(dm, "dm with ##{hash} created") assert(dm, "dm with ##{hash} created")
sleep 15
# fetch check system account # fetch check system account
sleep 15
article = nil article = nil
(1..2).each { (1..2).each {
Channel.fetch Channel.fetch
# check if ticket and article has been created # check if ticket and article has been created
article = Ticket::Article.find_by(message_id: dm.id) article = Ticket::Article.find_by(message_id: dm.id)
break if article break if article
sleep 10 sleep 10
} }
assert(article, "inbound article '#{text}' created") 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 ticket = article.ticket
assert(ticket, 'ticket of inbound article exists') assert(ticket, 'ticket of inbound article exists')
assert(ticket.articles, 'ticket.articles exists') assert(ticket.articles, 'ticket.articles exists')
@ -279,11 +279,12 @@ class TwitterTest < ActiveSupport::TestCase
updated_by_id: 1, updated_by_id: 1,
created_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(outbound_article, 'outbound article created')
assert_equal(2, outbound_article.ticket.articles.count, 'ticket article outbound count') 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 text = 'Ok. ' + hash
dm = client.create_direct_message( dm = client.create_direct_message(
@ -291,22 +292,22 @@ class TwitterTest < ActiveSupport::TestCase
text, text,
) )
assert(dm, "second dm with ##{hash} created") assert(dm, "second dm with ##{hash} created")
sleep 15
# fetch check system account # fetch check system account
sleep 15
article = nil article = nil
(1..2).each { (1..2).each {
Channel.fetch Channel.fetch
# check if ticket and article has been created # check if ticket and article has been created
article = Ticket::Article.find_by(message_id: dm.id) article = Ticket::Article.find_by(message_id: dm.id)
break if article break if article
sleep 10 sleep 10
} }
assert(article, "inbound article '#{text}' created") 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') assert_equal(article.ticket.id, ticket.id, 'still the same ticket')
ticket = article.ticket ticket = article.ticket
assert(ticket, 'ticket of inbound article exists') assert(ticket, 'ticket of inbound article exists')
@ -324,22 +325,22 @@ class TwitterTest < ActiveSupport::TestCase
text, text,
) )
assert(dm, "third dm with ##{hash} created") assert(dm, "third dm with ##{hash} created")
sleep 15
# fetch check system account # fetch check system account
sleep 15
article = nil article = nil
(1..2).each { (1..2).each {
Channel.fetch Channel.fetch
# check if ticket and article has been created # check if ticket and article has been created
article = Ticket::Article.find_by(message_id: dm.id) article = Ticket::Article.find_by(message_id: dm.id)
break if article break if article
sleep 10 sleep 10
} }
assert(article, "inbound article '#{text}' created") 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 ticket = article.ticket
assert(ticket, 'ticket of inbound article exists') assert(ticket, 'ticket of inbound article exists')
assert(ticket.articles, 'ticket.articles exists') assert(ticket.articles, 'ticket.articles exists')