Skip to content

Commit

Permalink
Add Misskey location, birthday
Browse files Browse the repository at this point in the history
  • Loading branch information
atsu1125 committed Dec 17, 2022
1 parent 60fb2c6 commit db8e295
Show file tree
Hide file tree
Showing 13 changed files with 112 additions and 5 deletions.
1 change: 1 addition & 0 deletions app/helpers/context_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ module ContextHelper
olm: { 'toot' => 'http://joinmastodon.org/ns#', 'Device' => 'toot:Device', 'Ed25519Signature' => 'toot:Ed25519Signature', 'Ed25519Key' => 'toot:Ed25519Key', 'Curve25519Key' => 'toot:Curve25519Key', 'EncryptedMessage' => 'toot:EncryptedMessage', 'publicKeyBase64' => 'toot:publicKeyBase64', 'deviceId' => 'toot:deviceId', 'claim' => { '@type' => '@id', '@id' => 'toot:claim' }, 'fingerprintKey' => { '@type' => '@id', '@id' => 'toot:fingerprintKey' }, 'identityKey' => { '@type' => '@id', '@id' => 'toot:identityKey' }, 'devices' => { '@type' => '@id', '@id' => 'toot:devices' }, 'messageFranking' => 'toot:messageFranking', 'messageType' => 'toot:messageType', 'cipherText' => 'toot:cipherText' },
suspended: { 'toot' => 'http://joinmastodon.org/ns#', 'suspended' => 'toot:suspended' },
is_cat: { 'isCat' => 'as:isCat' },
vcard: { 'vcard' => 'http://www.w3.org/2006/vcard/ns#' },
}.freeze

def full_context
Expand Down
1 change: 1 addition & 0 deletions app/javascript/flavours/glitch/locales/en.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import inherited from 'mastodon/locales/en.json';

