@@ -3,6 +3,7 @@ import type { Label, LabelId } from "@/api/domain/label";
33import type { Project , ProjectId } from "@/api/domain/project" ;
44import type { Section , SectionId } from "@/api/domain/section" ;
55import type { Task as ApiTask , CreateTaskParams , TaskId } from "@/api/domain/task" ;
6+ import type { UserInfo } from "@/api/domain/user" ;
67import { Repository , type RepositoryReader } from "@/data/repository" ;
78import { SubscriptionManager , type UnsubscribeCallback } from "@/data/subscriptions" ;
89import type { Task } from "@/data/task" ;
@@ -49,6 +50,7 @@ export class TodoistAdapter {
4950 private readonly subscriptions : SubscriptionManager < Subscription > ;
5051
5152 private readonly tasksPendingClose : TaskId [ ] ;
53+ private userInfo : UserInfo | undefined ;
5254
5355 private hasSynced = false ;
5456
@@ -64,6 +66,10 @@ export class TodoistAdapter {
6466 return this . api . hasValue ( ) && this . hasSynced ;
6567 }
6668
69+ public isPremium ( ) : boolean {
70+ return this . userInfo ?. isPremium ?? true ;
71+ }
72+
6773 public async initialize ( api : TodoistApiClient ) {
6874 this . api . insert ( api ) ;
6975 await this . sync ( ) ;
@@ -74,9 +80,12 @@ export class TodoistAdapter {
7480 return ;
7581 }
7682
77- await this . projects . sync ( ) ;
78- await this . sections . sync ( ) ;
79- await this . labels . sync ( ) ;
83+ await Promise . all ( [
84+ this . syncUserInfo ( ) ,
85+ this . projects . sync ( ) ,
86+ this . sections . sync ( ) ,
87+ this . labels . sync ( ) ,
88+ ] ) ;
8089
8190 for ( const subscription of this . subscriptions . list ( ) ) {
8291 await subscription . update ( ) ;
@@ -85,6 +94,17 @@ export class TodoistAdapter {
8594 this . hasSynced = true ;
8695 }
8796
97+ private async syncUserInfo ( ) : Promise < void > {
98+ try {
99+ if ( ! this . api . hasValue ( ) ) {
100+ return ;
101+ }
102+ this . userInfo = await this . api . withInner ( ( api ) => api . getUser ( ) ) ;
103+ } catch ( error ) {
104+ console . error ( "Failed to fetch user info:" , error ) ;
105+ }
106+ }
107+
88108 public data ( ) : DataAccessor {
89109 return {
90110 projects : this . projects ,
0 commit comments