Skip to content
Merged
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
6 changes: 5 additions & 1 deletion desktop/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ export default defineConfig({
},
{
name: "integration",
testMatch: ["**/stream.spec.ts", "**/integration.spec.ts"],
testMatch: [
"**/stream.spec.ts",
"**/integration.spec.ts",
"**/profile.spec.ts",
],
use: {
...devices["Desktop Chrome"],
},
Expand Down
61 changes: 61 additions & 0 deletions desktop/src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ pub struct IdentityInfo {
pub display_name: String,
}

#[derive(Serialize, Deserialize)]
pub struct ProfileInfo {
pub pubkey: String,
pub display_name: Option<String>,
pub avatar_url: Option<String>,
pub about: Option<String>,
pub nip05_handle: Option<String>,
}

#[derive(Serialize, Deserialize)]
pub struct ChannelInfo {
pub id: String,
Expand Down Expand Up @@ -108,6 +117,16 @@ struct AddMembersBody<'a> {
role: Option<&'a str>,
}

#[derive(Serialize)]
struct UpdateProfileBody<'a> {
#[serde(skip_serializing_if = "Option::is_none")]
display_name: Option<&'a str>,
#[serde(skip_serializing_if = "Option::is_none")]
avatar_url: Option<&'a str>,
#[serde(skip_serializing_if = "Option::is_none")]
about: Option<&'a str>,
}

#[derive(Serialize)]
struct GetFeedQuery<'a> {
#[serde(skip_serializing_if = "Option::is_none")]
Expand Down Expand Up @@ -278,6 +297,46 @@ fn get_relay_ws_url() -> String {
relay_ws_url()
}

#[tauri::command]
async fn get_profile(state: tauri::State<'_, AppState>) -> Result<ProfileInfo, String> {
let request = build_authed_request(
&state.http_client,
Method::GET,
"/api/users/me/profile",
&state,
)?;
send_json_request(request).await
}

#[tauri::command]
async fn update_profile(
display_name: Option<String>,
avatar_url: Option<String>,
about: Option<String>,
state: tauri::State<'_, AppState>,
) -> Result<ProfileInfo, String> {
let request = build_authed_request(
&state.http_client,
Method::PUT,
"/api/users/me/profile",
&state,
)?
.json(&UpdateProfileBody {
display_name: display_name.as_deref(),
avatar_url: avatar_url.as_deref(),
about: about.as_deref(),
});
send_empty_request(request).await?;

let request = build_authed_request(
&state.http_client,
Method::GET,
"/api/users/me/profile",
&state,
)?;
send_json_request(request).await
}

#[tauri::command]
fn sign_event(
kind: u16,
Expand Down Expand Up @@ -558,6 +617,8 @@ pub fn run() {
.manage(app_state)
.invoke_handler(tauri::generate_handler![
get_identity,
get_profile,
update_profile,
get_relay_ws_url,
sign_event,
create_auth_event,
Expand Down
12 changes: 12 additions & 0 deletions desktop/src/app/AppShell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
import { formatTimelineMessages } from "@/features/messages/lib/formatTimelineMessages";
import { MessageComposer } from "@/features/messages/ui/MessageComposer";
import { MessageTimeline } from "@/features/messages/ui/MessageTimeline";
import { ProfileSheet } from "@/features/profile/ui/ProfileSheet";
import { SearchDialog } from "@/features/search/ui/SearchDialog";
import { AppSidebar } from "@/features/sidebar/ui/AppSidebar";
import { getEventById } from "@/shared/api/tauri";
Expand All @@ -45,6 +46,7 @@ export function AppShell() {
const [selectedView, setSelectedView] = React.useState<AppView>("home");
const [isChannelManagementOpen, setIsChannelManagementOpen] =
React.useState(false);
const [isProfileOpen, setIsProfileOpen] = React.useState(false);
const [isSearchOpen, setIsSearchOpen] = React.useState(false);
const [searchAnchor, setSearchAnchor] = React.useState<SearchHit | null>(
null,
Expand Down Expand Up @@ -192,6 +194,9 @@ export function AppShell() {
onOpenSearch={() => {
setIsSearchOpen(true);
}}
onOpenProfile={() => {
setIsProfileOpen(true);
}}
onSelectHome={() => {
React.startTransition(() => {
setSelectedView("home");
Expand Down Expand Up @@ -331,6 +336,13 @@ export function AppShell() {
onOpenChange={setIsChannelManagementOpen}
open={isChannelManagementOpen && activeChannel !== null}
/>

<ProfileSheet
currentPubkey={identityQuery.data?.pubkey}
fallbackDisplayName={identityQuery.data?.displayName}
onOpenChange={setIsProfileOpen}
open={isProfileOpen}
/>
</SidebarInset>
</SidebarProvider>
);
Expand Down
29 changes: 29 additions & 0 deletions desktop/src/features/profile/hooks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";

import { getProfile, updateProfile } from "@/shared/api/tauri";
import type { Profile, UpdateProfileInput } from "@/shared/api/types";

export const profileQueryKey = ["profile"] as const;

export function useProfileQuery(enabled = true) {
return useQuery({
enabled,
queryKey: profileQueryKey,
queryFn: getProfile,
staleTime: 30_000,
});
}

export function useUpdateProfileMutation() {
const queryClient = useQueryClient();

return useMutation({
mutationFn: (input: UpdateProfileInput) => updateProfile(input),
onSuccess: (profile: Profile) => {
queryClient.setQueryData(profileQueryKey, profile);
},
onSettled: async () => {
await queryClient.invalidateQueries({ queryKey: profileQueryKey });
},
});
}
Loading