Skip to content

Commit 299f5e5

Browse files
authored
Merge pull request #746 from lootlog/fix/notifications
Fix/notifications
2 parents 22cb4f8 + a35fc2c commit 299f5e5

33 files changed

Lines changed: 2339 additions & 217 deletions

apps/api/src/users/users.service.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,12 @@ export class UsersService {
515515
for (const notificationType of notificationTypes) {
516516
normalizedSettings[notificationType] = this.normalizeNotificationSettings(
517517
settings?.[notificationType],
518-
defaultNotificationsSettings[notificationType],
518+
settings?.[notificationType] === undefined
519+
? defaultNotificationsSettings[notificationType]
520+
: {
521+
...defaultNotificationsSettings[notificationType],
522+
ignoreOtherWorlds: false,
523+
},
519524
);
520525
}
521526

apps/game-client/src/api/characters.api.ts

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,27 @@ export type MargonemCharacter = {
2020
world?: string;
2121
};
2222

23+
export const normalizeCharacterList = (
24+
characters: unknown,
25+
): MargonemCharacter[] => {
26+
if (!Array.isArray(characters)) {
27+
return [];
28+
}
29+
30+
return characters.filter((character): character is MargonemCharacter => {
31+
return (
32+
typeof character === "object" &&
33+
character !== null &&
34+
typeof character.id === "number" &&
35+
typeof character.icon === "string" &&
36+
typeof character.lvl === "number" &&
37+
typeof character.nick === "string" &&
38+
typeof character.prof === "string" &&
39+
typeof character.world === "string"
40+
);
41+
});
42+
};
43+
2344
type FetchCharacterListOptions = {
2445
accountId: number;
2546
world: string | undefined;
@@ -39,9 +60,11 @@ export async function fetchCharacterList({
3960
MargonemCharacter[]
4061
> | null;
4162

42-
const cached = accountId ? (charlist?.[accountId] ?? null) : null;
63+
const cached = accountId
64+
? normalizeCharacterList(charlist?.[accountId] ?? null)
65+
: [];
4366

44-
if (cached) {
67+
if (cached.length > 0) {
4568
return cached
4669
.filter((character) => character.world === world)
4770
.sort((a, b) => b.lvl - a.lvl);
@@ -66,7 +89,7 @@ export async function fetchCharacterList({
6689
throw new Error("Empty character list received from API");
6790
}
6891

69-
return response.data
92+
return normalizeCharacterList(response.data)
7093
.filter((character) => character.world === world)
7194
.sort((a, b) => b.lvl - a.lvl);
7295
}

apps/game-client/src/components/delete-timer-popover.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ import {
88
import { ContextMenuItem } from "@/components/ui/context-menu";
99
import { fetchGuildPermissions } from "@/api";
1010
import { useGuilds } from "@/hooks/api/use-guilds";
11+
import {
12+
getGuildPermissionsQueryKey,
13+
normalizeGuildPermissions,
14+
} from "@/hooks/api/use-guild-permissions";
1115
import type { TimerWithTimeLeft } from "@/features/timers/utils/timers-utils";
1216
import { cn } from "@/lib/utils";
1317
import { Permission } from "@lootlog/types";
@@ -42,7 +46,7 @@ export const DeleteTimerPopover: FC<DeleteTimerPopoverProps> = ({
4246

4347
const permissionsQueries = useQueries({
4448
queries: uniqueGuildIds.map((guildId) => ({
45-
queryKey: ["guild-permissions", guildId],
49+
queryKey: getGuildPermissionsQueryKey(guildId),
4650
queryFn: () => fetchGuildPermissions(guildId),
4751
staleTime: 5 * 60 * 1000,
4852
})),
@@ -51,9 +55,11 @@ export const DeleteTimerPopover: FC<DeleteTimerPopoverProps> = ({
5155
const guildsWithPermissions = useMemo(() => {
5256
return uniqueGuildIds
5357
.map((guildId, index) => {
54-
const permissions = permissionsQueries[index]?.data;
58+
const permissions = normalizeGuildPermissions(
59+
permissionsQueries[index]?.data,
60+
);
5561
const canDelete = REQUIRED_DELETE_PERMISSIONS.some((perm) =>
56-
permissions?.includes(perm),
62+
permissions.includes(perm),
5763
);
5864
const entry = guildEntries.find((e) => e.guildId === guildId);
5965
return {

0 commit comments

Comments
 (0)