@@ -21,139 +21,144 @@ impl ComposeWindow {
2121 let screen_rect = ctx. screen_rect ( ) ;
2222 let min_width = screen_rect. width ( ) . min ( 600.0 ) ;
2323 let min_height = screen_rect. height ( ) . min ( 400.0 ) ;
24-
24+
2525 // First collect all window IDs and their minimized state
2626 let state = app
2727 . state
2828 . compose_window
2929 . get_mut ( & id)
3030 . expect ( "no state found for id" ) ;
3131
32- egui:: Window :: new ( "New Message" )
33- . id ( id)
34- . default_size ( [ min_width, min_height] )
35- . min_width ( 300.0 )
36- . min_height ( 200.0 )
37- . default_pos ( [ screen_rect. right ( ) - min_width - 20.0 , screen_rect. bottom ( ) - min_height - 20.0 ] )
38- . show ( ctx, |ui| {
39- ui. vertical ( |ui| {
40- // Header section
41- ui. horizontal ( |ui| {
42- ui. label ( "To:" ) ;
43- ui. add_sized (
44- [ ui. available_width ( ) , 24.0 ] ,
45- egui:: TextEdit :: singleline ( & mut state. to_field )
46- ) ;
47- } ) ;
32+ egui:: Window :: new ( "New Message" )
33+ . id ( id)
34+ . default_size ( [ min_width, min_height] )
35+ . min_width ( 300.0 )
36+ . min_height ( 200.0 )
37+ . default_pos ( [
38+ screen_rect. right ( ) - min_width - 20.0 ,
39+ screen_rect. bottom ( ) - min_height - 20.0 ,
40+ ] )
41+ . show ( ctx, |ui| {
42+ ui. vertical ( |ui| {
43+ // Header section
44+ ui. horizontal ( |ui| {
45+ ui. label ( "To:" ) ;
46+ ui. add_sized (
47+ [ ui. available_width ( ) , 24.0 ] ,
48+ egui:: TextEdit :: singleline ( & mut state. to_field ) ,
49+ ) ;
50+ } ) ;
51+
52+ ui. horizontal ( |ui| {
53+ ui. label ( "Subject:" ) ;
54+ ui. add_sized (
55+ [ ui. available_width ( ) , 24.0 ] ,
56+ egui:: TextEdit :: singleline ( & mut state. subject ) ,
57+ ) ;
58+ } ) ;
59+
60+ // Toolbar
61+ ui. horizontal ( |ui| {
62+ ui. style_mut ( ) . spacing . button_padding = egui:: vec2 ( 4.0 , 4.0 ) ;
63+ if ui. button ( "B" ) . clicked ( ) { }
64+ if ui. button ( "I" ) . clicked ( ) { }
65+ if ui. button ( "U" ) . clicked ( ) { }
66+ ui. separator ( ) ;
67+ if ui. button ( "🔗" ) . clicked ( ) { }
68+ if ui. button ( "📎" ) . clicked ( ) { }
69+ if ui. button ( "😀" ) . clicked ( ) { }
70+ ui. separator ( ) ;
71+ if ui. button ( "⌄" ) . clicked ( ) { }
72+ } ) ;
4873
49- ui. horizontal ( |ui| {
50- ui. label ( "Subject:" ) ;
74+ // Message content
75+ let available_height = ui. available_height ( ) - 40.0 ; // Reserve space for bottom bar
76+ egui:: ScrollArea :: vertical ( )
77+ . max_height ( available_height)
78+ . show ( ui, |ui| {
5179 ui. add_sized (
52- [ ui. available_width ( ) , 24 .0] ,
53- egui:: TextEdit :: singleline ( & mut state. subject )
80+ [ ui. available_width ( ) , available_height - 20 .0] ,
81+ egui:: TextEdit :: multiline ( & mut state. content ) ,
5482 ) ;
5583 } ) ;
5684
57- // Toolbar
58- ui. horizontal ( |ui| {
59- ui. style_mut ( ) . spacing . button_padding = egui:: vec2 ( 4.0 , 4.0 ) ;
60- if ui. button ( "B" ) . clicked ( ) { }
61- if ui. button ( "I" ) . clicked ( ) { }
62- if ui. button ( "U" ) . clicked ( ) { }
63- ui. separator ( ) ;
64- if ui. button ( "🔗" ) . clicked ( ) { }
65- if ui. button ( "📎" ) . clicked ( ) { }
66- if ui. button ( "😀" ) . clicked ( ) { }
67- ui. separator ( ) ;
68- if ui. button ( "⌄" ) . clicked ( ) { }
69- } ) ;
70-
71- // Message content
72- let available_height = ui. available_height ( ) - 40.0 ; // Reserve space for bottom bar
73- egui:: ScrollArea :: vertical ( )
74- . max_height ( available_height)
75- . show ( ui, |ui| {
76- ui. add_sized (
77- [ ui. available_width ( ) , available_height - 20.0 ] ,
78- egui:: TextEdit :: multiline ( & mut state. content )
79- ) ;
80- } ) ;
85+ // Bottom bar with account selector and send button
86+ ui. with_layout ( egui:: Layout :: right_to_left ( egui:: Align :: Center ) , |ui| {
87+ if ui. button ( "Send" ) . clicked ( ) {
88+ if state. selected_account . is_none ( ) {
89+ error ! ( "No Account Selected!" ) ;
90+ return ;
91+ }
92+ // convert to field into PublicKey object
93+ let to_field = state. to_field . clone ( ) ;
8194
82- // Bottom bar with account selector and send button
83- ui. with_layout ( egui:: Layout :: right_to_left ( egui:: Align :: Center ) , |ui| {
84- if ui. button ( "Send" ) . clicked ( ) {
85- if state. selected_account . is_none ( ) {
86- error ! ( "No Account Selected!" ) ;
87- return ;
88- }
89- // convert to field into PublicKey object
90- let to_field = state. to_field . clone ( ) ;
91-
92- let mut recipient_keys: Vec < PublicKey > = Vec :: new ( ) ;
93- for key_string in to_field. split_whitespace ( ) {
94- use nostr:: FromBech32 ;
95- match PublicKey :: from_bech32 ( key_string) {
96- Ok ( k) => recipient_keys. push ( k) ,
97- Err ( e) => debug ! ( "could not parse public key as bech32: {}" , e) ,
98- } ;
99-
100- match PublicKey :: from_hex ( key_string) {
101- Ok ( k) => recipient_keys. push ( k) ,
102- Err ( e) => debug ! ( "could not parse public key as hex: {}" , e) ,
103- } ;
104- }
95+ let mut recipient_keys: Vec < PublicKey > = Vec :: new ( ) ;
96+ for key_string in to_field. split_whitespace ( ) {
97+ use nostr:: FromBech32 ;
98+ match PublicKey :: from_bech32 ( key_string) {
99+ Ok ( k) => recipient_keys. push ( k) ,
100+ Err ( e) => debug ! ( "could not parse public key as bech32: {}" , e) ,
101+ } ;
105102
106- let mut msg = MailMessage {
107- to : recipient_keys,
108- cc : vec ! [ ] ,
109- bcc : vec ! [ ] ,
110- parent_events : state. parent_events . clone ( ) ,
111- subject : state. subject . clone ( ) ,
112- content : state. content . clone ( ) ,
103+ match PublicKey :: from_hex ( key_string) {
104+ Ok ( k) => recipient_keys. push ( k) ,
105+ Err ( e) => debug ! ( "could not parse public key as hex: {}" , e) ,
113106 } ;
114- let events_to_send =
115- msg. to_events ( & state. selected_account . clone ( ) . unwrap ( ) ) ;
116-
117- // send over wire
118- for event in events_to_send {
119- match serde_json:: to_string ( & ClientMessage :: Event { event : event. 1 } ) {
120- Ok ( v) => match app. relays . send ( ewebsock:: WsMessage :: Text ( v) ) {
121- Ok ( r) => r,
122- Err ( e) => error ! ( "could not send event to relays: {}" , e) ,
123- } ,
124- Err ( e) => error ! ( "could not serialize event: {}" , e) ,
125- } ;
126- }
127107 }
128108
129- // Account selector
130- let accounts = app. account_manager . loaded_keys . clone ( ) ;
131- use nostr:: ToBech32 ;
132- let mut formatted_key = String :: new ( ) ;
133- if state. selected_account . is_some ( ) {
134- formatted_key = state
135- . selected_account
136- . clone ( )
137- . unwrap ( )
138- . public_key ( )
139- . to_bech32 ( )
140- . unwrap ( ) ;
109+ let mut msg = MailMessage {
110+ to : recipient_keys,
111+ cc : vec ! [ ] ,
112+ bcc : vec ! [ ] ,
113+ parent_events : state. parent_events . clone ( ) ,
114+ subject : state. subject . clone ( ) ,
115+ content : state. content . clone ( ) ,
116+ } ;
117+ let events_to_send =
118+ msg. to_events ( & state. selected_account . clone ( ) . unwrap ( ) ) ;
119+
120+ // send over wire
121+ for event in events_to_send {
122+ match serde_json:: to_string ( & ClientMessage :: Event {
123+ event : event. 1 ,
124+ } ) {
125+ Ok ( v) => match app. relays . send ( ewebsock:: WsMessage :: Text ( v) ) {
126+ Ok ( r) => r,
127+ Err ( e) => error ! ( "could not send event to relays: {}" , e) ,
128+ } ,
129+ Err ( e) => error ! ( "could not serialize event: {}" , e) ,
130+ } ;
141131 }
132+ }
142133
143- egui:: ComboBox :: from_id_source ( "account_selector" )
144- . selected_text ( format ! ( "{}" , formatted_key) )
145- . show_ui ( ui, |ui| {
146- for key in accounts {
147- ui. selectable_value (
148- & mut state. selected_account ,
149- Some ( key. clone ( ) ) ,
150- key. public_key ( ) . to_bech32 ( ) . unwrap ( ) ,
151- ) ;
152- }
153- } ) ;
154- } ) ;
134+ // Account selector
135+ let accounts = app. account_manager . loaded_keys . clone ( ) ;
136+ use nostr:: ToBech32 ;
137+ let mut formatted_key = String :: new ( ) ;
138+ if state. selected_account . is_some ( ) {
139+ formatted_key = state
140+ . selected_account
141+ . clone ( )
142+ . unwrap ( )
143+ . public_key ( )
144+ . to_bech32 ( )
145+ . unwrap ( ) ;
146+ }
147+
148+ egui:: ComboBox :: from_id_source ( "account_selector" )
149+ . selected_text ( format ! ( "{}" , formatted_key) )
150+ . show_ui ( ui, |ui| {
151+ for key in accounts {
152+ ui. selectable_value (
153+ & mut state. selected_account ,
154+ Some ( key. clone ( ) ) ,
155+ key. public_key ( ) . to_bech32 ( ) . unwrap ( ) ,
156+ ) ;
157+ }
158+ } ) ;
155159 } ) ;
156160 } ) ;
161+ } ) ;
157162 }
158163
159164 // Keep the original show method for backward compatibility
0 commit comments