Skip to content

Commit

Permalink
Fix: Misskey location, birthday
Browse files Browse the repository at this point in the history
  • Loading branch information
atsu1125 committed Dec 17, 2022
1 parent db8e295 commit 8f0a276
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 3 deletions.
1 change: 1 addition & 0 deletions app/helpers/context_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ module ContextHelper
suspended: { 'toot' => 'http://joinmastodon.org/ns#', 'suspended' => 'toot:suspended' },
is_cat: { 'isCat' => 'as:isCat' },
vcard: { 'vcard' => 'http://www.w3.org/2006/vcard/ns#' },
other_setting: { 'fedibird' => 'http://fedibird.com/ns#', 'otherSetting' => 'fedibird:otherSetting' },
}.freeze

def full_context
Expand Down
9 changes: 9 additions & 0 deletions app/models/account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
# devices_url :string
# suspension_origin :integer
# sensitized_at :datetime
# settings :jsonb default("{}"), not null
#

class Account < ApplicationRecord
Expand Down Expand Up @@ -387,6 +388,14 @@ def synchronization_uri_prefix
@synchronization_uri_prefix ||= "#{uri[URL_PREFIX_RE]}/"
end

def settings
self[:settings].class == String ? {} : self[:settings]
end

def other_settings
settings
end

class Field < ActiveModelSerializers::Model
attributes :name, :value, :verified_at, :account

Expand Down
18 changes: 15 additions & 3 deletions app/serializers/activitypub/actor_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ class ActivityPub::ActorSerializer < ActivityPub::Serializer

context_extensions :manually_approves_followers, :featured, :also_known_as,
:moved_to, :property_value, :identity_proof,
:discoverable, :olm, :suspended
:discoverable, :olm, :suspended,
:vcard, :other_setting

attributes :id, :type, :following, :followers,
:inbox, :outbox, :featured, :featured_tags,
:preferred_username, :name, :summary,
:url, :manually_approves_followers, :is_cat,
:discoverable, :published,
:vcard
:discoverable, :published

has_one :public_key, serializer: ActivityPub::PublicKeySerializer

Expand All @@ -28,6 +28,8 @@ class ActivityPub::ActorSerializer < ActivityPub::Serializer
attribute :bday, key: :'vcard:bday'
attribute :address, key: :'vcard:Address'

has_many :virtual_other_settings, key: :other_setting

class EndpointsSerializer < ActivityPub::Serializer
include RoutingHelper

Expand Down Expand Up @@ -169,6 +171,16 @@ def published
object.created_at.midnight.iso8601
end

def virtual_other_settings
object.other_settings.map do |k, v|
{
type: 'PropertyValue',
name: k,
value: v,
}
end
end

def bday
object.birthday
end
Expand Down
6 changes: 6 additions & 0 deletions app/serializers/rest/account_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ def value

has_many :fields

has_many :other_settings

def id
object.id.to_s
end
Expand Down Expand Up @@ -95,6 +97,10 @@ def fields
object.suspended? ? [] : object.fields
end

def other_settings
object.suspended? ? [] : object.other_settings
end

def suspended
object.suspended?
end
Expand Down
17 changes: 17 additions & 0 deletions db/migrate/20220202115057_add_settings_to_accounts.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
require Rails.root.join('lib', 'mastodon', 'migration_helpers')

class AddSettingsToAccounts < ActiveRecord::Migration[6.1]
include Mastodon::MigrationHelpers

disable_ddl_transaction!

def up
safety_assured { add_column_with_default :accounts, :settings, :jsonb, default: '{}', allow_null: false }
safety_assured { add_index :accounts, :settings, using: 'gin', algorithm: :concurrently, name: :index_accounts_on_settings }
end

def down
remove_index :accounts, name: :index_accounts_on_settings
remove_column :accounts, :settings
end
end
2 changes: 2 additions & 0 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,11 @@
t.string "devices_url"
t.integer "suspension_origin"
t.datetime "sensitized_at"
t.jsonb "settings", default: "{}", null: false
t.index "(((setweight(to_tsvector('simple'::regconfig, (display_name)::text), 'A'::\"char\") || setweight(to_tsvector('simple'::regconfig, (username)::text), 'B'::\"char\")) || setweight(to_tsvector('simple'::regconfig, (COALESCE(domain, ''::character varying))::text), 'C'::\"char\")))", name: "search_index", using: :gin
t.index "lower((username)::text), COALESCE(lower((domain)::text), ''::text)", name: "index_accounts_on_username_and_domain_lower", unique: true
t.index ["moved_to_account_id"], name: "index_accounts_on_moved_to_account_id"
t.index ["settings"], name: "index_accounts_on_settings", using: :gin
t.index ["uri"], name: "index_accounts_on_uri"
t.index ["url"], name: "index_accounts_on_url"
end
Expand Down

0 comments on commit 8f0a276

Please sign in to comment.