Skip to content

Commit f5c33d3

Browse files
klopez4212npub13fn4ahfnvaa2qwylvegdgeajqs0mph6v4qsw4jcqnw4mjh3hzh2quuucm5wesbillmanPinky
authored
feat(desktop): Send feedback modal + profile presence chip (#1756)
Signed-off-by: npub13fn4ahfnvaa2qwylvegdgeajqs0mph6v4qsw4jcqnw4mjh3hzh2quuucm5 <8a675edd33677aa0389f6650d467b2041fb0df4ca820eacb009babb95e3715d4@sprout-oss.stage.blox.sqprod.co> Signed-off-by: Wes <[email protected]> Co-authored-by: npub13fn4ahfnvaa2qwylvegdgeajqs0mph6v4qsw4jcqnw4mjh3hzh2quuucm5 <8a675edd33677aa0389f6650d467b2041fb0df4ca820eacb009babb95e3715d4@sprout-oss.stage.blox.sqprod.co> Co-authored-by: Wes <[email protected]> Co-authored-by: Pinky <44b8e82baa6e0e254e0208d68f335c283c94e7b78dd1fa10d5a49d3f13dd0435@sprout-oss.stage.blox.sqprod.co>
1 parent 406cf79 commit f5c33d3

15 files changed

Lines changed: 845 additions & 94 deletions

File tree

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

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,9 +300,15 @@ pub async fn upload_media(
300300

301301
/// Read a picked path through the TOCTOU-safe pipeline (fd pin → sniff →
302302
/// transcode-or-passthrough → MIME validation → upload).
303+
///
304+
/// When `images_only` is set, the file is rejected **before upload** if it is
305+
/// not an image (videos and non-image files error out; HEIC/HEIF still
306+
/// transcode to JPEG, which is an image). This keeps discarded/non-image
307+
/// files from ever leaving the client on image-only surfaces.
303308
async fn process_picked_path(
304309
path: std::path::PathBuf,
305310
state: &State<'_, AppState>,
311+
images_only: bool,
306312
) -> Result<BlobDescriptor, String> {
307313
// Pin the inode by opening the fd BEFORE spawn_blocking. This prevents a
308314
// local attacker from swapping the file between dialog return and read.
@@ -325,6 +331,9 @@ async fn process_picked_path(
325331
let n = file.read(&mut header).map_err(|e| e.to_string())?;
326332

327333
if is_video_file(&header[..n]) {
334+
if images_only {
335+
return Err("Please choose an image file.".to_string());
336+
}
328337
// ffmpeg needs a path, not an fd. Resolve the fd's real path
329338
// so we pass the actual inode's location, not the original
330339
// (potentially swapped) pathname. Same pattern as upload_media.
@@ -357,6 +366,12 @@ async fn process_picked_path(
357366

358367
let mime = detect_and_validate_mime(&body)?;
359368

369+
// Image-only surfaces (e.g. "Send feedback"): reject anything that didn't
370+
// sniff as an image, BEFORE the upload leaves the client.
371+
if images_only && !mime.starts_with("image/") {
372+
return Err("Please choose an image file.".to_string());
373+
}
374+
360375
// Upload video first, then poster (best-effort). If poster upload fails,
361376
// the video descriptor is returned without an image field.
362377
let mut descriptor = do_upload(body, &mime, state, None).await?;
@@ -414,13 +429,51 @@ pub async fn pick_and_upload_media(
414429
let mut descriptors = Vec::with_capacity(file_paths.len());
415430
for file_path in file_paths {
416431
let path = file_path.as_path().ok_or("invalid path")?.to_path_buf();
417-
let descriptor = process_picked_path(path, &state).await?;
432+
let descriptor = process_picked_path(path, &state, false).await?;
418433
descriptors.push(descriptor);
419434
}
420435

421436
Ok(descriptors)
422437
}
423438

439+
/// Open a native single-file dialog constrained to images, read the picked
440+
/// file, and upload it — rejecting anything that doesn't sniff as an image
441+
/// **before** the bytes leave the client.
442+
///
443+
/// This is the secure path for image-only surfaces (e.g. the "Send feedback"
444+
/// attachment). Unlike [`pick_and_upload_media`], the dialog is filtered to
445+
/// common image extensions and `process_picked_path` runs with
446+
/// `images_only = true`, so a user who bypasses the extension filter still
447+
/// can't upload a non-image (videos and other files error out during MIME
448+
/// validation, before `do_upload`). Returns `None` when the user cancels.
449+
#[tauri::command]
450+
pub async fn pick_and_upload_image(
451+
app: tauri::AppHandle,
452+
state: State<'_, AppState>,
453+
) -> Result<Option<BlobDescriptor>, String> {
454+
use tauri_plugin_dialog::DialogExt;
455+
456+
let (tx, rx) = tokio::sync::oneshot::channel();
457+
app.dialog()
458+
.file()
459+
.add_filter(
460+
"Images",
461+
&["png", "jpg", "jpeg", "gif", "webp", "heic", "heif", "bmp"],
462+
)
463+
.pick_file(move |path| {
464+
let _ = tx.send(path);
465+
});
466+
467+
let file_path = match rx.await.map_err(|_| "dialog cancelled".to_string())? {
468+
Some(path) => path,
469+
None => return Ok(None),
470+
};
471+
472+
let path = file_path.as_path().ok_or("invalid path")?.to_path_buf();
473+
let descriptor = process_picked_path(path, &state, true).await?;
474+
Ok(Some(descriptor))
475+
}
476+
424477
/// Upload raw bytes directly (for paste and drag-drop).
425478
///
426479
/// The renderer already has the bytes in memory from the clipboard/drag event.

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -815,6 +815,7 @@ pub fn run() {
815815
show_native_notification,
816816
upload_media,
817817
pick_and_upload_media,
818+
pick_and_upload_image,
818819
upload_media_bytes,
819820
download_image,
820821
download_file,

‎desktop/src/app/AppShell.tsx‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ import { useArchiveSync } from "@/features/local-archive/archiveSyncManager";
5555
import { useObserverArchiveSeed } from "@/features/local-archive/useObserverArchiveSeed";
5656
import { useAgentMetricArchiveSeed } from "@/features/local-archive/useAgentMetricArchiveSeed";
5757
import { useProfileQuery } from "@/features/profile/hooks";
58+
import { SendFeedbackController } from "@/features/settings/ui/SendFeedbackController";
5859
import {
5960
DEFAULT_SETTINGS_SECTION,
6061
type SettingsSection,
@@ -110,6 +111,7 @@ export function AppShell() {
110111
const [browseDialogType, setBrowseDialogType] =
111112
React.useState<BrowseDialogType>(null);
112113
const [isCreateChannelOpen, setIsCreateChannelOpen] = React.useState(false);
114+
const [isSendFeedbackOpen, setIsSendFeedbackOpen] = React.useState(false);
113115
const [isHuddleDrawerOpen, setIsHuddleDrawerOpen] = React.useState(false);
114116
const mainInsetRef = React.useRef<HTMLElement>(null);
115117
const location = useLocation();
@@ -767,6 +769,7 @@ export function AppShell() {
767769
onNewMessage={handleOpenNewDm}
768770
onCreateChannelOpenChange={setIsCreateChannelOpen}
769771
onOpenAddCommunity={() => setIsAddCommunityOpen(true)}
772+
onSendFeedback={() => setIsSendFeedbackOpen(true)}
770773
onUpdateCommunity={communitiesHook.updateCommunity}
771774
onRemoveCommunity={communitiesHook.removeCommunity}
772775
onSwitchCommunity={handleSwitchCommunity}
@@ -924,6 +927,10 @@ export function AppShell() {
924927
void goChannel(channelId);
925928
}}
926929
/>
930+
<SendFeedbackController
931+
onOpenChange={setIsSendFeedbackOpen}
932+
open={isSendFeedbackOpen}
933+
/>
927934
</SidebarProvider>
928935
</div>
929936

‎desktop/src/features/presence/lib/presence.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,15 @@ export function getPresenceDotClassName(status: PresenceStatus) {
5757
return "bg-muted-foreground/35";
5858
}
5959
}
60+
61+
// Chip styling for the presence pill (colored fill + matching text, no dot).
62+
export function getPresenceChipClassName(status: PresenceStatus) {
63+
switch (status) {
64+
case "online":
65+
return "bg-emerald-500/15 text-emerald-600 dark:text-emerald-400";
66+
case "away":
67+
return "bg-amber-500/15 text-amber-600 dark:text-amber-400";
68+
case "offline":
69+
return "bg-muted-foreground/15 text-muted-foreground";
70+
}
71+
}

0 commit comments

Comments
 (0)