Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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
7 changes: 6 additions & 1 deletion apps/api/src/users/users.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,12 @@ export class UsersService {
for (const notificationType of notificationTypes) {
normalizedSettings[notificationType] = this.normalizeNotificationSettings(
settings?.[notificationType],
defaultNotificationsSettings[notificationType],
settings?.[notificationType] === undefined
? defaultNotificationsSettings[notificationType]
: {
...defaultNotificationsSettings[notificationType],
ignoreOtherWorlds: false,
},
);
}

Expand Down
29 changes: 26 additions & 3 deletions apps/game-client/src/api/characters.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,27 @@ export type MargonemCharacter = {
world?: string;
};

export const normalizeCharacterList = (
characters: unknown,
): MargonemCharacter[] => {
if (!Array.isArray(characters)) {
return [];
}

return characters.filter((character): character is MargonemCharacter => {
return (
typeof character === "object" &&
character !== null &&
typeof character.id === "number" &&
typeof character.icon === "string" &&
typeof character.lvl === "number" &&
typeof character.nick === "string" &&
typeof character.prof === "string" &&
typeof character.world === "string"
);
});
Comment thread
coderabbitai[bot] marked this conversation as resolved.
};

type FetchCharacterListOptions = {
accountId: number;
world: string | undefined;
Expand All @@ -39,9 +60,11 @@ export async function fetchCharacterList({
MargonemCharacter[]
> | null;

const cached = accountId ? (charlist?.[accountId] ?? null) : null;
const cached = accountId
? normalizeCharacterList(charlist?.[accountId] ?? null)
: [];

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

return response.data
return normalizeCharacterList(response.data)
.filter((character) => character.world === world)
.sort((a, b) => b.lvl - a.lvl);
}
12 changes: 9 additions & 3 deletions apps/game-client/src/components/delete-timer-popover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import {
import { ContextMenuItem } from "@/components/ui/context-menu";
import { fetchGuildPermissions } from "@/api";
import { useGuilds } from "@/hooks/api/use-guilds";
import {
getGuildPermissionsQueryKey,
normalizeGuildPermissions,
} from "@/hooks/api/use-guild-permissions";
import type { TimerWithTimeLeft } from "@/features/timers/utils/timers-utils";
import { cn } from "@/lib/utils";
import { Permission } from "@lootlog/types";
Expand Down Expand Up @@ -42,7 +46,7 @@ export const DeleteTimerPopover: FC<DeleteTimerPopoverProps> = ({

const permissionsQueries = useQueries({
queries: uniqueGuildIds.map((guildId) => ({
queryKey: ["guild-permissions", guildId],
queryKey: getGuildPermissionsQueryKey(guildId),
queryFn: () => fetchGuildPermissions(guildId),
staleTime: 5 * 60 * 1000,
})),
Expand All @@ -51,9 +55,11 @@ export const DeleteTimerPopover: FC<DeleteTimerPopoverProps> = ({
const guildsWithPermissions = useMemo(() => {
return uniqueGuildIds
.map((guildId, index) => {
const permissions = permissionsQueries[index]?.data;
const permissions = normalizeGuildPermissions(
permissionsQueries[index]?.data,
);
const canDelete = REQUIRED_DELETE_PERMISSIONS.some((perm) =>
permissions?.includes(perm),
permissions.includes(perm),
);
const entry = guildEntries.find((e) => e.guildId === guildId);
return {
Expand Down
Loading
Loading