about summary refs log tree commit diff
path: root/app/models
diff options
context:
space:
mode:
authormultiple creatures <dev@multiple-creature.party>2019-08-06 13:55:54 -0500
committermultiple creatures <dev@multiple-creature.party>2019-08-06 13:55:54 -0500
commitda389a664b87bb131435f2ccb904c0754d5d1655 (patch)
tree79f6fe6b29f2c361f1c33aa9a811991892b2f0db /app/models
parent647ac0f86abb49b97c55229b70e9c06e943adc98 (diff)
added ability to link accounts with `account:link:token` + `account:link:add` & switch between them with `i:am`/`we:are` bangtags; remove links with `account:link:del:USERNAME` or `account:link:clear`; list links with `account:link:list`
Diffstat (limited to 'app/models')
-rw-r--r--app/models/linked_user.rb17
-rw-r--r--app/models/status.rb8
-rw-r--r--app/models/user.rb3
3 files changed, 28 insertions, 0 deletions
diff --git a/app/models/linked_user.rb b/app/models/linked_user.rb
new file mode 100644
index 000000000..e049c6f77
--- /dev/null
+++ b/app/models/linked_user.rb
@@ -0,0 +1,17 @@
+# == Schema Information
+#
+# Table name: linked_users
+#
+#  id             :bigint(8)        not null, primary key
+#  user_id        :bigint(8)
+#  target_user_id :bigint(8)
+#  created_at     :datetime         not null
+#  updated_at     :datetime         not null
+#
+
+class LinkedUser < ApplicationRecord
+  belongs_to :user, inverse_of: :linked_users
+  belongs_to :target_user, class_name: 'User'
+
+  validates :user_id, uniqueness: { scope: :target_user_id }
+end
diff --git a/app/models/status.rb b/app/models/status.rb
index a6be93789..9f11e6d5d 100644
--- a/app/models/status.rb
+++ b/app/models/status.rb
@@ -306,6 +306,14 @@ class Status < ApplicationRecord
     update_status_stat!(key => [public_send(key) - 1, 0].max)
   end
 
+  def session=(value)
+    @session = value
+  end
+
+  def session
+    @session || nil
+  end
+
   after_create_commit  :increment_counter_caches
   after_destroy_commit :decrement_counter_caches
 
diff --git a/app/models/user.rb b/app/models/user.rb
index cbe62d189..479392642 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -75,6 +75,9 @@ class User < ApplicationRecord
   has_many :applications, class_name: 'Doorkeeper::Application', as: :owner
   has_many :backups, inverse_of: :user
 
+  has_many :user_links, class_name: 'LinkedUser', foreign_key: :target_user_id, dependent: :destroy, inverse_of: :user
+  has_many :linked_users, through: :user_links, source: :user
+
   has_one :invite_request, class_name: 'UserInviteRequest', inverse_of: :user, dependent: :destroy
   accepts_nested_attributes_for :invite_request, reject_if: ->(attributes) { attributes['text'].blank? }