From 356225af14621d16cf1211f30ed05844a57bdcae Mon Sep 17 00:00:00 2001 From: MeiMei <30769358+mei23@users.noreply.github.com> Date: Thu, 2 Apr 2020 21:59:14 +0900 Subject: [PATCH] Use url if available (#6214) * Fix #6213 * other link * fix --- migration/1585772678853-ap-url.ts | 15 +++++++++++++++ src/client/components/note.vue | 8 ++++---- src/client/pages/note.vue | 2 +- src/models/entities/note.ts | 6 ++++++ src/models/repositories/note.ts | 5 +++-- src/remote/activitypub/models/note.ts | 3 ++- src/services/note/create.ts | 2 ++ 7 files changed, 33 insertions(+), 8 deletions(-) create mode 100644 migration/1585772678853-ap-url.ts diff --git a/migration/1585772678853-ap-url.ts b/migration/1585772678853-ap-url.ts new file mode 100644 index 0000000000..622d097276 --- /dev/null +++ b/migration/1585772678853-ap-url.ts @@ -0,0 +1,15 @@ +/* tslint:disable:quotemark class-name indent */ +import {MigrationInterface, QueryRunner} from "typeorm"; + +export class apUrl1585772678853 implements MigrationInterface { + name = 'apUrl1585772678853' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE "note" ADD "url" character varying(512)`, undefined); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE "note" DROP COLUMN "url"`, undefined); + } + +} diff --git a/src/client/components/note.vue b/src/client/components/note.vue index 48e37c33d3..07011ba50f 100644 --- a/src/client/components/note.vue +++ b/src/client/components/note.vue @@ -517,11 +517,11 @@ export default Vue.extend({ icon: faLink, text: this.$t('copyLink'), action: this.copyLink - }, this.appearNote.uri ? { + }, (this.appearNote.url || this.appearNote.uri) ? { icon: faExternalLinkSquareAlt, text: this.$t('showOnRemote'), action: () => { - window.open(this.appearNote.uri, '_blank'); + window.open(this.appearNote.url || this.appearNote.uri, '_blank'); } } : undefined, null, @@ -585,11 +585,11 @@ export default Vue.extend({ icon: faLink, text: this.$t('copyLink'), action: this.copyLink - }, this.appearNote.uri ? { + }, (this.appearNote.url || this.appearNote.uri) ? { icon: faExternalLinkSquareAlt, text: this.$t('showOnRemote'), action: () => { - window.open(this.appearNote.uri, '_blank'); + window.open(this.appearNote.url || this.appearNote.uri, '_blank'); } } : undefined] .filter(x => x !== undefined); diff --git a/src/client/pages/note.vue b/src/client/pages/note.vue index dbdf8c3d35..37c66833e9 100644 --- a/src/client/pages/note.vue +++ b/src/client/pages/note.vue @@ -13,7 +13,7 @@
- +
diff --git a/src/models/entities/note.ts b/src/models/entities/note.ts index e6fbd4ce75..79b6b5ab7d 100644 --- a/src/models/entities/note.ts +++ b/src/models/entities/note.ts @@ -112,6 +112,12 @@ export class Note { }) public uri: string | null; + @Column('varchar', { + length: 512, nullable: true, + comment: 'The human readable url of a note. it will be null when the note is local.' + }) + public url: string | null; + @Column('integer', { default: 0, select: false }) diff --git a/src/models/repositories/note.ts b/src/models/repositories/note.ts index 73d7ad86eb..2510830489 100644 --- a/src/models/repositories/note.ts +++ b/src/models/repositories/note.ts @@ -171,8 +171,8 @@ export class NoteRepository extends Repository { let text = note.text; - if (note.name && note.uri) { - text = `【${note.name}】\n${(note.text || '').trim()}\n${note.uri}`; + if (note.name && (note.url || note.uri)) { + text = `【${note.name}】\n${(note.text || '').trim()}\n\n${note.url || note.uri}`; } const packed = await awaitAll({ @@ -197,6 +197,7 @@ export class NoteRepository extends Repository { renoteId: note.renoteId, mentions: note.mentions.length > 0 ? note.mentions : undefined, uri: note.uri || undefined, + url: note.url || undefined, _featuredId_: (note as any)._featuredId_ || undefined, _prId_: (note as any)._prId_ || undefined, diff --git a/src/remote/activitypub/models/note.ts b/src/remote/activitypub/models/note.ts index 70ceb5e503..55b5440e6b 100644 --- a/src/remote/activitypub/models/note.ts +++ b/src/remote/activitypub/models/note.ts @@ -280,7 +280,8 @@ export async function createNote(value: string | IObject, resolver?: Resolver, s apHashtags, apEmojis, poll, - uri: note.id + uri: note.id, + url: note.url, }, silent); } diff --git a/src/services/note/create.ts b/src/services/note/create.ts index 60a5a5e69d..f506337924 100644 --- a/src/services/note/create.ts +++ b/src/services/note/create.ts @@ -104,6 +104,7 @@ type Option = { apHashtags?: string[] | null; apEmojis?: string[] | null; uri?: string | null; + url?: string | null; app?: App | null; }; @@ -407,6 +408,7 @@ async function insertNote(user: User, data: Option, tags: string[], emojis: stri }); if (data.uri != null) insert.uri = data.uri; + if (data.url != null) insert.url = data.url; // Append mentions data if (mentionedUsers.length > 0) {