Skip to content

Commit

Permalink
リバーシ連合v1.1.0 (#569)
Browse files Browse the repository at this point in the history
  • Loading branch information
kozakura913 authored Jan 11, 2025
1 parent 44822d6 commit 19a0caf
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 5 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG_YOJO.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
- Enhance: 高度な検索であいまい検索が無効な時ワイルドカードを利用可能に [#564](https://github.com/yojo-art/cherrypick/pull/564)
- Feat: フォローしているユーザーなら鍵ノートでもアンテナにひっかかるように [#568](https://github.com/yojo-art/cherrypick/pull/568)
- based-on https://github.com/team-shahu/misskey/pull/38

- Enhance: リバーシ連合時にリアクションを送れるように(v1.1.0) [#569](https://github.com/yojo-art/cherrypick/pull/569)

## 1.2.2
Cherrypick 4.13.0
Expand Down
16 changes: 14 additions & 2 deletions packages/backend/src/core/ReversiService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -840,15 +840,15 @@ export class ReversiService implements OnApplicationShutdown, OnModuleInit {
}

@bindThis
public async sendReaction(gameId: MiReversiGame['id'], user: MiUser, reaction: string) {
public async sendReaction(gameId: MiReversiGame['id'], user: MiUser, reaction: string | null) {
const game = await this.get(gameId);
if (game == null) throw new Error('game not found');
if (!game.isStarted || game.isEnded) return;
if ((game.user1Id !== user.id) && (game.user2Id !== user.id)) return;

let _reaction = '❤️';

const custom = reaction.match(isCustomEmojiRegexp);
const custom = reaction?.match(isCustomEmojiRegexp);

if (custom) {
const name = custom[1];
Expand All @@ -865,6 +865,18 @@ export class ReversiService implements OnApplicationShutdown, OnModuleInit {
userId: user.id,
reaction: _reaction,
});

const remote_user = game.user1Id === user.id ? game.user2 : game.user1;
if (user.host === null && remote_user && remote_user.host != null && game.federationId !== null) {
const like = await this.apRendererService.renderReversiLike(game.federationId, _reaction, user, remote_user as MiRemoteUser);
const content = this.apRendererService.addContext(like);
const dm = this.apDeliverManagerService.createDeliverManager({
id: user.id,
host: null,
}, content);
dm.addDirectRecipe(remote_user as MiRemoteUser);
trackPromise(dm.execute());
}
}

@bindThis
Expand Down
15 changes: 14 additions & 1 deletion packages/backend/src/core/activitypub/ApInboxService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,13 +200,26 @@ export class ApInboxService {
@bindThis
private async like(actor: MiRemoteUser, activity: ILike): Promise<string> {
const targetUri = getApId(activity.object);
const reaction = activity._misskey_reaction ?? activity.content ?? activity.name;
const parsed = this.apDbResolverService.parseUri(targetUri);
if (parsed.local) {
if (parsed.type === 'games') {
const game_id = parsed.id;
if (game_id === '1c086295-25e3-4b82-b31e-3e3959906312' && parsed.rest) {
await this.apNoteService.extractEmojis(activity.tag ?? [], actor.host).catch(() => null);
await this.apgameService.reversiInboxLike(actor, parsed.rest, reaction ?? null);
} else {
return 'skip like unknwon game';
}
}
}

const note = await this.apNoteService.fetchNote(targetUri);
if (!note) return `skip: target note not found ${targetUri}`;

await this.apNoteService.extractEmojis(activity.tag ?? [], actor.host).catch(() => null);

return await this.reactionService.create(actor, note, activity._misskey_reaction ?? activity.content ?? activity.name).catch(err => {
return await this.reactionService.create(actor, note, reaction).catch(err => {
if (err.id === '51c42bb4-931a-456b-bff7-e5a8a70dd298') {
return 'skip: already reacted';
} else {
Expand Down
22 changes: 22 additions & 0 deletions packages/backend/src/core/activitypub/ApRendererService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -886,4 +886,26 @@ export class ApRendererService {

return activity;
}
@bindThis
public async renderReversiLike(game_session_id:string, reaction:string, reaction_from:MiUser, reaction_to:MiRemoteUser): Promise<ILike> {
const url = new URL(reaction_to.uri).origin;
const activity: ILike = {
object: `${url}/games/1c086295-25e3-4b82-b31e-3e3959906312/${game_session_id}`,
actor: this.userEntityService.genLocalUserUri(reaction_from.id),
type: 'EmojiReaction',
published: new Date().toISOString(),
content: reaction,
_misskey_reaction: reaction,
};
activity.to = reaction_to.uri;
activity.cc = [];

if (reaction.startsWith(':')) {
const name = reaction.replaceAll(':', '');
const emoji = (await this.customEmojiService.localEmojisCache.fetch()).get(name);

if (emoji && !emoji.localOnly) activity.tag = [this.renderEmoji(emoji)];
}
return activity;
}
}
8 changes: 8 additions & 0 deletions packages/backend/src/core/activitypub/models/ApGameService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,14 @@ export class ApGameService {
user: await this.userEntityService.pack(fromUser, targetUser),
});
}
async reversiInboxLike(actor: MiRemoteUser, rest: string, emoji:string|null) {
const id = await this.reversiIdFromUUID(rest);
if (id === null) {
this.logger.error('Update reversi Id Solve error');
return;
}
this.reversiService.sendReaction(id, actor, emoji);
}
public async reversiIdFromUUID(game_session_id:string) :Promise<string|null> {
//キャッシュにあればそれ
const cache = await this.redisClient.get(`reversi:federationId:${game_session_id}`);
Expand Down
2 changes: 1 addition & 1 deletion packages/backend/src/server/NodeinfoServerService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const nodeinfo_homepage = 'https://misskey-hub.net';
@Injectable()
export class NodeinfoServerService {
//semverに従って割り当てる
static reversiVersion = '1.0.0-yojo';
static reversiVersion = '1.1.0-yojo';
constructor(
@Inject(DI.config)
private config: Config,
Expand Down

0 comments on commit 19a0caf

Please sign in to comment.