fix(web): stop invite auto-join retry spam on failures
Some checks failed
CI / test (push) Failing after 2m18s
Some checks failed
CI / test (push) Failing after 2m18s
This commit is contained in:
@@ -32,7 +32,7 @@ Legend:
|
|||||||
23. Groups - `PARTIAL` (create/add/remove/invite link; join-by-invite and invite permissions covered by integration tests; members API now returns profile fields (`username/name/avatar_url`) and web Chat Info consumes them to avoid extra per-member profile requests; add-member search also shows avatars; advanced moderation still partial)
|
23. Groups - `PARTIAL` (create/add/remove/invite link; join-by-invite and invite permissions covered by integration tests; members API now returns profile fields (`username/name/avatar_url`) and web Chat Info consumes them to avoid extra per-member profile requests; add-member search also shows avatars; advanced moderation still partial)
|
||||||
24. Roles - `DONE` (owner/admin/member)
|
24. Roles - `DONE` (owner/admin/member)
|
||||||
25. Admin Rights - `PARTIAL` (delete/pin/edit info + explicit ban APIs for groups/channels including ban list endpoint; web Chat Info now shows searchable `Banned users` with both inline and right-click `Unban` actions for owner/admin, member search, avatars in moderation lists, invite-link copy/regenerate actions, ban metadata (`who banned/when`), explicit member action button for touch/trackpad UX, `@username`-friendly moderation filters, and resilient profile hydration (`allSettled`) for partially missing users; integration tests cover channel member read-only, channel admin full-delete, channel message delete-for-all permissions, group profile edit permissions, owner-only role management rules, and admin-visible/member-forbidden ban-list access; remaining UX moderation tools limited)
|
25. Admin Rights - `PARTIAL` (delete/pin/edit info + explicit ban APIs for groups/channels including ban list endpoint; web Chat Info now shows searchable `Banned users` with both inline and right-click `Unban` actions for owner/admin, member search, avatars in moderation lists, invite-link copy/regenerate actions, ban metadata (`who banned/when`), explicit member action button for touch/trackpad UX, `@username`-friendly moderation filters, and resilient profile hydration (`allSettled`) for partially missing users; integration tests cover channel member read-only, channel admin full-delete, channel message delete-for-all permissions, group profile edit permissions, owner-only role management rules, and admin-visible/member-forbidden ban-list access; remaining UX moderation tools limited)
|
||||||
26. Channels - `PARTIAL` (create/post/edit/delete/subscribe/unsubscribe; integration tests now also cover invite-link permissions (member forbidden, admin allowed); web Chat Info differentiates channel actions by role: `Delete channel for all` for owner/admin and `Leave channel` for member; remaining UX edge-cases still polishing)
|
26. Channels - `PARTIAL` (create/post/edit/delete/subscribe/unsubscribe; integration tests now also cover invite-link permissions (member forbidden, admin allowed); web Chat Info differentiates channel actions by role: `Delete channel for all` for owner/admin and `Leave channel` for member; app auto-join by invite token is now single-shot with toast errors (no retry spam on invalid/expired links); remaining UX edge-cases still polishing)
|
||||||
27. Channel Types - `DONE` (public/private)
|
27. Channel Types - `DONE` (public/private)
|
||||||
28. Notifications - `PARTIAL` (browser notifications + mute/settings; chat mute is propagated in chat list payload, honored by web realtime notifications with mention override, and mute toggle now syncs instantly in chat store; backend now emits `chat_updated` after notification mute/unmute for cross-tab consistency; no mobile push infra)
|
28. Notifications - `PARTIAL` (browser notifications + mute/settings; chat mute is propagated in chat list payload, honored by web realtime notifications with mention override, and mute toggle now syncs instantly in chat store; backend now emits `chat_updated` after notification mute/unmute for cross-tab consistency; no mobile push infra)
|
||||||
29. Archive - `DONE`
|
29. Archive - `DONE`
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import { AuthPage } from "../pages/AuthPage";
|
|||||||
import { ChatsPage } from "../pages/ChatsPage";
|
import { ChatsPage } from "../pages/ChatsPage";
|
||||||
import { useAuthStore } from "../store/authStore";
|
import { useAuthStore } from "../store/authStore";
|
||||||
import { useChatStore } from "../store/chatStore";
|
import { useChatStore } from "../store/chatStore";
|
||||||
|
import { useUiStore } from "../store/uiStore";
|
||||||
import { applyAppearancePreferences, getAppPreferences } from "../utils/preferences";
|
import { applyAppearancePreferences, getAppPreferences } from "../utils/preferences";
|
||||||
|
|
||||||
const PENDING_INVITE_TOKEN_KEY = "bm_pending_invite_token";
|
const PENDING_INVITE_TOKEN_KEY = "bm_pending_invite_token";
|
||||||
@@ -19,6 +20,7 @@ export function App() {
|
|||||||
const logout = useAuthStore((s) => s.logout);
|
const logout = useAuthStore((s) => s.logout);
|
||||||
const loadChats = useChatStore((s) => s.loadChats);
|
const loadChats = useChatStore((s) => s.loadChats);
|
||||||
const setActiveChatId = useChatStore((s) => s.setActiveChatId);
|
const setActiveChatId = useChatStore((s) => s.setActiveChatId);
|
||||||
|
const showToast = useUiStore((s) => s.showToast);
|
||||||
const [joiningInvite, setJoiningInvite] = useState(false);
|
const [joiningInvite, setJoiningInvite] = useState(false);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -79,12 +81,15 @@ export function App() {
|
|||||||
const chat = await joinByInvite(token);
|
const chat = await joinByInvite(token);
|
||||||
await loadChats();
|
await loadChats();
|
||||||
setActiveChatId(chat.id);
|
setActiveChatId(chat.id);
|
||||||
window.localStorage.removeItem(PENDING_INVITE_TOKEN_KEY);
|
showToast("Joined by invite");
|
||||||
|
} catch (error) {
|
||||||
|
showToast(inviteJoinErrorMessage(error));
|
||||||
} finally {
|
} finally {
|
||||||
|
window.localStorage.removeItem(PENDING_INVITE_TOKEN_KEY);
|
||||||
setJoiningInvite(false);
|
setJoiningInvite(false);
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
}, [accessToken, me, joiningInvite, loadChats, setActiveChatId]);
|
}, [accessToken, me, joiningInvite, loadChats, setActiveChatId, showToast]);
|
||||||
|
|
||||||
if (!accessToken || !me) {
|
if (!accessToken || !me) {
|
||||||
return <AuthPage />;
|
return <AuthPage />;
|
||||||
@@ -120,3 +125,28 @@ function extractEmailVerificationTokenFromLocation(): string | null {
|
|||||||
}
|
}
|
||||||
return url.searchParams.get("token")?.trim() || null;
|
return url.searchParams.get("token")?.trim() || null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function inviteJoinErrorMessage(error: unknown): string {
|
||||||
|
const status = getHttpStatusCode(error);
|
||||||
|
if (status === 404) {
|
||||||
|
return "Invite link not found or expired.";
|
||||||
|
}
|
||||||
|
if (status === 403) {
|
||||||
|
return "You are not allowed to join by this invite.";
|
||||||
|
}
|
||||||
|
if (status === 409) {
|
||||||
|
return "You are already a member of this chat.";
|
||||||
|
}
|
||||||
|
return "Failed to join by invite.";
|
||||||
|
}
|
||||||
|
|
||||||
|
function getHttpStatusCode(error: unknown): number | null {
|
||||||
|
if (!error || typeof error !== "object") {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
const maybeResponse = (error as { response?: { status?: unknown } }).response;
|
||||||
|
if (!maybeResponse || typeof maybeResponse.status !== "number") {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return maybeResponse.status;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user