const messages = {
'account.joined': 'Joined {date}',
'getting_started.open_source_notice': 'Glitchsoc is free open source software forked from {Mastodon}. You can contribute or report issues on GitHub at {github}.',
'layout.auto': 'Auto',
'layout.current_is': 'Your current layout is:',
Expand Down
1 change: 1 addition & 0 deletions app/javascript/flavours/glitch/locales/ja.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import inherited from 'mastodon/locales/ja.json';

const messages = {
'account.joined': '{date} に登録',
'getting_started.open_source_notice': 'Glitchsocは{Mastodon}によるフリーなオープンソースソフトウェアです。誰でもGitHub({github})から開発に參加したり、問題を報告したりできます。',
'layout.auto': '自動',
'layout.current_is': 'あなたの現在のレイアウト:',
Expand Down
26 changes: 24 additions & 2 deletions app/javascript/mastodon/features/account/components/header.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import ImmutablePropTypes from 'react-immutable-proptypes';
import PropTypes from 'prop-types';
import { defineMessages, injectIntl, FormattedMessage } from 'react-intl';
import { defineMessages, injectIntl, FormattedMessage, FormattedDate } from 'react-intl';
import Button from 'mastodon/components/button';
import ImmutablePureComponent from 'react-immutable-pure-component';
import { autoPlayGif, me, isStaff, disableBlock, disableDomainBlock } from 'mastodon/initial_state';
Expand All @@ -14,6 +14,7 @@ import ShortNumber from 'mastodon/components/short_number';
import { NavLink } from 'react-router-dom';
import DropdownMenuContainer from 'mastodon/containers/dropdown_menu_container';
import AccountNoteContainer from '../containers/account_note_container';
import age from 's-age';

const messages = defineMessages({
unfollow: { id: 'account.unfollow', defaultMessage: 'Unfollow' },
Expand Down Expand Up @@ -271,6 +272,10 @@ class Header extends ImmutablePureComponent {
badge = null;
}

const location = account.getIn(['other_settings', 'location']);
const birthday = account.getIn(['other_settings', 'birthday']);
const joined = account.get('created_at');

return (
<div className={classNames('account__header', { inactive: !!account.get('moved') })} onMouseEnter={this.handleMouseEnter} onMouseLeave={this.handleMouseLeave}>
<div className='account__header__image'>
Expand Down Expand Up @@ -338,7 +343,24 @@ class Header extends ImmutablePureComponent {

{account.get('note').length > 0 && account.get('note') !== '<p></p>' && <div className='account__header__content translate' dangerouslySetInnerHTML={content} />}

<div className='account__header__joined'><FormattedMessage id='account.joined' defaultMessage='Joined {date}' values={{ date: intl.formatDate(account.get('created_at'), { year: 'numeric', month: 'short', day: '2-digit' }) }} /></div>
<div className='account__header__personal--wrapper'>
<table className='account__header__personal'>
<tbody>
{location && <tr>
<th><Icon id='map-marker' fixedWidth aria-hidden='true' /> <FormattedMessage id='account.location' defaultMessage='Location' /></th>
<td>{location}</td>
</tr>}
{birthday && <tr>
<th><Icon id='birthday-cake' fixedWidth aria-hidden='true' /> <FormattedMessage id='account.birthday' defaultMessage='Birthday' /></th>
<td><FormattedDate value={birthday} hour12={false} year='numeric' month='short' day='2-digit' />(<FormattedMessage id='account.age' defaultMessage='{age} years old}' values={{age: age(birthday)}} />)</td>
</tr>}
<tr>
<th><Icon id='calendar' fixedWidth aria-hidden='true' /> <FormattedMessage id='account.joined' defaultMessage='Joined' /></th>
<td><FormattedDate value={joined} hour12={false} year='numeric' month='short' day='2-digit' /></td>
</tr>
</tbody>
</table>
</div>
</div>

{!suspended && (
Expand Down
5 changes: 4 additions & 1 deletion app/javascript/mastodon/locales/en.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
{
"account.account_note_header": "Note",
"account.add_or_remove_from_list": "Add or Remove from lists",
"account.age": "{age} years old",
"account.badges.bot": "Bot",
"account.badges.cat": "Cat",
"account.badges.group": "Group",
"account.birthday": "Birthday",
"account.block": "Block @{name}",
"account.block_domain": "Block domain {domain}",
"account.blocked": "Blocked",
Expand All @@ -23,9 +25,10 @@
"account.follows.empty": "This user doesn't follow anyone yet.",
"account.follows_you": "Follows you",
"account.hide_reblogs": "Hide boosts from @{name}",
"account.joined": "Joined {date}",
"account.joined": "Joined",
"account.last_status": "Last active",
"account.link_verified_on": "Ownership of this link was checked on {date}",
"account.location": "Location",
"account.locked_info": "This account privacy status is set to locked. The owner manually reviews who can follow them.",
"account.media": "Media",
"account.mention": "Mention @{name}",
Expand Down
5 changes: 4 additions & 1 deletion app/javascript/mastodon/locales/ja.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
{
"account.account_note_header": "メモ",
"account.add_or_remove_from_list": "リストから追加または外す",
"account.age": "{age}歳",
"account.badges.bot": "Bot",
"account.badges.group": "Group",
"account.birthday": "誕生日",
"account.block": "@{name}さんをブロック",
"account.block_domain": "{domain}全体をブロック",
"account.blocked": "ブロック済み",
Expand All @@ -22,9 +24,10 @@
"account.follows.empty": "まだ誰もフォローしていません。",
"account.follows_you": "フォローされています",
"account.hide_reblogs": "@{name}さんからのブーストを非表示",
"account.joined": "{date} に登録",
"account.joined": "登録日",
"account.last_status": "最後の活動",
"account.link_verified_on": "このリンクの所有権は{date}に確認されました",
"account.location": "場所",
"account.locked_info": "このアカウントは承認制アカウントです。相手が承認するまでフォローは完了しません。",
"account.media": "メディア",
"account.mention": "@{name}さんに投稿",
Expand Down
19 changes: 19 additions & 0 deletions app/javascript/styles/mastodon/components.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6920,6 +6920,24 @@ noscript {
}
}

.account__header__personal {
font-size: 14px;
color: $darker-text-color;
margin: 5px auto;
border-collapse: separate;
border-spacing: 10px 3px;

th {
white-space: nowrap;
}

&--wrapper {
width: 100%;
margin-top: 10px;
border-top: 1px solid lighten($ui-base-color, 12%);
}
}

.account__header__fields {
margin: 0;
border-top: 1px solid lighten($ui-base-color, 12%);
Expand All @@ -6945,6 +6963,7 @@ noscript {
font-size: 14px;
color: $darker-text-color;
padding: 10px 0;
border-top: 1px solid lighten($ui-base-color, 12%);

a {
display: inline-block;
Expand Down
4 changes: 4 additions & 0 deletions app/javascript/styles/mastodon/forms.scss
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,10 @@ code {
max-width: 50%;
}

&-8 {
max-width: 66.67%;
}

.actions {
margin-top: 27px;
}
Expand Down
11 changes: 11 additions & 0 deletions app/lib/activitypub/case_transform.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ def camel_lower_cache
@camel_lower_cache ||= {}
end

NON_CONVERSIONS = %w(
_misskey_content
_misskey_quote
_misskey_reaction
_misskey_votes
_misskey_talk
vcard:Address
).freeze

def camel_lower(value)
case value
when Array then value.map { |item| camel_lower(item) }
Expand All @@ -14,6 +23,8 @@ def camel_lower(value)
when String
camel_lower_cache[value] ||= if value.start_with?('_:')
'_:' + value.gsub(/\A_:/, '').underscore.camelize(:lower)
elsif NON_CONVERSIONS.include? value
value
else
value.underscore.camelize(:lower)
end
Expand Down
13 changes: 12 additions & 1 deletion app/serializers/activitypub/actor_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ class ActivityPub::ActorSerializer < ActivityPub::Serializer
:inbox, :outbox, :featured, :featured_tags,
:preferred_username, :name, :summary,
:url, :manually_approves_followers, :is_cat,
:discoverable, :published
:discoverable, :published,
:vcard

has_one :public_key, serializer: ActivityPub::PublicKeySerializer

Expand All @@ -24,6 +25,8 @@ class ActivityPub::ActorSerializer < ActivityPub::Serializer
attribute :moved_to, if: :moved?
attribute :also_known_as, if: :also_known_as?
attribute :suspended, if: :suspended?
attribute :bday, key: :'vcard:bday'
attribute :address, key: :'vcard:Address'

class EndpointsSerializer < ActivityPub::Serializer
include RoutingHelper
Expand Down Expand Up @@ -166,6 +169,14 @@ def published
object.created_at.midnight.iso8601
end

def bday
object.birthday
end

def address
object.location
end

class CustomEmojiSerializer < ActivityPub::EmojiSerializer
end

Expand Down
25 changes: 25 additions & 0 deletions app/services/activitypub/process_account_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ def set_immediate_attributes!
@account.note = @json['summary'] || ''
@account.locked = @json['manuallyApprovesFollowers'] || false
@account.fields = property_values || {}
@account.settings = defer_settings.merge(other_settings, birthday, address)
@account.also_known_as = as_array(@json['alsoKnownAs'] || []).map { |item| value_or_id(item) }
@account.discoverable = @json['discoverable'] || false
end
Expand Down Expand Up @@ -212,6 +213,30 @@ def property_values
as_array(@json['attachment']).select { |attachment| attachment['type'] == 'PropertyValue' }.map { |attachment| attachment.slice('name', 'value') }
end

def birthday
return {} if @json['vcard:bday'].blank?
{ 'birthday' => ActiveRecord::Type::Date.new.cast(@json['vcard:bday']) }
end

def address
return {} if @json['vcard:Address'].blank?
{ 'location' => @json['vcard:Address'] }
end

DEFER_SETTINGS_KEYS = %w(
birthday
location
).freeze

def defer_settings
@account.settings.select { |key, _| DEFER_SETTINGS_KEYS.include?(key) }
end

def other_settings
return {} unless @json['otherSetting'].is_a?(Array)
@json['otherSetting'].each_with_object({}) { |v, h| h.merge!({v['name'] => v['value']}) if v['type'] == 'PropertyValue' }
end

def mismatching_origin?(url)
needle = Addressable::URI.parse(url).host
haystack = Addressable::URI.parse(@uri).host
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@
"requestidlecallback": "^0.3.0",
"reselect": "^4.1.5",
"rimraf": "^3.0.2",
"s-age": "^1.1.2",
"sass": "^1.49.7",
"sass-loader": "^10.2.0",
"stacktrace-js": "^2.0.2",
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9638,6 +9638,11 @@ rx-lite@^3.1.2:
resolved "https://registry.yarnpkg.com/rx-lite/-/rx-lite-3.1.2.tgz#19ce502ca572665f3b647b10939f97fd1615f102"
integrity sha1-Gc5QLKVyZl87ZHsQk5+X/RYV8QI=

s-age@^1.1.2:
version "1.1.2"
resolved "https://registry.yarnpkg.com/s-age/-/s-age-1.1.2.tgz#c0cf15233ccc93f41de92ea42c36d957977d1ea2"
integrity sha512-aSN2TlF39WLoZA/6cgYSJZhKt63kJ4EaadejPWjWY9/h4rksIqvfWY3gfd+3uAegSM1IXsA9aWeEhJtkxkFQtA==

safe-buffer@5.1.2, safe-buffer@~5.1.0, safe-buffer@~5.1.1:
version "5.1.2"
resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.1.2.tgz#991ec69d296e0313747d59bdfd2b745c35f8828d"
Expand Down

0 comments on commit db8e295

Please sign in to comment.