Skip to content

Commit c9c868b

Browse files
tlongwell-blocknpub1qyvc0c5kl4gqv2fd97fsk46tu378sqgy35vc83rvgfwne90sel7s0ed67dTyler Longwellnpub17jjz49l9jjmhhk7cac63j8yt9z555n9cw8vk7v5jz4vzw4ppld5qgj57ccnpub1cc3ha7z055mu0rwwu7806t2wt8mj3pvu0uv5mfp2c50dahaqhczshdalg6
authored
Community moderation UI: integration branch (data layer + member surface base) (block#1617)
Signed-off-by: Tyler Longwell <[email protected]> Signed-off-by: tlongwell-block <[email protected]> Signed-off-by: npub1mprnacetjua2xx3p5eddmhxyk6wv929ymm5py8kd2xfxurxahspqqlgyta <d8473ee32b973aa31a21a65adddcc4b69cc2a8a4dee8121ecd51926e0cddbc02@sprout-oss.stage.blox.sqprod.co> Co-authored-by: npub1qyvc0c5kl4gqv2fd97fsk46tu378sqgy35vc83rvgfwne90sel7s0ed67d <011987e296fd5006292d2f930b574be47c7801048d1983c46c425d3c95f0cffd@sprout-oss.stage.blox.sqprod.co> Co-authored-by: Tyler Longwell <[email protected]> Co-authored-by: npub17jjz49l9jjmhhk7cac63j8yt9z555n9cw8vk7v5jz4vzw4ppld5qgj57cc <f4a42a97e594b77bdbd8ee35191c8b28a94a4cb871d96f32921558275421fb68@sprout-oss.stage.blox.sqprod.co> Co-authored-by: npub1cc3ha7z055mu0rwwu7806t2wt8mj3pvu0uv5mfp2c50dahaqhczshdalg6 <c6237ef84fa537c78dcee78efd2d4e59f728859c7f194da42ac51ededfa0be05@sprout-oss.stage.blox.sqprod.co> Co-authored-by: npub1jmc9dt2lyvzu3h0kxlwxt5zg4fxp9476awyxw6gwxn72g6cw7exqs64whm <96f056ad5f2305c8ddf637dc65d048aa4c12d7daeb8867690e34fca46b0ef64c@sprout-oss.stage.blox.sqprod.co> Co-authored-by: npub1mprnacetjua2xx3p5eddmhxyk6wv929ymm5py8kd2xfxurxahspqqlgyta <d8473ee32b973aa31a21a65adddcc4b69cc2a8a4dee8121ecd51926e0cddbc02@sprout-oss.stage.blox.sqprod.co>
1 parent 863aeb7 commit c9c868b

31 files changed

Lines changed: 3360 additions & 115 deletions

‎desktop/src-tauri/src/commands/identity_archive.rs‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ struct RelayInformationDocument {
227227
self_: Option<String>,
228228
}
229229

230-
async fn fetch_relay_self(state: &AppState) -> Result<Option<String>, String> {
230+
pub(crate) async fn fetch_relay_self(state: &AppState) -> Result<Option<String>, String> {
231231
let relay_url = relay_ws_url_with_override(state);
232232
let http_url = relay_http_base_url(&relay_url);
233233
let response = state
@@ -318,6 +318,18 @@ pub async fn list_archived_identities(
318318
})
319319
}
320320

321+
/// Read the active relay's NIP-11 `self` pubkey (its own signing key, hex).
322+
///
323+
/// A public, unauthenticated document read reused by the moderation UI to tell
324+
/// whether a DM peer is the relay identity (a moderation DM). Fails open: an
325+
/// unreachable relay, a document without `self`, or a malformed value all
326+
/// return `None`, and callers must treat that as "not the relay" — the disable
327+
/// is an affordance, not enforcement, so a false negative is the safe failure.
328+
#[tauri::command]
329+
pub async fn get_relay_self(state: State<'_, AppState>) -> Result<Option<String>, String> {
330+
fetch_relay_self(&state).await
331+
}
332+
321333
// ── Tests ───────────────────────────────────────────────────────────────────
322334

323335
#[cfg(test)]

‎desktop/src-tauri/src/lib.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,7 @@ pub fn run() {
518518
archive_identity,
519519
unarchive_identity,
520520
list_archived_identities,
521+
get_relay_self,
521522
resolve_oa_owner,
522523
list_relay_agents,
523524
list_managed_agents,

‎desktop/src/features/channels/ui/ChannelPane.tsx‎

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ import { Bot, Hash, LogIn, Plus, Sparkles, UserPlus } from "lucide-react";
33
import { useAppNavigation } from "@/app/navigation/useAppNavigation";
44
import { useMediaUpload } from "@/features/messages/lib/useMediaUpload";
55
import { MessageComposer } from "@/features/messages/ui/MessageComposer";
6+
import { ComposerTimeoutBanner } from "@/features/moderation/ui/ComposerTimeoutBanner";
7+
import { useTimeoutState } from "@/features/moderation/lib/timeoutStore";
8+
import { isModerationDm } from "@/features/moderation/lib/moderationDm";
9+
import { useRelaySelfQuery } from "@/features/moderation/hooks";
610
import { DropZoneOverlay } from "@/features/messages/ui/ComposerAttachments";
711
import {
812
MessageThreadPanel,
@@ -269,10 +273,24 @@ export const ChannelPane = React.memo(function ChannelPane({
269273
return true;
270274
}, [findLastOwnEditable, onEdit, threadHeadMessage, threadMessages]);
271275

276+
const timeoutState = useTimeoutState();
277+
278+
// A moderation DM (1:1 with the relay identity) is read-only for the member;
279+
// only DMs pay for the NIP-11 `self` lookup. Fails open: no `relaySelf` →
280+
// ordinary DM, composer enabled.
281+
const relaySelfQuery = useRelaySelfQuery(activeChannel?.channelType === "dm");
282+
const isModerationDmChannel = isModerationDm(
283+
activeChannel ?? null,
284+
currentPubkey,
285+
relaySelfQuery.data,
286+
);
287+
272288
const isComposerDisabled =
273289
!activeChannel?.isMember ||
274290
activeChannel.archivedAt !== null ||
275291
activeChannel.channelType === "forum" ||
292+
timeoutState.active ||
293+
isModerationDmChannel ||
276294
isSending;
277295
const knownAgentPubkeys = React.useMemo(() => {
278296
const pubkeys = new Set<string>();
@@ -676,7 +694,11 @@ export const ChannelPane = React.memo(function ChannelPane({
676694
ref={composerWrapperRef}
677695
>
678696
<div className="pointer-events-auto">
679-
{isActiveWelcomeChannel ? (
697+
{timeoutState.active ? (
698+
<ComposerTimeoutBanner
699+
expiresAtMs={timeoutState.expiresAtMs}
700+
/>
701+
) : isActiveWelcomeChannel ? (
680702
<WelcomeComposerBanner state={welcomeComposerBannerState} />
681703
) : null}
682704
<MessageComposer
@@ -696,16 +718,20 @@ export const ChannelPane = React.memo(function ChannelPane({
696718
onSend={handleSendMessage}
697719
profiles={profiles}
698720
placeholder={
699-
activeChannel?.archivedAt
700-
? "Archived channels are read-only."
701-
: activeChannel?.channelType === "forum"
702-
? "Forum posting is not wired in this pass."
703-
: activeChannel
704-
? activeChannel.channelType === "dm" &&
705-
directMessageIntro
706-
? `Message ${directMessageIntro.displayName}`
707-
: `Message #${activeChannel.name}`
708-
: "Select a channel"
721+
timeoutState.active
722+
? "You're timed out by community moderators."
723+
: isModerationDmChannel
724+
? "This channel is read-only."
725+
: activeChannel?.archivedAt
726+
? "Archived channels are read-only."
727+
: activeChannel?.channelType === "forum"
728+
? "Forum posting is not wired in this pass."
729+
: activeChannel
730+
? activeChannel.channelType === "dm" &&
731+
directMessageIntro
732+
? `Message ${directMessageIntro.displayName}`
733+
: `Message #${activeChannel.name}`
734+
: "Select a channel"
709735
}
710736
showTopBorder={false}
711737
/>
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
import * as React from "react";
2+
3+
import { useUpdateManagedAgentMutation } from "@/features/agents/hooks";
4+
import { CreateAgentRespondToField } from "@/features/agents/ui/RespondToField";
5+
import type { ManagedAgent, RespondToMode } from "@/shared/api/types";
6+
import { Button } from "@/shared/ui/button";
7+
import {
8+
Dialog,
9+
DialogContent,
10+
DialogDescription,
11+
DialogHeader,
12+
DialogTitle,
13+
} from "@/shared/ui/dialog";
14+
15+
export function EditRespondToDialog({
16+
agent,
17+
currentPubkey,
18+
onOpenChange,
19+
open,
20+
}: {
21+
agent: ManagedAgent | null;
22+
currentPubkey?: string;
23+
onOpenChange: (open: boolean) => void;
24+
open: boolean;
25+
}) {
26+
const updateMutation = useUpdateManagedAgentMutation();
27+
const [respondTo, setRespondTo] = React.useState<RespondToMode>("owner-only");
28+
const [respondToAllowlist, setRespondToAllowlist] = React.useState<string[]>(
29+
[],
30+
);
31+
32+
React.useEffect(() => {
33+
if (agent) {
34+
setRespondTo(agent.respondTo);
35+
setRespondToAllowlist([...agent.respondToAllowlist]);
36+
}
37+
}, [agent]);
38+
39+
const respondToValid =
40+
respondTo !== "allowlist" || respondToAllowlist.length > 0;
41+
42+
async function handleSave() {
43+
if (!agent) return;
44+
await updateMutation.mutateAsync({
45+
pubkey: agent.pubkey,
46+
respondTo,
47+
respondToAllowlist:
48+
respondTo === "allowlist" ? respondToAllowlist : undefined,
49+
});
50+
onOpenChange(false);
51+
}
52+
53+
return (
54+
<Dialog onOpenChange={onOpenChange} open={open}>
55+
<DialogContent className="max-w-md">
56+
<DialogHeader>
57+
<DialogTitle>Edit respond-to</DialogTitle>
58+
<DialogDescription>
59+
Choose who {agent?.name ?? "this agent"} responds to.
60+
</DialogDescription>
61+
</DialogHeader>
62+
<CreateAgentRespondToField
63+
allowlist={respondToAllowlist}
64+
disabled={updateMutation.isPending}
65+
mode={respondTo}
66+
onAllowlistChange={setRespondToAllowlist}
67+
onModeChange={setRespondTo}
68+
ownerPubkey={currentPubkey}
69+
/>
70+
{updateMutation.error instanceof Error ? (
71+
<p className="text-sm text-destructive">
72+
{updateMutation.error.message}
73+
</p>
74+
) : null}
75+
<div className="flex justify-end gap-2">
76+
<Button
77+
onClick={() => onOpenChange(false)}
78+
size="sm"
79+
type="button"
80+
variant="outline"
81+
>
82+
Cancel
83+
</Button>
84+
<Button
85+
disabled={!respondToValid || updateMutation.isPending}
86+
onClick={() => void handleSave()}
87+
size="sm"
88+
type="button"
89+
>
90+
{updateMutation.isPending ? "Saving..." : "Save"}
91+
</Button>
92+
</div>
93+
</DialogContent>
94+
</Dialog>
95+
);
96+
}

‎desktop/src/features/channels/ui/MembersSidebar.tsx‎

Lines changed: 27 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,11 @@ import {
66
useChannelMembersQuery,
77
useChannelsQuery,
88
} from "@/features/channels/hooks";
9-
import { useUpdateManagedAgentMutation } from "@/features/agents/hooks";
109
import {
1110
coalesceAgentAutocompleteCandidates,
1211
getMentionableAgentPubkeys,
1312
getSharedChannelIds,
1413
} from "@/features/agents/lib/agentAutocompleteEligibility";
15-
import { CreateAgentRespondToField } from "@/features/agents/ui/RespondToField";
1614
import { useIsArchivedPredicate } from "@/features/identity-archive/hooks";
1715
import { useClassifiedMembers } from "@/features/channels/lib/useClassifiedMembers";
1816
import { formatMemberName } from "@/features/channels/lib/memberUtils";
@@ -32,15 +30,13 @@ import type {
3230
Channel,
3331
ChannelMember,
3432
ManagedAgent,
35-
RespondToMode,
3633
UserSearchResult,
3734
} from "@/shared/api/types";
3835
import { Button } from "@/shared/ui/button";
3936
import {
4037
Dialog,
4138
DialogClose,
4239
DialogContent,
43-
DialogDescription,
4440
DialogHeader,
4541
DialogTitle,
4642
} from "@/shared/ui/dialog";
@@ -54,10 +50,13 @@ import {
5450
MODAL_SEARCH_SHELL_CLASS,
5551
} from "@/shared/ui/modalSearchStyles";
5652
import { MembersSidebarMemberCard } from "./MembersSidebarMemberCard";
53+
import { EditRespondToDialog } from "./EditRespondToDialog";
5754
import { useMembersSidebarActions } from "./useMembersSidebarActions";
55+
import { useMembersSidebarModeration } from "./useMembersSidebarModeration";
5856
const MEMBER_ADD_RESULT_LIMIT = 50;
5957
const MEMBER_ROW_INSET_DIVIDER_CLASS =
6058
"after:pointer-events-none after:absolute after:bottom-0 after:left-[3.75rem] after:right-0 after:h-px after:bg-border/60 after:content-[''] last:after:hidden";
59+
6160
function formatAddCandidateName(user: UserSearchResult) {
6261
return (
6362
user.displayName?.trim() ||
@@ -437,6 +436,17 @@ export function MembersSidebar({
437436

438437
const canManageMembers =
439438
selfMember?.role === "owner" || selfMember?.role === "admin";
439+
440+
const {
441+
canModerate,
442+
isModerationPending,
443+
moderationStateByPubkey,
444+
onBan,
445+
onUnban,
446+
onTimeout,
447+
onUntimeout,
448+
} = useMembersSidebarModeration(open);
449+
440450
const isArchived =
441451
channel?.archivedAt !== null && channel?.archivedAt !== undefined;
442452
const managedAgentByPubkey = React.useMemo(
@@ -563,8 +573,13 @@ export function MembersSidebar({
563573
<div className="content-visibility-auto" key={member.pubkey}>
564574
<MembersSidebarMemberCard
565575
canChangeRole={canManageMembers && member.pubkey !== currentPubkey}
576+
canModerate={canModerate && member.pubkey !== currentPubkey}
566577
canRemoveMember={canRemoveMember(member)}
567-
isActionPending={isActionPending || changeRoleMutation.isPending}
578+
isActionPending={
579+
isActionPending ||
580+
changeRoleMutation.isPending ||
581+
isModerationPending
582+
}
568583
isArchived={isArchived}
569584
managedAgent={
570585
memberIsBot
@@ -577,6 +592,10 @@ export function MembersSidebar({
577592
member.displayName ?? truncatePubkey(member.pubkey)
578593
}
579594
memberLabel={formatMemberName(member, currentPubkey)}
595+
moderationState={moderationStateByPubkey.get(
596+
normalizePubkey(member.pubkey),
597+
)}
598+
onBan={onBan}
580599
onChangeRole={(m, role) => {
581600
void changeRoleMutation.mutateAsync({ pubkey: m.pubkey, role });
582601
}}
@@ -586,6 +605,9 @@ export function MembersSidebar({
586605
}}
587606
onOpenProfile={handleOpenProfile}
588607
onRemoveMember={handleRemoveMember}
608+
onTimeout={onTimeout}
609+
onUnban={onUnban}
610+
onUntimeout={onUntimeout}
589611
onViewActivity={
590612
onViewActivity
591613
? (pubkey: string) => {
@@ -897,86 +919,3 @@ function AddMemberSearchResultRow({
897919
</div>
898920
);
899921
}
900-
901-
function EditRespondToDialog({
902-
agent,
903-
currentPubkey,
904-
onOpenChange,
905-
open,
906-
}: {
907-
agent: ManagedAgent | null;
908-
currentPubkey?: string;
909-
onOpenChange: (open: boolean) => void;
910-
open: boolean;
911-
}) {
912-
const updateMutation = useUpdateManagedAgentMutation();
913-
const [respondTo, setRespondTo] = React.useState<RespondToMode>("owner-only");
914-
const [respondToAllowlist, setRespondToAllowlist] = React.useState<string[]>(
915-
[],
916-
);
917-
918-
React.useEffect(() => {
919-
if (agent) {
920-
setRespondTo(agent.respondTo);
921-
setRespondToAllowlist([...agent.respondToAllowlist]);
922-
}
923-
}, [agent]);
924-
925-
const respondToValid =
926-
respondTo !== "allowlist" || respondToAllowlist.length > 0;
927-
928-
async function handleSave() {
929-
if (!agent) return;
930-
await updateMutation.mutateAsync({
931-
pubkey: agent.pubkey,
932-
respondTo,
933-
respondToAllowlist:
934-
respondTo === "allowlist" ? respondToAllowlist : undefined,
935-
});
936-
onOpenChange(false);
937-
}
938-
939-
return (
940-
<Dialog onOpenChange={onOpenChange} open={open}>
941-
<DialogContent className="max-w-md">
942-
<DialogHeader>
943-
<DialogTitle>Edit respond-to</DialogTitle>
944-
<DialogDescription>
945-
Choose who {agent?.name ?? "this agent"} responds to.
946-
</DialogDescription>
947-
</DialogHeader>
948-
<CreateAgentRespondToField
949-
allowlist={respondToAllowlist}
950-
disabled={updateMutation.isPending}
951-
mode={respondTo}
952-
onAllowlistChange={setRespondToAllowlist}
953-
onModeChange={setRespondTo}
954-
ownerPubkey={currentPubkey}
955-
/>
956-
{updateMutation.error instanceof Error ? (
957-
<p className="text-sm text-destructive">
958-
{updateMutation.error.message}
959-
</p>
960-
) : null}
961-
<div className="flex justify-end gap-2">
962-
<Button
963-
onClick={() => onOpenChange(false)}
964-
size="sm"
965-
type="button"
966-
variant="outline"
967-
>
968-
Cancel
969-
</Button>
970-
<Button
971-
disabled={!respondToValid || updateMutation.isPending}
972-
onClick={() => void handleSave()}
973-
size="sm"
974-
type="button"
975-
>
976-
{updateMutation.isPending ? "Saving..." : "Save"}
977-
</Button>
978-
</div>
979-
</DialogContent>
980-
</Dialog>
981-
);
982-
}

0 commit comments

Comments
 (0)