Skip to content

armgit / alook

Public Imported from GitHub
0

Multi-Agent Collaboration for Team and Friends

fix(community): resolve users/entities by id, never by display name

Gener220683781571
diff --git a/src/web/src/app/api/community/invites/[token]/info/route.ts b/src/web/src/app/api/community/invites/[token]/info/route.ts
index f87e4bb71..1da1ccbdc 100644
--- a/src/web/src/app/api/community/invites/[token]/info/route.ts
+++ b/src/web/src/app/api/community/invites/[token]/info/route.ts
@@ -30,6 +30,7 @@ export const GET = withAuth(async (_req, ctx) => {
const memberCount = await queries.communityMember.countMembers(db, invite.serverId)
return writeJSON({
+ serverId: invite.serverId,
serverName: server.name,
serverIcon: serverIconUrl(server),
memberCount,
diff --git a/src/web/src/app/community/channels/[serverId]/[channelId]/page.tsx b/src/web/src/app/community/channels/[serverId]/[channelId]/page.tsx
index a346f1d8e..ba41b335a 100644
--- a/src/web/src/app/community/channels/[serverId]/[channelId]/page.tsx
+++ b/src/web/src/app/community/channels/[serverId]/[channelId]/page.tsx
@@ -504,23 +504,17 @@ function ChannelView() {
searchQuery,
myRole,
onSearch: doSearch,
- onSetRole: (name: string, role: Role) => {
- const m = members.find((x) => x.name === name)
- if (m) {
- setMemberRoleMut.mutate({ serverId, memberId: m.id, role }, {
- onSuccess: () => toast("Role updated"),
- onError: () => toast("Failed to update role"),
- })
- }
+ onSetRole: (memberId: string, role: Role) => {
+ setMemberRoleMut.mutate({ serverId, memberId, role }, {
+ onSuccess: () => toast("Role updated"),
+ onError: () => toast("Failed to update role"),
+ })
},
- onKickMember: (name: string) => {
- const m = members.find((x) => x.name === name)
- if (m) {
- kickMemberMut.mutate({ serverId, memberId: m.id }, {
- onSuccess: () => toast("Member kicked"),
- onError: () => toast("Failed to kick member"),
- })
- }
+ onKickMember: (memberId: string) => {
+ kickMemberMut.mutate({ serverId, memberId }, {
+ onSuccess: () => toast("Member kicked"),
+ onError: () => toast("Failed to kick member"),
+ })
},
onJumpToMessage: (id: string) => {
setScrollToMessageId(id)
diff --git a/src/web/src/app/community/channels/layout.tsx b/src/web/src/app/community/channels/layout.tsx
index 24d7e5d60..ddc03e607 100644
--- a/src/web/src/app/community/channels/layout.tsx
+++ b/src/web/src/app/community/channels/layout.tsx
@@ -395,23 +395,17 @@ export default function ServerLayout({ children }: { children: ReactNode }) {
invitesLoading={invitesLoading}
auditLog={auditLog}
auditLogLoading={auditLogLoading}
- onKickMember={(name) => {
- const m = membersHook.members.find((x) => x.name === name)
- if (m) {
- kickMemberMut.mutate({ serverId, memberId: m.id }, {
- onSuccess: () => toast("Member kicked"),
- onError: () => toast("Failed to kick member"),
- })
- }
+ onKickMember={(memberId) => {
+ kickMemberMut.mutate({ serverId, memberId }, {
+ onSuccess: () => toast("Member kicked"),
+ onError: () => toast("Failed to kick member"),
+ })
}}
- onSetRole={(name, role) => {
- const m = membersHook.members.find((x) => x.name === name)
- if (m) {
- setMemberRoleMut.mutate({ serverId, memberId: m.id, role }, {
- onSuccess: () => toast("Role updated"),
- onError: () => toast("Failed to update role"),
- })
- }
+ onSetRole={(memberId, role) => {
+ setMemberRoleMut.mutate({ serverId, memberId, role }, {
+ onSuccess: () => toast("Role updated"),
+ onError: () => toast("Failed to update role"),
+ })
}}
onRevokeInvite={(code) => revokeInviteMut.mutate({ serverId, code }, {
onSuccess: () => toast("Invite revoked"),
diff --git a/src/web/src/app/community/preview/_mock.ts b/src/web/src/app/community/preview/_mock.ts
index 9b23ec95f..b9f498c9c 100644
--- a/src/web/src/app/community/preview/_mock.ts
+++ b/src/web/src/app/community/preview/_mock.ts
@@ -301,9 +301,9 @@ export const DM_MESSAGES: Record<string, Msg[]> = {
}
export const PROFILES: Record<string, Profile> = {
- Gener: { name: "Gener", discriminator: "0042", avatar: "G", role: "Owner", about: "Building Alook. Coffee, agents, and warm gray UIs.", mutual: 3, statusEmoji: "🎧", statusText: "Vibing" },
- Gus: { name: "Gus", discriminator: "1337", avatar: "Gu", role: "Admin", about: "Tinkering with email-driven workflows.", mutual: 2, statusEmoji: "πŸ¦₯", statusText: "Chillin'" },
- Lindsay: { name: "Lindsay", discriminator: "0007", avatar: "L", role: "Admin", about: "Research lead. Ask me about presets.", mutual: 2 },
+ Gener: { name: "Gener", userId: "u_gener", discriminator: "0042", avatar: "G", role: "Owner", about: "Building Alook. Coffee, agents, and warm gray UIs.", mutual: 3, statusEmoji: "🎧", statusText: "Vibing" },
+ Gus: { name: "Gus", userId: "u_gus", discriminator: "1337", avatar: "Gu", role: "Admin", about: "Tinkering with email-driven workflows.", mutual: 2, statusEmoji: "πŸ¦₯", statusText: "Chillin'" },
+ Lindsay: { name: "Lindsay", userId: "u_lindsay", discriminator: "0007", avatar: "L", role: "Admin", about: "Research lead. Ask me about presets.", mutual: 2 },
}
export const INVITES: InviteRow[] = [
diff --git a/src/web/src/app/community/preview/page.tsx b/src/web/src/app/community/preview/page.tsx
index 50f411e67..0f30460ab 100644
--- a/src/web/src/app/community/preview/page.tsx
+++ b/src/web/src/app/community/preview/page.tsx
@@ -135,6 +135,7 @@ export default function CommunityPreview() {
?? friendList.find((f) => f.name === name)
let data: Profile = PROFILES[name] ?? {
name,
+ userId: member?.userId ?? member?.id,
avatar: member?.avatar ?? name.charAt(0).toUpperCase(),
role: "member",
about: member && "sub" in member && member.sub ? member.sub : "No bio yet.",
@@ -153,10 +154,12 @@ export default function CommunityPreview() {
let msgSeq = messages.length
// message from profile card β€” find or create a DM, append the message, and navigate
- const profileMessage = (name: string, text: string) => {
- let target = dmList.find((d) => d.name === name)
+ const profileMessage = (userId: string, text: string) => {
+ const source = memberList.find((m) => m.userId === userId) ?? friendList.find((f) => f.userId === userId)
+ const name = source?.name ?? userId
+ let target = dmList.find((d) => d.userId === userId)
if (!target) {
- target = { id: `dm_${name.toLowerCase()}`, userId: `u_${name.toLowerCase()}`, name, avatar: name.charAt(0).toUpperCase(), status: "online" as const, preview: text.slice(0, 40) }
+ target = { id: `dm_${userId}`, userId, name, avatar: name.charAt(0).toUpperCase(), status: "online" as const, preview: text.slice(0, 40) }
setDmList((prev) => [target!, ...prev])
}
const dmId = target.id
@@ -591,7 +594,7 @@ export default function CommunityPreview() {
{...profileProps}
/>
)}
- {profile && <ProfileCard data={profile.data} x={profile.x} y={profile.y} bp={bp} onClose={() => setProfile(null)} onMessage={profileMessage} isSelf={profile.data.name === "Gener"} onUpdateStatus={(emoji, text) => { setMyStatus({ emoji, text }); setProfile((p) => p ? { ...p, data: { ...p.data, statusEmoji: emoji, statusText: text } } : p) }} />}
+ {profile && <ProfileCard data={profile.data} x={profile.x} y={profile.y} bp={bp} onClose={() => setProfile(null)} onMessage={profileMessage} isSelf={profile.data.userId === "u_gener"} onUpdateStatus={(emoji, text) => { setMyStatus({ emoji, text }); setProfile((p) => p ? { ...p, data: { ...p.data, statusEmoji: emoji, statusText: text } } : p) }} />}
{preview && <ImageLightbox src={preview} onClose={() => setPreview(null)} />}
{dialogs}
</Shell>
@@ -628,7 +631,7 @@ export default function CommunityPreview() {
{...profileProps}
/>
)}
- {profile && <ProfileCard data={profile.data} x={profile.x} y={profile.y} bp={bp} onClose={() => setProfile(null)} onMessage={profileMessage} isSelf={profile.data.name === "Gener"} onUpdateStatus={(emoji, text) => { setMyStatus({ emoji, text }); setProfile((p) => p ? { ...p, data: { ...p.data, statusEmoji: emoji, statusText: text } } : p) }} />}
+ {profile && <ProfileCard data={profile.data} x={profile.x} y={profile.y} bp={bp} onClose={() => setProfile(null)} onMessage={profileMessage} isSelf={profile.data.userId === "u_gener"} onUpdateStatus={(emoji, text) => { setMyStatus({ emoji, text }); setProfile((p) => p ? { ...p, data: { ...p.data, statusEmoji: emoji, statusText: text } } : p) }} />}
{preview && <ImageLightbox src={preview} onClose={() => setPreview(null)} />}
{dialogs}
</Shell>
diff --git a/src/web/src/components/community/_types.ts b/src/web/src/components/community/_types.ts
index 6a30536d5..81c09b2a6 100644
--- a/src/web/src/components/community/_types.ts
+++ b/src/web/src/components/community/_types.ts
@@ -214,6 +214,10 @@ export type DM = {
// ── Profile ──────────────────────────────────────────────────────────────────
export type Profile = {
name: string
+ // Stable user id of the profile's owner β€” the exact-match key for DM-target
+ // resolution and self-detection (never match by non-unique display name).
+ // Optional so mock/older Profile-constructing sites keep type-checking.
+ userId?: string
// 4-digit discriminator hash of user.id (`"0042"`) β€” undefined while the
// profile fetch is in flight. See computeDiscriminator in @alook/shared.
discriminator?: string
diff --git a/src/web/src/components/community/community-invite-card.tsx b/src/web/src/components/community/community-invite-card.tsx
index 05dd12024..3ec5ea512 100644
--- a/src/web/src/components/community/community-invite-card.tsx
+++ b/src/web/src/components/community/community-invite-card.tsx
@@ -11,6 +11,7 @@ import { Button } from "@/components/ui/button"
import { Skeleton } from "@/components/ui/skeleton"
type InviteInfo = {
+ serverId: string
serverName: string
serverIcon: string | null
memberCount: number
@@ -35,7 +36,7 @@ export function CommunityInviteCard({ token }: { token: string }) {
})
const alreadyMemberServerId = data
- ? servers.find((s) => s.name === data.serverName)?.id
+ ? servers.find((s) => s.id === data.serverId)?.id
: undefined
const onJoin = async () => {
diff --git a/src/web/src/components/community/profile-card.tsx b/src/web/src/components/community/profile-card.tsx
index e7c9df584..c38ac9d26 100644
--- a/src/web/src/components/community/profile-card.tsx
+++ b/src/web/src/components/community/profile-card.tsx
@@ -29,7 +29,7 @@ export function ProfileCard({ data, x, y, bp, onClose, onMessage, isSelf, onUpda
y: number
bp: Breakpoint
onClose: () => void
- onMessage?: (name: string, text: string) => void
+ onMessage?: (userId: string, text: string) => void
isSelf?: boolean
// Only used when `isSelf` β€” the inline status row opens `StatusEditor` and
// calls this on a preset pick / free-text commit / emoji override / clear.
@@ -41,8 +41,8 @@ export function ProfileCard({ data, x, y, bp, onClose, onMessage, isSelf, onUpda
const close = () => setOpen(false)
const send = () => {
const text = msg.trim()
- if (!text) return
- onMessage?.(data.name, text)
+ if (!text || !data.userId) return
+ onMessage?.(data.userId, text)
setMsg("")
mobile ? onClose() : close()
}
diff --git a/src/web/src/components/community/server-settings.tsx b/src/web/src/components/community/server-settings.tsx
index 8ea6b2215..acaf3ecd7 100644
--- a/src/web/src/components/community/server-settings.tsx
+++ b/src/web/src/components/community/server-settings.tsx
@@ -51,8 +51,8 @@ export function ServerSettings({
auditLog: AuditEntry[]
auditLogLoading?: boolean
onOpenProfile?: OpenProfile
- onKickMember?: (name: string) => void
- onSetRole?: (name: string, role: Role) => void
+ onKickMember?: (memberId: string) => void
+ onSetRole?: (memberId: string, role: Role) => void
onRevokeInvite?: (code: string) => void
onCopyInvite?: (code: string) => void
onDeleteServer?: () => void
@@ -173,8 +173,8 @@ function SettingsMembers({ members, loading, loadingMore, hasMore, total, onLoad
onLoadMore?: () => void
onSearch?: (q: string) => void
onOpenProfile?: OpenProfile
- onKickMember?: (name: string) => void
- onSetRole?: (name: string, role: Role) => void
+ onKickMember?: (memberId: string) => void
+ onSetRole?: (memberId: string, role: Role) => void
}) {
const [query, setQuery] = useState("")
const scrollRef = useRef<HTMLDivElement>(null)
@@ -272,13 +272,13 @@ function SettingsMembers({ members, loading, loadingMore, hasMore, total, onLoad
</DropdownMenuTrigger>
<DropdownMenuContent align="end" className="w-32">
{SETTABLE_ROLES.map((r) => (
- <DropdownMenuItem key={r} onClick={() => onSetRole?.(m.name, r)}>{capitalize(r)}</DropdownMenuItem>
+ <DropdownMenuItem key={r} onClick={() => onSetRole?.(m.id, r)}>{capitalize(r)}</DropdownMenuItem>
))}
</DropdownMenuContent>
</DropdownMenu>
)}
{m.role !== "owner" && (
- <Button variant="ghost" size="icon-sm" className="text-muted-foreground hover:text-destructive" aria-label="Kick member" onClick={() => onKickMember?.(m.name)}><Trash2 className="size-4" /></Button>
+ <Button variant="ghost" size="icon-sm" className="text-muted-foreground hover:text-destructive" aria-label="Kick member" onClick={() => onKickMember?.(m.id)}><Trash2 className="size-4" /></Button>
)}
</div>
</div>
diff --git a/src/web/src/components/community/shell-frame.tsx b/src/web/src/components/community/shell-frame.tsx
index b66ba7406..21dd74a03 100644
--- a/src/web/src/components/community/shell-frame.tsx
+++ b/src/web/src/components/community/shell-frame.tsx
@@ -311,10 +311,11 @@ export function ShellFrame({
// pages can trigger this from anywhere via `useCommunityStore.uiHandlers`.
const openProfile = useCallback(
(name: string, e: React.MouseEvent, discriminator?: string, targetUserId?: string) => {
- const isSelf = targetUserId ? targetUserId === currentUser.id : name === currentUser.name
+ const isSelf = !!targetUserId && targetUserId === currentUser.id
if (isSelf) {
const data: Profile = {
name: currentUser.name,
+ userId: currentUser.id,
discriminator: currentUser.discriminator,
avatar: currentUser.avatar || currentUser.name.charAt(0).toUpperCase(),
role: "You",
@@ -337,6 +338,7 @@ export function ShellFrame({
const userId = member && "userId" in member ? (member as { userId: string }).userId : member?.id
const data: Profile = {
name,
+ userId,
// discriminator is undefined until the /profile fetch below hydrates it.
avatar: member?.avatar ?? name.charAt(0).toUpperCase(),
role: displayRole,
@@ -407,17 +409,14 @@ export function ShellFrame({
}
}
- const profileMessage = async (name: string, text: string) => {
- const member = members.find((m) => m.name === name)
- const friend = friends.find((f) => f.name === name)
- const targetUserId = member?.userId ?? friend?.userId
- if (!targetUserId) {
- toast(`Could not find user ${name}`)
+ const profileMessage = async (userId: string, text: string) => {
+ if (!userId) {
+ toast("Could not find user")
return
}
let dmId: string
try {
- const data = await createOrGetDm.mutateAsync({ userId: targetUserId })
+ const data = await createOrGetDm.mutateAsync({ userId })
dmId = data.conversation.id
} catch {
toast("Failed to open DM")
@@ -621,7 +620,7 @@ export function ShellFrame({
<UserBar user={{ name: currentUser.name, avatar: currentUser.avatar }} onOpenProfile={openProfile} onEditProfile={() => setEditingProfile(true)} inbox={inboxElement} hasUnread={inboxHasUnread} />
</div>
</div>
- {profile && <ProfileCard data={profile.data} x={profile.x} y={profile.y} bp={bp} onClose={() => setProfile(null)} onMessage={profileMessage} isSelf={profile.data.name === currentUser.name} onUpdateStatus={updateOwnStatus} />}
+ {profile && <ProfileCard data={profile.data} x={profile.x} y={profile.y} bp={bp} onClose={() => setProfile(null)} onMessage={profileMessage} isSelf={!!profile.data.userId && profile.data.userId === currentUser.id} onUpdateStatus={updateOwnStatus} />}
{preview && <ImageLightbox src={preview} onClose={() => setPreview(null)} />}
{userSettingsDialog}
{avatarCropDialog}
@@ -646,7 +645,7 @@ export function ShellFrame({
{children}
</div>
)}
- {profile && <ProfileCard data={profile.data} x={profile.x} y={profile.y} bp={bp} onClose={() => setProfile(null)} onMessage={profileMessage} isSelf={profile.data.name === currentUser.name} onUpdateStatus={updateOwnStatus} />}
+ {profile && <ProfileCard data={profile.data} x={profile.x} y={profile.y} bp={bp} onClose={() => setProfile(null)} onMessage={profileMessage} isSelf={!!profile.data.userId && profile.data.userId === currentUser.id} onUpdateStatus={updateOwnStatus} />}
{preview && <ImageLightbox src={preview} onClose={() => setPreview(null)} />}
{userSettingsDialog}
{avatarCropDialog}
diff --git a/src/web/src/contexts/channel-context.tsx b/src/web/src/contexts/channel-context.tsx
index 426391092..d494514c8 100644
--- a/src/web/src/contexts/channel-context.tsx
+++ b/src/web/src/contexts/channel-context.tsx
@@ -50,6 +50,11 @@ export function ChannelProvider({
children: ReactNode;
}) {
const [channels, setChannels] = useState<Channel[]>([]);
+ // TODO(id-identity): activeChannel is keyed by name (persisted to
+ // localStorage, compared in rename/delete). Switching to channel id would be
+ // the correct identity key but requires threading id through the context,
+ // its persistence, and every consumer. Collisions are schema-prevented today
+ // (channel is unique on (workspaceId, name)), so this is a follow-up.
const [activeChannel, setActiveChannelState] = useState<string>("default");
const [loading, setLoading] = useState(true);
const [agentId, setAgentId] = useState<string | null>(null);