diff --git a/shared/chat/blocking/invitation-to-block.tsx b/shared/chat/blocking/invitation-to-block.tsx index ac6cce6fe772..5d2dacaac26b 100644 --- a/shared/chat/blocking/invitation-to-block.tsx +++ b/shared/chat/blocking/invitation-to-block.tsx @@ -1,4 +1,5 @@ import * as C from '@/constants' +import {isAssertion} from '@/constants/chat/helpers' import * as Chat from '@/stores/chat' import * as ConvoState from '@/stores/convostate' import * as Kb from '@/common-adapters' @@ -23,7 +24,7 @@ const BlockButtons = () => { } const adder = blockButtonInfo.adder const others = (team ? participantInfo.all : participantInfo.name).filter( - person => person !== currentUser && person !== adder && !Chat.isAssertion(person) + person => person !== currentUser && person !== adder && !isAssertion(person) ) const onViewProfile = () => navToProfile(adder) diff --git a/shared/chat/conversation/attachment-fullscreen/hooks.tsx b/shared/chat/conversation/attachment-fullscreen/hooks.tsx index 486340c1cb10..d7790dd38f90 100644 --- a/shared/chat/conversation/attachment-fullscreen/hooks.tsx +++ b/shared/chat/conversation/attachment-fullscreen/hooks.tsx @@ -1,5 +1,6 @@ import * as React from 'react' import * as C from '@/constants' +import {clampImageSize} from '@/constants/chat/helpers' import * as Chat from '@/stores/chat' import * as ConvoState from '@/stores/convostate' import type * as T from '@/constants/types' @@ -42,7 +43,7 @@ export const useData = (initialOrdinal: T.Chat.Ordinal) => { const attachmentDownload = ConvoState.useChatContext(s => s.dispatch.attachmentDownload) const {downloadPath, fileURL: path, fullHeight, fullWidth, fileType} = message const {previewHeight, previewURL: previewPath, previewWidth, title, transferProgress} = message - const {height: clampedHeight, width: clampedWidth} = Chat.clampImageSize( + const {height: clampedHeight, width: clampedWidth} = clampImageSize( previewWidth, previewHeight, maxWidth, diff --git a/shared/chat/conversation/bot/install.tsx b/shared/chat/conversation/bot/install.tsx index fe9bb2d77c63..aba316cac0d0 100644 --- a/shared/chat/conversation/bot/install.tsx +++ b/shared/chat/conversation/bot/install.tsx @@ -1,7 +1,6 @@ import * as C from '@/constants' import * as ChatCommon from '@/constants/chat/common' import * as Meta from '@/constants/chat/meta' -import * as Chat from '@/stores/chat' import * as ConvoState from '@/stores/convostate' import * as Kb from '@/common-adapters' import * as Teams from '@/stores/teams' @@ -76,7 +75,6 @@ export const useBotConversationIDKey = (inConvIDKey?: T.Chat.ConversationIDKey, const cleanInConvIDKey = T.Chat.isValidConversationIDKey(inConvIDKey ?? '') ? inConvIDKey : undefined const [conversationIDKey, setConversationIDKey] = React.useState(cleanInConvIDKey) const findGeneralConvIDFromTeamID = C.useRPC(T.RPCChat.localFindGeneralConvFromTeamIDRpcPromise) - const metasReceived = Chat.useChatState(s => s.dispatch.metasReceived) const requestIDRef = React.useRef(0) React.useEffect(() => { @@ -99,7 +97,7 @@ export const useBotConversationIDKey = (inConvIDKey?: T.Chat.ConversationIDKey, if (!meta) { return } - metasReceived([meta]) + ConvoState.metasReceived([meta]) setConversationIDKey(meta.conversationIDKey) }, () => {} @@ -109,7 +107,7 @@ export const useBotConversationIDKey = (inConvIDKey?: T.Chat.ConversationIDKey, requestIDRef.current += 1 } } - }, [cleanInConvIDKey, findGeneralConvIDFromTeamID, metasReceived, teamID]) + }, [cleanInConvIDKey, findGeneralConvIDFromTeamID, teamID]) return conversationIDKey } diff --git a/shared/chat/conversation/header-area/index.native.tsx b/shared/chat/conversation/header-area/index.native.tsx index 9ae699695a9b..447322afcc59 100644 --- a/shared/chat/conversation/header-area/index.native.tsx +++ b/shared/chat/conversation/header-area/index.native.tsx @@ -1,5 +1,6 @@ import * as C from '@/constants' import * as Chat from '@/stores/chat' +import {chatStores} from '@/stores/convo-registry' import * as ConvoState from '@/stores/convostate' import {getConvoState} from '@/stores/convostate' import * as Kb from '@/common-adapters' @@ -13,6 +14,7 @@ import {useSafeAreaFrame} from 'react-native-safe-area-context' import {useUsersState} from '@/stores/users' import {useCurrentUserState} from '@/stores/current-user' import {navToProfile} from '@/constants/router' +import * as React from 'react' export const HeaderAreaRight = () => { const conversationIDKey = ConvoState.useChatContext(s => s.id) @@ -159,7 +161,18 @@ export const useBackBadge = () => { const visiblePath = C.Router2.getVisiblePath() const onTopOfInbox = visiblePath[visiblePath.length - 2]?.name === 'chatRoot' const conversationIDKey = ConvoState.useChatContext(s => s.id) - const badgeNumber = Chat.useChatState(s => s.getBackCount(conversationIDKey)) + const badgeStateVersion = Chat.useChatState(s => s.badgeStateVersion) + const badgeNumber = React.useMemo(() => { + void badgeStateVersion + let count = 0 + for (const store of chatStores.values()) { + const {badge, id} = store.getState() + if (id !== conversationIDKey) { + count += badge + } + } + return count + }, [badgeStateVersion, conversationIDKey]) if (!onTopOfInbox) return 0 return badgeNumber } diff --git a/shared/chat/conversation/info-panel/attachments.tsx b/shared/chat/conversation/info-panel/attachments.tsx index fcde94137999..3042e9f05a6a 100644 --- a/shared/chat/conversation/info-panel/attachments.tsx +++ b/shared/chat/conversation/info-panel/attachments.tsx @@ -1,5 +1,5 @@ import * as C from '@/constants' -import * as Chat from '@/stores/chat' +import {zoomImage} from '@/constants/chat/helpers' import * as ConvoState from '@/stores/convostate' import * as Kb from '@/common-adapters' import type {StylesTextCrossPlatform} from '@/common-adapters/text.shared' @@ -582,7 +582,7 @@ export const useAttachmentSections = ( maxMediaThumbSize, width: thumb.width, }, - sizing: Chat.zoomImage(thumb.width, thumb.height, maxMediaThumbSize), + sizing: zoomImage(thumb.width, thumb.height, maxMediaThumbSize), thumb, })) const dataChunked = useFlexWrap ? [dataUnchunked] : chunk(dataUnchunked, rowSize) diff --git a/shared/chat/conversation/info-panel/members.tsx b/shared/chat/conversation/info-panel/members.tsx index f1a8710baf77..5d24907d0014 100644 --- a/shared/chat/conversation/info-panel/members.tsx +++ b/shared/chat/conversation/info-panel/members.tsx @@ -1,5 +1,5 @@ import * as C from '@/constants' -import * as Chat from '@/stores/chat' +import {getBotsAndParticipants} from '@/constants/chat/helpers' import * as ConvoState from '@/stores/convostate' import * as Teams from '@/stores/teams' import * as React from 'react' @@ -47,7 +47,7 @@ const MembersTab = (props: Props) => { const refreshParticipants = C.useRPC(T.RPCChat.localRefreshParticipantsRpcPromise) const participantInfo = ConvoState.useChatContext(s => s.participants) const participants = ConvoState.useChatContext( - C.useShallow(s => Chat.getBotsAndParticipants(s.meta, s.participants, teamMembers).participants) + C.useShallow(s => getBotsAndParticipants(s.meta, s.participants, teamMembers).participants) ) const [lastTeamName, setLastTeamName] = React.useState('') React.useEffect(() => { diff --git a/shared/chat/conversation/info-panel/settings/index.tsx b/shared/chat/conversation/info-panel/settings/index.tsx index 6bbb7bfdb700..dddc99e33694 100644 --- a/shared/chat/conversation/info-panel/settings/index.tsx +++ b/shared/chat/conversation/info-panel/settings/index.tsx @@ -1,4 +1,5 @@ import * as C from '@/constants' +import {isAssertion} from '@/constants/chat/helpers' import * as Chat from '@/stores/chat' import * as ConvoState from '@/stores/convostate' import * as Kb from '@/common-adapters' @@ -36,7 +37,7 @@ const SettingsPanel = (props: SettingsPanelProps) => { const teamMembers = Teams.useTeamsState(s => s.teamIDToMembers.get(teamID)) const participantInfo = ConvoState.useChatContext(s => s.participants) const membersForBlock = (teamMembers?.size ? [...teamMembers.keys()] : participantInfo.name).filter( - u => u !== username && !Chat.isAssertion(u) + u => u !== username && !isAssertion(u) ) const navigateAppend = ConvoState.useChatNavigateAppend() diff --git a/shared/chat/conversation/input-area/normal/index.tsx b/shared/chat/conversation/input-area/normal/index.tsx index d4a5d0079beb..171da7ec3a7c 100644 --- a/shared/chat/conversation/input-area/normal/index.tsx +++ b/shared/chat/conversation/input-area/normal/index.tsx @@ -228,7 +228,7 @@ const ConnectedPlatformInput = function ConnectedPlatformInput() { React.useEffect(() => { const rows = [loadIDOnUnloadRef.current] return () => { - Chat.useChatState.getState().dispatch.unboxRows(rows) + ConvoState.unboxRows(rows) } }, [loadIDOnUnloadRef]) diff --git a/shared/chat/conversation/messages/attachment/shared.tsx b/shared/chat/conversation/messages/attachment/shared.tsx index f5e63866e92c..317c20cd468b 100644 --- a/shared/chat/conversation/messages/attachment/shared.tsx +++ b/shared/chat/conversation/messages/attachment/shared.tsx @@ -1,5 +1,5 @@ import * as C from '@/constants' -import * as Chat from '@/stores/chat' +import {clampImageSize} from '@/constants/chat/helpers' import * as ConvoState from '@/stores/convostate' import * as Kb from '@/common-adapters' import * as React from 'react' @@ -174,7 +174,7 @@ export const getAttachmentPreviewSize = ( ) => { const {fileURL, previewHeight, previewWidth} = message let {previewURL} = message - let {height, width} = Chat.clampImageSize(previewWidth, previewHeight, maxWidth, maxHeight) + let {height, width} = clampImageSize(previewWidth, previewHeight, maxWidth, maxHeight) // This is mostly a sanity check and also allows us to handle HEIC even though the go side doesn't // understand. if (useSquareFallback && (height === 0 || width === 0)) { diff --git a/shared/chat/conversation/messages/cards/team-journey/container.tsx b/shared/chat/conversation/messages/cards/team-journey/container.tsx index ad8adcdd867a..2e5842867319 100644 --- a/shared/chat/conversation/messages/cards/team-journey/container.tsx +++ b/shared/chat/conversation/messages/cards/team-journey/container.tsx @@ -1,4 +1,5 @@ import * as C from '@/constants' +import {isBigTeam as getIsBigTeam} from '@/constants/chat/helpers' import * as Chat from '@/stores/chat' import * as ConvoState from '@/stores/convostate' import * as T from '@/constants/types' @@ -20,7 +21,7 @@ const TeamJourneyConnected = (ownProps: OwnProps) => { const {cannotWrite, channelname, teamname, teamID} = conv const welcomeMessage = {display: '', raw: '', set: false} const canShowcase = Teams.useTeamsState(s => Teams.canShowcase(s, teamID)) - const isBigTeam = Chat.useChatState(s => Chat.isBigTeam(s, teamID)) + const isBigTeam = Chat.useChatState(s => getIsBigTeam(s.inboxLayout, teamID)) const navigateAppend = C.Router2.navigateAppend const _onAuthorClick = (teamID: T.Teams.TeamID) => navigateAppend({name: 'team', params: {teamID}}) const dismissJourneycard = ConvoState.useChatContext(s => s.dispatch.dismissJourneycard) diff --git a/shared/chat/conversation/messages/special-top-message.tsx b/shared/chat/conversation/messages/special-top-message.tsx index ebb812290b2f..265edc9c34ff 100644 --- a/shared/chat/conversation/messages/special-top-message.tsx +++ b/shared/chat/conversation/messages/special-top-message.tsx @@ -1,5 +1,4 @@ import * as C from '@/constants' -import * as Chat from '@/stores/chat' import * as ConvoState from '@/stores/convostate' import * as T from '@/constants/types' import * as Kb from '@/common-adapters' @@ -17,10 +16,9 @@ import {useCurrentUserState} from '@/stores/current-user' const ErrorMessage = () => { const createConversationError = useChatThreadRouteParams()?.createConversationError - const createConversation = Chat.useChatState(s => s.dispatch.createConversation) const _onCreateWithoutThem = (allowedUsers: ReadonlyArray) => { - createConversation(allowedUsers) + ConvoState.createConversation(allowedUsers) } const navigateToInbox = C.Router2.navigateToInbox @@ -120,9 +118,9 @@ function SpecialTopMessage() { const {teamType, supersedes, retentionPolicy, teamRetentionPolicy} = meta const loadMoreType = s.moreToLoadBack ? 'moreToLoad' : 'noMoreToLoad' const pendingState = - s.id === Chat.pendingWaitingConversationIDKey + s.id === T.Chat.pendingWaitingConversationIDKey ? 'waiting' - : s.id === Chat.pendingErrorConversationIDKey + : s.id === T.Chat.pendingErrorConversationIDKey ? 'error' : 'done' @@ -132,7 +130,7 @@ function SpecialTopMessage() { const isSelfConversation = teamType === 'adhoc' && partNum === 1 && partAll.includes(username) const showTeamOffer = hasLoadedEver && loadMoreType === 'noMoreToLoad' && teamType === 'adhoc' && partNum > 2 - const hasOlderResetConversation = supersedes !== Chat.noConversationIDKey + const hasOlderResetConversation = supersedes !== T.Chat.noConversationIDKey // don't show default header in the case of the retention notice being visible const showRetentionNotice = retentionPolicy.type !== 'retain' && diff --git a/shared/chat/conversation/messages/text/reply.tsx b/shared/chat/conversation/messages/text/reply.tsx index eab74216309b..350a5f27b13d 100644 --- a/shared/chat/conversation/messages/text/reply.tsx +++ b/shared/chat/conversation/messages/text/reply.tsx @@ -1,6 +1,6 @@ import * as Kb from '@/common-adapters' import * as React from 'react' -import * as Chat from '@/stores/chat' +import {zoomImage} from '@/constants/chat/helpers' import {useIsHighlighted} from '../ids-context' import type * as T from '@/constants/types' @@ -38,7 +38,7 @@ const ReplyImage = () => { if (!imageURL) return null const imageHeight = replyTo.previewHeight const imageWidth = replyTo.previewWidth - const sizing = imageWidth && imageHeight ? Chat.zoomImage(imageWidth, imageHeight, 80) : undefined + const sizing = imageWidth && imageHeight ? zoomImage(imageWidth, imageHeight, 80) : undefined return ( diff --git a/shared/chat/conversation/messages/text/unfurl/unfurl-list/image/index.tsx b/shared/chat/conversation/messages/text/unfurl/unfurl-list/image/index.tsx index fff9f4e7ccae..89a5573a6b2d 100644 --- a/shared/chat/conversation/messages/text/unfurl/unfurl-list/image/index.tsx +++ b/shared/chat/conversation/messages/text/unfurl/unfurl-list/image/index.tsx @@ -1,6 +1,6 @@ import type * as React from 'react' import * as Kb from '@/common-adapters/index' -import * as Chat from '@/stores/chat' +import {clampImageSize} from '@/constants/chat/helpers' import {maxWidth} from '@/chat/conversation/messages/attachment/shared' import {Video} from './video' import {openURL} from '@/util/misc' @@ -24,7 +24,7 @@ const UnfurlImage = (p: Props) => { linkURL && openURL(linkURL) } const maxSize = Math.min(maxWidth, 320) - (widthPadding || 0) - const {height, width} = Chat.clampImageSize(p.width, p.height, maxSize, 320) + const {height, width} = clampImageSize(p.width, p.height, maxSize, 320) return isVideo ? (