about summary refs log tree commit diff
path: root/src/state/models
diff options
context:
space:
mode:
Diffstat (limited to 'src/state/models')
-rw-r--r--src/state/models/content/list-membership.ts25
-rw-r--r--src/state/models/content/list.ts39
-rw-r--r--src/state/models/discovery/foafs.ts16
-rw-r--r--src/state/models/feeds/post.ts2
-rw-r--r--src/state/models/lists/lists-list.ts13
-rw-r--r--src/state/models/ui/shell.ts12
6 files changed, 77 insertions, 30 deletions
diff --git a/src/state/models/content/list-membership.ts b/src/state/models/content/list-membership.ts
index b4af4472b..20d9b60af 100644
--- a/src/state/models/content/list-membership.ts
+++ b/src/state/models/content/list-membership.ts
@@ -9,6 +9,16 @@ interface Membership {
   value: AppBskyGraphListitem.Record
 }
 
+interface ListitemRecord {
+  uri: string
+  value: AppBskyGraphListitem.Record
+}
+
+interface ListitemListResponse {
+  cursor?: string
+  records: ListitemRecord[]
+}
+
 export class ListMembershipModel {
   // data
   memberships: Membership[] = []
@@ -32,13 +42,14 @@ export class ListMembershipModel {
     // it needs to be replaced with server side list membership queries
     // -prf
     let cursor
-    let records = []
+    let records: ListitemRecord[] = []
     for (let i = 0; i < 100; i++) {
-      const res = await this.rootStore.agent.app.bsky.graph.listitem.list({
-        repo: this.rootStore.me.did,
-        cursor,
-        limit: PAGE_SIZE,
-      })
+      const res: ListitemListResponse =
+        await this.rootStore.agent.app.bsky.graph.listitem.list({
+          repo: this.rootStore.me.did,
+          cursor,
+          limit: PAGE_SIZE,
+        })
       records = records.concat(
         res.records.filter(record => record.value.subject === this.subject),
       )
@@ -99,7 +110,7 @@ export class ListMembershipModel {
     })
   }
 
-  async updateTo(uris: string) {
+  async updateTo(uris: string[]) {
     for (const uri of uris) {
       await this.add(uri)
     }
diff --git a/src/state/models/content/list.ts b/src/state/models/content/list.ts
index 673ee9430..3913d3e62 100644
--- a/src/state/models/content/list.ts
+++ b/src/state/models/content/list.ts
@@ -4,6 +4,7 @@ import {
   AppBskyGraphGetList as GetList,
   AppBskyGraphDefs as GraphDefs,
   AppBskyGraphList,
+  AppBskyGraphListitem,
 } from '@atproto/api'
 import {Image as RNImage} from 'react-native-image-crop-picker'
 import {RootStoreModel} from '../root-store'
@@ -13,6 +14,16 @@ import {bundleAsync} from 'lib/async/bundle'
 
 const PAGE_SIZE = 30
 
+interface ListitemRecord {
+  uri: string
+  value: AppBskyGraphListitem.Record
+}
+
+interface ListitemListResponse {
+  cursor?: string
+  records: ListitemRecord[]
+}
+
 export class ListModel {
   // state
   isLoading = false
@@ -33,7 +44,7 @@ export class ListModel {
       name,
       description,
       avatar,
-    }: {name: string; description: string; avatar: RNImage | undefined},
+    }: {name: string; description: string; avatar: RNImage | null | undefined},
   ) {
     const record: AppBskyGraphList.Record = {
       purpose: 'app.bsky.graph.defs#modlist',
@@ -124,6 +135,9 @@ export class ListModel {
     description: string
     avatar: RNImage | null | undefined
   }) {
+    if (!this.list) {
+      return
+    }
     if (!this.isOwner) {
       throw new Error('Cannot edit this list')
     }
@@ -157,15 +171,20 @@ export class ListModel {
   }
 
   async delete() {
+    if (!this.list) {
+      return
+    }
+
     // fetch all the listitem records that belong to this list
     let cursor
-    let records = []
+    let records: ListitemRecord[] = []
     for (let i = 0; i < 100; i++) {
-      const res = await this.rootStore.agent.app.bsky.graph.listitem.list({
-        repo: this.rootStore.me.did,
-        cursor,
-        limit: PAGE_SIZE,
-      })
+      const res: ListitemListResponse =
+        await this.rootStore.agent.app.bsky.graph.listitem.list({
+          repo: this.rootStore.me.did,
+          cursor,
+          limit: PAGE_SIZE,
+        })
       records = records.concat(
         res.records.filter(record => record.value.list === this.uri),
       )
@@ -193,6 +212,9 @@ export class ListModel {
   }
 
   async subscribe() {
+    if (!this.list) {
+      return
+    }
     await this.rootStore.agent.app.bsky.graph.muteActorList({
       list: this.list.uri,
     })
@@ -200,6 +222,9 @@ export class ListModel {
   }
 
   async unsubscribe() {
+    if (!this.list) {
+      return
+    }
     await this.rootStore.agent.app.bsky.graph.unmuteActorList({
       list: this.list.uri,
     })
diff --git a/src/state/models/discovery/foafs.ts b/src/state/models/discovery/foafs.ts
index f6e3157b7..4bbd32807 100644
--- a/src/state/models/discovery/foafs.ts
+++ b/src/state/models/discovery/foafs.ts
@@ -1,4 +1,7 @@
-import {AppBskyActorDefs} from '@atproto/api'
+import {
+  AppBskyActorDefs,
+  AppBskyGraphGetFollows as GetFollows,
+} from '@atproto/api'
 import {makeAutoObservable, runInAction} from 'mobx'
 import sampleSize from 'lodash.samplesize'
 import {bundleAsync} from 'lib/async/bundle'
@@ -43,11 +46,12 @@ export class FoafsModel {
       {
         let cursor
         for (let i = 0; i < 10; i++) {
-          const res = await this.rootStore.agent.getFollows({
-            actor: this.rootStore.me.did,
-            cursor,
-            limit: 100,
-          })
+          const res: GetFollows.Response =
+            await this.rootStore.agent.getFollows({
+              actor: this.rootStore.me.did,
+              cursor,
+              limit: 100,
+            })
           this.rootStore.me.follows.hydrateProfiles(res.data.follows)
           if (!res.data.cursor) {
             break
diff --git a/src/state/models/feeds/post.ts b/src/state/models/feeds/post.ts
index 0c411d448..18a90ee82 100644
--- a/src/state/models/feeds/post.ts
+++ b/src/state/models/feeds/post.ts
@@ -67,7 +67,7 @@ export class PostsFeedItemModel {
   }
 
   get rootUri(): string {
-    if (this.reply?.root.uri) {
+    if (typeof this.reply?.root.uri === 'string') {
       return this.reply.root.uri
     }
     return this.post.uri
diff --git a/src/state/models/lists/lists-list.ts b/src/state/models/lists/lists-list.ts
index 309ab0e03..6618c3bf6 100644
--- a/src/state/models/lists/lists-list.ts
+++ b/src/state/models/lists/lists-list.ts
@@ -61,7 +61,7 @@ export class ListsListModel {
     }
     this._xLoading(replace)
     try {
-      let res
+      let res: GetLists.Response
       if (this.source === 'my-modlists') {
         res = {
           success: true,
@@ -170,7 +170,7 @@ async function fetchAllUserLists(
 
   let cursor
   for (let i = 0; i < 100; i++) {
-    const res = await store.agent.app.bsky.graph.getLists({
+    const res: GetLists.Response = await store.agent.app.bsky.graph.getLists({
       actor: did,
       cursor,
       limit: 50,
@@ -199,10 +199,11 @@ async function fetchAllMyMuteLists(
 
   let cursor
   for (let i = 0; i < 100; i++) {
-    const res = await store.agent.app.bsky.graph.getListMutes({
-      cursor,
-      limit: 50,
-    })
+    const res: GetListMutes.Response =
+      await store.agent.app.bsky.graph.getListMutes({
+        cursor,
+        limit: 50,
+      })
     cursor = res.data.cursor
     acc.data.lists = acc.data.lists.concat(res.data.lists)
     if (!cursor) {
diff --git a/src/state/models/ui/shell.ts b/src/state/models/ui/shell.ts
index a77ffbdfb..3853f2395 100644
--- a/src/state/models/ui/shell.ts
+++ b/src/state/models/ui/shell.ts
@@ -8,6 +8,12 @@ import {ImageModel} from '../media/image'
 import {ListModel} from '../content/list'
 import {GalleryModel} from '../media/gallery'
 
+export type ColorMode = 'system' | 'light' | 'dark'
+
+export function isColorMode(v: unknown): v is ColorMode {
+  return v === 'system' || v === 'light' || v === 'dark'
+}
+
 export interface ConfirmModal {
   name: 'confirm'
   title: string
@@ -189,7 +195,7 @@ export interface ComposerOpts {
 }
 
 export class ShellUiModel {
-  colorMode = 'system'
+  colorMode: ColorMode = 'system'
   minimalShellMode = false
   isDrawerOpen = false
   isDrawerSwipeDisabled = false
@@ -216,13 +222,13 @@ export class ShellUiModel {
 
   hydrate(v: unknown) {
     if (isObj(v)) {
-      if (hasProp(v, 'colorMode') && typeof v.colorMode === 'string') {
+      if (hasProp(v, 'colorMode') && isColorMode(v.colorMode)) {
         this.colorMode = v.colorMode
       }
     }
   }
 
-  setColorMode(mode: string) {
+  setColorMode(mode: ColorMode) {
     this.colorMode = mode
   }