@@ -101,6 +101,7 @@ use uuid::Uuid;
101
101
102
102
use crate :: labels:: LabelItem ;
103
103
use crate :: nostr:: NostrKeySource ;
104
+ use crate :: storage:: SUBSCRIPTION_TIMESTAMP ;
104
105
use crate :: utils:: parse_profile_metadata;
105
106
#[ cfg( test) ]
106
107
use mockall:: { automock, predicate:: * } ;
@@ -1483,8 +1484,24 @@ impl<S: MutinyStorage> MutinyWallet<S> {
1483
1484
/// Returns Some(u64) for their unix expiration timestamp, which may be in the
1484
1485
/// past or in the future, depending on whether or not it is currently active.
1485
1486
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
+ }
1488
1505
} else {
1489
1506
Ok ( None )
1490
1507
}
0 commit comments