Skip to content

Commit ef9d97c

Browse files
authored
attachment undo collapse fix (keybase#25686)
* fix unfurl * lint * images also
1 parent 1b9b3be commit ef9d97c

7 files changed

Lines changed: 33 additions & 16 deletions

File tree

‎shared/actions/chat2-gen.tsx‎

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎shared/actions/chat2/index.tsx‎

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2944,10 +2944,22 @@ const toggleMessageCollapse = async (
29442944
state: Container.TypedState,
29452945
action: Chat2Gen.ToggleMessageCollapsePayload
29462946
) => {
2947-
const {conversationIDKey, messageID} = action.payload
2948-
const collapse = !state.chat2.messageMap.get(conversationIDKey)?.get(messageID)?.isCollapsed
2947+
const {conversationIDKey, messageID, ordinal} = action.payload
2948+
const m = state.chat2.messageMap.get(conversationIDKey)?.get(ordinal)
2949+
let isCollapsed = false
2950+
2951+
if (messageID !== ordinal) {
2952+
const unfurlInfos = [...(m?.unfurls?.values() ?? [])]
2953+
const ui = unfurlInfos.find(u => u.unfurlMessageID === messageID)
2954+
2955+
if (ui) {
2956+
isCollapsed = ui.isCollapsed
2957+
}
2958+
} else {
2959+
isCollapsed = m?.isCollapsed ?? false
2960+
}
29492961
await RPCChatTypes.localToggleMessageCollapseRpcPromise({
2950-
collapse,
2962+
collapse: !isCollapsed,
29512963
convID: Types.keyToConversationID(conversationIDKey),
29522964
msgID: messageID,
29532965
})

‎shared/actions/json/chat2.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,8 @@
617617
"toggleMessageCollapse": {
618618
"_description": "Toggle the collapse status of a message",
619619
"conversationIDKey": "Types.ConversationIDKey",
620-
"messageID": "Types.MessageID"
620+
"messageID": "Types.MessageID",
621+
"ordinal": "Types.Ordinal"
621622
},
622623
"updateCoinFlipStatus": {
623624
"_description": "Update status of a coin flip game",

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ const useCollapseAction = () => {
141141
(e: React.BaseSyntheticEvent) => {
142142
e.stopPropagation()
143143
const {conversationIDKey, ordinal} = getIds()
144-
dispatch(Chat2Gen.createToggleMessageCollapse({conversationIDKey, messageID: ordinal}))
144+
dispatch(Chat2Gen.createToggleMessageCollapse({conversationIDKey, messageID: ordinal, ordinal}))
145145
},
146146
[dispatch, getIds]
147147
)

‎shared/chat/conversation/messages/text/unfurl/unfurl-list/generic.tsx‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,11 @@ const UnfurlGeneric = React.memo(function UnfurlGeneric(p: {idx: number}) {
5555
}
5656
}, shallowEqual)
5757

58-
const {onClose, onCollapse} = useActions(
58+
const {onClose, onToggleCollapse} = useActions(
5959
conversationIDKey,
6060
data?.youAreAuthor ?? false,
61-
data?.unfurlMessageID ?? 0
61+
data?.unfurlMessageID ?? 0,
62+
ordinal
6263
)
6364

6465
if (!data) return null
@@ -99,7 +100,7 @@ const UnfurlGeneric = React.memo(function UnfurlGeneric(p: {idx: number}) {
99100
<Kb.Icon
100101
boxStyle={styles.collapseBox}
101102
noContainer={Styles.isMobile}
102-
onClick={onCollapse}
103+
onClick={onToggleCollapse}
103104
sizeType="Tiny"
104105
type={isCollapsed ? 'iconfont-caret-right' : 'iconfont-caret-down'}
105106
/>

‎shared/chat/conversation/messages/text/unfurl/unfurl-list/giphy.tsx‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,11 @@ const UnfurlGiphy = React.memo(function UnfurlGiphy(p: {idx: number}) {
3838
}
3939
}, shallowEqual)
4040

41-
const {onClose, onCollapse} = useActions(
41+
const {onClose, onToggleCollapse} = useActions(
4242
conversationIDKey,
4343
data?.youAreAuthor ?? false,
44-
data?.unfurlMessageID ?? 0
44+
data?.unfurlMessageID ?? 0,
45+
ordinal
4546
)
4647

4748
if (data === null) return null
@@ -61,7 +62,7 @@ const UnfurlGiphy = React.memo(function UnfurlGiphy(p: {idx: number}) {
6162
<Kb.Icon
6263
boxStyle={styles.collapseBox}
6364
style={styles.collapse}
64-
onClick={onCollapse}
65+
onClick={onToggleCollapse}
6566
sizeType="Tiny"
6667
type={isCollapsed ? 'iconfont-caret-right' : 'iconfont-caret-down'}
6768
/>

‎shared/chat/conversation/messages/text/unfurl/unfurl-list/use-redux.tsx‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,18 @@ import type * as Types from '../../../../../../constants/types/chat2'
66
export const useActions = (
77
conversationIDKey: Types.ConversationIDKey,
88
youAreAuthor: boolean,
9-
messageID: Types.MessageID
9+
messageID: Types.MessageID,
10+
ordinal: Types.Ordinal
1011
) => {
1112
const dispatch = Container.useDispatch()
1213
const onClose = React.useCallback(() => {
1314
dispatch(Chat2Gen.createUnfurlRemove({conversationIDKey, messageID}))
1415
}, [dispatch, conversationIDKey, messageID])
15-
const onCollapse = React.useCallback(() => {
16-
dispatch(Chat2Gen.createToggleMessageCollapse({conversationIDKey, messageID}))
17-
}, [dispatch, conversationIDKey, messageID])
16+
const onToggleCollapse = React.useCallback(() => {
17+
dispatch(Chat2Gen.createToggleMessageCollapse({conversationIDKey, messageID, ordinal}))
18+
}, [dispatch, conversationIDKey, messageID, ordinal])
1819

19-
return {onClose: youAreAuthor ? onClose : undefined, onCollapse}
20+
return {onClose: youAreAuthor ? onClose : undefined, onToggleCollapse}
2021
}
2122

2223
export const getUnfurlInfo = (

0 commit comments

Comments
 (0)