Skip to content

Commit

Permalink
Merge pull request #50 from lqvp/shahu-feat
Browse files Browse the repository at this point in the history
fix+enhance: フォロー/フォロリクの履歴周りのコミット
  • Loading branch information
chan-mai authored Dec 13, 2024
2 parents ce96945 + bbe197f commit 628bc61
Show file tree
Hide file tree
Showing 5 changed files with 248 additions and 140 deletions.
22 changes: 22 additions & 0 deletions packages/backend/src/core/UserFollowingService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,28 @@ export class UserFollowingService implements OnModuleInit {
});

if (isFollowed) autoAccept = true;

// フォローリクエストを承認された側(送信者)の履歴
if (this.userEntityService.isLocalUser(follower)) {
await this.followRequestHistoryRepository.insert({
id: this.idService.gen(),
type: 'wasApproved',
fromUserId: follower.id,
toUserId: followee.id,
timestamp: new Date(),
});
}

// フォローリクエストを承認した側(受信者)の履歴
if (this.userEntityService.isLocalUser(followee)) {
await this.followRequestHistoryRepository.insert({
id: this.idService.gen(),
type: 'approved',
fromUserId: follower.id,
toUserId: followee.id,
timestamp: new Date(),
});
}
}

// Automatically accept if the follower is an account who has moved and the locked followee had accepted the old account.
Expand Down
10 changes: 6 additions & 4 deletions packages/backend/src/server/api/endpoints/following/history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,10 @@ export const meta = {
fromUser: {
type: 'object',
optional: false, nullable: false,
ref: 'UserDetailedNotMe',
},
toUser: {
type: 'object',
optional: false, nullable: false,
ref: 'UserDetailedNotMe',
},
timestamp: {
type: 'string',
Expand Down Expand Up @@ -199,8 +197,12 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
return await Promise.all(histories.map(async history => ({
id: history.id,
type: history.type,
fromUser: await this.userEntityService.pack(history.fromUser ?? history.fromUserId, me, { schema: 'UserDetailed' }),
toUser: await this.userEntityService.pack(history.toUser ?? history.toUserId, me, { schema: 'UserDetailed' }),
fromUser: history.fromUser
? await this.userEntityService.pack(history.fromUser ?? history.fromUserId, me)
: { name: 'unknown user' },
toUser: history.toUser
? await this.userEntityService.pack(history.toUser ?? history.toUserId, me)
: { name: 'unknown user' },
timestamp: history.timestamp.toISOString(),
})));
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,10 @@ export const meta = {
fromUser: {
type: 'object',
optional: false, nullable: false,
ref: 'UserDetailedNotMe',
},
toUser: {
type: 'object',
optional: false, nullable: false,
ref: 'UserDetailedNotMe',
},
timestamp: {
type: 'string',
Expand Down Expand Up @@ -200,8 +198,12 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
return await Promise.all(histories.map(async history => ({
id: history.id,
type: history.type,
fromUser: await this.userEntityService.pack(history.fromUser ?? history.fromUserId, me, { schema: 'UserDetailed' }),
toUser: await this.userEntityService.pack(history.toUser ?? history.toUserId, me, { schema: 'UserDetailed' }),
fromUser: history.fromUser
? await this.userEntityService.pack(history.fromUser ?? history.fromUserId, me)
: { name: 'unknown user' },
toUser: history.toUser
? await this.userEntityService.pack(history.toUser ?? history.toUserId, me)
: { name: 'unknown user' },
timestamp: history.timestamp.toISOString(),
})));
});
Expand Down
187 changes: 114 additions & 73 deletions packages/frontend/src/pages/follow-history.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,41 @@ SPDX-License-Identifier: AGPL-3.0-only
<template #default="{items}">
<div class="mk-follow-requests _gaps">
<div v-for="history in items" :key="history.id" class="history _panel" :class="getActionConfig(history.type).className">
<MkAvatar class="avatar" :user="history[getActionConfig(history.type).avatarUser]" indicator link preview/>
<MkAvatar
v-if="hasUserProps(history[getActionConfig(history.type).avatarUser])"
class="avatar"
:user="history[getActionConfig(history.type).avatarUser]"
indicator
link
preview
/>
<div v-else class="unknown-user">
<span>?</span>
</div>
<div class="body">
<div class="content">
<div class="users">
<MkA v-user-preview="history.fromUser.id" class="name" :to="userPage(history.fromUser)">
<MkUserName :user="history.fromUser"/>
<MkA
v-if="hasUserProps(history.fromUser)"
v-user-preview="history.fromUser.id"
class="name"
:to="userPage(history.fromUser)"
>
<MkUserName v-if="hasUserProps(history.fromUser)" :user="history.fromUser"/>
<span v-else>unknown user</span>
</MkA>
<span v-else>unknown user</span>
<i class="ti ti-arrow-right"></i>
<MkA v-user-preview="history.toUser.id" class="name" :to="userPage(history.toUser)">
<MkUserName :user="history.toUser"/>
<MkA
v-if="hasUserProps(history.toUser)"
v-user-preview="history.toUser.id"
class="name"
:to="userPage(history.toUser)"
>
<MkUserName v-if="hasUserProps(history.toUser)" :user="history.toUser"/>
<span v-else>unknown user</span>
</MkA>
<span v-else>unknown user</span>
</div>
<p class="action">
<i :class="getActionConfig(history.type).icon"></i>
Expand Down Expand Up @@ -69,6 +93,10 @@ import { $i } from '@/account.js';
import MkHorizontalSwipe from '@/components/MkHorizontalSwipe.vue';
import { dateString } from '@/filters/date.js';

function hasUserProps(user: any): boolean {
return !!(user && (user.id || user.username || user.avatarUrl));
}

const ACTION_CONFIG = {
follow: {
icon: 'ti ti-user-plus',
Expand Down Expand Up @@ -215,93 +243,106 @@ definePageMetadata(() => ({
}));
</script>

<style lang="scss" scoped>
.mk-follow-requests {
> .history {
display: flex;
padding: 16px;
border: 2px solid transparent;
transition: border-color 0.2s ease;
<style lang="scss" scoped>
.unknown-user {
display: flex;
align-items: center;
justify-content: center;
width: 42px;
height: 42px;
border-radius: 8px;
background: var(--panel);
color: var(--fg);
font-size: 1.2em;
opacity: 0.5;
}

&.history--follow {
border-color: var(--MI_THEME-link);
}
.mk-follow-requests {
> .history {
display: flex;
padding: 16px;
border: 2px solid transparent;
transition: border-color 0.2s ease;

&.history--unfollow {
border-color: var(--MI_THEME-error);
}
&.history--follow {
border-color: var(--MI_THEME-link);
}

&.history--wasfollow {
border-color: var(--MI_THEME-success);
}
&.history--unfollow {
border-color: var(--MI_THEME-error);
}

&.history--wasunfollow {
border-color: var(--MI_THEME-error);
}
&.history--wasfollow {
border-color: var(--MI_THEME-success);
}

&.history--blocked {
border-color: var(--MI_THEME-warn);
}
&.history--wasunfollow {
border-color: var(--MI_THEME-error);
}

&.history--unblocked {
border-color: var(--MI_THEME-renote);
}
&.history--blocked {
border-color: var(--MI_THEME-warn);
}

&.history--wasblocked {
border-color: var(--MI_THEME-warn);
}
&.history--unblocked {
border-color: var(--MI_THEME-renote);
}

&.history--wasunblocked {
border-color: var(--MI_THEME-renote);
}
&.history--wasblocked {
border-color: var(--MI_THEME-warn);
}

> .avatar {
display: block;
flex-shrink: 0;
margin: 0 12px 0 0;
width: 42px;
height: 42px;
border-radius: 8px;
}
&.history--wasunblocked {
border-color: var(--MI_THEME-renote);
}

> .body {
display: flex;
flex-direction: column;
flex: 1;
gap: 4px;

> .content {
> .users {
display: flex;
align-items: center;
gap: 8px;
font-size: 15px;

> .ti {
opacity: 0.7;
}
}
> .avatar {
display: block;
flex-shrink: 0;
margin: 0 12px 0 0;
width: 42px;
height: 42px;
border-radius: 8px;
}

> .action {
margin: 4px 0 0 0;
opacity: 0.7;
font-size: 14px;
> .body {
display: flex;
flex-direction: column;
flex: 1;
gap: 4px;

> .content {
> .users {
display: flex;
align-items: center;
gap: 8px;
font-size: 15px;

> .ti {
margin-right: 4px;
}
> .ti {
opacity: 0.7;
}
}

> .info {
font-size: 0.9em;
> .action {
margin: 4px 0 0 0;
opacity: 0.7;
font-size: 14px;

> .timestamp {
margin-right: 8px;
> .ti {
margin-right: 4px;
}
}
}

> .info {
font-size: 0.9em;
opacity: 0.7;

> .timestamp {
margin-right: 8px;
}
}
}
}
</style>
}
</style>
Loading

0 comments on commit 628bc61

Please sign in to comment.