Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
coalesceAgentAutocompleteCandidates,
getMentionableAgentPubkeys,
getSharedChannelIds,
isAgentIdentityInManagedList,
isAgentIdentityInAllowedList,
relayAgentIsSharedWithUser,
shouldHideAgentFromMentions,
} from "./agentAutocompleteEligibility.ts";
Expand Down Expand Up @@ -136,27 +136,27 @@ test("getMentionableAgentPubkeys: keeps managed agents and shared relay agents",
assert.deepEqual(result, new Set([PUB_A, PUB_B, PUB_C]));
});

test("isAgentIdentityInManagedList: keeps people and only current managed agent identities", () => {
const managedAgentPubkeys = new Set([PUB_A]);
test("isAgentIdentityInAllowedList: keeps people and only listed agent identities", () => {
const allowedAgentPubkeys = new Set([PUB_A]);

assert.equal(
isAgentIdentityInManagedList(
isAgentIdentityInAllowedList(
{ isAgent: false, pubkey: PUB_B },
managedAgentPubkeys,
allowedAgentPubkeys,
),
true,
);
assert.equal(
isAgentIdentityInManagedList(
isAgentIdentityInAllowedList(
{ isAgent: true, pubkey: PUB_A.toUpperCase() },
managedAgentPubkeys,
allowedAgentPubkeys,
),
true,
);
assert.equal(
isAgentIdentityInManagedList(
isAgentIdentityInAllowedList(
{ isAgent: true, pubkey: PUB_B },
managedAgentPubkeys,
allowedAgentPubkeys,
),
false,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ export function getMentionableAgentPubkeys({
return pubkeys;
}

export function isAgentIdentityInManagedList(
export function isAgentIdentityInAllowedList(
candidate: { isAgent?: boolean; pubkey: string },
managedAgentPubkeys: ReadonlySet<string>,
allowedAgentPubkeys: ReadonlySet<string>,
) {
return (
candidate.isAgent !== true ||
managedAgentPubkeys.has(normalizePubkey(candidate.pubkey))
allowedAgentPubkeys.has(normalizePubkey(candidate.pubkey))
);
}

Expand Down
4 changes: 2 additions & 2 deletions desktop/src/features/channels/ui/MembersSidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
import { attachManagedAgentToChannel } from "@/features/agents/channelAgents";
import {
coalesceAgentAutocompleteCandidates,
isAgentIdentityInManagedList,
isAgentIdentityInAllowedList,
} from "@/features/agents/lib/agentAutocompleteEligibility";
import { useIsArchivedPredicate } from "@/features/identity-archive/hooks";
import { useClassifiedMembers } from "@/features/channels/lib/useClassifiedMembers";
Expand Down Expand Up @@ -282,7 +282,7 @@ export function MembersSidebar({
)) ||
memberPubkeys.has(pubkey) ||
isArchivedDiscovery(pubkey) ||
!isAgentIdentityInManagedList(candidate, managedAgentPubkeys)
!isAgentIdentityInAllowedList(candidate, managedAgentPubkeys)
) {
return;
}
Expand Down
3 changes: 2 additions & 1 deletion desktop/src/features/forum/ui/ForumComposer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import { useCompactComposerInteractions } from "./useCompactComposerInteractions

export function ForumComposer({
channelId = null,
channelType,
members,
className,
placeholder,
Expand Down Expand Up @@ -69,7 +70,7 @@ export function ForumComposer({
if (compact) setIsCompactExpanded(true);
}, [compact]);

const mentions = useMentions(channelId, members, profiles);
const mentions = useMentions(channelId, members, profiles, { channelType });
const channelLinks = useChannelLinks();
const media = useMediaUpload();
const { handlePaperclipClick, handleToolbarMouseDown, shouldIgnoreBlur } =
Expand Down
4 changes: 3 additions & 1 deletion desktop/src/features/forum/ui/ForumComposer.types.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import type * as React from "react";

import type { UserProfileLookup } from "@/features/profile/lib/identity";
import type { ChannelMember } from "@/shared/api/types";
import type { ChannelMember, ChannelType } from "@/shared/api/types";

export type ForumComposerProps = {
channelId?: string | null;
/** Known channel type for channel-backed composers; omitted uses fail closed. */
channelType?: ChannelType | null;
/** Override mention source when no channel is available (e.g. Pulse). */
members?: ChannelMember[];
className?: string;
Expand Down
1 change: 1 addition & 0 deletions desktop/src/features/forum/ui/ForumThreadPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ export function ForumThreadPanel({
<div className="border-t border-border/60 p-4">
<ForumComposer
channelId={channelId}
channelType="forum"
isSending={isSendingReply}
onSubmit={onReply}
placeholder="Reply to this post..."
Expand Down
1 change: 1 addition & 0 deletions desktop/src/features/forum/ui/ForumView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ export function ForumView({
<ForumComposer
autocompleteBelow
channelId={channel.id}
channelType="forum"
isSending={createPostMutation.isPending}
onCancel={() => setIsComposerOpen(false)}
onSubmit={async (content, mentionPubkeys, mediaTags) => {
Expand Down
14 changes: 7 additions & 7 deletions desktop/src/features/messages/lib/useMentions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
coalesceAutocompleteCandidatesByKey,
getMentionableAgentPubkeys,
getSharedChannelIds,
isAgentIdentityInManagedList,
isAgentIdentityInAllowedList,
shouldHideAgentFromMentions,
} from "@/features/agents/lib/agentAutocompleteEligibility";
import {
Expand Down Expand Up @@ -93,7 +93,6 @@ export function useMentions(
const mentionMapRef = React.useRef<Map<string, string>>(new Map());
const personaMentionMapRef = React.useRef<Map<string, string>>(new Map());
const previousSuggestionsRef = React.useRef<MentionSuggestion[]>([]);
void options?.channelType;
const mentionSearchQuery = mentionQuery?.trim() ?? "";
const canSearchGlobalPeople = mentionSearchQuery.length > 0;
const identityQuery = useIdentityQuery();
Expand Down Expand Up @@ -238,15 +237,18 @@ export function useMentions(
new Set((members ?? []).map((member) => normalizePubkey(member.pubkey))),
[members],
);
const allowedAgentPubkeys =
options?.channelType === "stream" || options?.channelType === "forum"
? mentionableAgentPubkeys
: managedAgentPubkeys;
const mentionCandidates = React.useMemo<MentionCandidate[]>(() => {
const candidatesByPubkey = new Map<string, MentionCandidate>();

const addCandidate = (candidate: MentionCandidate & { pubkey: string }) => {
const pubkey = normalizePubkey(candidate.pubkey);
if (isArchivedDiscovery(pubkey)) {
return;
}
if (!isAgentIdentityInManagedList(candidate, managedAgentPubkeys)) {
if (!isAgentIdentityInAllowedList(candidate, allowedAgentPubkeys)) {
return;
}
if (
Expand All @@ -265,7 +267,6 @@ export function useMentions(
candidatesByPubkey.set(pubkey, { ...candidate, pubkey });
return;
}

candidatesByPubkey.set(pubkey, {
...current,
avatarUrl: current.avatarUrl ?? candidate.avatarUrl ?? null,
Expand Down Expand Up @@ -330,7 +331,6 @@ export function useMentions(
: null,
});
}

for (const agent of relayAgentsQuery.data ?? []) {
const pubkey = normalizePubkey(agent.pubkey);
addCandidate({
Expand Down Expand Up @@ -412,6 +412,7 @@ export function useMentions(
}, [
activePersonaById,
activePersonas,
allowedAgentPubkeys,
userSearchResults,
canSearchGlobalUsers,
currentPubkey,
Expand All @@ -420,7 +421,6 @@ export function useMentions(
managedAgentNamesByPubkey,
managedAgentPersonaIds,
managedAgentPersonaIdsByPubkey,
managedAgentPubkeys,
managedAgentsQuery.data,
memberPubkeys,
members,
Expand Down
Loading