From 638d81b66ee48bab0264ab9bb71fd3feddad5a14 Mon Sep 17 00:00:00 2001 From: MeiMei <30769358+mei23@users.noreply.github.com> Date: Tue, 11 Dec 2018 20:18:12 +0900 Subject: [PATCH] Show user fields (#3590) --- .../views/pages/deck/deck.user-column.vue | 33 +++++++++++++++++ .../desktop/views/pages/user/user.header.vue | 35 +++++++++++++++++++ src/client/app/mobile/views/pages/user.vue | 35 +++++++++++++++++++ src/mfm/html-to-mfm.ts | 2 +- src/models/user.ts | 4 +++ src/remote/activitypub/models/person.ts | 23 ++++++++++++ src/remote/activitypub/models/tag.ts | 1 + 7 files changed, 132 insertions(+), 1 deletion(-) diff --git a/src/client/app/desktop/views/pages/deck/deck.user-column.vue b/src/client/app/desktop/views/pages/deck/deck.user-column.vue index ddfb4310bc..6f0b38434f 100644 --- a/src/client/app/desktop/views/pages/deck/deck.user-column.vue +++ b/src/client/app/desktop/views/pages/deck/deck.user-column.vue @@ -26,6 +26,14 @@
+
+
+
{{ field.name }}
+
+ +
+
+
{{ user.notesCount | number }} @@ -416,6 +424,31 @@ export default Vue.extend({ border-right solid 16px transparent border-bottom solid 16px var(--face) + > .fields + margin-top 8px + + > .field + display flex + padding 0 + margin 0 + + > .name + padding 4px + margin 4px + width 30% + overflow hidden + white-space nowrap + text-overflow ellipsis + font-weight bold + + > .value + padding 4px + margin 4px + width 70% + overflow hidden + white-space nowrap + text-overflow ellipsis + > .counts display grid grid-template-columns 1fr 1fr 1fr diff --git a/src/client/app/desktop/views/pages/user/user.header.vue b/src/client/app/desktop/views/pages/user/user.header.vue index e451e770c3..f9b4f53aed 100644 --- a/src/client/app/desktop/views/pages/user/user.header.vue +++ b/src/client/app/desktop/views/pages/user/user.header.vue @@ -18,6 +18,14 @@
+
+
+
{{ field.name }}
+
+ +
+
+
{{ user.profile.location }} {{ user.profile.birthday.replace('-', $t('year')).replace('-', $t('month')) + $t('day') }} ({{ $t('years-old', { age }) }}) @@ -174,6 +182,33 @@ export default Vue.extend({ padding 16px 16px 16px 154px color var(--text) + > .fields + margin-top 16px + + > .field + display flex + padding 0 + margin 0 + + > .name + border-right solid 1px var(--faceDivider) + padding 4px + margin 4px + width 30% + overflow hidden + white-space nowrap + text-overflow ellipsis + font-weight bold + text-align center + + > .value + padding 4px + margin 4px + width 70% + overflow hidden + white-space nowrap + text-overflow ellipsis + > .info margin-top 16px padding-top 16px diff --git a/src/client/app/mobile/views/pages/user.vue b/src/client/app/mobile/views/pages/user.vue index 804168a187..dc03f10f91 100644 --- a/src/client/app/mobile/views/pages/user.vue +++ b/src/client/app/mobile/views/pages/user.vue @@ -24,6 +24,14 @@
+
+
+
{{ field.name }}
+
+ +
+
+

{{ user.profile.location }} @@ -301,6 +309,33 @@ main margin 8px 0 color var(--mobileUserPageDescription) + > .fields + margin 8px 0 + + > .field + display flex + padding 0 + margin 0 + + > .name + padding 4px + margin 4px + width 30% + overflow hidden + white-space nowrap + text-overflow ellipsis + font-weight bold + color var(--mobileUserPageStatusHighlight) + + > .value + padding 4px + margin 4px + width 70% + overflow hidden + white-space nowrap + text-overflow ellipsis + color var(--mobileUserPageStatusHighlight) + > .info margin 8px 0 diff --git a/src/mfm/html-to-mfm.ts b/src/mfm/html-to-mfm.ts index aa887c5560..9a9fbbb86c 100644 --- a/src/mfm/html-to-mfm.ts +++ b/src/mfm/html-to-mfm.ts @@ -41,7 +41,7 @@ export default function(html: string): string { if ((rel && rel.value.match('tag') !== null) || !href || href.value == txt) { text += txt; // メンション - } else if (txt.startsWith('@')) { + } else if (txt.startsWith('@') && !rel || !rel.value.match(/^me /)) { const part = txt.split('@'); if (part.length == 2) { diff --git a/src/models/user.ts b/src/models/user.ts index 90c74fe279..0b19ffa7ba 100644 --- a/src/models/user.ts +++ b/src/models/user.ts @@ -109,6 +109,10 @@ export interface ILocalUser extends IUserBase { birthday: string; // 'YYYY-MM-DD' tags: string[]; }; + fields?: { + name: string; + value: string; + }[]; isCat: boolean; isAdmin?: boolean; isModerator?: boolean; diff --git a/src/remote/activitypub/models/person.ts b/src/remote/activitypub/models/person.ts index 9bbc41e628..6f62da5ca7 100644 --- a/src/remote/activitypub/models/person.ts +++ b/src/remote/activitypub/models/person.ts @@ -17,6 +17,7 @@ import registerInstance from '../../../services/register-instance'; import Instance from '../../../models/instance'; import getDriveFileUrl from '../../../misc/get-drive-file-url'; import { IEmoji } from '../../../models/emoji'; +import { ITag } from './tag'; const log = debug('misskey:activitypub'); @@ -135,6 +136,10 @@ export async function createPerson(uri: string, resolver?: Resolver): Promise { + console.log(`cat not extract fields: ${e}`); + }); + const isBot = object.type == 'Service'; // Create user @@ -164,6 +169,7 @@ export async function createPerson(uri: string, resolver?: Resolver): Promise emoji.name); + const fields = await extractFields(person.attachment).catch(e => { + console.log(`cat not extract fields: ${e}`); + }); + // Update user await User.update({ _id: exist._id }, { $set: { @@ -346,6 +356,7 @@ export async function updatePerson(uri: string, resolver?: Resolver, hint?: obje name: person.name, url: person.url, endpoints: person.endpoints, + fields, isBot: object.type == 'Service', isCat: (person as any).isCat === true, isLocked: person.manuallyApprovesFollowers, @@ -382,6 +393,18 @@ export async function resolvePerson(uri: string, verifier?: string, resolver?: R return await createPerson(uri, resolver); } +export async function extractFields(attachments: ITag[]) { + if (!attachments) return []; + + return attachments.filter(a => a.type === 'PropertyValue' && a.name && a.value) + .map(a => { + return { + name: a.name, + value: htmlToMFM(a.value) + }; + }); +} + export async function updateFeatured(userId: mongo.ObjectID) { const user = await User.findOne({ _id: userId }); if (!isRemoteUser(user)) return; diff --git a/src/remote/activitypub/models/tag.ts b/src/remote/activitypub/models/tag.ts index 5cdbfa43b1..7c9b41eb22 100644 --- a/src/remote/activitypub/models/tag.ts +++ b/src/remote/activitypub/models/tag.ts @@ -7,6 +7,7 @@ export type ITag = { id: string; type: string; name?: string; + value?: string; updated?: Date; icon?: IIcon; };