Services are in mysql, contact_for and add_contact_to_aspect work again
This commit is contained in:
parent
232de40457
commit
0c67e271df
6 changed files with 35 additions and 17 deletions
|
|
@ -2,19 +2,11 @@
|
||||||
# licensed under the Affero General Public License version 3 or later. See
|
# licensed under the Affero General Public License version 3 or later. See
|
||||||
# the COPYRIGHT file.
|
# the COPYRIGHT file.
|
||||||
|
|
||||||
class Service
|
class Service < ActiveRecord::Base
|
||||||
include MongoMapper::Document
|
|
||||||
include ActionView::Helpers::TextHelper
|
include ActionView::Helpers::TextHelper
|
||||||
|
|
||||||
belongs_to :user
|
belongs_to :user
|
||||||
|
|
||||||
key :provider, String
|
|
||||||
key :uid, String
|
|
||||||
key :access_token, String
|
|
||||||
key :access_secret, String
|
|
||||||
key :nickname, String
|
|
||||||
timestamps!
|
|
||||||
|
|
||||||
def public_message(post, length, url = "")
|
def public_message(post, length, url = "")
|
||||||
url = "" if post.respond_to?(:photos) && post.photos.count == 0
|
url = "" if post.respond_to?(:photos) && post.photos.count == 0
|
||||||
space_for_url = url.blank? ? 0 : (url.length + 1)
|
space_for_url = url.blank? ? 0 : (url.length + 1)
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,7 @@ class User < ActiveRecord::Base
|
||||||
has_many :aspect_memberships, :through => :aspects
|
has_many :aspect_memberships, :through => :aspects
|
||||||
has_many :contacts
|
has_many :contacts
|
||||||
has_many :contact_people, :through => :contacts
|
has_many :contact_people, :through => :contacts
|
||||||
|
has_many :services
|
||||||
# many :visible_people, :in => :visible_person_ids, :class => Person # One of these needs to go
|
# many :visible_people, :in => :visible_person_ids, :class => Person # One of these needs to go
|
||||||
# many :raw_visible_posts, :in => :visible_post_ids, :class => Post
|
# many :raw_visible_posts, :in => :visible_post_ids, :class => Post
|
||||||
|
|
||||||
|
|
@ -88,9 +89,8 @@ class User < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def add_contact_to_aspect(contact, aspect)
|
def add_contact_to_aspect(contact, aspect)
|
||||||
return true if contact.aspect_ids.include?(aspect.id)
|
return true if contact.aspect_memberships.where(:aspect_id => aspect.id).count > 0
|
||||||
contact.aspects << aspect
|
contact.aspect_memberships.create!(:aspect => aspect)
|
||||||
contact.save!
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def delete_person_from_aspect(person_id, aspect_id, opts = {})
|
def delete_person_from_aspect(person_id, aspect_id, opts = {})
|
||||||
|
|
|
||||||
|
|
@ -123,6 +123,18 @@ class CreateSchema < ActiveRecord::Migration
|
||||||
add_index :requests, :recipient_id
|
add_index :requests, :recipient_id
|
||||||
add_index :requests, [:sender_id, :recipient_id], :unique => true
|
add_index :requests, [:sender_id, :recipient_id], :unique => true
|
||||||
|
|
||||||
|
create_table :services do |t|
|
||||||
|
t.string :_type
|
||||||
|
t.integer :user_id
|
||||||
|
t.string :provider
|
||||||
|
t.string :uid
|
||||||
|
t.string :access_token
|
||||||
|
t.string :access_secret
|
||||||
|
t.string :nickname
|
||||||
|
t.timestamps
|
||||||
|
end
|
||||||
|
add_index :services, :user_id
|
||||||
|
|
||||||
create_table :users do |t|
|
create_table :users do |t|
|
||||||
t.string :username
|
t.string :username
|
||||||
t.text :serialized_private_key
|
t.text :serialized_private_key
|
||||||
|
|
|
||||||
14
db/schema.rb
14
db/schema.rb
|
|
@ -157,6 +157,20 @@ ActiveRecord::Schema.define(:version => 0) do
|
||||||
add_index "requests", ["sender_id", "recipient_id"], :name => "index_requests_on_sender_id_and_recipient_id", :unique => true
|
add_index "requests", ["sender_id", "recipient_id"], :name => "index_requests_on_sender_id_and_recipient_id", :unique => true
|
||||||
add_index "requests", ["sender_id"], :name => "index_requests_on_sender_id"
|
add_index "requests", ["sender_id"], :name => "index_requests_on_sender_id"
|
||||||
|
|
||||||
|
create_table "services", :force => true do |t|
|
||||||
|
t.string "_type"
|
||||||
|
t.integer "user_id"
|
||||||
|
t.string "provider"
|
||||||
|
t.string "uid"
|
||||||
|
t.string "access_token"
|
||||||
|
t.string "access_secret"
|
||||||
|
t.string "nickname"
|
||||||
|
t.datetime "created_at"
|
||||||
|
t.datetime "updated_at"
|
||||||
|
end
|
||||||
|
|
||||||
|
add_index "services", ["user_id"], :name => "index_services_on_user_id"
|
||||||
|
|
||||||
create_table "users", :force => true do |t|
|
create_table "users", :force => true do |t|
|
||||||
t.string "username"
|
t.string "username"
|
||||||
t.text "serialized_private_key"
|
t.text "serialized_private_key"
|
||||||
|
|
|
||||||
|
|
@ -42,13 +42,11 @@ module Diaspora
|
||||||
end
|
end
|
||||||
|
|
||||||
def contact_for(person)
|
def contact_for(person)
|
||||||
id = person.id
|
contact_for_person_id(person.id)
|
||||||
contact_for_person_id(id)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def contact_for_person_id(person_id)
|
def contact_for_person_id(person_id)
|
||||||
contacts.first(:person_id => person_id) if person_id
|
Contact.where(:user_id => self.id, :person_id => person_id).first if person_id
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def contacts_not_in_aspect( aspect )
|
def contacts_not_in_aspect( aspect )
|
||||||
|
|
|
||||||
|
|
@ -25,8 +25,10 @@ describe User do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'saves post into visible post ids' do
|
it 'saves post into visible post ids' do
|
||||||
|
pp user.raw_visible_posts
|
||||||
proc {
|
proc {
|
||||||
user.add_to_streams(@post, @aspect_ids)
|
user.add_to_streams(@post, @aspect_ids)
|
||||||
|
pp user.raw_visible_posts
|
||||||
}.should change(user.raw_visible_posts, :count).by(1)
|
}.should change(user.raw_visible_posts, :count).by(1)
|
||||||
user.reload.raw_visible_posts.should include @post
|
user.reload.raw_visible_posts.should include @post
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue