Skip to content

Commit 668d785

Browse files
authored
why did 2 (keybase#26137)
1 parent 1c0a375 commit 668d785

13 files changed

Lines changed: 87 additions & 44 deletions

File tree

‎shared/chat/blocking/invitation-to-block.tsx‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const BlockButtons = () => {
77
const nav = Container.useSafeNavigation()
88
const conversationIDKey = C.useChatContext(s => s.id)
99

10-
const teamname = C.useChatContext(s => s.meta.teamname)
10+
const team = C.useChatContext(s => s.meta.teamname)
1111
const teamID = C.useChatContext(s => s.meta.teamID)
1212
const blockButtonInfo = C.useChatState(s => {
1313
const blockButtonsMap = s.blockButtonsMap
@@ -20,7 +20,6 @@ const BlockButtons = () => {
2020
if (!blockButtonInfo) {
2121
return null
2222
}
23-
const team = teamname
2423
const adder = blockButtonInfo.adder
2524
const others = (team ? participantInfo.all : participantInfo.name).filter(
2625
person => person !== currentUser && person !== adder && !C.Chat.isAssertion(person)

‎shared/chat/conversation/input-area/container.tsx‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@ import ThreadSearch from '../search/container'
66
const InputAreaContainer = () => {
77
const conversationIDKey = C.useChatContext(s => s.id)
88
const showThreadSearch = C.useChatContext(s => s.threadSearchInfo.visible)
9-
const {membershipType, resetParticipants, wasFinalizedBy} = C.useChatContext(s => s.meta)
9+
const {membershipType, resetParticipants, wasFinalizedBy} = C.useChatContext(
10+
C.useShallow(s => {
11+
const {membershipType, resetParticipants, wasFinalizedBy} = s.meta
12+
return {membershipType, resetParticipants, wasFinalizedBy}
13+
})
14+
)
1015

1116
let noInput = resetParticipants.size > 0 || !!wasFinalizedBy
1217
if (

‎shared/chat/conversation/input-area/normal/index.tsx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ const ConnectedPlatformInput = React.memo(function ConnectedPlatformInput() {
8787
const showGiphySearch = C.useChatContext(s => s.giphyWindow)
8888
const showCommandMarkdown = C.useChatContext(s => !!s.commandMarkdown)
8989
const showTypingStatus = isTyping && !showGiphySearch && !showCommandMarkdown
90-
const {cannotWrite, minWriterRole} = C.useChatContext(s => s.meta)
90+
const cannotWrite = C.useChatContext(s => s.meta.cannotWrite)
91+
const minWriterRole = C.useChatContext(s => s.meta.minWriterRole)
9192
const replyTo = C.useChatContext(s => s.messageMap.get(s.replyTo)?.id)
9293
const editOrdinal = C.useChatContext(s => s.editing)
9394
const isEditExploded = C.useChatContext(s =>

‎shared/chat/conversation/messages/separator.tsx‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -205,17 +205,16 @@ const useStateFast = (_trailingItem: T.Chat.Ordinal, _leadingItem: T.Chat.Ordina
205205
}
206206

207207
const useState = (ordinal: T.Chat.Ordinal) => {
208-
const participantInfoNames = C.useChatContext(s => s.participants.name)
209-
const meta = C.useChatContext(s => s.meta)
210208
const d = C.useChatContext(
211209
C.useShallow(s => {
212210
const m = s.messageMap.get(ordinal) ?? missingMessage
211+
const participantInfoNames = s.participants.name
213212
const {author, timestamp} = m
214-
const {teamID, botAliases, teamType} = meta
213+
const {teamID, botAliases, teamType, teamname} = s.meta
215214
// TODO not reactive
216215
const authorRoleInTeam = C.useTeamsState.getState().teamIDToMembers.get(teamID)?.get(author)?.type
217216
const botAlias = botAliases[author] ?? ''
218-
const authorIsBot = meta.teamname
217+
const authorIsBot = teamname
219218
? authorRoleInTeam === 'restrictedbot' || authorRoleInTeam === 'bot'
220219
: teamType === 'adhoc' && participantInfoNames.length > 0 // teams without info may have type adhoc with an empty participant name list
221220
? !participantInfoNames.includes(author) // if adhoc, check if author in participants
@@ -229,7 +228,7 @@ const useState = (ordinal: T.Chat.Ordinal) => {
229228
}
230229
})
231230
)
232-
return {...d, participantInfoNames}
231+
return {...d}
233232
}
234233

235234
type SProps = {

‎shared/chat/conversation/messages/special-top-message.tsx‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,11 @@ const SpecialTopMessage = React.memo(function SpecialTopMessage() {
115115
const {teamType, supersedes, retentionPolicy, teamRetentionPolicy} = meta
116116
return {
117117
hasLoadedEver,
118-
loadMoreType,
119118
ordinal,
120119
retentionPolicy,
121120
supersedes,
122121
teamRetentionPolicy,
123122
teamType,
124-
username,
125123
}
126124
})
127125
)

‎shared/chat/conversation/normal/container.tsx‎

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,8 @@ const useOrangeLine = () => {
1616
const maxMsgID = C.useChatContext(s => s.meta.maxMsgID)
1717
const metaOrangeShow = maxMsgID > readMsgID
1818
const active = C.useActiveState(s => s.active)
19-
20-
const initOrangeLine = () => {
21-
return metaOrangeShow ? readMsgID : 0
22-
}
23-
const [orangeLine, setOrangeLine] = React.useState(initOrangeLine())
19+
const initOrangeLine = metaOrangeShow ? readMsgID : 0
20+
const [orangeLine, setOrangeLine] = React.useState(initOrangeLine)
2421
const [lastCID, setLastCID] = React.useState(conversationIDKey)
2522
const [lastReadMsgID, setLastReadMsgID] = React.useState(readMsgID)
2623
const [metaGood, setMetaGood] = React.useState(readMsgID > 0)
@@ -40,7 +37,7 @@ const useOrangeLine = () => {
4037
if (lastCID !== conversationIDKey) {
4138
setLastCID(conversationIDKey)
4239
setLastReadMsgID(readMsgID)
43-
setOrangeLine(initOrangeLine())
40+
setOrangeLine(initOrangeLine)
4441
}
4542

4643
// not active and we should show?
@@ -57,10 +54,9 @@ const useOrangeLine = () => {
5754
return orangeLine
5855
}
5956

60-
const NormalWrapper = React.memo(function NormalWrapper() {
61-
const orangeLine = useOrangeLine()
57+
const WithOrange = React.memo(function WithOrange(p: {orangeLine: number}) {
6258
return (
63-
<OrangeLineContext.Provider value={orangeLine}>
59+
<OrangeLineContext.Provider value={p.orangeLine}>
6460
<FocusProvider>
6561
<ScrollProvider>
6662
<Normal />
@@ -69,4 +65,9 @@ const NormalWrapper = React.memo(function NormalWrapper() {
6965
</OrangeLineContext.Provider>
7066
)
7167
})
68+
69+
const NormalWrapper = React.memo(function NormalWrapper() {
70+
const orangeLine = useOrangeLine()
71+
return <WithOrange orangeLine={orangeLine} />
72+
})
7273
export default NormalWrapper

‎shared/chat/conversation/pinned-message/container.tsx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import PinnedMessage from '.'
66
const PinnedMessageContainer = React.memo(function PinnedMessageContainer() {
77
const conversationIDKey = C.useChatContext(s => s.id)
88
const you = C.useCurrentUserState(s => s.username)
9-
const {teamname, pinnedMsg} = C.useChatContext(s => s.meta)
9+
const teamname = C.useChatContext(s => s.meta.teamname)
10+
const pinnedMsg = C.useChatContext(s => s.meta.pinnedMsg)
1011
const replyJump = C.useChatContext(s => s.dispatch.replyJump)
1112
const message = pinnedMsg?.message
1213
const yourOperations = C.useTeamsState(s => C.Teams.getCanPerform(s, teamname))

‎shared/chat/inbox-and-conversation-header.tsx‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,12 @@ const Header2 = (props: Props) => {
2222
const username = C.useCurrentUserState(s => s.username)
2323
const infoPanelShowing = C.useChatState(s => s.infoPanelShowing)
2424
const participantInfo = C.useChatContext(s => s.participants)
25-
const meta = C.useChatContext(s => s.meta)
26-
const {channelname, descriptionDecorated, isMuted, teamType, teamname} = meta
25+
const {channelname, descriptionDecorated, isMuted, teamType, teamname} = C.useChatContext(
26+
C.useShallow(s => {
27+
const {channelname, descriptionDecorated, isMuted, teamType, teamname} = s.meta
28+
return {channelname, descriptionDecorated, isMuted, teamType, teamname}
29+
})
30+
)
2731
// TODO not reactive
2832
const canEditDesc = C.Teams.getCanPerform(C.useTeamsState.getState(), teamname).editChannelDescription
2933
const otherParticipants = C.Chat.getRowParticipants(participantInfo, username)

‎shared/chat/inbox/row/big-team-channel.tsx‎

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,38 @@ import * as Kb from '@/common-adapters'
33
import * as React from 'react'
44
import * as RowSizes from './sizes'
55
import * as T from '@/constants/types'
6+
import * as RPCChatTypes from '@/constants/types/rpc-chat-gen'
67

78
type Props = {
89
layoutChannelname: string
910
navKey: string
1011
selected: boolean
12+
layoutSnippetDecoration?: RPCChatTypes.SnippetDecoration
1113
}
1214

1315
const BigTeamChannel = React.memo(function BigTeamChannel(props: Props) {
14-
const {selected, layoutChannelname} = props
15-
const channelname = C.useChatContext(s => s.meta.channelname) || layoutChannelname
16+
const {selected, layoutChannelname, layoutSnippetDecoration} = props
17+
const channelname = C.useChatContext(s => s.meta.channelname || layoutChannelname)
1618
const isError = C.useChatContext(s => s.meta.trustedState === 'error')
17-
const snippetDecoration = C.useChatContext(s => s.meta.snippetDecoration)
19+
const snippetDecoration = C.useChatContext(s => {
20+
const d =
21+
s.meta.conversationIDKey === C.noConversationIDKey
22+
? layoutSnippetDecoration ?? RPCChatTypes.SnippetDecoration.none
23+
: s.meta.snippetDecoration
24+
25+
switch (d) {
26+
case T.RPCChat.SnippetDecoration.pendingMessage:
27+
case T.RPCChat.SnippetDecoration.failedPendingMessage:
28+
return d
29+
default:
30+
return 0
31+
}
32+
})
1833
const hasBadge = C.useChatContext(s => s.badge > 0)
1934
const hasDraft = C.useChatContext(s => !!s.meta.draft)
2035
const hasUnread = C.useChatContext(s => s.unread > 0)
2136
const isMuted = C.useChatContext(s => s.meta.isMuted)
2237
const navigateToThread = C.useChatContext(s => s.dispatch.navigateToThread)
23-
2438
const onSelectConversation = () => navigateToThread('inboxBig')
2539

2640
let outboxIcon: React.ReactNode = null

‎shared/chat/inbox/row/index.tsx‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,12 @@ const makeRow = (
3232
case 'big':
3333
return (
3434
<C.ChatProvider id={item.conversationIDKey}>
35-
<BigTeamChannel layoutChannelname={item.channelname} selected={selected} navKey={navKey} />
35+
<BigTeamChannel
36+
layoutChannelname={item.channelname}
37+
selected={selected}
38+
navKey={navKey}
39+
layoutSnippetDecoration={item.snippetDecoration}
40+
/>
3641
</C.ChatProvider>
3742
)
3843
case 'small':
@@ -46,6 +51,7 @@ const makeRow = (
4651
isSelected={selected}
4752
layoutTime={item.time}
4853
layoutSnippet={item.snippet}
54+
layoutSnippetDecoration={item.snippetDecoration}
4955
swipeCloseRef={swipeCloseRef}
5056
/>
5157
</C.ChatProvider>

0 commit comments

Comments
 (0)