Fix go to pinned message targeting outgoing messages

This commit is contained in:
Jamie
2026-02-11 09:42:45 -08:00
committed by GitHub
parent 8d2706bf25
commit bb3dfdc8a5
3 changed files with 14 additions and 2 deletions

View File

@@ -895,6 +895,7 @@ type ReadableInterface = {
_getAllReactions: () => Array<ReactionType>;
getMessageByAuthorAciAndSentAt: (
ourAci: AciString,
authorAci: AciString,
sentAtTimestamp: number,
options: { includeEdits: boolean }

View File

@@ -3450,11 +3450,18 @@ function getAllMessageIds(db: ReadableDB): Array<string> {
function getMessageByAuthorAciAndSentAt(
db: ReadableDB,
ourAci: AciString,
authorAci: AciString,
sentAtTimestamp: number,
options: { includeEdits: boolean }
): MessageType | null {
return db.transaction(() => {
const isSentByUs = ourAci === authorAci;
const senderPredicate = isSentByUs
? sqlFragment`(messages.sourceServiceId = ${authorAci} OR messages.type IS 'outgoing')`
: sqlFragment`(messages.sourceServiceId = ${authorAci})`;
// Return sentAt/readStatus from the messages table, when we edit a message
// we add the original message to messages.editHistory and update original
// message's sentAt/readStatus columns.
@@ -3466,14 +3473,14 @@ function getMessageByAuthorAciAndSentAt(
FROM edited_messages
INNER JOIN messages ON
messages.id = edited_messages.messageId
WHERE messages.sourceServiceId = ${authorAci}
WHERE ${senderPredicate}
AND edited_messages.sentAt = ${sentAtTimestamp}
`;
const messagesQuery = sqlFragment`
SELECT ${MESSAGE_COLUMNS_FRAGMENT}
FROM messages
WHERE messages.sourceServiceId = ${authorAci}
WHERE ${senderPredicate}
AND messages.sent_at = ${sentAtTimestamp}
`;

View File

@@ -107,6 +107,7 @@ import {
isVideoTypeSupported,
} from '../../util/GoogleChrome.std.js';
import type { StateThunk } from '../types.std.js';
import { itemStorage } from '../../textsecure/Storage.preload.js';
const { debounce, isEqual } = lodash;
@@ -390,7 +391,10 @@ function scrollToPinnedMessage(
pinMessage: PinMessageData
): StateThunk<ShowToastActionType | ScrollToMessageActionType> {
return async (dispatch, getState) => {
const ourAci = itemStorage.user.getCheckedAci();
const pinnedMessage = await DataReader.getMessageByAuthorAciAndSentAt(
ourAci,
pinMessage.targetAuthorAci,
pinMessage.targetSentTimestamp,
{ includeEdits: true }