about summary refs log tree commit diff
path: root/app/models
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2016-02-22 18:10:30 +0100
committerEugen Rochko <eugen@zeonfederated.com>2016-02-22 18:10:30 +0100
commit1dad72bf13f5e28781a2b2b6654f72624d205576 (patch)
tree27cc73b474b1cce88751a822374431837f24309a /app/models
parent709c6685a90bb819696566cc9e42e587546d72dc (diff)
Fixes and general progress
Diffstat (limited to 'app/models')
-rw-r--r--app/models/account.rb12
-rw-r--r--app/models/follow.rb22
-rw-r--r--app/models/status.rb18
-rw-r--r--app/models/stream_entry.rb31
-rw-r--r--app/models/user.rb2
5 files changed, 68 insertions, 17 deletions
diff --git a/app/models/account.rb b/app/models/account.rb
index 90e8d7610..fac835168 100644
--- a/app/models/account.rb
+++ b/app/models/account.rb
@@ -29,6 +29,18 @@ class Account < ActiveRecord::Base
     self.domain.nil?
   end
 
+  def acct
+    local? ? self.username : "#{self.username}@#{self.domain}"
+  end
+
+  def object_type
+    :person
+  end
+
+  def subscribed?
+    !(self.secret.blank? || self.verify_token.blank?)
+  end
+
   def keypair
     self.private_key.nil? ? OpenSSL::PKey::RSA.new(self.public_key) : OpenSSL::PKey::RSA.new(self.private_key)
   end
diff --git a/app/models/follow.rb b/app/models/follow.rb
index eec01b9ba..203215947 100644
--- a/app/models/follow.rb
+++ b/app/models/follow.rb
@@ -2,6 +2,28 @@ class Follow < ActiveRecord::Base
   belongs_to :account
   belongs_to :target_account, class_name: 'Account'
 
+  validates :account, :target_account, presence: true
+
+  def verb
+    :follow
+  end
+
+  def object_type
+    :person
+  end
+
+  def target
+    self.target_account
+  end
+
+  def content
+    "#{self.account.acct} started following #{self.target_account.acct}"
+  end
+
+  def title
+    content
+  end
+
   after_create do
     self.account.stream_entries.create!(activity: self)
   end
diff --git a/app/models/status.rb b/app/models/status.rb
index d98297643..c0b0ca9d9 100644
--- a/app/models/status.rb
+++ b/app/models/status.rb
@@ -1,6 +1,24 @@
 class Status < ActiveRecord::Base
   belongs_to :account, inverse_of: :statuses
 
+  validates :account, presence: true
+
+  def verb
+    :post
+  end
+
+  def object_type
+    :note
+  end
+
+  def content
+    self.text
+  end
+
+  def title
+    content.truncate(80, omission: "...")
+  end
+
   after_create do
     self.account.stream_entries.create!(activity: self)
   end
diff --git a/app/models/stream_entry.rb b/app/models/stream_entry.rb
index cee151a07..7a182bb5d 100644
--- a/app/models/stream_entry.rb
+++ b/app/models/stream_entry.rb
@@ -2,32 +2,29 @@ class StreamEntry < ActiveRecord::Base
   belongs_to :account, inverse_of: :stream_entries
   belongs_to :activity, polymorphic: true
 
+  validates :account, :activity, presence: true
+
   def object_type
-    case self.activity_type
-    when 'Status'
-      :note
-    when 'Follow'
-      :person
-    end
+    self.activity.object_type
   end
 
   def verb
-    case self.activity_type
-    when 'Status'
-      :post
-    when 'Follow'
-      :follow
-    end
+    self.activity.verb
+  end
+
+  def targeted?
+    [:follow].include? self.verb
   end
 
   def target
-    case self.activity_type
-    when 'Follow'
-      self.activity.target_account
-    end
+    self.activity.target
+  end
+
+  def title
+    self.activity.title
   end
 
   def content
-    self.activity.text if self.activity_type == 'Status'
+    self.activity.content
   end
 end
diff --git a/app/models/user.rb b/app/models/user.rb
index ccfa54e4f..d23f5d608 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -1,3 +1,5 @@
 class User < ActiveRecord::Base
   belongs_to :account, inverse_of: :user
+
+  validates :account, presence: true
 end