This new class replaces all existing server side message rendering helpers and is the new global entry point for such needs. All models with relevant fields now expose an instance of MessageRenderer for those. MessageRenderer acts as gateway between the existing processing solutions for markdown, mentions and tags and provides a very flexible interface for all output needs. This makes the API to obtain a message in a certain format clear. As a result of centralizing the processing a lot of duplication is eliminated. Centralizing the message processing also makes it clear where to change its behaviour, add new representations and what options are already available.
56 lines
1.3 KiB
Ruby
56 lines
1.3 KiB
Ruby
# Copyright (c) 2010-2011, Diaspora Inc. This file is
|
|
# licensed under the Affero General Public License version 3 or later. See
|
|
# the COPYRIGHT file.
|
|
|
|
class Service < ActiveRecord::Base
|
|
attr_accessor :provider, :info, :access_level
|
|
|
|
belongs_to :user
|
|
validates_uniqueness_of :uid, :scope => :type
|
|
|
|
def profile_photo_url
|
|
nil
|
|
end
|
|
|
|
def delete_post(post)
|
|
#don't do anything (should be overriden by service extensions)
|
|
end
|
|
|
|
class << self
|
|
|
|
def titles(service_strings)
|
|
service_strings.map {|s| "Services::#{s.titleize}"}
|
|
end
|
|
|
|
def first_from_omniauth( auth_hash )
|
|
@@auth = auth_hash
|
|
where( type: service_type, uid: options[:uid] ).first
|
|
end
|
|
|
|
def initialize_from_omniauth( auth_hash )
|
|
@@auth = auth_hash
|
|
service_type.constantize.new( options )
|
|
end
|
|
|
|
def auth
|
|
@@auth
|
|
end
|
|
|
|
def service_type
|
|
"Services::#{options[:provider].camelize}"
|
|
end
|
|
|
|
def options
|
|
{
|
|
nickname: auth['info']['nickname'],
|
|
access_token: auth['credentials']['token'],
|
|
access_secret: auth['credentials']['secret'],
|
|
uid: auth['uid'],
|
|
provider: auth['provider'],
|
|
info: auth['info']
|
|
}
|
|
end
|
|
|
|
private :auth, :service_type, :options
|
|
end
|
|
end
|