about summary refs log tree commit diff
path: root/app/models
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2016-11-04 19:12:59 +0100
committerEugen Rochko <eugen@zeonfederated.com>2016-11-04 19:12:59 +0100
commit62292797eccc5bcf47abae9f4daaa2c186660644 (patch)
treefb324996024317abc9605015845f7467508d5d73 /app/models
parent6471a548feadf34d65fb96660f958bf808331c8f (diff)
Adding hashtag model
Diffstat (limited to 'app/models')
-rw-r--r--app/models/account.rb6
-rw-r--r--app/models/status.rb8
-rw-r--r--app/models/tag.rb5
-rw-r--r--app/models/user.rb2
4 files changed, 17 insertions, 4 deletions
diff --git a/app/models/account.rb b/app/models/account.rb
index 0a6ba182b..9999f05dd 100644
--- a/app/models/account.rb
+++ b/app/models/account.rb
@@ -33,12 +33,12 @@ class Account < ApplicationRecord
   has_many :active_relationships,  class_name: 'Follow', foreign_key: 'account_id',        dependent: :destroy
   has_many :passive_relationships, class_name: 'Follow', foreign_key: 'target_account_id', dependent: :destroy
 
-  has_many :following, -> { order('follows.created_at desc') }, through: :active_relationships,  source: :target_account
-  has_many :followers, -> { order('follows.created_at desc') }, through: :passive_relationships, source: :account
+  has_many :following, -> { order('follows.id desc') }, through: :active_relationships,  source: :target_account
+  has_many :followers, -> { order('follows.id desc') }, through: :passive_relationships, source: :account
 
   # Block relationships
   has_many :block_relationships, class_name: 'Block', foreign_key: 'account_id', dependent: :destroy
-  has_many :blocking, -> { order('blocks.created_at desc') }, through: :block_relationships, source: :target_account
+  has_many :blocking, -> { order('blocks.id desc') }, through: :block_relationships, source: :target_account
 
   has_many :media_attachments, dependent: :destroy
 
diff --git a/app/models/status.rb b/app/models/status.rb
index 1cd56c97b..c26e73d71 100644
--- a/app/models/status.rb
+++ b/app/models/status.rb
@@ -77,6 +77,14 @@ class Status < ApplicationRecord
     ids.map { |id| statuses[id].first }
   end
 
+  def reblogged_by(limit)
+    Account.where(id: reblogs.limit(limit).pluck(:account_id)).with_counters
+  end
+
+  def favourited_by(limit)
+    Account.where(id: favourites.limit(limit).pluck(:account_id)).with_counters
+  end
+
   def self.as_home_timeline(account)
     where(account: [account] + account.following).with_includes.with_counters
   end
diff --git a/app/models/tag.rb b/app/models/tag.rb
new file mode 100644
index 000000000..a25785e08
--- /dev/null
+++ b/app/models/tag.rb
@@ -0,0 +1,5 @@
+class Tag < ApplicationRecord
+  HASHTAG_RE = /[?:^|\s|\.|>]#([[:word:]_]+)/i
+
+  validates :name, presence: true, uniqueness: true
+end
diff --git a/app/models/user.rb b/app/models/user.rb
index bd5512a31..de3521989 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -7,7 +7,7 @@ class User < ApplicationRecord
   validates :account, presence: true
 
   scope :prolific, -> { joins('inner join statuses on statuses.account_id = users.account_id').select('users.*, count(statuses.id) as statuses_count').group('users.id').order('statuses_count desc') }
-  scope :recent,   -> { order('created_at desc') }
+  scope :recent,   -> { order('id desc') }
   scope :admins,   -> { where(admin: true) }
 
   has_settings do |s|