Some twitter to/from fixes.
This commit is contained in:
parent
7a56b48d42
commit
6e926250a5
4 changed files with 64 additions and 57 deletions
|
@ -312,7 +312,8 @@ class App.TicketZoomArticleNew extends App.Controller
|
||||||
@textarea.focus()
|
@textarea.focus()
|
||||||
|
|
||||||
openTextarea: (event, withoutAnimation) =>
|
openTextarea: (event, withoutAnimation) =>
|
||||||
event.stopPropagation()
|
if event
|
||||||
|
event.stopPropagation()
|
||||||
if @articleNewEdit.hasClass('is-open')
|
if @articleNewEdit.hasClass('is-open')
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
|
@ -30,19 +30,30 @@ class Observer::Ticket::Article::CommunicateTwitter < ActiveRecord::Observer
|
||||||
)
|
)
|
||||||
|
|
||||||
# fill article with tweet info
|
# fill article with tweet info
|
||||||
record.from = tweet.user.screen_name
|
|
||||||
if tweet.user_mentions
|
# direct message
|
||||||
to = ''
|
if tweet.class == Twitter::DirectMessage
|
||||||
twitter_mention_ids = []
|
record.from = "@#{tweet.sender.screen_name}"
|
||||||
tweet.user_mentions.each {|user|
|
record.to = "@#{tweet.recipient.screen_name}"
|
||||||
if to != ''
|
|
||||||
to += ' '
|
# regular tweet
|
||||||
end
|
elsif tweet.class == Twitter::Tweet
|
||||||
to += "@#{user.screen_name}"
|
record.from = "@#{tweet.user.screen_name}"
|
||||||
twitter_mention_ids.push user.id
|
if tweet.user_mentions
|
||||||
}
|
to = ''
|
||||||
record.to = to
|
twitter_mention_ids = []
|
||||||
record.preferences[:twitter_mention_ids] = twitter_mention_ids
|
tweet.user_mentions.each {|user|
|
||||||
|
if to != ''
|
||||||
|
to += ' '
|
||||||
|
end
|
||||||
|
to += "@#{user.screen_name}"
|
||||||
|
twitter_mention_ids.push user.id
|
||||||
|
}
|
||||||
|
record.to = to
|
||||||
|
record.preferences[:twitter_mention_ids] = twitter_mention_ids
|
||||||
|
end
|
||||||
|
else
|
||||||
|
fail "Unknown tweet type '#{tweet.class}'"
|
||||||
end
|
end
|
||||||
|
|
||||||
record.message_id = tweet.id
|
record.message_id = tweet.id
|
||||||
|
|
32
lib/tweet.rb
32
lib/tweet.rb
|
@ -110,22 +110,16 @@ 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(
|
ticket = Ticket.find_by(
|
||||||
from: tweet.sender.screen_name,
|
create_article_type: Ticket::Article::Type.lookup(name: 'twitter direct-message'),
|
||||||
type_id: Ticket::Article::Type.find_by(name: 'twitter direct-message').id,
|
customer_id: user.id,
|
||||||
)
|
state: Ticket::State.where.not(
|
||||||
if article
|
state_type_id: Ticket::StateType.where(
|
||||||
ticket = Ticket.find_by(
|
name: %w(closed merged removed),
|
||||||
id: article.ticket_id,
|
|
||||||
customer_id: user.id,
|
|
||||||
state: Ticket::State.where.not(
|
|
||||||
state_type_id: Ticket::StateType.where(
|
|
||||||
name: %w(closed merged removed),
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
return ticket if ticket
|
)
|
||||||
end
|
return ticket if ticket
|
||||||
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}'"
|
||||||
|
|
|
@ -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')
|
||||||
|
|
Loading…
Reference in a new issue