@@ -29,7 +29,7 @@ use nostr::prelude::{Coordinate, EventIdOrCoordinate};
2929use nostr:: {
3030 nips:: nip04:: { decrypt, encrypt} ,
3131 Alphabet , Event , EventBuilder , EventId , Filter , JsonUtil , Keys , Kind , Metadata , SecretKey ,
32- SingleLetterTag , Tag , TagKind , Timestamp , UncheckedUrl ,
32+ SingleLetterTag , Tag , TagKind , Timestamp ,
3333} ;
3434use nostr_sdk:: { Client , NostrSigner , RelayPoolNotification } ;
3535use serde:: { Deserialize , Serialize } ;
@@ -476,15 +476,25 @@ impl<S: MutinyStorage, P: PrimalApi, C: NostrClient> NostrManager<S, P, C> {
476476 } )
477477 . collect ( ) ;
478478 let builder = EventBuilder :: new ( Kind :: ContactList , json ! ( content) . to_string ( ) , tags) ;
479- self . client . send_event_builder ( builder) . await ?;
479+ let event = self
480+ . nostr_keys
481+ . read ( )
482+ . await
483+ . signer
484+ . sign_event_builder ( builder)
485+ . await ?;
486+
487+ self . client . send_event ( event. clone ( ) ) . await ?;
488+
489+ update_nostr_contact_list ( & self . storage , event) ?;
480490 }
481491
482492 // create real relay list
483493 {
484494 let builder = EventBuilder :: relay_list (
485495 RELAYS
486496 . iter ( )
487- . map ( |x| ( UncheckedUrl :: from ( x. to_string ( ) ) , None ) ) ,
497+ . map ( |x| ( nostr :: UncheckedUrl :: from ( x. to_string ( ) ) , None ) ) ,
488498 ) ;
489499 self . client . send_event_builder ( builder) . await ?;
490500 }
@@ -3108,4 +3118,93 @@ mod test {
31083118 assert_ne ! ( profile. name, Some ( "test profile" . to_string( ) ) ) ;
31093119 assert_eq ! ( profile, Metadata :: default ( ) ) ;
31103120 }
3121+
3122+ #[ tokio:: test]
3123+ async fn test_profile_changes ( ) {
3124+ let mut nostr_manager = create_nostr_manager ( ) . await ;
3125+ let npub = nostr_manager. get_npub ( ) . await ;
3126+ nostr_manager
3127+ . client
3128+ . expect_send_event ( )
3129+ . returning ( |e| Ok ( e. id ) ) ;
3130+ nostr_manager
3131+ . client
3132+ . expect_send_event_builder ( )
3133+ . returning ( |e| Ok ( e. to_event ( & Keys :: generate ( ) ) . unwrap ( ) . id ) ) ;
3134+ // setup profile
3135+ nostr_manager
3136+ . primal_client
3137+ . expect_get_user_profile ( )
3138+ . with ( eq ( npub) )
3139+ . times ( 1 )
3140+ . returning ( |_| Ok ( None ) ) ;
3141+ let setup = nostr_manager
3142+ . setup_new_profile ( Some ( "test profile" . to_string ( ) ) , None , None , None )
3143+ . await
3144+ . unwrap ( ) ;
3145+
3146+ let npub = nostr_manager. get_npub ( ) . await ;
3147+
3148+ // check our follow list
3149+ let list = nostr_manager. get_follow_list ( ) . unwrap ( ) ;
3150+ assert_eq ! ( list. len( ) , 1 ) ;
3151+ assert ! ( list. contains( & npub) ) ;
3152+
3153+ // check our profile
3154+ let profile = nostr_manager. get_profile ( ) . unwrap ( ) ;
3155+ assert_eq ! ( profile, setup) ;
3156+ assert_eq ! ( profile. name, Some ( "test profile" . to_string( ) ) ) ;
3157+ assert_eq ! ( profile. display_name, Some ( "test profile" . to_string( ) ) ) ;
3158+ assert_eq ! ( profile. lud06, None ) ;
3159+ assert_eq ! ( profile. lud16, None ) ;
3160+ assert_eq ! ( profile. picture, None ) ;
3161+ assert_eq ! ( profile. about, None ) ;
3162+ assert ! ( profile. custom. is_empty( ) ) ;
3163+
3164+ let pfp = "https://pfp.nostr.build/11670ef3e4b85e22e85a6558a7e7ea6eda960fc72f1a211042173609dce4be4e.jpg" ;
3165+ let lnurl = "lnurl1dp68gurn8ghj7mrww4exctnxd9shg6npvchxxmmd9akxuatjdskkx6rpdehx2mplwdjhxumfdahr6err8ycnzef3xyunxenrvenxydf3xq6xgvekxgmrqc3cx33n2erxvc6kzce38ycnqdf5vdjr2vpevv6kvc3sv4jryenx8yuxgefex4ssq7l4mq" ;
3166+
3167+ // edit profile
3168+ nostr_manager
3169+ . primal_client
3170+ . expect_get_user_profile ( )
3171+ . with ( eq ( npub) )
3172+ . times ( 1 )
3173+ . return_once ( |_| Ok ( Some ( profile) ) ) ;
3174+ let edited = nostr_manager
3175+ . edit_profile (
3176+ None ,
3177+ Some ( Url :: from_str ( pfp) . unwrap ( ) ) ,
3178+ Some ( LnUrl :: from_str ( lnurl) . unwrap ( ) ) ,
3179+ None ,
3180+ )
3181+ . await
3182+ . unwrap ( ) ;
3183+
3184+ // check our profile
3185+ let profile = nostr_manager. get_profile ( ) . unwrap ( ) ;
3186+ assert_eq ! ( profile, edited) ;
3187+ assert_eq ! ( profile. name, Some ( "test profile" . to_string( ) ) ) ;
3188+ assert_eq ! ( profile. display_name, Some ( "test profile" . to_string( ) ) ) ;
3189+ assert_eq ! ( profile. lud06, Some ( lnurl. to_string( ) ) ) ;
3190+ assert_eq ! ( profile. lud16, None ) ;
3191+ assert_eq ! ( profile. picture, Some ( pfp. to_string( ) ) ) ;
3192+ assert_eq ! ( profile. about, None ) ;
3193+ assert ! ( profile. custom. is_empty( ) ) ;
3194+
3195+ // delete profile
3196+ let deleted = nostr_manager. delete_profile ( ) . await . unwrap ( ) ;
3197+
3198+ // verify it was properly deleted
3199+ let profile = nostr_manager. get_profile ( ) . unwrap ( ) ;
3200+ assert_eq ! ( profile, deleted) ;
3201+ assert_eq ! ( profile. name, Some ( "Deleted" . to_string( ) ) ) ;
3202+ assert_eq ! ( profile. display_name, Some ( "Deleted" . to_string( ) ) ) ;
3203+ assert_eq ! ( profile. lud06, None ) ;
3204+ assert_eq ! ( profile. lud16, None ) ;
3205+ assert_eq ! ( profile. picture, None ) ;
3206+ assert_eq ! ( profile. about, Some ( "Deleted" . to_string( ) ) ) ;
3207+ assert_eq ! ( profile. custom. len( ) , 1 ) ;
3208+ assert_eq ! ( profile. custom. get( "deleted" ) . unwrap( ) . as_bool( ) , Some ( true ) ) ;
3209+ }
31113210}
0 commit comments