|
@@ -62,7 +62,7 @@ class TweetBase
|
|
user_data[:active] = true
|
|
user_data[:active] = true
|
|
user_data[:role_ids] = Role.signup_role_ids
|
|
user_data[:role_ids] = Role.signup_role_ids
|
|
|
|
|
|
- user = User.create(user_data)
|
|
|
|
|
|
+ user = User.create!(user_data)
|
|
end
|
|
end
|
|
|
|
|
|
if user_data[:image_source]
|
|
if user_data[:image_source]
|
|
@@ -93,7 +93,7 @@ class TweetBase
|
|
if auth
|
|
if auth
|
|
auth.update_attributes(auth_data)
|
|
auth.update_attributes(auth_data)
|
|
else
|
|
else
|
|
- Authorization.create(auth_data)
|
|
|
|
|
|
+ Authorization.create!(auth_data)
|
|
end
|
|
end
|
|
|
|
|
|
user
|
|
user
|
|
@@ -128,10 +128,10 @@ class TweetBase
|
|
|
|
|
|
state = get_state(channel, tweet)
|
|
state = get_state(channel, tweet)
|
|
|
|
|
|
- Ticket.create(
|
|
|
|
|
|
+ Ticket.create!(
|
|
customer_id: user.id,
|
|
customer_id: user.id,
|
|
title: title,
|
|
title: title,
|
|
- group_id: group_id,
|
|
|
|
|
|
+ group_id: group_id || Group.first.id,
|
|
state: state,
|
|
state: state,
|
|
priority: Ticket::Priority.find_by(name: '2 normal'),
|
|
priority: Ticket::Priority.find_by(name: '2 normal'),
|
|
preferences: {
|
|
preferences: {
|
|
@@ -235,29 +235,12 @@ class TweetBase
|
|
|
|
|
|
Rails.logger.debug 'import tweet'
|
|
Rails.logger.debug 'import tweet'
|
|
|
|
|
|
- ticket = nil
|
|
|
|
# use transaction
|
|
# use transaction
|
|
if @connection_type == 'stream'
|
|
if @connection_type == 'stream'
|
|
ActiveRecord::Base.connection.reconnect!
|
|
ActiveRecord::Base.connection.reconnect!
|
|
-
|
|
|
|
- # if sender is a system account, wait until twitter message id is stored
|
|
|
|
- # on article to prevent two (own created & twitter created) articles
|
|
|
|
- tweet_user = user(tweet)
|
|
|
|
- Channel.where(area: 'Twitter::Account').each { |local_channel|
|
|
|
|
- next if !local_channel.options
|
|
|
|
- next if !local_channel.options[:user]
|
|
|
|
- next if !local_channel.options[:user][:id]
|
|
|
|
- next if local_channel.options[:user][:id].to_s != tweet_user.id.to_s
|
|
|
|
- sleep 5
|
|
|
|
-
|
|
|
|
- # return if tweet already exists (send via system)
|
|
|
|
- if Ticket::Article.find_by(message_id: tweet.id)
|
|
|
|
- Rails.logger.debug "Do not import tweet.id #{tweet.id}, article already exists"
|
|
|
|
- return nil
|
|
|
|
- end
|
|
|
|
- }
|
|
|
|
end
|
|
end
|
|
|
|
|
|
|
|
+ ticket = nil
|
|
Transaction.execute(reset_user_id: true) do
|
|
Transaction.execute(reset_user_id: true) do
|
|
|
|
|
|
# check if parent exists
|
|
# check if parent exists
|
|
@@ -272,6 +255,11 @@ class TweetBase
|
|
ticket = existing_article.ticket
|
|
ticket = existing_article.ticket
|
|
else
|
|
else
|
|
begin
|
|
begin
|
|
|
|
+
|
|
|
|
+ # in case of streaming mode, get parent tweet via REST client
|
|
|
|
+ if !@client && @auth
|
|
|
|
+ @client = TweetRest.new(@auth)
|
|
|
|
+ end
|
|
parent_tweet = @client.status(tweet.in_reply_to_status_id)
|
|
parent_tweet = @client.status(tweet.in_reply_to_status_id)
|
|
ticket = to_group(parent_tweet, group_id, channel)
|
|
ticket = to_group(parent_tweet, group_id, channel)
|
|
rescue Twitter::Error::NotFound, Twitter::Error::Forbidden => e
|
|
rescue Twitter::Error::NotFound, Twitter::Error::Forbidden => e
|
|
@@ -343,11 +331,12 @@ class TweetBase
|
|
Ticket::State.find_by(default_follow_up: true)
|
|
Ticket::State.find_by(default_follow_up: true)
|
|
end
|
|
end
|
|
|
|
|
|
- def tweet_limit_reached(tweet)
|
|
|
|
|
|
+ def tweet_limit_reached(tweet, factor = 1)
|
|
max_count = 120
|
|
max_count = 120
|
|
if @connection_type == 'stream'
|
|
if @connection_type == 'stream'
|
|
max_count = 30
|
|
max_count = 30
|
|
end
|
|
end
|
|
|
|
+ max_count = max_count * factor
|
|
type_id = Ticket::Article::Type.lookup(name: 'twitter status').id
|
|
type_id = Ticket::Article::Type.lookup(name: 'twitter status').id
|
|
created_at = Time.zone.now - 15.minutes
|
|
created_at = Time.zone.now - 15.minutes
|
|
created_count = Ticket::Article.where('created_at > ? AND type_id = ?', created_at, type_id).count
|
|
created_count = Ticket::Article.where('created_at > ? AND type_id = ?', created_at, type_id).count
|
|
@@ -358,11 +347,12 @@ class TweetBase
|
|
false
|
|
false
|
|
end
|
|
end
|
|
|
|
|
|
- def direct_message_limit_reached(tweet)
|
|
|
|
|
|
+ def direct_message_limit_reached(tweet, factor = 1)
|
|
max_count = 100
|
|
max_count = 100
|
|
if @connection_type == 'stream'
|
|
if @connection_type == 'stream'
|
|
max_count = 40
|
|
max_count = 40
|
|
end
|
|
end
|
|
|
|
+ max_count = max_count * factor
|
|
type_id = Ticket::Article::Type.lookup(name: 'twitter direct-message').id
|
|
type_id = Ticket::Article::Type.lookup(name: 'twitter direct-message').id
|
|
created_at = Time.zone.now - 15.minutes
|
|
created_at = Time.zone.now - 15.minutes
|
|
created_count = Ticket::Article.where('created_at > ? AND type_id = ?', created_at, type_id).count
|
|
created_count = Ticket::Article.where('created_at > ? AND type_id = ?', created_at, type_id).count
|
|
@@ -390,4 +380,17 @@ class TweetBase
|
|
preferences
|
|
preferences
|
|
end
|
|
end
|
|
|
|
|
|
|
|
+ def locale_sender?(tweet)
|
|
|
|
+ tweet_user = user(tweet)
|
|
|
|
+ Channel.where(area: 'Twitter::Account').each { |local_channel|
|
|
|
|
+ next if !local_channel.options
|
|
|
|
+ next if !local_channel.options[:user]
|
|
|
|
+ next if !local_channel.options[:user][:id]
|
|
|
|
+ next if local_channel.options[:user][:id].to_s != tweet_user.id.to_s
|
|
|
|
+ Rails.logger.debug "Tweet is sent by local account with user id #{tweet_user.id} and tweet.id #{tweet.id}"
|
|
|
|
+ return true
|
|
|
|
+ }
|
|
|
|
+ false
|
|
|
|
+ end
|
|
|
|
+
|
|
end
|
|
end
|