chore: use display event ID as token position cache key to prevent out-of-date positions being used to render edited messages (#2844)

This commit is contained in:
ggurdin 2025-05-20 09:46:44 -04:00 committed by GitHub
parent e5e7f40220
commit 3adac7f63c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -49,8 +49,12 @@ class MessageTextUtil {
return null;
}
if (_tokenPositionsCache.containsKey(pangeaMessageEvent.eventId)) {
return _tokenPositionsCache[pangeaMessageEvent.eventId]!
final cacheKey = pangeaMessageEvent.event
.getDisplayEvent(pangeaMessageEvent.timeline)
.eventId;
if (_tokenPositionsCache.containsKey(cacheKey)) {
return _tokenPositionsCache[cacheKey]!
.map(
(t) => TokenPosition(
start: t.start,
@ -154,7 +158,7 @@ class MessageTextUtil {
continue;
}
_tokenPositionsCache[pangeaMessageEvent.eventId] = tokenPositions;
_tokenPositionsCache[cacheKey] = tokenPositions;
return tokenPositions;
} catch (err, s) {