mirror of https://git.lenooby09.tech/LeNooby09/social-app.git
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

[🐴] Mod disabled (#4089)

* Handle send failures

* Add chat disabled state

authored by

Eric Bailey and committed by
GitHub
49314e2d 8b3bfb3c

+109 -10
+26
src/screens/Messages/Conversation/ChatDisabled.tsx
··· 1 + import React from 'react' 2 + import {View} from 'react-native' 3 + import {Trans} from '@lingui/macro' 4 + 5 + import {atoms as a, useTheme} from '#/alf' 6 + import {Text} from '#/components/Typography' 7 + 8 + export function ChatDisabled() { 9 + const t = useTheme() 10 + return ( 11 + <View style={[a.p_md]}> 12 + <View style={[a.p_xl, a.rounded_md, t.atoms.bg_contrast_25]}> 13 + <Text 14 + style={[a.text_md, a.font_bold, a.pb_sm, t.atoms.text_contrast_high]}> 15 + <Trans>Your chats have been disabled</Trans> 16 + </Text> 17 + <Text style={[a.text_sm, a.leading_snug, t.atoms.text_contrast_medium]}> 18 + <Trans> 19 + Our moderators have reviewed reports and decided to disable your 20 + access to chats on Bluesky. 21 + </Trans> 22 + </Text> 23 + </View> 24 + </View> 25 + ) 26 + }
+12 -5
src/screens/Messages/Conversation/MessagesList.tsx
··· 16 16 import {shortenLinks} from '#/lib/strings/rich-text-manip' 17 17 import {isIOS, isNative} from '#/platform/detection' 18 18 import {useConvoActive} from '#/state/messages/convo' 19 - import {ConvoItem} from '#/state/messages/convo/types' 19 + import {ConvoItem, ConvoStatus} from '#/state/messages/convo/types' 20 20 import {useAgent} from '#/state/session' 21 21 import {ScrollProvider} from 'lib/ScrollContext' 22 22 import {isWeb} from 'platform/detection' 23 23 import {List} from 'view/com/util/List' 24 + import {ChatDisabled} from '#/screens/Messages/Conversation/ChatDisabled' 24 25 import {MessageInput} from '#/screens/Messages/Conversation/MessageInput' 25 26 import {MessageListError} from '#/screens/Messages/Conversation/MessageListError' 26 27 import {atoms as a} from '#/alf' ··· 296 297 /> 297 298 </ScrollProvider> 298 299 {!blocked ? ( 299 - <MessageInput 300 - onSendMessage={onSendMessage} 301 - scrollToEnd={scrollToEndNow} 302 - /> 300 + <> 301 + {convoState.status === ConvoStatus.Disabled ? ( 302 + <ChatDisabled /> 303 + ) : ( 304 + <MessageInput 305 + onSendMessage={onSendMessage} 306 + scrollToEnd={scrollToEndNow} 307 + /> 308 + )} 309 + </> 303 310 ) : ( 304 311 footer 305 312 )}
+43 -3
src/state/messages/convo/agent.ts
··· 152 152 fetchMessageHistory: undefined, 153 153 } 154 154 } 155 + case ConvoStatus.Disabled: 155 156 case ConvoStatus.Suspended: 156 157 case ConvoStatus.Backgrounded: 157 158 case ConvoStatus.Ready: { ··· 241 242 this.withdrawRequestedPollInterval() 242 243 break 243 244 } 245 + case ConvoDispatchEvent.Disable: { 246 + this.status = ConvoStatus.Disabled 247 + this.fetchMessageHistory() // finish init 248 + this.cleanupFirehoseConnection?.() 249 + this.withdrawRequestedPollInterval() 250 + break 251 + } 244 252 } 245 253 break 246 254 } ··· 269 277 this.withdrawRequestedPollInterval() 270 278 break 271 279 } 280 + case ConvoDispatchEvent.Disable: { 281 + this.status = ConvoStatus.Disabled 282 + this.cleanupFirehoseConnection?.() 283 + this.withdrawRequestedPollInterval() 284 + break 285 + } 272 286 } 273 287 break 274 288 } ··· 303 317 this.withdrawRequestedPollInterval() 304 318 break 305 319 } 320 + case ConvoDispatchEvent.Disable: { 321 + this.status = ConvoStatus.Disabled 322 + this.cleanupFirehoseConnection?.() 323 + this.withdrawRequestedPollInterval() 324 + break 325 + } 306 326 } 307 327 break 308 328 } ··· 321 341 this.error = action.payload 322 342 break 323 343 } 344 + case ConvoDispatchEvent.Disable: { 345 + this.status = ConvoStatus.Disabled 346 + break 347 + } 324 348 } 325 349 break 326 350 } ··· 343 367 this.error = action.payload 344 368 break 345 369 } 370 + case ConvoDispatchEvent.Disable: { 371 + this.status = ConvoStatus.Disabled 372 + break 373 + } 346 374 } 375 + break 376 + } 377 + case ConvoStatus.Disabled: { 378 + // can't do anything 347 379 break 348 380 } 349 381 default: ··· 424 456 throw new Error('Convo: could not find recipients in convo') 425 457 } 426 458 427 - // await new Promise(y => setTimeout(y, 2000)) 428 - // throw new Error('UNCOMMENT TO TEST INIT FAILURE') 429 - this.dispatch({event: ConvoDispatchEvent.Ready}) 459 + const userIsDisabled = this.sender.chatDisabled as boolean 460 + 461 + if (userIsDisabled) { 462 + this.dispatch({event: ConvoDispatchEvent.Disable}) 463 + } else { 464 + this.dispatch({event: ConvoDispatchEvent.Ready}) 465 + } 430 466 } catch (e: any) { 431 467 logger.error(e, {context: 'Convo: setup failed'}) 432 468 ··· 828 864 ...this.recipients!.map(r => r.did), 829 865 ], 830 866 }) 867 + break 868 + case 'Account is disabled': 869 + this.pendingMessageFailure = 'unrecoverable' 870 + this.dispatch({event: ConvoDispatchEvent.Disable}) 831 871 break 832 872 default: 833 873 logger.warn(
+2
src/state/messages/convo/index.tsx
··· 8 8 ConvoParams, 9 9 ConvoState, 10 10 ConvoStateBackgrounded, 11 + ConvoStateDisabled, 11 12 ConvoStateReady, 12 13 ConvoStateSuspended, 13 14 } from '#/state/messages/convo/types' ··· 40 41 | ConvoStateReady 41 42 | ConvoStateBackgrounded 42 43 | ConvoStateSuspended 44 + | ConvoStateDisabled 43 45 if (!ctx) { 44 46 throw new Error('useConvo must be used within a ConvoProvider') 45 47 }
+18
src/state/messages/convo/types.ts
··· 20 20 Error = 'error', 21 21 Backgrounded = 'backgrounded', 22 22 Suspended = 'suspended', 23 + Disabled = 'disabled', 23 24 } 24 25 25 26 export enum ConvoItemError { ··· 50 51 Background = 'background', 51 52 Suspend = 'suspend', 52 53 Error = 'error', 54 + Disable = 'disable', 53 55 } 54 56 55 57 export type ConvoDispatch = ··· 71 73 | { 72 74 event: ConvoDispatchEvent.Error 73 75 payload: ConvoError 76 + } 77 + | { 78 + event: ConvoDispatchEvent.Disable 74 79 } 75 80 76 81 export type ConvoItem = ··· 194 199 sendMessage: undefined 195 200 fetchMessageHistory: undefined 196 201 } 202 + export type ConvoStateDisabled = { 203 + status: ConvoStatus.Disabled 204 + items: ConvoItem[] 205 + convo: ChatBskyConvoDefs.ConvoView 206 + error: undefined 207 + sender: AppBskyActorDefs.ProfileViewBasic 208 + recipients: AppBskyActorDefs.ProfileViewBasic[] 209 + isFetchingHistory: boolean 210 + deleteMessage: DeleteMessage 211 + sendMessage: SendMessage 212 + fetchMessageHistory: FetchMessageHistory 213 + } 197 214 export type ConvoState = 198 215 | ConvoStateUninitialized 199 216 | ConvoStateInitializing ··· 201 218 | ConvoStateBackgrounded 202 219 | ConvoStateSuspended 203 220 | ConvoStateError 221 + | ConvoStateDisabled 204 222 205 223 export type ConvoEvent = { 206 224 type: 'invalidate-block-state'
+8 -2
src/state/messages/convo/util.ts
··· 1 1 import { 2 2 ConvoState, 3 3 ConvoStateBackgrounded, 4 + ConvoStateDisabled, 4 5 ConvoStateReady, 5 6 ConvoStateSuspended, 6 7 ConvoStatus, ··· 13 14 */ 14 15 export function isConvoActive( 15 16 convo: ConvoState, 16 - ): convo is ConvoStateReady | ConvoStateBackgrounded | ConvoStateSuspended { 17 + ): convo is 18 + | ConvoStateReady 19 + | ConvoStateBackgrounded 20 + | ConvoStateSuspended 21 + | ConvoStateDisabled { 17 22 return ( 18 23 convo.status === ConvoStatus.Ready || 19 24 convo.status === ConvoStatus.Backgrounded || 20 - convo.status === ConvoStatus.Suspended 25 + convo.status === ConvoStatus.Suspended || 26 + convo.status === ConvoStatus.Disabled 21 27 ) 22 28 }