From 31aabeb149cbefa915775d4c58623b731059c3cf Mon Sep 17 00:00:00 2001 From: Rhenium Date: Sun, 17 Nov 2013 11:21:57 +0900 Subject: add in_reply_to support --- app/assets/stylesheets/tweets.css.sass | 3 +++ app/models/tweet.rb | 4 ++++ app/views/tweets/_tweet.html.haml | 2 ++ collector/stream.rb | 1 + db/migrate/20131116225336_add_in_reply_to_column_to_tweet.rb | 6 ++++++ db/schema.rb | 4 +++- 6 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20131116225336_add_in_reply_to_column_to_tweet.rb diff --git a/app/assets/stylesheets/tweets.css.sass b/app/assets/stylesheets/tweets.css.sass index ca26a99..1adb1f7 100644 --- a/app/assets/stylesheets/tweets.css.sass +++ b/app/assets/stylesheets/tweets.css.sass @@ -41,6 +41,9 @@ :font-size 14px .screen_name :font-size 12px + .in_reply_to + :float right + :font-size 12px .text :font-size 18px :line-height 25px diff --git a/app/models/tweet.rb b/app/models/tweet.rb index 0954906..f08ab97 100644 --- a/app/models/tweet.rb +++ b/app/models/tweet.rb @@ -1,6 +1,9 @@ class Tweet < ActiveRecord::Base belongs_to :user + belongs_to :in_reply_to, class_name: "Tweet" + has_many :replies, class_name: "Tweet", foreign_key: "in_reply_to_id" + has_many :favorites, -> { order("favorites.id") }, dependent: :delete_all has_many :retweets, -> { order("retweets.id") }, dependent: :delete_all @@ -83,6 +86,7 @@ class Tweet < ActiveRecord::Base text: msg["text"], source: msg["source"], tweeted_at: Time.parse(msg["tweeted_at"]), + in_reply_to_id: msg["in_reply_to_status_id"], user: u) end logger.debug("Created Tweet: #{msg["id"]}") diff --git a/app/views/tweets/_tweet.html.haml b/app/views/tweets/_tweet.html.haml index e2cd7fe..167d4a7 100644 --- a/app/views/tweets/_tweet.html.haml +++ b/app/views/tweets/_tweet.html.haml @@ -14,6 +14,8 @@ .user %span.name= link_to tweet.user.name, user_path(tweet.user.screen_name) %span.screen_name= link_to tweet.user.screen_name, user_path(tweet.user.screen_name) + - if tweet.in_reply_to + %span.in_reply_to= link_to "in reply to @" + tweet.in_reply_to.user.screen_name, tweet_path(tweet.in_reply_to.id) .text - if authorized_to_show_user?(tweet.user) = simple_format(format_tweet_text(tweet.text)) diff --git a/collector/stream.rb b/collector/stream.rb index e2bcf05..239c9f5 100644 --- a/collector/stream.rb +++ b/collector/stream.rb @@ -140,6 +140,7 @@ module Aclog text: format_text(status), source: format_source(status), tweeted_at: status[:created_at], + in_reply_to_status_id: status[:in_reply_to_status_id], user: conv_user(status[:user])} end diff --git a/db/migrate/20131116225336_add_in_reply_to_column_to_tweet.rb b/db/migrate/20131116225336_add_in_reply_to_column_to_tweet.rb new file mode 100644 index 0000000..489fcf1 --- /dev/null +++ b/db/migrate/20131116225336_add_in_reply_to_column_to_tweet.rb @@ -0,0 +1,6 @@ +class AddInReplyToColumnToTweet < ActiveRecord::Migration + def change + add_column :tweets, :in_reply_to_id, :integer, limit: 8 + add_index :tweets, :in_reply_to_id + end +end diff --git a/db/schema.rb b/db/schema.rb index 014a337..2c7e393 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20131113033645) do +ActiveRecord::Schema.define(version: 20131116225336) do create_table "accounts", force: true do |t| t.integer "user_id", limit: 8, null: false @@ -51,8 +51,10 @@ ActiveRecord::Schema.define(version: 20131113033645) do t.integer "favorites_count", default: 0, null: false t.integer "retweets_count", default: 0, null: false t.integer "reactions_count", default: 0, null: false + t.integer "in_reply_to_id", limit: 8 end + add_index "tweets", ["in_reply_to_id"], name: "index_tweets_on_in_reply_to_id", using: :btree add_index "tweets", ["reactions_count"], name: "index_tweets_on_reactions_count", using: :btree add_index "tweets", ["user_id", "reactions_count"], name: "index_tweets_on_user_id_and_reactions_count", using: :btree -- cgit v1.2.3