[🐴] Mod disabled (#4089)
* Handle send failures * Add chat disabled state
This commit is contained in:
parent
8b3bfb3cf7
commit
49314e2d1f
6 changed files with 109 additions and 10 deletions
|
@ -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`,
|
||||
|
|
|
@ -8,6 +8,7 @@ import {
|
|||
ConvoParams,
|
||||
ConvoState,
|
||||
ConvoStateBackgrounded,
|
||||
ConvoStateDisabled,
|
||||
ConvoStateReady,
|
||||
ConvoStateSuspended,
|
||||
} from '#/state/messages/convo/types'
|
||||
|
@ -40,6 +41,7 @@ export function useConvoActive() {
|
|||
| ConvoStateReady
|
||||
| ConvoStateBackgrounded
|
||||
| ConvoStateSuspended
|
||||
| ConvoStateDisabled
|
||||
if (!ctx) {
|
||||
throw new Error('useConvo must be used within a ConvoProvider')
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ export enum ConvoStatus {
|
|||
Error = 'error',
|
||||
Backgrounded = 'backgrounded',
|
||||
Suspended = 'suspended',
|
||||
Disabled = 'disabled',
|
||||
}
|
||||
|
||||
export enum ConvoItemError {
|
||||
|
@ -50,6 +51,7 @@ export enum ConvoDispatchEvent {
|
|||
Background = 'background',
|
||||
Suspend = 'suspend',
|
||||
Error = 'error',
|
||||
Disable = 'disable',
|
||||
}
|
||||
|
||||
export type ConvoDispatch =
|
||||
|
@ -72,6 +74,9 @@ export type ConvoDispatch =
|
|||
event: ConvoDispatchEvent.Error
|
||||
payload: ConvoError
|
||||
}
|
||||
| {
|
||||
event: ConvoDispatchEvent.Disable
|
||||
}
|
||||
|
||||
export type ConvoItem =
|
||||
| {
|
||||
|
@ -194,6 +199,18 @@ export type ConvoStateError = {
|
|||
sendMessage: undefined
|
||||
fetchMessageHistory: undefined
|
||||
}
|
||||
export type ConvoStateDisabled = {
|
||||
status: ConvoStatus.Disabled
|
||||
items: ConvoItem[]
|
||||
convo: ChatBskyConvoDefs.ConvoView
|
||||
error: undefined
|
||||
sender: AppBskyActorDefs.ProfileViewBasic
|
||||
recipients: AppBskyActorDefs.ProfileViewBasic[]
|
||||
isFetchingHistory: boolean
|
||||
deleteMessage: DeleteMessage
|
||||
sendMessage: SendMessage
|
||||
fetchMessageHistory: FetchMessageHistory
|
||||
}
|
||||
export type ConvoState =
|
||||
| ConvoStateUninitialized
|
||||
| ConvoStateInitializing
|
||||
|
@ -201,6 +218,7 @@ export type ConvoState =
|
|||
| ConvoStateBackgrounded
|
||||
| ConvoStateSuspended
|
||||
| ConvoStateError
|
||||
| ConvoStateDisabled
|
||||
|
||||
export type ConvoEvent = {
|
||||
type: 'invalidate-block-state'
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import {
|
||||
ConvoState,
|
||||
ConvoStateBackgrounded,
|
||||
ConvoStateDisabled,
|
||||
ConvoStateReady,
|
||||
ConvoStateSuspended,
|
||||
ConvoStatus,
|
||||
|
@ -13,10 +14,15 @@ import {
|
|||
*/
|
||||
export function isConvoActive(
|
||||
convo: ConvoState,
|
||||
): convo is ConvoStateReady | ConvoStateBackgrounded | ConvoStateSuspended {
|
||||
): convo is
|
||||
| ConvoStateReady
|
||||
| ConvoStateBackgrounded
|
||||
| ConvoStateSuspended
|
||||
| ConvoStateDisabled {
|
||||
return (
|
||||
convo.status === ConvoStatus.Ready ||
|
||||
convo.status === ConvoStatus.Backgrounded ||
|
||||
convo.status === ConvoStatus.Suspended
|
||||
convo.status === ConvoStatus.Suspended ||
|
||||
convo.status === ConvoStatus.Disabled
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue