From 6521d27fd310e853287809c25a09bf0d7047be89 Mon Sep 17 00:00:00 2001 From: Naman Gupta <01namangupta@gmail.com> Date: Thu, 2 Aug 2018 02:41:14 +0530 Subject: [PATCH 01/40] Added reply by tweet feature --- app/models/comment.rb | 70 +++++++++++++++++++ config/initializers/twitter_client.rb | 7 ++ config/schedule.rb | 15 ++-- ...80801125000_add_tweet_column_to_comment.rb | 5 ++ db/schema.rb.example | 5 +- 5 files changed, 96 insertions(+), 6 deletions(-) create mode 100644 config/initializers/twitter_client.rb create mode 100644 db/migrate/20180801125000_add_tweet_column_to_comment.rb diff --git a/app/models/comment.rb b/app/models/comment.rb index 53fea5ec1b..1ca20226f7 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -331,4 +331,74 @@ def self.gmail_parsed_mail(mail_doc) def trimmed_content? comment.include?(COMMENT_FILTER) end + + def self.receive_tweet + comments = Comment.where.not(since: nil) + if comments.any? + receive_tweet_using_since comments + else + receive_tweet_without_using_since + end + end + + def self.receive_tweet_using_since comments + comment = comments.last + since_id = comment.tweet_id + tweets = Client.search("to:publiclab", since: since_id).collect do |tweet| + tweet + end + check_and_add_tweets tweets + end + + + def self.receive_tweet_without_using_since + tweets = Client.search("to:publiclab").collect do |tweet| + tweet + end + check_and_add_tweets tweets + end + + def self.check_and_add_tweets tweets + tweets.each do |tweet| + if tweet.reply? + in_reply_to_tweet_id = tweet.in_reply_to_tweet_id + parent_tweet = Client.status(in_reply_to_tweet_id, tweet_mode: "extended") + parent_tweet_full_text = parent_tweet.attrs[:text] || parent_tweet.attrs[:full_text] + urls = URI.extract(parent_tweet_full_text) + node = get_node_from_urls_present(urls) + unless node.nil? + twitter_user_id = tweet.user + twitter_email = Client.user(twitter_user_id).email + users = User.where(email: twitter_email) + if users.any? + user = users.first + replied_tweet_text = tweet.text + if tweet.truncated? + replied_tweet_text = Client.status(tweet.id, tweet_mode: "extended") + replied_tweet_full_text = replied_tweet_text.attrs[:text] || replied_tweet_text.attrs[:full_text] + end + comment = node.add_comment(uid: user.uid, body: replied_tweet_full_text, comment_via: 2, twitter_id: tweet.id) + comment.notify user + end + end + end + end + end + + def self.get_node_from_urls_present(urls) + urls.each do |url| + response = Net::HTTP.get_response(URI(url)) # Get redirected link from twitter link shortner + if response['location'].include? ("://publiclab.org/n/") + node_id = t['location'].split("/")[-1] + if node_id != nil + node = Node.where(nid: node_id.to_i) + if node.any? + node.first + end + end + end + end + return nil + end + end diff --git a/config/initializers/twitter_client.rb b/config/initializers/twitter_client.rb new file mode 100644 index 0000000000..9b42285f3b --- /dev/null +++ b/config/initializers/twitter_client.rb @@ -0,0 +1,7 @@ +require 'twitter' +::Client = Twitter::REST::Client.new do |config| + config.consumer_key = ENV["TWITTER_CONSUMER_KEY"] + config.consumer_secret = ENV["TWITTER_CONSUMER_SECRET"] + config.access_token = ENV["TWITTER_ACCESS_TOKEN"] + config.access_token_secret = ENV["TWITTER_ACCESS_TOKEN_SECRET"] +end \ No newline at end of file diff --git a/config/schedule.rb b/config/schedule.rb index c35d37e4f1..260320644a 100644 --- a/config/schedule.rb +++ b/config/schedule.rb @@ -28,10 +28,15 @@ command "date -u" #This will print utc time every 1 min in log/cron_log.log file end -every 1.day do - runner "DigestMailJob.perform_async(0)" +every 1.minutes do + runner "Comment.receive_tweet" end -every 1.week do - runner "DigestMailJob.perform_async(1)" -end \ No newline at end of file + +# every 1.day do +# runner "DigestMailJob.perform_async(0)" +# end + +# every 1.week do +# runner "DigestMailJob.perform_async(1)" +# end diff --git a/db/migrate/20180801125000_add_tweet_column_to_comment.rb b/db/migrate/20180801125000_add_tweet_column_to_comment.rb new file mode 100644 index 0000000000..e2d14bb6de --- /dev/null +++ b/db/migrate/20180801125000_add_tweet_column_to_comment.rb @@ -0,0 +1,5 @@ +class AddSinceColumnToComment < ActiveRecord::Migration[5.2] + def change + add_column :comments, :tweet_id, :string + end +end diff --git a/db/schema.rb.example b/db/schema.rb.example index a550840348..167c08f38b 100644 --- a/db/schema.rb.example +++ b/db/schema.rb.example @@ -11,7 +11,8 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2018_08_04_215454) do + +ActiveRecord::Schema.define(version: 2018_08_01_125000) do create_table "answer_selections", force: true do |t| t.integer "user_id" @@ -51,6 +52,8 @@ ActiveRecord::Schema.define(version: 2018_08_04_215454) do t.integer "aid", default: 0, null: false t.integer "comment_via", limit: 4, default: 0 t.string "message_id", limit: 255 + t.string "tweet_id" + end add_index "comments", ["comment"], name: "index_comments_on_comment", type: :fulltext if ActiveRecord::Base.connection.adapter_name == 'Mysql2' From c2550600b4efe69d3515414695c4335050c82e4d Mon Sep 17 00:00:00 2001 From: Naman Gupta <01namangupta@gmail.com> Date: Thu, 2 Aug 2018 02:44:38 +0530 Subject: [PATCH 02/40] Updated schedule.rb file --- config/application.yml | 2 ++ config/schedule.rb | 12 ++++++------ 2 files changed, 8 insertions(+), 6 deletions(-) create mode 100644 config/application.yml diff --git a/config/application.yml b/config/application.yml new file mode 100644 index 0000000000..544ce3b331 --- /dev/null +++ b/config/application.yml @@ -0,0 +1,2 @@ +OAUTH_TWITTER_APP_KEY: H59J9kJBVQvtZvWhr2SUAht4o +OAUTH_TWITTER_APP_SECRET: GEQOygPITjGj2Imzg5ALJeCqE0GdQU2GAmTYOS9kEPcLVlMxQu \ No newline at end of file diff --git a/config/schedule.rb b/config/schedule.rb index 260320644a..758a264931 100644 --- a/config/schedule.rb +++ b/config/schedule.rb @@ -33,10 +33,10 @@ end -# every 1.day do -# runner "DigestMailJob.perform_async(0)" -# end +every 1.day do + runner "DigestMailJob.perform_async(0)" +end -# every 1.week do -# runner "DigestMailJob.perform_async(1)" -# end +every 1.week do + runner "DigestMailJob.perform_async(1)" +end From 9c4a9d501f1f8ac182b6f4a9bb65f416a5297b64 Mon Sep 17 00:00:00 2001 From: Naman Gupta <01namangupta@gmail.com> Date: Fri, 3 Aug 2018 03:01:32 +0530 Subject: [PATCH 03/40] Finalized reply-by-tweet --- app/models/comment.rb | 36 +++++++++++++++++++++++------------- app/models/node.rb | 3 ++- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/app/models/comment.rb b/app/models/comment.rb index 1ca20226f7..5a7661ee83 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -333,7 +333,7 @@ def trimmed_content? end def self.receive_tweet - comments = Comment.where.not(since: nil) + comments = Comment.where.not(tweet_id: nil) if comments.any? receive_tweet_using_since comments else @@ -344,17 +344,19 @@ def self.receive_tweet def self.receive_tweet_using_since comments comment = comments.last since_id = comment.tweet_id - tweets = Client.search("to:publiclab", since: since_id).collect do |tweet| + tweets = Client.search("to:PublicLab", since_id: since_id).collect do |tweet| tweet end + tweets = tweets.reverse check_and_add_tweets tweets end def self.receive_tweet_without_using_since - tweets = Client.search("to:publiclab").collect do |tweet| + tweets = Client.search("to:PublicLab").collect do |tweet| tweet end + tweets = tweets.reverse check_and_add_tweets tweets end @@ -367,17 +369,17 @@ def self.check_and_add_tweets tweets urls = URI.extract(parent_tweet_full_text) node = get_node_from_urls_present(urls) unless node.nil? - twitter_user_id = tweet.user - twitter_email = Client.user(twitter_user_id).email - users = User.where(email: twitter_email) + twitter_user_name = tweet.user.screen_name + tweet_email = find_email(twitter_user_name) + users = User.where(email: tweet_email) if users.any? user = users.first replied_tweet_text = tweet.text if tweet.truncated? - replied_tweet_text = Client.status(tweet.id, tweet_mode: "extended") - replied_tweet_full_text = replied_tweet_text.attrs[:text] || replied_tweet_text.attrs[:full_text] + replied_tweet = Client.status(tweet.id, tweet_mode: "extended") + replied_tweet_text = replied_tweet.attrs[:text] || replied_tweet.attrs[:full_text] end - comment = node.add_comment(uid: user.uid, body: replied_tweet_full_text, comment_via: 2, twitter_id: tweet.id) + comment = node.add_comment(uid: user.uid, body: replied_tweet_text, comment_via: 2, tweet_id: tweet.id) comment.notify user end end @@ -387,13 +389,12 @@ def self.check_and_add_tweets tweets def self.get_node_from_urls_present(urls) urls.each do |url| - response = Net::HTTP.get_response(URI(url)) # Get redirected link from twitter link shortner - if response['location'].include? ("://publiclab.org/n/") - node_id = t['location'].split("/")[-1] + if url.include? ("://publiclab.org/n/") + node_id = url.split("/")[-1] if node_id != nil node = Node.where(nid: node_id.to_i) if node.any? - node.first + return node.first end end end @@ -401,4 +402,13 @@ def self.get_node_from_urls_present(urls) return nil end + def self.find_email (twitter_user_name) + UserTag.all.each do |user_tag| + data = user_tag["data"] + if data["info"]["nickname"].to_s == twitter_user_name + return data["info"]["email"] + end + end + end + end diff --git a/app/models/node.rb b/app/models/node.rb index cc0bd2367a..7dd4c1f845 100644 --- a/app/models/node.rb +++ b/app/models/node.rb @@ -583,7 +583,8 @@ def add_comment(params = {}) thread: thread, timestamp: DateTime.now.to_i, comment_via: comment_via_status, - message_id: params[:message_id]) + message_id: params[:message_id], + tweet_id: params[:tweet_id]) c.save c end From 192db2523e62205ca1d9c84597b19abae3828d8b Mon Sep 17 00:00:00 2001 From: Naman Gupta <01namangupta@gmail.com> Date: Fri, 3 Aug 2018 03:52:53 +0530 Subject: [PATCH 04/40] Corrected schema version --- db/schema.rb.example | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/schema.rb.example b/db/schema.rb.example index 167c08f38b..d6fd4ff128 100644 --- a/db/schema.rb.example +++ b/db/schema.rb.example @@ -12,7 +12,7 @@ # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2018_08_01_125000) do +ActiveRecord::Schema.define(version: 2018_08_02_114514) do create_table "answer_selections", force: true do |t| t.integer "user_id" From d835e932d3e135d3a2e2eb81811c043635d1da24 Mon Sep 17 00:00:00 2001 From: Naman Gupta <01namangupta@gmail.com> Date: Fri, 3 Aug 2018 03:54:17 +0530 Subject: [PATCH 05/40] Minor change --- config/application.yml | 2 -- 1 file changed, 2 deletions(-) delete mode 100644 config/application.yml diff --git a/config/application.yml b/config/application.yml deleted file mode 100644 index 544ce3b331..0000000000 --- a/config/application.yml +++ /dev/null @@ -1,2 +0,0 @@ -OAUTH_TWITTER_APP_KEY: H59J9kJBVQvtZvWhr2SUAht4o -OAUTH_TWITTER_APP_SECRET: GEQOygPITjGj2Imzg5ALJeCqE0GdQU2GAmTYOS9kEPcLVlMxQu \ No newline at end of file From e5415f29d401905cb5c10be691b2b23c286ca2da Mon Sep 17 00:00:00 2001 From: Naman Gupta <01namangupta@gmail.com> Date: Sat, 4 Aug 2018 23:47:03 +0530 Subject: [PATCH 06/40] Added reply_by_tweet doc --- doc/reply_by_tweet.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 doc/reply_by_tweet.md diff --git a/doc/reply_by_tweet.md b/doc/reply_by_tweet.md new file mode 100644 index 0000000000..051768aff3 --- /dev/null +++ b/doc/reply_by_tweet.md @@ -0,0 +1,21 @@ +##Reply By Tweet + +- We are using [twitter gem](https://github.com/sferik/twitter "twitter gem") which implements twitter apis and gives functions to easily implement twitter apis. + +###Steps: + +- Cron job for polling for getting new tweets to `publiclab` is defined in [config/schedule.rb](https://github.com/publiclab/plots2/blob/master/config/schedule.rb "config/schedule.rb") using whenever gem which will call `receive_tweet` function of [models/comment.rb](https://github.com/publiclab/plots2/blob/master/app/models/comment.rb "models/comment.rb") in the interval of one minute. + +- `receive_tweet` method of [models/comment.rb](https://github.com/publiclab/plots2/blob/master/app/models/comment.rb "models/comment.rb") will look for if there is any comment already present that contains tweet_id if it does it will call `receive_tweet_using_since` otherwise it will call `receive_tweet_without_using_since `. + +- `receive_tweet_using_since` will search for the tweets to the `publiclab` which are tweeted after that tweet with the `tweet_id` present in the database. + +- After that check if that tweet is the reply of some other tweet. If it does then find the parent tweet otherwise ignore this tweet and check next tweets untill tweets end. + +- After finding parent tweet, search for the links present in the tweets in the form of `https://publiclab.org/n/_____` and find the the node_id present in `https://publiclab.org/n/node_id` if there is any node present in the database with this node_id then search for the user's email who did the tweet using the username and email data present in the hash form in the `data` column otherwise ignore this tweet. + +- If that twitter username is present in the `user_tags` column then add the tweet otherwise ignore the current tweet. + +- Same process is with when there are no comment present with tweet_id in the comment table where we search for all the replied tweets to the `publiclab`. + + From 20f02d97eaa52e8519b7ae50689ad8df90639a63 Mon Sep 17 00:00:00 2001 From: Naman Gupta <01namangupta@gmail.com> Date: Sun, 5 Aug 2018 00:03:46 +0530 Subject: [PATCH 07/40] Minor changes --- app/models/comment.rb | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/app/models/comment.rb b/app/models/comment.rb index 5a7661ee83..18df878932 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -341,7 +341,7 @@ def self.receive_tweet end end - def self.receive_tweet_using_since comments + def self.receive_tweet_using_since(comments) comment = comments.last since_id = comment.tweet_id tweets = Client.search("to:PublicLab", since_id: since_id).collect do |tweet| @@ -351,7 +351,6 @@ def self.receive_tweet_using_since comments check_and_add_tweets tweets end - def self.receive_tweet_without_using_since tweets = Client.search("to:PublicLab").collect do |tweet| tweet @@ -360,13 +359,13 @@ def self.receive_tweet_without_using_since check_and_add_tweets tweets end - def self.check_and_add_tweets tweets + def self.check_and_add_tweets(tweets) tweets.each do |tweet| if tweet.reply? in_reply_to_tweet_id = tweet.in_reply_to_tweet_id parent_tweet = Client.status(in_reply_to_tweet_id, tweet_mode: "extended") parent_tweet_full_text = parent_tweet.attrs[:text] || parent_tweet.attrs[:full_text] - urls = URI.extract(parent_tweet_full_text) + urls = URI.extract(parent_tweet_full_text) node = get_node_from_urls_present(urls) unless node.nil? twitter_user_name = tweet.user.screen_name @@ -389,9 +388,9 @@ def self.check_and_add_tweets tweets def self.get_node_from_urls_present(urls) urls.each do |url| - if url.include? ("://publiclab.org/n/") + if url.include? "://publiclab.org/n/" node_id = url.split("/")[-1] - if node_id != nil + if !node_id.nil? node = Node.where(nid: node_id.to_i) if node.any? return node.first @@ -402,7 +401,7 @@ def self.get_node_from_urls_present(urls) return nil end - def self.find_email (twitter_user_name) + def self.find_email(twitter_user_name) UserTag.all.each do |user_tag| data = user_tag["data"] if data["info"]["nickname"].to_s == twitter_user_name @@ -410,5 +409,4 @@ def self.find_email (twitter_user_name) end end end - end From 4be39a4d74ea5065d88038ff20d807b722d431a2 Mon Sep 17 00:00:00 2001 From: Naman Gupta <01namangupta@gmail.com> Date: Sun, 5 Aug 2018 00:23:07 +0530 Subject: [PATCH 08/40] Added twitter gem --- Gemfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Gemfile b/Gemfile index bc913763af..e41dcae877 100644 --- a/Gemfile +++ b/Gemfile @@ -68,6 +68,8 @@ gem 'mailman', require: false # To convert html to markdown gem 'reverse_markdown' +gem 'twitter' + # run with `bundle install --without production` or `bundle install --without mysql` to exclude this group :mysql, :production do gem 'mysql2', '>= 0.4.4' From 245c4be1cc6015d1f555ae8dd057d0e67217e732 Mon Sep 17 00:00:00 2001 From: Naman Gupta <01namangupta@gmail.com> Date: Tue, 7 Aug 2018 16:18:29 +0530 Subject: [PATCH 09/40] Minor changes --- app/models/comment.rb | 6 +++--- doc/reply_by_tweet.md | 7 +++++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/app/models/comment.rb b/app/models/comment.rb index 18df878932..f10d60bfdd 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -344,7 +344,7 @@ def self.receive_tweet def self.receive_tweet_using_since(comments) comment = comments.last since_id = comment.tweet_id - tweets = Client.search("to:PublicLab", since_id: since_id).collect do |tweet| + tweets = Client.search(ENV["TWEET_SEARCH"], since_id: since_id).collect do |tweet| tweet end tweets = tweets.reverse @@ -352,7 +352,7 @@ def self.receive_tweet_using_since(comments) end def self.receive_tweet_without_using_since - tweets = Client.search("to:PublicLab").collect do |tweet| + tweets = Client.search(ENV["TWEET_SEARCH"]).collect do |tweet| tweet end tweets = tweets.reverse @@ -388,7 +388,7 @@ def self.check_and_add_tweets(tweets) def self.get_node_from_urls_present(urls) urls.each do |url| - if url.include? "://publiclab.org/n/" + if url.include? ENV["WEBSITE_HOST_PATTERN"] node_id = url.split("/")[-1] if !node_id.nil? node = Node.where(nid: node_id.to_i) diff --git a/doc/reply_by_tweet.md b/doc/reply_by_tweet.md index 051768aff3..6eab1cf09e 100644 --- a/doc/reply_by_tweet.md +++ b/doc/reply_by_tweet.md @@ -1,8 +1,8 @@ -##Reply By Tweet +## Reply By Tweet - We are using [twitter gem](https://github.com/sferik/twitter "twitter gem") which implements twitter apis and gives functions to easily implement twitter apis. -###Steps: +### Steps: - Cron job for polling for getting new tweets to `publiclab` is defined in [config/schedule.rb](https://github.com/publiclab/plots2/blob/master/config/schedule.rb "config/schedule.rb") using whenever gem which will call `receive_tweet` function of [models/comment.rb](https://github.com/publiclab/plots2/blob/master/app/models/comment.rb "models/comment.rb") in the interval of one minute. @@ -18,4 +18,7 @@ - Same process is with when there are no comment present with tweet_id in the comment table where we search for all the replied tweets to the `publiclab`. +- Set environment varible `TWEET_SEARCH` to `to:PublicLab` and `WEBSITE_HOST_PATTERN` to `://publiclab.org/n/` + + From f65eb9a24e9bb2342f034572f071bdba38730fa7 Mon Sep 17 00:00:00 2001 From: Naman Gupta <01namangupta@gmail.com> Date: Tue, 7 Aug 2018 20:33:00 +0530 Subject: [PATCH 10/40] Added Environment variables in Docker --- containers/docker-compose-production.yml | 6 ++++++ containers/docker-compose-stable.yml | 6 ++++++ containers/docker-compose-unstable.yml | 6 ++++++ 3 files changed, 18 insertions(+) diff --git a/containers/docker-compose-production.yml b/containers/docker-compose-production.yml index 4185519efb..85226c8cae 100644 --- a/containers/docker-compose-production.yml +++ b/containers/docker-compose-production.yml @@ -37,6 +37,12 @@ services: - OAUTH_FACEBOOK_APP_KEY=${OAUTH_FACEBOOK_APP_KEY} - OAUTH_FACEBOOK_APP_SECRET=${OAUTH_FACEBOOK_APP_SECRET} - REDIS_URL=redis://redis:6379/0 + - TWITTER_CONSUMER_KEY=${TWITTER_CONSUMER_KEY} + - TWITTER_CONSUMER_SECRET=${TWITTER_CONSUMER_SECRET} + - TWITTER_ACCESS_TOKEN=${TWITTER_ACCESS_TOKEN} + - TWITTER_ACCESS_TOKEN_SECRET=${TWITTER_ACCESS_TOKEN_SECRET} + - WEBSITE_HOST_PATTERN=${WEBSITE_HOST_PATTERN} + - TWEET_SEARCH=${TWEET_SEARCH} volumes: - ..:/app - /etc/passwd:/etc/passwd:ro diff --git a/containers/docker-compose-stable.yml b/containers/docker-compose-stable.yml index 30316e9b38..4bd1aa2685 100644 --- a/containers/docker-compose-stable.yml +++ b/containers/docker-compose-stable.yml @@ -37,6 +37,12 @@ services: - OAUTH_FACEBOOK_APP_KEY=${OAUTH_FACEBOOK_APP_KEY} - OAUTH_FACEBOOK_APP_SECRET=${OAUTH_FACEBOOK_APP_SECRET} - REDIS_URL=redis://redis:6379/0 + - TWITTER_CONSUMER_KEY=${TWITTER_CONSUMER_KEY} + - TWITTER_CONSUMER_SECRET=${TWITTER_CONSUMER_SECRET} + - TWITTER_ACCESS_TOKEN=${TWITTER_ACCESS_TOKEN} + - TWITTER_ACCESS_TOKEN_SECRET=${TWITTER_ACCESS_TOKEN_SECRET} + - WEBSITE_HOST_PATTERN=${WEBSITE_HOST_PATTERN} + - TWEET_SEARCH=${TWEET_SEARCH} volumes: - ..:/app - /etc/passwd:/etc/passwd:ro diff --git a/containers/docker-compose-unstable.yml b/containers/docker-compose-unstable.yml index 618a3d8231..b58a211748 100644 --- a/containers/docker-compose-unstable.yml +++ b/containers/docker-compose-unstable.yml @@ -37,6 +37,12 @@ services: - OAUTH_FACEBOOK_APP_KEY=${OAUTH_FACEBOOK_APP_KEY} - OAUTH_FACEBOOK_APP_SECRET=${OAUTH_FACEBOOK_APP_SECRET} - REDIS_URL=redis://redis:6379/0 + - TWITTER_CONSUMER_KEY=${TWITTER_CONSUMER_KEY} + - TWITTER_CONSUMER_SECRET=${TWITTER_CONSUMER_SECRET} + - TWITTER_ACCESS_TOKEN=${TWITTER_ACCESS_TOKEN} + - TWITTER_ACCESS_TOKEN_SECRET=${TWITTER_ACCESS_TOKEN_SECRET} + - WEBSITE_HOST_PATTERN=${WEBSITE_HOST_PATTERN} + - TWEET_SEARCH=${TWEET_SEARCH} volumes: - ..:/app - /etc/passwd:/etc/passwd:ro From 09582ed7ed0e3f90ceaaa9a8103049ffc547b287 Mon Sep 17 00:00:00 2001 From: Naman Gupta <01namangupta@gmail.com> Date: Wed, 8 Aug 2018 19:57:38 +0530 Subject: [PATCH 11/40] Added summery in Doc file --- doc/reply_by_tweet.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/reply_by_tweet.md b/doc/reply_by_tweet.md index 6eab1cf09e..8d1abde713 100644 --- a/doc/reply_by_tweet.md +++ b/doc/reply_by_tweet.md @@ -20,5 +20,7 @@ - Set environment varible `TWEET_SEARCH` to `to:PublicLab` and `WEBSITE_HOST_PATTERN` to `://publiclab.org/n/` +### Summery +Once a minute, this system scans tweets "to:PublicLab" (or specified search, see below) for URLs matching our shortlink pattern, i.e. "https://publiclab.org/n/_____", where "_____" is a node nid. Each of the returned tweets is added as a comment to the node it responded to. From 55af02e661eea8151d5b5ae7b33e68554b2ee000 Mon Sep 17 00:00:00 2001 From: Naman Gupta <01namangupta@gmail.com> Date: Wed, 8 Aug 2018 20:20:59 +0530 Subject: [PATCH 12/40] Corrected schema version --- db/schema.rb.example | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/schema.rb.example b/db/schema.rb.example index d6fd4ff128..e11d7198d4 100644 --- a/db/schema.rb.example +++ b/db/schema.rb.example @@ -12,7 +12,7 @@ # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2018_08_02_114514) do +ActiveRecord::Schema.define(version: 2018_08_04_215454) do create_table "answer_selections", force: true do |t| t.integer "user_id" From b960952f43642f75d3b2acd5e9c526e4480e2ae0 Mon Sep 17 00:00:00 2001 From: Naman Gupta <01namangupta@gmail.com> Date: Thu, 9 Aug 2018 02:11:34 +0530 Subject: [PATCH 13/40] Added some documentation --- doc/reply_by_tweet.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/doc/reply_by_tweet.md b/doc/reply_by_tweet.md index 8d1abde713..3dfc5ae07b 100644 --- a/doc/reply_by_tweet.md +++ b/doc/reply_by_tweet.md @@ -20,6 +20,13 @@ - Set environment varible `TWEET_SEARCH` to `to:PublicLab` and `WEBSITE_HOST_PATTERN` to `://publiclab.org/n/` +To use this feature we have to set some environment variables which includes Twitter Api keys and Searching Query: + +For getting Twitter Keys go to [Twitter app keys](https://apps.twitter.com/) +Environment varible used for twitter keys are : `TWITTER_CONSUMER_KEY`, `TWITTER_CONSUMER_SECRET`, `TWITTER_ACCESS_TOKEN` and `TWITTER_ACCESS_TOKEN_SECRET`. + +Other Environment variable used are : `WEBSITE_HOST_PATTERN` which can be like `//publiclab.org/n/` and `TWEET_SEARCH` which is used to search for the twwets and can be like `to:publiclab`. + ### Summery Once a minute, this system scans tweets "to:PublicLab" (or specified search, see below) for URLs matching our shortlink pattern, i.e. "https://publiclab.org/n/_____", where "_____" is a node nid. Each of the returned tweets is added as a comment to the node it responded to. From f5a680da90ad14b0fb80600a649ee0e9e89457bd Mon Sep 17 00:00:00 2001 From: Naman Gupta <01namangupta@gmail.com> Date: Thu, 9 Aug 2018 02:15:29 +0530 Subject: [PATCH 14/40] Added some documentation --- doc/reply_by_tweet.md | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/doc/reply_by_tweet.md b/doc/reply_by_tweet.md index 3dfc5ae07b..2e65b7d973 100644 --- a/doc/reply_by_tweet.md +++ b/doc/reply_by_tweet.md @@ -18,14 +18,10 @@ - Same process is with when there are no comment present with tweet_id in the comment table where we search for all the replied tweets to the `publiclab`. -- Set environment varible `TWEET_SEARCH` to `to:PublicLab` and `WEBSITE_HOST_PATTERN` to `://publiclab.org/n/` - -To use this feature we have to set some environment variables which includes Twitter Api keys and Searching Query: - -For getting Twitter Keys go to [Twitter app keys](https://apps.twitter.com/) +To use this feature we have to set some environment variables which includes Twitter Api keys and Searching Query: For getting Twitter Keys go to [Twitter app keys](https://apps.twitter.com/) Environment varible used for twitter keys are : `TWITTER_CONSUMER_KEY`, `TWITTER_CONSUMER_SECRET`, `TWITTER_ACCESS_TOKEN` and `TWITTER_ACCESS_TOKEN_SECRET`. -Other Environment variable used are : `WEBSITE_HOST_PATTERN` which can be like `//publiclab.org/n/` and `TWEET_SEARCH` which is used to search for the twwets and can be like `to:publiclab`. +Other Environment variable used are : `WEBSITE_HOST_PATTERN` which can be like `//publiclab.org/n/` and `TWEET_SEARCH` which is used to search for the tweets and can be like `to:publiclab`. ### Summery From 712d7f2bc49c9e28f76ce7ffc106abf13133be9a Mon Sep 17 00:00:00 2001 From: Naman Gupta <01namangupta@gmail.com> Date: Thu, 9 Aug 2018 11:13:08 +0530 Subject: [PATCH 15/40] Migration timestamp changed --- ...comment.rb => 20180809125000_add_tweet_column_to_comment.rb} | 0 db/schema.rb.example | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename db/migrate/{20180801125000_add_tweet_column_to_comment.rb => 20180809125000_add_tweet_column_to_comment.rb} (100%) diff --git a/db/migrate/20180801125000_add_tweet_column_to_comment.rb b/db/migrate/20180809125000_add_tweet_column_to_comment.rb similarity index 100% rename from db/migrate/20180801125000_add_tweet_column_to_comment.rb rename to db/migrate/20180809125000_add_tweet_column_to_comment.rb diff --git a/db/schema.rb.example b/db/schema.rb.example index e11d7198d4..963b9149c1 100644 --- a/db/schema.rb.example +++ b/db/schema.rb.example @@ -12,7 +12,7 @@ # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2018_08_04_215454) do +ActiveRecord::Schema.define(version: 2018_08_09_125000) do create_table "answer_selections", force: true do |t| t.integer "user_id" From 3ceb0c227de8c9ad0a6f8dbf8450a6610d585d87 Mon Sep 17 00:00:00 2001 From: Naman Gupta <01namangupta@gmail.com> Date: Thu, 9 Aug 2018 11:18:14 +0530 Subject: [PATCH 16/40] Changed migration --- db/migrate/20180809125000_add_tweet_column_to_comment.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/migrate/20180809125000_add_tweet_column_to_comment.rb b/db/migrate/20180809125000_add_tweet_column_to_comment.rb index e2d14bb6de..b4c14a8962 100644 --- a/db/migrate/20180809125000_add_tweet_column_to_comment.rb +++ b/db/migrate/20180809125000_add_tweet_column_to_comment.rb @@ -1,4 +1,4 @@ -class AddSinceColumnToComment < ActiveRecord::Migration[5.2] +class AddTweetColumnToComment < ActiveRecord::Migration[5.2] def change add_column :comments, :tweet_id, :string end From 73ba28c23c89cd8cec54ed7c50d4d79c4e60f655 Mon Sep 17 00:00:00 2001 From: Naman Gupta <01namangupta@gmail.com> Date: Thu, 9 Aug 2018 11:40:04 +0530 Subject: [PATCH 17/40] Minor change --- Gemfile.lock | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index a20f069803..22eaf8c004 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -65,6 +65,7 @@ GEM ice_nine (~> 0.11.0) thread_safe (~> 0.3, >= 0.3.1) bindex (0.5.0) + buftok (0.2.0) builder (3.2.3) byebug (10.0.2) chronic (0.10.2) @@ -147,9 +148,16 @@ GEM grease (0.3.1) hashie (3.5.7) highline (1.7.10) + http (3.3.0) + addressable (~> 2.3) + http-cookie (~> 1.0) + http-form_data (~> 2.0) + http_parser.rb (~> 0.6.0) http-cookie (1.0.3) domain_name (~> 0.5) + http-form_data (2.1.1) http_accept_language (2.1.1) + http_parser.rb (0.6.0) i18n (1.0.1) concurrent-ruby (~> 1.0) i18n-js (3.0.11) @@ -205,6 +213,8 @@ GEM maildir (>= 0.5.0) marcel (0.3.2) mimemagic (~> 0.3.2) + memoizable (0.4.2) + thread_safe (~> 0.3, >= 0.3.1) metaclass (0.0.4) method_source (0.9.0) mime-types (3.1) @@ -228,6 +238,7 @@ GEM mustermann-grape (1.0.0) mustermann (~> 1.0.0) mysql2 (0.5.2) + naught (1.1.0) netrc (0.11.0) nifty-generators (0.4.6) nio4r (2.3.1) @@ -396,11 +407,16 @@ GEM connection_pool (~> 2.2, >= 2.2.0) rack-protection (>= 1.5.0) redis (>= 3.3.5, < 5) + simple_oauth (0.3.1) simplecov (0.16.1) docile (~> 1.1) json (>= 1.8, < 3) simplecov-html (~> 0.10.0) simplecov-html (0.10.2) + skylight (2.0.2) + skylight-core (= 2.0.2) + skylight-core (2.0.2) + activesupport (>= 4.2.0) sprockets (3.7.2) concurrent-ruby (~> 1.0) rack (> 1, < 3) @@ -428,6 +444,17 @@ GEM turbolinks (5.1.1) turbolinks-source (~> 5.1) turbolinks-source (5.1.0) + twitter (6.2.0) + addressable (~> 2.3) + buftok (~> 0.2.0) + equalizer (~> 0.0.11) + http (~> 3.0) + http-form_data (~> 2.0) + http_parser.rb (~> 0.6.0) + memoizable (~> 0.4.0) + multipart-post (~> 2.0) + naught (~> 1.0) + simple_oauth (~> 0.3.0) tzinfo (1.2.5) thread_safe (~> 0.1) uglifier (4.1.15) @@ -532,12 +559,14 @@ DEPENDENCIES sass-rails (~> 5.0, >= 5.0.7) scrypt (~> 3) sidekiq + skylight sqlite3 teaspoon-mocha test-unit therubyracer timecop turbolinks (~> 5) + twitter tzinfo-data uglifier (>= 1.0.3) unicode-emoji @@ -546,8 +575,5 @@ DEPENDENCIES will_paginate (>= 3.0.6) will_paginate-bootstrap (>= 1.0.1) -RUBY VERSION - ruby 2.4.1p111 - BUNDLED WITH 1.16.2 From 73df811450176090407f311211965b8ebff3c30e Mon Sep 17 00:00:00 2001 From: Naman Gupta <01namangupta@gmail.com> Date: Thu, 9 Aug 2018 11:43:07 +0530 Subject: [PATCH 18/40] Minor changes --- Gemfile.lock | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Gemfile.lock b/Gemfile.lock index 22eaf8c004..f207addbdc 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -575,5 +575,8 @@ DEPENDENCIES will_paginate (>= 3.0.6) will_paginate-bootstrap (>= 1.0.1) +RUBY VERSION + ruby 2.4.1p111 + BUNDLED WITH 1.16.2 From 0a4ab125cb386201ff573320d9cb08cbdb73423c Mon Sep 17 00:00:00 2001 From: Naman Gupta <01namangupta@gmail.com> Date: Thu, 9 Aug 2018 12:08:10 +0530 Subject: [PATCH 19/40] Added rake to general gem list --- Gemfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index e41dcae877..5f3b7d8c8a 100644 --- a/Gemfile +++ b/Gemfile @@ -70,6 +70,8 @@ gem 'reverse_markdown' gem 'twitter' +gem 'rake', '~> 12.3.1' + # run with `bundle install --without production` or `bundle install --without mysql` to exclude this group :mysql, :production do gem 'mysql2', '>= 0.4.4' @@ -104,7 +106,6 @@ group :test, :development do gem 'openssl', '~> 2.0.0.beta.1' gem 'phantomjs' gem 'rails-perftest' - gem 'rake', '~> 12.3.1' gem 'rest-client' gem 'rspec' gem 'test-unit' From 9e88993442b1440ea3cd45a2846b865c10cb1399 Mon Sep 17 00:00:00 2001 From: Naman Gupta <01namangupta@gmail.com> Date: Thu, 9 Aug 2018 13:54:10 +0530 Subject: [PATCH 20/40] Added bundle exec for rake/rails tasks in schedule.rb --- config/schedule.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/config/schedule.rb b/config/schedule.rb index 758a264931..0415689442 100644 --- a/config/schedule.rb +++ b/config/schedule.rb @@ -22,6 +22,8 @@ # Cron Job log file set :output, "#{Dir.pwd}/public/cron_log.log" +set :bundle_command, 'bundle exec' + # To simply print date into the log file for checking if cron job is working properly every 1.minutes do puts Dir.pwd From 8073289bda4e7545c81b43b477306aa1f08f44cc Mon Sep 17 00:00:00 2001 From: Naman Gupta <01namangupta@gmail.com> Date: Thu, 9 Aug 2018 20:41:40 +0530 Subject: [PATCH 21/40] Added path env variable --- config/schedule.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/config/schedule.rb b/config/schedule.rb index 0415689442..5de7c68a60 100644 --- a/config/schedule.rb +++ b/config/schedule.rb @@ -24,6 +24,8 @@ set :bundle_command, 'bundle exec' +env :PATH, ENV['PATH'] + # To simply print date into the log file for checking if cron job is working properly every 1.minutes do puts Dir.pwd From 974d62a7b6a9d9bca322d7a69c8a7347330e4e92 Mon Sep 17 00:00:00 2001 From: Naman Gupta <01namangupta@gmail.com> Date: Thu, 9 Aug 2018 22:29:41 +0530 Subject: [PATCH 22/40] MINOR CHANGE --- config/schedule.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/schedule.rb b/config/schedule.rb index 5de7c68a60..9efe632a65 100644 --- a/config/schedule.rb +++ b/config/schedule.rb @@ -20,11 +20,11 @@ # Learn more: http://github.com/javan/whenever # Cron Job log file -set :output, "#{Dir.pwd}/public/cron_log.log" set :bundle_command, 'bundle exec' +job_type :runner, "cd :path && :bundle_command rails runner -e :environment ':task' :output" -env :PATH, ENV['PATH'] +set :output, "#{Dir.pwd}/public/cron_log.log" # To simply print date into the log file for checking if cron job is working properly every 1.minutes do From 6a2a03629d1e5352e0ed0d71960b8645bdaabcf6 Mon Sep 17 00:00:00 2001 From: Naman Gupta <01namangupta@gmail.com> Date: Thu, 9 Aug 2018 23:03:23 +0530 Subject: [PATCH 23/40] MINOR CHANGE --- config/schedule.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/config/schedule.rb b/config/schedule.rb index 9efe632a65..5428c90fa6 100644 --- a/config/schedule.rb +++ b/config/schedule.rb @@ -21,8 +21,10 @@ # Cron Job log file -set :bundle_command, 'bundle exec' -job_type :runner, "cd :path && :bundle_command rails runner -e :environment ':task' :output" +# set :bundle_command, 'bundle exec' +# job_type :runner, "cd :path && :bundle_command rails runner -e :environment ':task' :output" + +ENV.each { |k, v| env(k, v) } set :output, "#{Dir.pwd}/public/cron_log.log" From 0d80b0331fcafd974af62cb9df0fe171380c5103 Mon Sep 17 00:00:00 2001 From: Naman Gupta <01namangupta@gmail.com> Date: Thu, 9 Aug 2018 23:07:37 +0530 Subject: [PATCH 24/40] MINOR CHANGE --- config/schedule.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/schedule.rb b/config/schedule.rb index 5428c90fa6..e8eeecff44 100644 --- a/config/schedule.rb +++ b/config/schedule.rb @@ -21,8 +21,8 @@ # Cron Job log file -# set :bundle_command, 'bundle exec' -# job_type :runner, "cd :path && :bundle_command rails runner -e :environment ':task' :output" +set :bundle_command, 'bundle exec' +job_type :runner, "cd :path && :bundle_command rails runner -e :environment ':task' :output" ENV.each { |k, v| env(k, v) } From 4d7fa41218d93ed6662496156035461c218afdcf Mon Sep 17 00:00:00 2001 From: Naman Gupta <01namangupta@gmail.com> Date: Fri, 10 Aug 2018 00:11:48 +0530 Subject: [PATCH 25/40] MINOR CHANGE --- app/models/comment.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/models/comment.rb b/app/models/comment.rb index f10d60bfdd..ee57f43c8f 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -333,6 +333,7 @@ def trimmed_content? end def self.receive_tweet + puts "i am here" comments = Comment.where.not(tweet_id: nil) if comments.any? receive_tweet_using_since comments @@ -347,6 +348,9 @@ def self.receive_tweet_using_since(comments) tweets = Client.search(ENV["TWEET_SEARCH"], since_id: since_id).collect do |tweet| tweet end + tweets.each do |tweet| + puts tweet.text + end tweets = tweets.reverse check_and_add_tweets tweets end From 4056f4acb811e06bcc77a923097d6e645d59294c Mon Sep 17 00:00:00 2001 From: Naman Gupta <01namangupta@gmail.com> Date: Fri, 10 Aug 2018 00:18:21 +0530 Subject: [PATCH 26/40] Added print statement to check print --- app/models/comment.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/models/comment.rb b/app/models/comment.rb index ee57f43c8f..3f102b0dc8 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -361,6 +361,9 @@ def self.receive_tweet_without_using_since end tweets = tweets.reverse check_and_add_tweets tweets + tweets.each do |tweet| + puts tweet.text + end end def self.check_and_add_tweets(tweets) From c97344343aee73d2544c5c8d2b893323630ffa38 Mon Sep 17 00:00:00 2001 From: Naman Gupta <01namangupta@gmail.com> Date: Fri, 10 Aug 2018 22:20:41 +0530 Subject: [PATCH 27/40] Minor change --- config/schedule.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/schedule.rb b/config/schedule.rb index e8eeecff44..3e382c9878 100644 --- a/config/schedule.rb +++ b/config/schedule.rb @@ -22,7 +22,7 @@ # Cron Job log file set :bundle_command, 'bundle exec' -job_type :runner, "cd :path && :bundle_command rails runner -e :environment ':task' :output" +#job_type :runner, "cd :path && :bundle_command rails runner -e :environment ':task' :output" ENV.each { |k, v| env(k, v) } From f4d07f3096562a36cbac0086b72902aa36da2813 Mon Sep 17 00:00:00 2001 From: Naman Gupta <01namangupta@gmail.com> Date: Fri, 10 Aug 2018 22:29:28 +0530 Subject: [PATCH 28/40] Minor change --- config/schedule.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/schedule.rb b/config/schedule.rb index 3e382c9878..7332a57a2c 100644 --- a/config/schedule.rb +++ b/config/schedule.rb @@ -21,10 +21,10 @@ # Cron Job log file -set :bundle_command, 'bundle exec' +#set :bundle_command, 'bundle exec' #job_type :runner, "cd :path && :bundle_command rails runner -e :environment ':task' :output" -ENV.each { |k, v| env(k, v) } +#ENV.each { |k, v| env(k, v) } set :output, "#{Dir.pwd}/public/cron_log.log" From 8f1b4a3686b5a3a4f6a41f0db72cea2daa1580cc Mon Sep 17 00:00:00 2001 From: Naman Gupta <01namangupta@gmail.com> Date: Sat, 11 Aug 2018 01:29:13 +0530 Subject: [PATCH 29/40] Changed whenever config --- config/schedule.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/config/schedule.rb b/config/schedule.rb index 7332a57a2c..e8eeecff44 100644 --- a/config/schedule.rb +++ b/config/schedule.rb @@ -21,10 +21,10 @@ # Cron Job log file -#set :bundle_command, 'bundle exec' -#job_type :runner, "cd :path && :bundle_command rails runner -e :environment ':task' :output" +set :bundle_command, 'bundle exec' +job_type :runner, "cd :path && :bundle_command rails runner -e :environment ':task' :output" -#ENV.each { |k, v| env(k, v) } +ENV.each { |k, v| env(k, v) } set :output, "#{Dir.pwd}/public/cron_log.log" From c3a68eff12b0d7d60bcaab034a8838dfe88bae80 Mon Sep 17 00:00:00 2001 From: Naman Gupta <01namangupta@gmail.com> Date: Tue, 14 Aug 2018 23:18:00 +0530 Subject: [PATCH 30/40] Minor change --- app/models/comment.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/models/comment.rb b/app/models/comment.rb index 3f102b0dc8..11edfa6453 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -405,6 +405,7 @@ def self.get_node_from_urls_present(urls) end end end + return nil end From 9cd5cbb081c32e9c374ac26811e71e7a408f38cb Mon Sep 17 00:00:00 2001 From: Naman Gupta <01namangupta@gmail.com> Date: Tue, 15 Jan 2019 23:36:24 +0530 Subject: [PATCH 31/40] Completed reply by tweet feature --- app/models/comment.rb | 56 ++++++++++++++++++++++++------------------- 1 file changed, 32 insertions(+), 24 deletions(-) diff --git a/app/models/comment.rb b/app/models/comment.rb index 11edfa6453..eb327e3244 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -333,7 +333,6 @@ def trimmed_content? end def self.receive_tweet - puts "i am here" comments = Comment.where.not(tweet_id: nil) if comments.any? receive_tweet_using_since comments @@ -370,23 +369,25 @@ def self.check_and_add_tweets(tweets) tweets.each do |tweet| if tweet.reply? in_reply_to_tweet_id = tweet.in_reply_to_tweet_id - parent_tweet = Client.status(in_reply_to_tweet_id, tweet_mode: "extended") - parent_tweet_full_text = parent_tweet.attrs[:text] || parent_tweet.attrs[:full_text] - urls = URI.extract(parent_tweet_full_text) - node = get_node_from_urls_present(urls) - unless node.nil? - twitter_user_name = tweet.user.screen_name - tweet_email = find_email(twitter_user_name) - users = User.where(email: tweet_email) - if users.any? - user = users.first - replied_tweet_text = tweet.text - if tweet.truncated? - replied_tweet = Client.status(tweet.id, tweet_mode: "extended") - replied_tweet_text = replied_tweet.attrs[:text] || replied_tweet.attrs[:full_text] + if in_reply_to_tweet_id.class == Fixnum + parent_tweet = Client.status(in_reply_to_tweet_id, tweet_mode: "extended") + parent_tweet_full_text = parent_tweet.attrs[:text] || parent_tweet.attrs[:full_text] + urls = URI.extract(parent_tweet_full_text) + node = get_node_from_urls_present(urls) + unless node.nil? + twitter_user_name = tweet.user.screen_name + tweet_email = find_email(twitter_user_name) + users = User.where(email: tweet_email) + if users.any? + user = users.first + replied_tweet_text = tweet.text + if tweet.truncated? + replied_tweet = Client.status(tweet.id, tweet_mode: "extended") + replied_tweet_text = replied_tweet.attrs[:text] || replied_tweet.attrs[:full_text] + end + comment = node.add_comment(uid: user.uid, body: replied_tweet_text, comment_via: 2, tweet_id: tweet.id) + comment.notify user end - comment = node.add_comment(uid: user.uid, body: replied_tweet_text, comment_via: 2, tweet_id: tweet.id) - comment.notify user end end end @@ -395,17 +396,24 @@ def self.check_and_add_tweets(tweets) def self.get_node_from_urls_present(urls) urls.each do |url| - if url.include? ENV["WEBSITE_HOST_PATTERN"] - node_id = url.split("/")[-1] - if !node_id.nil? - node = Node.where(nid: node_id.to_i) - if node.any? - return node.first + if url.include? "https://" + if url.last == "." + url = url[0...url.length-1] + end + response = Net::HTTP.get_response(URI(url)) + redirected_url = response['location'] + if redirected_url != nil && redirected_url.include?(ENV["WEBSITE_HOST_PATTERN"]) + node_id = redirected_url.split("/")[-1] + if !node_id.nil? + node = Node.where(nid: node_id.to_i) + if node.any? + return node.first + end end end end + end - return nil end From a57097d65fa74be6a15a3247ed2502755aba4673 Mon Sep 17 00:00:00 2001 From: Naman Gupta <01namangupta@gmail.com> Date: Tue, 15 Jan 2019 23:55:04 +0530 Subject: [PATCH 32/40] Minor change --- app/models/comment.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/app/models/comment.rb b/app/models/comment.rb index a23f270981..b455a58a97 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -370,7 +370,6 @@ def trimmed_content? comment.include?(COMMENT_FILTER) end -<<<<<<< HEAD def self.receive_tweet comments = Comment.where.not(tweet_id: nil) if comments.any? From 6eeb4bc2fedf47da26204cc3ae13ed70717a77e7 Mon Sep 17 00:00:00 2001 From: Naman Gupta <01namangupta@gmail.com> Date: Wed, 16 Jan 2019 00:01:56 +0530 Subject: [PATCH 33/40] Minor change --- Gemfile | 2 -- 1 file changed, 2 deletions(-) diff --git a/Gemfile b/Gemfile index b0c1d61ab6..dabdfde7fd 100644 --- a/Gemfile +++ b/Gemfile @@ -72,8 +72,6 @@ gem 'reverse_markdown' gem 'twitter' -gem 'rake', '~> 12.3.1' - # run with `bundle install --without production` or `bundle install --without mysql` to exclude this group :mysql, :production do gem 'mysql2', '>= 0.4.4' From 093d5037649c90627142a727471b8108ab55efb7 Mon Sep 17 00:00:00 2001 From: Naman Gupta <01namangupta@gmail.com> Date: Mon, 21 Jan 2019 21:31:11 +0530 Subject: [PATCH 34/40] Added gemfile.lock --- Gemfile.lock | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index 2ba12776a2..4a31acce53 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -149,10 +149,16 @@ GEM highline (2.0.0) hoe (3.17.0) rake (>= 0.8, < 13.0) + http (3.3.0) + addressable (~> 2.3) + http-cookie (~> 1.0) + http-form_data (~> 2.0) + http_parser.rb (~> 0.6.0) http-cookie (1.0.3) domain_name (~> 0.5) http-form_data (2.1.1) http_accept_language (2.1.1) + http_parser.rb (0.6.0) i18n (1.5.2) concurrent-ruby (~> 1.0) i18n-js (3.2.0) @@ -449,6 +455,17 @@ GEM turbolinks (5.2.0) turbolinks-source (~> 5.2) turbolinks-source (5.2.0) + twitter (6.2.0) + addressable (~> 2.3) + buftok (~> 0.2.0) + equalizer (~> 0.0.11) + http (~> 3.0) + http-form_data (~> 2.0) + http_parser.rb (~> 0.6.0) + memoizable (~> 0.4.0) + multipart-post (~> 2.0) + naught (~> 1.0) + simple_oauth (~> 0.3.0) tzinfo (1.2.5) thread_safe (~> 0.1) uglifier (4.1.20) @@ -573,7 +590,7 @@ DEPENDENCIES will_paginate-bootstrap (>= 1.0.1) RUBY VERSION - ruby 2.4.4p296 + ruby 2.3.1p112 BUNDLED WITH 1.17.1 From 11361848620d39bc2cd24b0eaad5cd257fe152f4 Mon Sep 17 00:00:00 2001 From: Jeffrey Warren Date: Sat, 9 Feb 2019 00:32:01 -0500 Subject: [PATCH 35/40] Update comment.rb --- app/models/comment.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/models/comment.rb b/app/models/comment.rb index b455a58a97..ff78ac9479 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -494,3 +494,4 @@ def render_body end body end +end From 7af11b59ea441346be7a41da5c237d0f09418b28 Mon Sep 17 00:00:00 2001 From: Naman Gupta <01namangupta@gmail.com> Date: Sat, 9 Feb 2019 19:26:14 +0530 Subject: [PATCH 36/40] Added gemfile.lock --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index 346305bfe9..1a4451c248 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -590,7 +590,7 @@ DEPENDENCIES will_paginate-bootstrap (>= 1.0.1) RUBY VERSION - ruby 2.3.1p112 + ruby 2.4.4p296 BUNDLED WITH 1.17.1 From 5ea493cd5e06f951e107b49456ee96dc5a863c05 Mon Sep 17 00:00:00 2001 From: Naman Gupta <01namangupta@gmail.com> Date: Wed, 6 Mar 2019 03:23:42 +0530 Subject: [PATCH 37/40] Minor changes --- app/models/comment.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/models/comment.rb b/app/models/comment.rb index 4f70b50e3f..439b8ce744 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -422,6 +422,8 @@ def self.check_and_add_tweets(tweets) replied_tweet = Client.status(tweet.id, tweet_mode: "extended") replied_tweet_text = replied_tweet.attrs[:text] || replied_tweet.attrs[:full_text] end + replied_tweet_text = replied_tweet_text.gsub(/@(\S+)/){|m| "[#{m}](https://twitter.com/#{m})"} + replied_tweet_text = replied_tweet_text.gsub('@','') comment = node.add_comment(uid: user.uid, body: replied_tweet_text, comment_via: 2, tweet_id: tweet.id) comment.notify user end @@ -457,7 +459,7 @@ def self.get_node_from_urls_present(urls) def self.find_email(twitter_user_name) UserTag.all.each do |user_tag| data = user_tag["data"] - if data["info"]["nickname"].to_s == twitter_user_name + if data != nil && data["info"] != nil && data["info"]["nickname"] && data["info"]["nickname"].to_s == twitter_user_name return data["info"]["email"] end end From 3d07ec2d3116fe619250f4f1c61cb5e69916b95c Mon Sep 17 00:00:00 2001 From: Naman Gupta <01namangupta@gmail.com> Date: Wed, 6 Mar 2019 03:30:04 +0530 Subject: [PATCH 38/40] Minor changes --- app/models/comment.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/comment.rb b/app/models/comment.rb index f7693ca81f..ab032f1e76 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -434,7 +434,7 @@ def self.get_node_from_urls_present(urls) def self.find_email(twitter_user_name) UserTag.all.each do |user_tag| data = user_tag["data"] - if data != nil && data["info"] != nil && data["info"]["nickname"] && data["info"]["nickname"].to_s == twitter_user_name + if data != nil && data["info"] != nil && data["info"]["nickname"] != nil && data["info"]["nickname"].to_s == twitter_user_name return data["info"]["email"] end end From b4a755776b4a2b3a0b33ed7dddc4afad1160fcf5 Mon Sep 17 00:00:00 2001 From: Naman Gupta <01namangupta@gmail.com> Date: Wed, 6 Mar 2019 03:33:59 +0530 Subject: [PATCH 39/40] Minor changes --- db/schema.rb.example | 5 ----- 1 file changed, 5 deletions(-) diff --git a/db/schema.rb.example b/db/schema.rb.example index 9dccd2e7df..c68b4f8211 100644 --- a/db/schema.rb.example +++ b/db/schema.rb.example @@ -11,13 +11,8 @@ # # It's strongly recommended that you check this file into your version control system. -<<<<<<< HEAD - ActiveRecord::Schema.define(version: 2019_01_04_173959) do -======= ActiveRecord::Schema.define(version: 2019_03_01_075323) do ->>>>>>> 960dba001799555d6c2a6f225b7e296ce1e03f00 - create_table "answer_selections", force: true do |t| t.integer "user_id" From f4d965c94de289ef3244bc7eb3d555ef4edcfbe0 Mon Sep 17 00:00:00 2001 From: Naman Gupta <01namangupta@gmail.com> Date: Wed, 6 Mar 2019 03:45:15 +0530 Subject: [PATCH 40/40] Minor changes --- db/schema.rb.example | 1 - 1 file changed, 1 deletion(-) diff --git a/db/schema.rb.example b/db/schema.rb.example index c68b4f8211..ae42681179 100644 --- a/db/schema.rb.example +++ b/db/schema.rb.example @@ -11,7 +11,6 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2019_01_04_173959) do ActiveRecord::Schema.define(version: 2019_03_01_075323) do create_table "answer_selections", force: true do |t|