From 97198533025132386726ce333544310a89bd2750 Mon Sep 17 00:00:00 2001 From: Stedoss <29103029+Stedoss@users.noreply.github.com> Date: Fri, 5 Jul 2024 00:20:56 +0100 Subject: [PATCH 1/4] Allow `getUserDetails()` to lookup on `userId` when user not found by username query --- .../com/nisemoe/nise/database/UserService.kt | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/nise-backend/src/main/kotlin/com/nisemoe/nise/database/UserService.kt b/nise-backend/src/main/kotlin/com/nisemoe/nise/database/UserService.kt index 823cc88..dbd2ca5 100644 --- a/nise-backend/src/main/kotlin/com/nisemoe/nise/database/UserService.kt +++ b/nise-backend/src/main/kotlin/com/nisemoe/nise/database/UserService.kt @@ -43,7 +43,7 @@ class UserService( } fun getUserDetails(identifier: Any): UserDetailsExtended? { - val user = when (identifier) { + var user = when (identifier) { is Long -> dslContext.selectFrom(USERS) .where(USERS.USER_ID.eq(identifier)) .fetchOneInto(UsersRecord::class.java) @@ -53,6 +53,16 @@ class UserService( else -> null } + // Lookup user by ID if we have not found a user via a username lookup and the identifier is a valid number + if (user == null && identifier is String) { + val longIdentifier = identifier.toLongOrNull() + if (longIdentifier != null) { + user = dslContext.selectFrom(USERS) + .where(USERS.USER_ID.eq(longIdentifier)) + .fetchOneInto(UsersRecord::class.java) + } + } + if (user != null) { val userDetails = UserDetails( user.userId!!, @@ -75,7 +85,7 @@ class UserService( // The database does NOT have the user; we will now use the osu!api val apiUser = when (identifier) { is Long -> this.osuApi.getUserProfile(userId = identifier.toString(), mode = "osu", key = "id") - is String -> this.osuApi.getUserProfile(userId = identifier, mode = "osu", key = "username") + is String -> this.osuApi.getUserProfile(userId = identifier, mode = "osu") else -> null } ?: return null From cfcab7d7cf25af067159c62351d65df8bb6a6a9f Mon Sep 17 00:00:00 2001 From: Stedoss <29103029+Stedoss@users.noreply.github.com> Date: Fri, 5 Jul 2024 00:47:26 +0100 Subject: [PATCH 2/4] Use `userId` for `/u/` route links --- nise-frontend/src/app/search/search.component.html | 2 +- nise-frontend/src/app/search/search.component.ts | 2 +- .../src/app/view-replay-pair/view-replay-pair.component.html | 4 ++-- nise-frontend/src/app/view-score/view-score.component.html | 4 ++-- .../view-suspicious-scores.component.html | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/nise-frontend/src/app/search/search.component.html b/nise-frontend/src/app/search/search.component.html index 8f18dbe..f7662a6 100644 --- a/nise-frontend/src/app/search/search.component.html +++ b/nise-frontend/src/app/search/search.component.html @@ -157,7 +157,7 @@ - {{ getValue(entry, column.name) }} + {{ getValue(entry, column.name) }} {{ getValue(entry, column.name) }} diff --git a/nise-frontend/src/app/search/search.component.ts b/nise-frontend/src/app/search/search.component.ts index b5652f5..2ee4a61 100644 --- a/nise-frontend/src/app/search/search.component.ts +++ b/nise-frontend/src/app/search/search.component.ts @@ -346,7 +346,7 @@ export class SearchComponent implements OnInit { getLink(entry: any): any { if(this.searchType === 'user') { - return "/u/" + this.getValue(entry, 'username'); + return "/u/" + this.getValue(entry, 'user_id'); } else { return "/s/" + this.getValue(entry, 'replay_id'); } diff --git a/nise-frontend/src/app/view-replay-pair/view-replay-pair.component.html b/nise-frontend/src/app/view-replay-pair/view-replay-pair.component.html index 6a6582a..b0fb616 100644 --- a/nise-frontend/src/app/view-replay-pair/view-replay-pair.component.html +++ b/nise-frontend/src/app/view-replay-pair/view-replay-pair.component.html @@ -62,11 +62,11 @@ Player - {{ this.pair.replays[0].username }} + {{ this.pair.replays[0].username }} osu!web - {{ this.pair.replays[1].username }} + {{ this.pair.replays[1].username }} osu!web diff --git a/nise-frontend/src/app/view-score/view-score.component.html b/nise-frontend/src/app/view-score/view-score.component.html index a47c08c..2ca4224 100644 --- a/nise-frontend/src/app/view-score/view-score.component.html +++ b/nise-frontend/src/app/view-score/view-score.component.html @@ -33,7 +33,7 @@
- Played by {{ this.replayData.username }} osu!web + Played by {{ this.replayData.username }} osu!web
Submitted on {{ this.replayData.date }} @@ -196,7 +196,7 @@ - {{ score.username }} + {{ score.username }} {{ score.pp | number: '1.2-2' }} diff --git a/nise-frontend/src/app/view-suspicious-scores/view-suspicious-scores.component.html b/nise-frontend/src/app/view-suspicious-scores/view-suspicious-scores.component.html index 9a5d872..e0faf7f 100644 --- a/nise-frontend/src/app/view-suspicious-scores/view-suspicious-scores.component.html +++ b/nise-frontend/src/app/view-suspicious-scores/view-suspicious-scores.component.html @@ -98,7 +98,7 @@ - + {{ score.username }} From 7bb7b5c39a271cea38d4b34c81c21c1de26ac310 Mon Sep 17 00:00:00 2001 From: Stedoss <29103029+Stedoss@users.noreply.github.com> Date: Fri, 5 Jul 2024 00:48:57 +0100 Subject: [PATCH 3/4] Replace `username` with `userId` in `view-user` location state --- nise-frontend/src/app/view-user/view-user.component.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/nise-frontend/src/app/view-user/view-user.component.ts b/nise-frontend/src/app/view-user/view-user.component.ts index 4ef05d4..1d3a964 100644 --- a/nise-frontend/src/app/view-user/view-user.component.ts +++ b/nise-frontend/src/app/view-user/view-user.component.ts @@ -3,7 +3,7 @@ import {SimilarReplay, SuspiciousScore} from "../replays"; import { HttpClient } from "@angular/common/http"; import {catchError, EMPTY, finalize, Observable, Subscription} from "rxjs"; import {environment} from "../../environments/environment"; -import {DatePipe, DecimalPipe, JsonPipe, NgForOf, NgIf, NgOptimizedImage} from "@angular/common"; +import {DatePipe, DecimalPipe, JsonPipe, Location, NgForOf, NgIf, NgOptimizedImage} from "@angular/common"; import {ActivatedRoute, RouterLink} from "@angular/router"; import {UserDetails, UserQueueDetails} from "../userDetails"; import {calculateTimeAgo, countryCodeToFlag, formatDuration} from "../format"; @@ -68,6 +68,7 @@ export class ViewUserComponent implements OnInit, OnChanges, OnDestroy { private activatedRoute: ActivatedRoute, private title: Title, private rxStompService: RxStompService, + private location: Location, public userService: UserService, public followService: FollowService ) { } @@ -135,6 +136,8 @@ export class ViewUserComponent implements OnInit, OnChanges, OnDestroy { this.subscribeToUser(); } this.checkIfUserIsFollowed(); + + this.location.replaceState(`u/${this.userInfo.user_details.user_id}`); } ); } From 0df62d926e6a370edbe69c8e6ca6c66b2e9ae144 Mon Sep 17 00:00:00 2001 From: Stedoss <29103029+Stedoss@users.noreply.github.com> Date: Fri, 5 Jul 2024 18:04:21 +0100 Subject: [PATCH 4/4] Fix null coalescing on user page --- nise-frontend/src/app/replays.ts | 2 +- nise-frontend/src/app/view-score/view-score.component.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/nise-frontend/src/app/replays.ts b/nise-frontend/src/app/replays.ts index f44d104..e5ee510 100644 --- a/nise-frontend/src/app/replays.ts +++ b/nise-frontend/src/app/replays.ts @@ -68,7 +68,7 @@ export function getMockReplayData(): ReplayData { export interface ReplayData { replay_id: number | null; - user_id: number; + user_id: number | null; username: string; date: string; beatmap_id: number; diff --git a/nise-frontend/src/app/view-score/view-score.component.html b/nise-frontend/src/app/view-score/view-score.component.html index 2ca4224..8bb35ef 100644 --- a/nise-frontend/src/app/view-score/view-score.component.html +++ b/nise-frontend/src/app/view-score/view-score.component.html @@ -33,7 +33,7 @@
- Played by {{ this.replayData.username }} osu!web + Played by {{ this.replayData.username }} osu!web
Submitted on {{ this.replayData.date }}