@@ -101,6 +101,7 @@ use uuid::Uuid;
101101
102102use crate :: labels:: LabelItem ;
103103use crate :: nostr:: NostrKeySource ;
104+ use crate :: storage:: SUBSCRIPTION_TIMESTAMP ;
104105use crate :: utils:: parse_profile_metadata;
105106#[ cfg( test) ]
106107use mockall:: { automock, predicate:: * } ;
@@ -1483,8 +1484,24 @@ impl<S: MutinyStorage> MutinyWallet<S> {
14831484 /// Returns Some(u64) for their unix expiration timestamp, which may be in the
14841485 /// past or in the future, depending on whether or not it is currently active.
14851486 pub async fn check_subscribed ( & self ) -> Result < Option < u64 > , MutinyError > {
1486- if let Some ( subscription_client) = self . subscription_client . clone ( ) {
1487- Ok ( subscription_client. check_subscribed ( ) . await ?)
1487+ if let Some ( ref subscription_client) = self . subscription_client {
1488+ let now = utils:: now ( ) . as_secs ( ) ;
1489+ match self . storage . get_data :: < u64 > ( SUBSCRIPTION_TIMESTAMP ) {
1490+ Ok ( Some ( timestamp) ) if timestamp > now => {
1491+ // if we have a timestamp and it is in the future, we are subscribed
1492+ Ok ( Some ( timestamp) )
1493+ }
1494+ _ => {
1495+ // if we don't have a timestamp or it is in the past, check with the server
1496+ let time = subscription_client. check_subscribed ( ) . await ?;
1497+ // if we are subscribed, save the timestamp
1498+ if let Some ( time) = time. filter ( |t| * t > now) {
1499+ self . storage
1500+ . set_data ( SUBSCRIPTION_TIMESTAMP . to_string ( ) , time, None ) ?;
1501+ }
1502+ Ok ( time)
1503+ }
1504+ }
14881505 } else {
14891506 Ok ( None )
14901507 }
0 commit comments