Skip to content

Commit

Permalink
ap/showでEmojiを持ってこれる機能
Browse files Browse the repository at this point in the history
  • Loading branch information
mei23 committed Oct 31, 2021
1 parent abd3304 commit 2a601f6
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 10 deletions.
7 changes: 5 additions & 2 deletions src/client/app/common/views/components/dialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
</template>
<template v-else>
<div class="icon" v-if="!input && !select && !user" :class="type"><fa :icon="icon"/></div>
<header v-if="title"><mfm :text="title"/></header>
<div class="body" v-if="text"><mfm :text="text"/></div>
<header v-if="title"><mfm :text="title" :custom-emojis="mfmCustomEmojis"/></header>
<div class="body" v-if="text"><mfm :text="text" :custom-emojis="mfmCustomEmojis"/></div>
<ui-input v-if="input" v-model="inputValue" autofocus :type="input.type || 'text'" :placeholder="input.placeholder" @keydown="onInputKeydown"></ui-input>
<ui-input v-if="user" v-model="userInputValue" autofocus @keydown="onInputKeydown"><template #prefix>@</template></ui-input>
<ui-select v-if="select" v-model="selectedValue" autofocus>
Expand Down Expand Up @@ -56,6 +56,9 @@ export default Vue.extend({
type: String,
required: false
},
mfmCustomEmojis: {
required: false
},
input: {
required: false
},
Expand Down
6 changes: 6 additions & 0 deletions src/client/app/common/views/components/search-box.vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ export default Vue.extend({
this.$router.push(`/@${res.object.username}${ res.object.host ? `@${res.object.host}` : '' }`);
} else if (res.type == 'Note') {
this.$router.push(`/notes/${res.object.id}`);
} else if (res.type == 'Emoji') {
this.$root.dialog({
type: 'success',
text: `:${res.object.name}:`,
mfmCustomEmojis: [ res.object ]
});
}
} catch (e) {
// TODO
Expand Down
6 changes: 6 additions & 0 deletions src/client/app/desktop/views/components/ui.header.search.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ export default Vue.extend({
this.$router.push(`/@${res.object.username}${ res.object.host ? `@${res.object.host}` : '' }`);
} else if (res.type == 'Note') {
this.$router.push(`/notes/${res.object.id}`);
} else if (res.type == 'Emoji') {
this.$root.dialog({
type: 'success',
text: `:${res.object.name}:`,
mfmCustomEmojis: [ res.object ]
});
}
} catch (e) {
// TODO
Expand Down
6 changes: 6 additions & 0 deletions src/client/app/desktop/views/components/ui.sidebar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,12 @@ export default Vue.extend({
this.$router.push(`/@${res.object.username}${ res.object.host ? `@${res.object.host}` : '' }`);
} else if (res.type == 'Note') {
this.$router.push(`/notes/${res.object.id}`);
} else if (res.type == 'Emoji') {
this.$root.dialog({
type: 'success',
text: `:${res.object.name}:`,
mfmCustomEmojis: [ res.object ]
});
}
} catch (e) {
// TODO
Expand Down
6 changes: 6 additions & 0 deletions src/client/app/mobile/views/components/ui.nav.vue
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,12 @@ export default Vue.extend({
this.$router.push(`/@${res.object.username}${ res.object.host ? `@${res.object.host}` : '' }`);
} else if (res.type == 'Note') {
this.$router.push(`/notes/${res.object.id}`);
} else if (res.type == 'Emoji') {
this.$root.dialog({
type: 'success',
text: `:${res.object.name}:`,
mfmCustomEmojis: [ res.object ]
});
}
} catch (e) {
// TODO
Expand Down
35 changes: 27 additions & 8 deletions src/server/api/endpoints/ap/show.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@ import config from '../../../../config';
import User, { pack as packUser, IUser } from '../../../../models/user';
import { createPerson } from '../../../../remote/activitypub/models/person';
import Note, { pack as packNote, INote } from '../../../../models/note';
import { createNote } from '../../../../remote/activitypub/models/note';
import { createNote, extractEmojis } from '../../../../remote/activitypub/models/note';
import Resolver from '../../../../remote/activitypub/resolver';
import { ApiError } from '../../error';
import { extractApHost } from '../../../../misc/convert-host';
import { isActor, isPost, getApId } from '../../../../remote/activitypub/type';
import { isActor, isPost, getApId, isEmoji } from '../../../../remote/activitypub/type';
import { isBlockedHost } from '../../../../services/instance-moderation';
import * as ms from 'ms';
import * as escapeRegexp from 'escape-regexp';
import { StatusError } from '../../../../misc/fetch';
import Emoji, { IEmoji } from '../../../../models/emoji';

export const meta = {
tags: ['federation'],
Expand Down Expand Up @@ -111,12 +112,17 @@ async function fetchAny(uri: string) {
// それでもみつからなければ新規であるため登録
if (isActor(object)) {
const user = await createPerson(getApId(object));
return mergePack({ user });
return await mergePack({ user });
}

if (isPost(object)) {
const note = await createNote(getApId(object), null, true);
return mergePack({ note });
return await mergePack({ note });
}

if (isEmoji(object)) {
const emojis = await extractEmojis(object, extractApHost(uri));
return await mergePack({ emoji: emojis[0] });
}

return null;
Expand All @@ -139,6 +145,7 @@ async function processLocal(uri: string) {
return await mergePack({
user: type === 'users' ? await User.findOne({ _id: id }) : null,
note: type === 'notes' ? await Note.findOne({ _id: id }) : null,
emoji: type === 'emojis' ? await Emoji.findOne({ name: id, host: null }) : null,
});
}

Expand All @@ -162,20 +169,21 @@ async function processLocal(uri: string) {
* @throws RejectedError on deleted, moderated or hidden.
*/
async function processRemote(uri: string) {
const [user, note] = await Promise.all([
const [user, note, emoji] = await Promise.all([
User.findOne({ uri: uri }),
Note.findOne({ uri: uri })
Note.findOne({ uri: uri }),
Emoji.findOne({ uri: uri }),
]);

return await mergePack({ user, note });
return await mergePack({ user, note, emoji });
}

/**
* Pack DB Object for API Response
* @returns Packed API response, or null on not found.
* @throws RejectedError on deleted, moderated or hidden.
*/
async function mergePack(opts: { user?: IUser | null, note?: INote | null }) {
async function mergePack(opts: { user?: IUser | null, note?: INote | null, emoji?: IEmoji | null }) {
if (opts.user != null) {
if (opts.user.isDeleted) throw new RejectedError('User is deleted');
if (opts.user.isSuspended) throw new RejectedError('User is suspended');
Expand All @@ -194,6 +202,17 @@ async function mergePack(opts: { user?: IUser | null, note?: INote | null }) {
};
}

if (opts.emoji != null) {
return {
type: 'Emoji',
object: {
name: `${opts.emoji.name}${ opts.emoji.host ? `@${opts.emoji.host}` : '' }`,
host: opts.emoji.host,
url: opts.emoji.url,
},
};
}

return null;
}

Expand Down

0 comments on commit 2a601f6

Please sign in to comment.