Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions shared/chat/blocking/invitation-to-block.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {isAssertion} from '@/constants/chat/helpers'
import * as Chat from '@/stores/chat'
import * as ConvoState from '@/stores/convostate'
import * as Kb from '@/common-adapters'
import * as React from 'react'
import {useCurrentUserState} from '@/stores/current-user'
import {navToProfile} from '@/constants/router'

Expand All @@ -18,7 +19,17 @@ const BlockButtons = () => {
})
const participantInfo = ConvoState.useChatContext(s => s.participants)
const currentUser = useCurrentUserState(s => s.username)
const hasOwnMessage = ConvoState.useChatContext(s =>
!!currentUser && [...(s.messageOrdinals ?? [])].some(ordinal => s.messageMap.get(ordinal)?.author === currentUser)
)
const dismissBlockButtons = Chat.useChatState(s => s.dispatch.dismissBlockButtons)

React.useEffect(() => {
if (hasOwnMessage && blockButtonInfo && teamID) {
dismissBlockButtons(teamID)
}
}, [blockButtonInfo, dismissBlockButtons, hasOwnMessage, teamID])

if (!blockButtonInfo) {
return null
}
Expand Down
4 changes: 2 additions & 2 deletions shared/chat/conversation/attachment-get-titles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const Container = (ownProps: OwnProps) => {
const noDragDrop = ownProps.noDragDrop ?? false
const selectConversationWithReason = ownProps.selectConversationWithReason
const navigateUp = C.Router2.navigateUp
const navigateToThread = ConvoState.useChatContext(s => s.dispatch.navigateToThread)
const conversationIDKey = ConvoState.useChatContext(s => s.id)
const attachmentUploadCanceled = ConvoState.useChatContext(s => s.dispatch.attachmentUploadCanceled)
const onCancel = () => {
attachmentUploadCanceled(
Expand All @@ -65,7 +65,7 @@ const Container = (ownProps: OwnProps) => {
clearModals()

if (selectConversationWithReason) {
navigateToThread(selectConversationWithReason)
C.Router2.navigateToThread(conversationIDKey, selectConversationWithReason)
}
}
const pathAndInfos = pathAndOutboxIDs.map(({path, outboxID, url}) => {
Expand Down
2 changes: 1 addition & 1 deletion shared/chat/conversation/bot/install.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ const InstallBotPopup = (props: Props) => {
const dispatchClearWaiting = C.Waiting.useDispatchClearWaiting()
const loadBotPublicCommands = C.useRPC(T.RPCChat.localListPublicBotCommandsLocalRpcPromise)
const botPublicCommandsRequestIDRef = React.useRef(0)
const clearedWaitingForBotRef = React.useRef<string>()
const clearedWaitingForBotRef = React.useRef<string | undefined>(undefined)
React.useEffect(() => {
setBotPublicCommands(undefined)
}, [botUsername])
Expand Down
4 changes: 2 additions & 2 deletions shared/chat/conversation/info-panel/menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ const InfoPanelMenuConnector = function InfoPanelMenuConnector(p: OwnProps) {
}

const onJoinChannel = ConvoState.useChatContext(s => s.dispatch.joinConversation)
const onLeaveChannel = ConvoState.useChatContext(s => s.dispatch.leaveConversation)
const conversationIDKey = ConvoState.useChatContext(s => s.id)
const onLeaveChannel = () => C.Router2.leaveConversation(conversationIDKey)
const onLeaveTeam = () => teamID && chatNavigateAppend(() => ({name: 'teamReallyLeaveTeam', params: {teamID}}))
const onManageChannels = () => {
manageChatChannels(teamID)
Expand Down Expand Up @@ -210,7 +211,6 @@ const InfoPanelMenuConnector = function InfoPanelMenuConnector(p: OwnProps) {
),
} as const

const conversationIDKey = ConvoState.useChatContext(s => s.id)
const hideItem = (() => {
if (!conversationIDKey) {
return null
Expand Down
5 changes: 2 additions & 3 deletions shared/chat/conversation/info-panel/settings/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ const SettingsPanel = (props: SettingsPanelProps) => {
}
}

const leaveConversation = ConvoState.useChatContext(s => s.dispatch.leaveConversation)
const conversationIDKey = ConvoState.useChatContext(s => s.id)
const onLeaveConversation = () => {
leaveConversation()
C.Router2.leaveConversation(conversationIDKey)
}

const onArchive = () => {
Expand All @@ -77,7 +77,6 @@ const SettingsPanel = (props: SettingsPanelProps) => {
}

const showDangerZone = canDeleteHistory || entityType === 'adhoc' || entityType !== 'channel'
const conversationIDKey = ConvoState.useChatContext(s => s.id)
return (
<Kb.ScrollView>
<Kb.Box2
Expand Down
5 changes: 3 additions & 2 deletions shared/chat/conversation/input-area/preview.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import * as C from '@/constants'
import * as ConvoState from '@/stores/convostate'
import * as React from 'react'
import * as Kb from '@/common-adapters'

const Preview = () => {
const conversationIDKey = ConvoState.useChatContext(s => s.id)
const meta = ConvoState.useChatContext(s => s.meta)
const onJoinChannel = ConvoState.useChatContext(s => s.dispatch.joinConversation)
const onLeaveChannel = ConvoState.useChatContext(s => s.dispatch.leaveConversation)
const {channelname} = meta
const [clicked, setClicked] = React.useState<undefined | 'join' | 'leave'>(undefined)

Expand All @@ -14,7 +15,7 @@ const Preview = () => {
if (join) {
onJoinChannel()
} else {
onLeaveChannel()
C.Router2.leaveConversation(conversationIDKey)
}
}

Expand Down
2 changes: 1 addition & 1 deletion shared/chat/conversation/messages/special-top-message.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const ErrorMessage = () => {
const createConversationError = useChatThreadRouteParams()?.createConversationError

const _onCreateWithoutThem = (allowedUsers: ReadonlyArray<string>) => {
ConvoState.createConversation(allowedUsers)
C.Router2.createConversation(allowedUsers)
}

const navigateToInbox = C.Router2.navigateToInbox
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as ConvoState from '@/stores/convostate'
import type * as T from '@/constants/types'
import {previewConversation} from '@/constants/router'
import {navigateToThread, previewConversation} from '@/constants/router'
import {Text} from '@/common-adapters'
import UserNotice from '../user-notice'

Expand All @@ -11,7 +11,7 @@ const SystemOldProfileResetNotice = () => {
const nextConversationIDKey = meta.supersededBy
const username = meta.wasFinalizedBy || ''
const onOpenConversation = (conversationIDKey: T.Chat.ConversationIDKey) => {
ConvoState.getConvoState(conversationIDKey).dispatch.navigateToThread('jumpFromReset')
navigateToThread(conversationIDKey, 'jumpFromReset')
}
const startConversation = (participants: ReadonlyArray<string>) => {
previewConversation({participants, reason: 'fromAReset'})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as ConvoState from '@/stores/convostate'
import * as C from '@/constants'
import type * as T from '@/constants/types'
import * as Kb from '@/common-adapters'
import UserNotice from './user-notice'
Expand All @@ -8,7 +9,7 @@ const SystemProfileResetNotice = () => {
const prevConversationIDKey = meta.supersedes
const username = meta.wasFinalizedBy || ''
const _onOpenOlderConversation = (conversationIDKey: T.Chat.ConversationIDKey) => {
ConvoState.getConvoState(conversationIDKey).dispatch.navigateToThread('jumpToReset')
C.Router2.navigateToThread(conversationIDKey, 'jumpToReset')
}
const onOpenOlderConversation = () => {
prevConversationIDKey && _onOpenOlderConversation(prevConversationIDKey)
Expand Down
21 changes: 14 additions & 7 deletions shared/chat/inbox-and-conversation-shared.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import type {ThreadSearchRouteProps} from './conversation/thread-search-route'
export type InboxAndConversationProps = ThreadSearchRouteProps & {
conversationIDKey?: T.Chat.ConversationIDKey
infoPanel?: {tab?: Panel}
refreshInbox?: T.Chat.ChatRootInboxRefresh
}

export type ChatRootRouteParams = InboxAndConversationProps
Expand All @@ -24,24 +25,30 @@ export function InboxAndConversationShell(props: Props) {
const conversationIDKey = props.conversationIDKey ?? Chat.noConversationIDKey
const infoPanel = props.infoPanel
const validConvoID = conversationIDKey && conversationIDKey !== Chat.noConversationIDKey
const seenValidCIDRef = React.useRef(validConvoID ? conversationIDKey : '')
const lastValidCIDRef = React.useRef(validConvoID ? conversationIDKey : '')
const lastAutoSelectedCIDRef = React.useRef('')
const selectNextConvo = Chat.useChatState(s => {
if (seenValidCIDRef.current) {
if (validConvoID) {
return null
}
const first = s.inboxLayout?.smallTeams?.[0]
return first?.convID
return first?.convID === lastValidCIDRef.current ? null : first?.convID
})

React.useEffect(() => {
if (selectNextConvo && seenValidCIDRef.current !== selectNextConvo) {
seenValidCIDRef.current = selectNextConvo
if (validConvoID) {
lastValidCIDRef.current = conversationIDKey
lastAutoSelectedCIDRef.current = ''
return
}
if (selectNextConvo && lastAutoSelectedCIDRef.current !== selectNextConvo) {
lastAutoSelectedCIDRef.current = selectNextConvo
// need to defer , not sure why, shouldn't be
setTimeout(() => {
ConvoState.getConvoState(selectNextConvo).dispatch.navigateToThread('findNewestConversationFromLayout')
C.Router2.navigateToThread(selectNextConvo, 'findNewestConversationFromLayout')
}, 100)
}
}, [selectNextConvo])
}, [conversationIDKey, selectNextConvo, validConvoID])

return (
<ConvoState.ChatProvider id={conversationIDKey} canBeNull={true}>
Expand Down
2 changes: 1 addition & 1 deletion shared/chat/inbox-and-conversation.desktop.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default function InboxAndConversationDesktop(props: InboxAndConversationP
const headerPortal = useInboxHeaderPortal(search)
const leftPane = (
<Kb.Box2 direction="vertical" fullHeight={true} style={styles.inboxPane}>
<Inbox conversationIDKey={props.conversationIDKey} search={search} />
<Inbox conversationIDKey={props.conversationIDKey} refreshInbox={props.refreshInbox} search={search} />
</Kb.Box2>
)

Expand Down
4 changes: 3 additions & 1 deletion shared/chat/inbox-and-conversation.native.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ export default function InboxAndConversationNative(props: InboxAndConversationPr
{headerPortal}
<InboxAndConversationShell
{...props}
leftPane={<Inbox conversationIDKey={props.conversationIDKey} search={search} />}
leftPane={
<Inbox conversationIDKey={props.conversationIDKey} refreshInbox={props.refreshInbox} search={search} />
}
/>
</>
)
Expand Down
3 changes: 2 additions & 1 deletion shared/chat/inbox/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import type * as React from 'react'
import type {ConversationIDKey} from '@/constants/types/chat'
import type {ChatRootInboxRefresh, ConversationIDKey} from '@/constants/types/chat'
import type {InboxSearchController} from './use-inbox-search'

type Props = {
conversationIDKey?: ConversationIDKey
refreshInbox?: ChatRootInboxRefresh
search?: InboxSearchController
}

Expand Down
17 changes: 11 additions & 6 deletions shared/chat/inbox/index.desktop.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -200,22 +200,27 @@ const DragLine = (p: {

type InboxProps = {
conversationIDKey?: T.Chat.ConversationIDKey
refreshInbox?: T.Chat.ChatRootInboxRefresh
search?: InboxSearchController
}

type ControlledInboxProps = {
conversationIDKey?: T.Chat.ConversationIDKey
refreshInbox?: T.Chat.ChatRootInboxRefresh
search: InboxSearchController
}

function InboxWithSearch(props: {conversationIDKey?: T.Chat.ConversationIDKey}) {
function InboxWithSearch(props: {
conversationIDKey?: T.Chat.ConversationIDKey
refreshInbox?: T.Chat.ChatRootInboxRefresh
}) {
const search = useInboxSearch()
return <InboxBody conversationIDKey={props.conversationIDKey} search={search} />
return <InboxBody conversationIDKey={props.conversationIDKey} refreshInbox={props.refreshInbox} search={search} />
}

function InboxBody(props: ControlledInboxProps) {
const {conversationIDKey, search} = props
const inbox = useInboxState(conversationIDKey, search.isSearching)
const {conversationIDKey, refreshInbox, search} = props
const inbox = useInboxState(conversationIDKey, search.isSearching, refreshInbox)
const {smallTeamsExpanded, rows, unreadIndices, unreadTotal, inboxNumSmallRows} = inbox
const {toggleSmallTeamsExpanded, selectedConversationIDKey, onUntrustedInboxVisible} = inbox
const {setInboxNumSmallRows, allowShowFloatingButton} = inbox
Expand Down Expand Up @@ -338,9 +343,9 @@ function InboxBody(props: ControlledInboxProps) {

function Inbox(props: InboxProps) {
return props.search ? (
<InboxBody conversationIDKey={props.conversationIDKey} search={props.search} />
<InboxBody conversationIDKey={props.conversationIDKey} refreshInbox={props.refreshInbox} search={props.search} />
) : (
<InboxWithSearch conversationIDKey={props.conversationIDKey} />
<InboxWithSearch conversationIDKey={props.conversationIDKey} refreshInbox={props.refreshInbox} />
)
}

Expand Down
15 changes: 10 additions & 5 deletions shared/chat/inbox/index.native.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,22 +53,27 @@ const NoChats = (props: {onNewChat: () => void}) => (

type InboxProps = {
conversationIDKey?: T.Chat.ConversationIDKey
refreshInbox?: T.Chat.ChatRootInboxRefresh
search?: InboxSearchController
}

type ControlledInboxProps = {
conversationIDKey?: T.Chat.ConversationIDKey
refreshInbox?: T.Chat.ChatRootInboxRefresh
search: InboxSearchController
}

function InboxWithSearch(props: {conversationIDKey?: T.Chat.ConversationIDKey}) {
function InboxWithSearch(props: {
conversationIDKey?: T.Chat.ConversationIDKey
refreshInbox?: T.Chat.ChatRootInboxRefresh
}) {
const search = useInboxSearch()
return <InboxBody conversationIDKey={props.conversationIDKey} search={search} />
return <InboxBody conversationIDKey={props.conversationIDKey} refreshInbox={props.refreshInbox} search={search} />
}

function InboxBody(p: ControlledInboxProps) {
const {search} = p
const inbox = useInboxState(p.conversationIDKey, search.isSearching)
const inbox = useInboxState(p.conversationIDKey, search.isSearching, p.refreshInbox)
const {onUntrustedInboxVisible, toggleSmallTeamsExpanded, selectedConversationIDKey} = inbox
const {unreadIndices, unreadTotal, rows, smallTeamsExpanded, isSearching, allowShowFloatingButton} = inbox
const {neverLoaded, onNewChat, inboxNumSmallRows, setInboxNumSmallRows} = inbox
Expand Down Expand Up @@ -200,9 +205,9 @@ function InboxBody(p: ControlledInboxProps) {

function Inbox(props: InboxProps) {
return props.search ? (
<InboxBody conversationIDKey={props.conversationIDKey} search={props.search} />
<InboxBody conversationIDKey={props.conversationIDKey} refreshInbox={props.refreshInbox} search={props.search} />
) : (
<InboxWithSearch conversationIDKey={props.conversationIDKey} />
<InboxWithSearch conversationIDKey={props.conversationIDKey} refreshInbox={props.refreshInbox} />
)
}

Expand Down
5 changes: 2 additions & 3 deletions shared/chat/inbox/row/big-team-channel.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as ConvoState from '@/stores/convostate'
import * as C from '@/constants'
import type * as React from 'react'
import * as Kb from '@/common-adapters'
import * as RowSizes from './sizes'
Expand All @@ -15,8 +15,7 @@ const BigTeamChannel = (props: Props) => {
const row = useInboxRowBig(conversationIDKey)
const {channelname, isMuted, hasBadge, hasDraft, hasUnread, isError, snippetDecoration} = row

const onSelectConversation = () =>
ConvoState.getConvoState(conversationIDKey).dispatch.navigateToThread('inboxBig')
const onSelectConversation = () => C.Router2.navigateToThread(conversationIDKey, 'inboxBig')

let outboxTooltip: string | undefined
let outboxIcon: React.ReactNode = null
Expand Down
2 changes: 1 addition & 1 deletion shared/chat/inbox/row/small-team/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const SmallTeam = (p: Props) => {
: (p.onSelectConversation ??
(() => {
setOpenedRow(Chat.noConversationIDKey)
ConvoState.getConvoState(conversationIDKey).dispatch.navigateToThread('inboxSmall')
C.Router2.navigateToThread(conversationIDKey, 'inboxSmall')
}))

const backgroundColor = isSelected
Expand Down
10 changes: 3 additions & 7 deletions shared/chat/inbox/use-inbox-search.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as C from '@/constants'
import {ignorePromise} from '@/constants/utils'
import * as T from '@/constants/types'
import logger from '@/logger'
Expand Down Expand Up @@ -447,14 +448,9 @@ export function useInboxSearch(): InboxSearchController {
}

if (query) {
ConvoState.getConvoState(conversationIDKey).dispatch.navigateToThread(
'inboxSearch',
undefined,
undefined,
query
)
C.Router2.navigateToThread(conversationIDKey, 'inboxSearch', undefined, query)
} else {
ConvoState.getConvoState(conversationIDKey).dispatch.navigateToThread('inboxSearch')
C.Router2.navigateToThread(conversationIDKey, 'inboxSearch')
clearSearch()
}
},
Expand Down
Loading