about summary refs log tree commit diff
path: root/src/state/messages/convo/agent.ts
diff options
context:
space:
mode:
authorEric Bailey <git@esb.lol>2024-05-17 18:05:21 -0500
committerGitHub <noreply@github.com>2024-05-17 16:05:21 -0700
commit49314e2d1f20d7471f1d05ce2b118bd030c44aa2 (patch)
tree01a7db1360ac945debbbf2294c0b98709e9909c5 /src/state/messages/convo/agent.ts
parent8b3bfb3cf7459af59fb4535241a6251e35e88eb9 (diff)
downloadvoidsky-49314e2d1f20d7471f1d05ce2b118bd030c44aa2.tar.zst
[🐴] Mod disabled (#4089)
* Handle send failures

* Add chat disabled state
Diffstat (limited to 'src/state/messages/convo/agent.ts')
-rw-r--r--src/state/messages/convo/agent.ts46
1 files changed, 43 insertions, 3 deletions
diff --git a/src/state/messages/convo/agent.ts b/src/state/messages/convo/agent.ts
index 8673c70ad..0a75401c2 100644
--- a/src/state/messages/convo/agent.ts
+++ b/src/state/messages/convo/agent.ts
@@ -152,6 +152,7 @@ export class Convo {
           fetchMessageHistory: undefined,
         }
       }
+      case ConvoStatus.Disabled:
       case ConvoStatus.Suspended:
       case ConvoStatus.Backgrounded:
       case ConvoStatus.Ready: {
@@ -241,6 +242,13 @@ export class Convo {
             this.withdrawRequestedPollInterval()
             break
           }
+          case ConvoDispatchEvent.Disable: {
+            this.status = ConvoStatus.Disabled
+            this.fetchMessageHistory() // finish init
+            this.cleanupFirehoseConnection?.()
+            this.withdrawRequestedPollInterval()
+            break
+          }
         }
         break
       }
@@ -269,6 +277,12 @@ export class Convo {
             this.withdrawRequestedPollInterval()
             break
           }
+          case ConvoDispatchEvent.Disable: {
+            this.status = ConvoStatus.Disabled
+            this.cleanupFirehoseConnection?.()
+            this.withdrawRequestedPollInterval()
+            break
+          }
         }
         break
       }
@@ -303,6 +317,12 @@ export class Convo {
             this.withdrawRequestedPollInterval()
             break
           }
+          case ConvoDispatchEvent.Disable: {
+            this.status = ConvoStatus.Disabled
+            this.cleanupFirehoseConnection?.()
+            this.withdrawRequestedPollInterval()
+            break
+          }
         }
         break
       }
@@ -321,6 +341,10 @@ export class Convo {
             this.error = action.payload
             break
           }
+          case ConvoDispatchEvent.Disable: {
+            this.status = ConvoStatus.Disabled
+            break
+          }
         }
         break
       }
@@ -343,9 +367,17 @@ export class Convo {
             this.error = action.payload
             break
           }
+          case ConvoDispatchEvent.Disable: {
+            this.status = ConvoStatus.Disabled
+            break
+          }
         }
         break
       }
+      case ConvoStatus.Disabled: {
+        // can't do anything
+        break
+      }
       default:
         break
     }
@@ -424,9 +456,13 @@ export class Convo {
         throw new Error('Convo: could not find recipients in convo')
       }
 
-      // await new Promise(y => setTimeout(y, 2000))
-      // throw new Error('UNCOMMENT TO TEST INIT FAILURE')
-      this.dispatch({event: ConvoDispatchEvent.Ready})
+      const userIsDisabled = this.sender.chatDisabled as boolean
+
+      if (userIsDisabled) {
+        this.dispatch({event: ConvoDispatchEvent.Disable})
+      } else {
+        this.dispatch({event: ConvoDispatchEvent.Ready})
+      }
     } catch (e: any) {
       logger.error(e, {context: 'Convo: setup failed'})
 
@@ -829,6 +865,10 @@ export class Convo {
               ],
             })
             break
+          case 'Account is disabled':
+            this.pendingMessageFailure = 'unrecoverable'
+            this.dispatch({event: ConvoDispatchEvent.Disable})
+            break
           default:
             logger.warn(
               `Convo handleSendMessageFailure could not handle error`,