Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Discordのユーザー名形式の変更に対応 #4644

Merged
merged 2 commits into from
Jun 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/client/app/common/views/components/integrations.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div class="nbogcrmo" :v-if="user.twitter || user.github || user.discord">
<x-integration v-if="user.twitter" service="twitter" :url="`https://twitter.com/${user.twitter.screenName}`" :text="user.twitter.screenName" :icon="['fab', 'twitter']"/>
<x-integration v-if="user.github" service="github" :url="`https://github.com/${user.github.login}`" :text="user.github.login" :icon="['fab', 'github']"/>
<x-integration v-if="user.discord" service="discord" :url="`https://discord.com/users/${user.discord.id}`" :text="`${user.discord.username}#${user.discord.discriminator}`" :icon="['fab', 'discord']"/>
<x-integration v-if="user.discord" service="discord" :url="`https://discord.com/users/${user.discord.id}`" :text="discordName" :icon="['fab', 'discord']"/>
</div>
</template>

Expand All @@ -14,7 +14,14 @@ export default Vue.extend({
components: {
XIntegration
},
props: ['user']
props: ['user'],
computed: {
discordName(): string {
return this.user.discord.global_name
? `${this.user.discord.username}`
: `${this.user.discord.username}#${this.user.discord.discriminator}`;
},
},
});
</script>

Expand Down
10 changes: 9 additions & 1 deletion src/client/app/common/views/components/settings/integration.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

<section v-if="enableDiscordIntegration">
<header>Discord</header>
<p v-if="$store.state.i.discord">{{ $t('connected-to') }}: <a :href="`https://discord.com/users/${$store.state.i.discord.id}`" rel="nofollow noopener" target="_blank">@{{ $store.state.i.discord.username }}#{{ $store.state.i.discord.discriminator }}</a></p>
<p v-if="$store.state.i.discord">{{ $t('connected-to') }}: <a :href="`https://discord.com/users/${$store.state.i.discord.id}`" rel="nofollow noopener" target="_blank">@{{ discordName }}</a></p>
<ui-button v-if="$store.state.i.discord" @click="disconnectDiscord">{{ $t('disconnect') }}</ui-button>
<ui-button v-else @click="connectDiscord">{{ $t('connect') }}</ui-button>
</section>
Expand Down Expand Up @@ -70,6 +70,14 @@ export default Vue.extend({
});
},

computed: {
discordName(): string {
return this.$store.state.i.discord.global_name
? `${this.$store.state.i.discord.username}`
: `${this.$store.state.i.discord.username}#${this.$store.state.i.discord.discriminator}`;
},
},

methods: {
connectTwitter() {
this.twitterForm = window.open(apiUrl + '/connect/twitter',
Expand Down
1 change: 1 addition & 0 deletions src/models/packed-schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ export type PackedUser = ThinPackedUser & {
};
discord?: {
id: string;
global_name?: string;
username: string;
discriminator: string;
};
Expand Down
8 changes: 5 additions & 3 deletions src/models/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ export interface ILocalUser extends IUserBase {
refreshToken: string;
expiresDate: number;
id: string;
global_name?: string;
username: string;
discriminator: string;
};
Expand Down Expand Up @@ -519,16 +520,17 @@ export async function pack(
twitter: db.twitter ? {
screenName: db.twitter?.screenName,
userId: db.twitter?.userId
} : undefined,
} : null,
github: db.github ? {
id: db.github?.id,
login: db.github?.login
} : undefined,
} : null,
discord: db.discord ? {
id: db.discord?.id,
global_name: db.discord?.global_name,
username: db.discord?.username,
discriminator: db.discord?.discriminator,
} : undefined,
} : null,
}: {}),
} : {}),

Expand Down
6 changes: 4 additions & 2 deletions src/server/api/service/discord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ router.get('/dc/cb', async ctx => {
});
}));

const { id, username, discriminator } = await getJson('https://discord.com/api/users/@me', '*/*', 10 * 1000, {
const { id, global_name, username, discriminator } = await getJson('https://discord.com/api/users/@me', '*/*', 10 * 1000, {
'Authorization': `Bearer ${accessToken}`,
});

Expand Down Expand Up @@ -198,6 +198,7 @@ router.get('/dc/cb', async ctx => {
accessToken,
refreshToken,
expiresDate,
global_name,
username,
discriminator
}
Expand Down Expand Up @@ -244,7 +245,7 @@ router.get('/dc/cb', async ctx => {
});
}));

const { id, username, discriminator } = await getJson('https://discord.com/api/users/@me', '*/*', 10 * 1000, {
const { id, global_name, username, discriminator } = await getJson('https://discord.com/api/users/@me', '*/*', 10 * 1000, {
'Authorization': `Bearer ${accessToken}`,
});
if (!id || !username || !discriminator) {
Expand All @@ -262,6 +263,7 @@ router.get('/dc/cb', async ctx => {
refreshToken,
expiresDate,
id,
global_name,
username,
discriminator
}
Expand Down