Skip to content

Commit 56682e8

Browse files
authored
remove mesageMapAttachments and filter out gallery loads (keybase#26645)
1 parent b6815a7 commit 56682e8

8 files changed

Lines changed: 31 additions & 23 deletions

File tree

‎shared/chat/conversation/attachment-fullscreen/hooks.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export const useData = (initialOrdinal: T.Chat.Ordinal) => {
99
const [ordinal, setOrdinal] = React.useState(initialOrdinal)
1010

1111
const message: T.Chat.MessageAttachment = C.useChatContext(s => {
12-
const m = s.messageMap.get(ordinal) ?? s.messageMapAttachments.get(ordinal)
12+
const m = s.messageMap.get(ordinal)
1313
return m?.type === 'attachment' ? m : blankMessage
1414
})
1515

‎shared/chat/conversation/messages/message-popup/attachment.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const emptyMessage = C.Chat.makeMessageAttachment({})
1818

1919
const PopAttach = (ownProps: OwnProps) => {
2020
const {ordinal, attachTo, onHidden, position, style, visible} = ownProps
21-
const m = C.useChatContext(s => s.messageMap.get(ordinal) ?? s.messageMapAttachments.get(ordinal))
21+
const m = C.useChatContext(s => s.messageMap.get(ordinal))
2222
const message = m?.type === 'attachment' ? m : emptyMessage
2323
const {downloadPath, attachmentType} = message
2424
const pending = !!message.transferState

‎shared/chat/conversation/messages/message-popup/hooks.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {formatTimeForPopup, formatTimeForRevoked} from '@/util/timestamp'
99
const emptyText = C.Chat.makeMessageText({})
1010

1111
export const useItems = (ordinal: T.Chat.Ordinal, onHidden: () => void) => {
12-
const m = C.useChatContext(s => s.messageMap.get(ordinal) ?? s.messageMapAttachments.get(ordinal))
12+
const m = C.useChatContext(s => s.messageMap.get(ordinal))
1313
const isAttach = m?.type === 'attachment'
1414
const message = m || emptyText
1515
const {author, id, deviceName, timestamp, deviceRevokedAt} = message
@@ -229,7 +229,7 @@ export const useItems = (ordinal: T.Chat.Ordinal, onHidden: () => void) => {
229229
}
230230

231231
export const useHeader = (ordinal: T.Chat.Ordinal) => {
232-
const m = C.useChatContext(s => s.messageMap.get(ordinal) ?? s.messageMapAttachments.get(ordinal))
232+
const m = C.useChatContext(s => s.messageMap.get(ordinal))
233233
const you = C.useCurrentUserState(s => s.username)
234234
const message = m || emptyText
235235
const {author, deviceType, deviceName, botUsername, timestamp, exploding, explodingTime} = message

‎shared/chat/conversation/messages/message-popup/index.tsx‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ type Props = {
1717

1818
const MessagePopup = React.memo(function MessagePopup(p: Props) {
1919
const {ordinal, attachTo, onHidden, position, style, visible} = p
20-
const type = C.useChatContext(
21-
s => s.messageMap.get(ordinal)?.type ?? s.messageMapAttachments.get(ordinal)?.type
22-
)
20+
const type = C.useChatContext(s => s.messageMap.get(ordinal)?.type)
2321
switch (type) {
2422
case 'text':
2523
case 'setChannelname':

‎shared/chat/conversation/messages/message-popup/journeycard.tsx‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@ type OwnProps = {
1616
const JourneyCard = (ownProps: OwnProps) => {
1717
const {ordinal, attachTo, onHidden, style, visible, position} = ownProps
1818
const cardType = C.useChatContext(
19-
s =>
20-
s.messageMap.get(ordinal)?.cardType ??
21-
s.messageMapAttachments.get(ordinal)?.cardType ??
22-
T.RPCChat.JourneycardType.unused
19+
s => s.messageMap.get(ordinal)?.cardType ?? T.RPCChat.JourneycardType.unused
2320
)
2421

2522
const dismissJourneycard = C.useChatContext(s => s.dispatch.dismissJourneycard)

‎shared/chat/conversation/messages/message-popup/text.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const emptyMessage = C.Chat.makeMessageText({})
1919

2020
const PopText = (ownProps: OwnProps) => {
2121
const {ordinal, attachTo, onHidden, position, style, visible} = ownProps
22-
const m = C.useChatContext(s => s.messageMap.get(ordinal) ?? s.messageMapAttachments.get(ordinal))
22+
const m = C.useChatContext(s => s.messageMap.get(ordinal))
2323
const you = C.useCurrentUserState(s => s.username)
2424
const message = m || emptyMessage
2525
const {conversationIDKey, author} = message

‎shared/constants/chat2/convostate.tsx‎

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ type ConvoStore = T.Immutable<{
104104
messageTypeMap: Map<T.Chat.Ordinal, T.Chat.RenderMessageType> // messages T.Chat to help the thread, text is never used
105105
messageOrdinals?: ReadonlyArray<T.Chat.Ordinal> // ordered ordinals in a thread,
106106
messageMap: Map<T.Chat.Ordinal, T.Chat.Message> // messages in a thread,
107-
messageMapAttachments: Map<T.Chat.Ordinal, T.Chat.Message> // messages that are loaded from the gallery, kept separate
108107
meta: T.Chat.ConversationMeta // metadata about a thread, There is a special node for the pending conversation,
109108
moreToLoad: boolean
110109
mutualTeams: ReadonlyArray<T.Teams.TeamID>
@@ -142,7 +141,6 @@ const initialConvoStore: ConvoStore = {
142141
maxMsgIDSeen: T.Chat.numberToMessageID(-1),
143142
messageCenterOrdinal: undefined,
144143
messageMap: new Map(),
145-
messageMapAttachments: new Map(),
146144
messageOrdinals: undefined,
147145
messageTypeMap: new Map(),
148146
meta: Meta.makeConversationMeta(),
@@ -440,7 +438,13 @@ const createSlice: Z.ImmerStateCreator<ConvoState> = (set, get) => {
440438

441439
// things that depend on messageMap, like the ordinals and the maxMsgIDSeen
442440
const syncMessageDerived = (s: Z.WritableDraft<ConvoState>) => {
443-
const mo = [...s.messageMap.keys()].sort((a, b) => a - b)
441+
const mo = [...s.messageMap]
442+
.filter(([, m]) => {
443+
const regularMessage = m.conversationMessage !== false
444+
return regularMessage
445+
})
446+
.map(([ord]) => ord)
447+
.sort((a, b) => a - b)
444448
if (C.shallowEqual(s.messageOrdinals, mo)) {
445449
return
446450
}
@@ -514,18 +518,20 @@ const createSlice: Z.ImmerStateCreator<ConvoState> = (set, get) => {
514518
set(s => {
515519
for (const _m of messages) {
516520
const m = T.castDraft(_m)
521+
const regularMessage = m.conversationMessage !== false
522+
517523
// we capture the highest one, cause sometimes we'll not track it in the map
518524
// aka for deleted or placeholders
519-
if (m.id > s.maxMsgIDSeen) {
525+
if (regularMessage && m.id > s.maxMsgIDSeen) {
520526
s.maxMsgIDSeen = m.id
521527
}
522-
if (m.type === 'deleted') {
528+
if (regularMessage && m.type === 'deleted') {
523529
s.messageMap.delete(m.ordinal)
524530
s.messageTypeMap.delete(m.ordinal)
525531
} else {
526532
let mapOrdinal = m.ordinal
527533
// if we've sent it we use the outbox id to manage the ordinal relationship
528-
if (m.outboxID) {
534+
if (regularMessage && m.outboxID) {
529535
const existingSent = s.pendingOutboxToOrdinal.get(m.outboxID)
530536
if (existingSent) {
531537
mapOrdinal = existingSent
@@ -545,7 +551,11 @@ const createSlice: Z.ImmerStateCreator<ConvoState> = (set, get) => {
545551
}
546552

547553
s.messageMap.set(mapOrdinal, T.castDraft(m))
548-
if (m.outboxID && T.Chat.messageIDToNumber(m.id) !== T.Chat.ordinalToNumber(m.ordinal)) {
554+
if (
555+
regularMessage &&
556+
m.outboxID &&
557+
T.Chat.messageIDToNumber(m.id) !== T.Chat.ordinalToNumber(m.ordinal)
558+
) {
549559
s.pendingOutboxToOrdinal.set(m.outboxID, mapOrdinal)
550560
}
551561
if (m.type === 'text') {
@@ -1314,15 +1324,16 @@ const createSlice: Z.ImmerStateCreator<ConvoState> = (set, get) => {
13141324
const getLastOrdinal = () => get().messageOrdinals?.at(-1) ?? T.Chat.numberToOrdinal(0)
13151325
const username = C.useCurrentUserState.getState().username
13161326
const devicename = C.useCurrentUserState.getState().deviceName
1317-
const message = Message.uiMessageToMessage(
1327+
const m = Message.uiMessageToMessage(
13181328
conversationIDKey,
13191329
hit.message,
13201330
username,
13211331
getLastOrdinal,
13221332
devicename
13231333
)
13241334

1325-
if (message) {
1335+
if (m) {
1336+
const message = {...m, conversationMessage: false}
13261337
set(s => {
13271338
const info = mapGetEnsureValue(
13281339
s.attachmentViewMap,
@@ -1332,9 +1343,9 @@ const createSlice: Z.ImmerStateCreator<ConvoState> = (set, get) => {
13321343
if (!info.messages.find(item => item.id === message.id)) {
13331344
info.messages = info.messages.concat(T.castDraft(message)).sort((l, r) => r.id - l.id)
13341345
}
1335-
1336-
s.messageMapAttachments.set(message.ordinal, T.castDraft(message))
13371346
})
1347+
// inject them into the message map
1348+
messagesAdd([message], 'gallery inject', false)
13381349
}
13391350
},
13401351
},

‎shared/constants/types/chat2/message.tsx‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ interface _MessageCommon {
114114
readonly transferErrMsg?: string
115115
readonly transferState?: MessageAttachmentTransferState
116116
readonly unfurls?: UnfurlMap
117+
// can be false for out of band calls like gallery load
118+
readonly conversationMessage?: boolean
117119
}
118120

119121
// Message types have a lot of copy and paste. Originally I had this split out but this

0 commit comments

Comments
 (0)