mirror of
https://github.com/signalapp/Signal-Desktop.git
synced 2026-04-02 08:13:37 +01:00
Add expiration timer to pinned message notification
This commit is contained in:
@@ -2493,6 +2493,7 @@ export async function startApp(): Promise<void> {
|
||||
targetAuthorAci: data.message.pinMessage.targetAuthorAci,
|
||||
pinDuration: data.message.pinMessage.pinDuration,
|
||||
pinnedByAci: data.sourceAci,
|
||||
sentAtTimestamp: data.timestamp,
|
||||
receivedAtTimestamp: data.receivedAtDate,
|
||||
});
|
||||
confirm();
|
||||
@@ -3000,6 +3001,7 @@ export async function startApp(): Promise<void> {
|
||||
targetAuthorAci: data.message.pinMessage.targetAuthorAci,
|
||||
pinDuration: data.message.pinMessage.pinDuration,
|
||||
pinnedByAci: sourceServiceId,
|
||||
sentAtTimestamp: data.timestamp,
|
||||
receivedAtTimestamp: data.receivedAtDate,
|
||||
});
|
||||
confirm();
|
||||
|
||||
@@ -27,6 +27,7 @@ export type PinnedMessageAddProps = Readonly<{
|
||||
targetAuthorAci: AciString;
|
||||
pinDuration: DurationInSeconds | null;
|
||||
pinnedByAci: AciString;
|
||||
sentAtTimestamp: number;
|
||||
receivedAtTimestamp: number;
|
||||
}>;
|
||||
|
||||
@@ -115,12 +116,14 @@ export async function onPinnedMessageAdd(
|
||||
drop(pinnedMessagesCleanupService.trigger('onPinnedMessageAdd'));
|
||||
|
||||
if (result.change?.inserted) {
|
||||
await targetConversation.addNotification('pinned-message-notification', {
|
||||
await targetConversation.addPinnedMessageNotification({
|
||||
pinMessage: {
|
||||
targetSentTimestamp: props.targetSentTimestamp,
|
||||
targetAuthorAci: props.targetAuthorAci,
|
||||
},
|
||||
sourceServiceId: props.pinnedByAci,
|
||||
senderAci: props.pinnedByAci,
|
||||
sentAtTimestamp: props.sentAtTimestamp,
|
||||
receivedAtTimestamp: props.receivedAtTimestamp,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ import type {
|
||||
ConversationLastProfileType,
|
||||
ConversationRenderInfoType,
|
||||
MessageAttributesType,
|
||||
PinMessageData,
|
||||
QuotedMessageType,
|
||||
SenderKeyInfoType,
|
||||
SettableConversationAttributesType,
|
||||
@@ -3561,6 +3562,36 @@ export class ConversationModel {
|
||||
await maybeNotify({ message: message.attributes, conversation: this });
|
||||
}
|
||||
|
||||
async addPinnedMessageNotification(params: {
|
||||
pinMessage: PinMessageData;
|
||||
senderAci: AciString;
|
||||
sentAtTimestamp: number;
|
||||
receivedAtTimestamp: number;
|
||||
}): Promise<void> {
|
||||
const ourAci = itemStorage.user.getCheckedAci();
|
||||
const senderIsMe = params.senderAci === ourAci;
|
||||
|
||||
const message = new MessageModel({
|
||||
...generateMessageId(incrementMessageCounter()),
|
||||
conversationId: this.id,
|
||||
type: 'pinned-message-notification',
|
||||
sent_at: params.sentAtTimestamp,
|
||||
received_at_ms: params.receivedAtTimestamp,
|
||||
timestamp: params.sentAtTimestamp,
|
||||
readStatus: senderIsMe ? ReadStatus.Read : ReadStatus.Unread,
|
||||
seenStatus: senderIsMe ? SeenStatus.Seen : SeenStatus.Unseen,
|
||||
sourceServiceId: params.senderAci,
|
||||
expireTimer: this.get('expireTimer'),
|
||||
expirationStartTimestamp: senderIsMe ? params.sentAtTimestamp : null,
|
||||
pinMessage: params.pinMessage,
|
||||
});
|
||||
|
||||
await window.MessageCache.saveMessage(message, { forceSave: true });
|
||||
window.MessageCache.register(message);
|
||||
|
||||
drop(this.onNewMessage(message));
|
||||
}
|
||||
|
||||
async addNotification(
|
||||
type: MessageAttributesType['type'],
|
||||
extra: Partial<MessageAttributesType> = {}
|
||||
|
||||
@@ -3462,7 +3462,7 @@ function getUnreadByConversationAndMarkRead(
|
||||
WHERE
|
||||
conversationId = ${conversationId} AND
|
||||
${storyReplyFilter} AND
|
||||
type IN ('incoming', 'poll-terminate') AND
|
||||
type IS NOT 'outgoing' AND
|
||||
hasExpireTimer IS 1 AND
|
||||
received_at <= ${readMessageReceivedAt}
|
||||
`;
|
||||
@@ -5901,16 +5901,11 @@ function getMessagesUnexpectedlyMissingExpirationStartTimestamp(
|
||||
INDEXED BY messages_unexpectedly_missing_expiration_start_timestamp
|
||||
WHERE
|
||||
expireTimer > 0 AND
|
||||
expirationStartTimestamp IS NULL AND
|
||||
(
|
||||
type IS 'outgoing' OR
|
||||
(type IS 'incoming' AND (
|
||||
readStatus = ${ReadStatus.Read} OR
|
||||
readStatus = ${ReadStatus.Viewed} OR
|
||||
readStatus IS NULL
|
||||
)) OR
|
||||
(type IS 'poll-terminate')
|
||||
);
|
||||
expirationStartTimestamp IS NULL AND (
|
||||
readStatus = ${ReadStatus.Read} OR
|
||||
readStatus = ${ReadStatus.Viewed} OR
|
||||
readStatus IS NULL
|
||||
)
|
||||
`
|
||||
)
|
||||
.all();
|
||||
|
||||
@@ -5218,12 +5218,14 @@ function onPinnedMessageAdd(
|
||||
});
|
||||
drop(pinnedMessagesCleanupService.trigger('onPinnedMessageAdd'));
|
||||
|
||||
await targetConversation.addNotification('pinned-message-notification', {
|
||||
await targetConversation.addPinnedMessageNotification({
|
||||
pinMessage: {
|
||||
targetSentTimestamp: target.targetSentTimestamp,
|
||||
targetAuthorAci: target.targetAuthorAci,
|
||||
},
|
||||
sourceServiceId: itemStorage.user.getCheckedAci(),
|
||||
senderAci: itemStorage.user.getCheckedAci(),
|
||||
sentAtTimestamp: pinnedAt,
|
||||
receivedAtTimestamp: pinnedAt,
|
||||
});
|
||||
|
||||
dispatch(onPinnedMessagesChanged(target.conversationId));
|
||||
|
||||
@@ -251,7 +251,7 @@ export const _withSchemaVersion = ({
|
||||
upgradedMessage = await upgrade(message, context);
|
||||
} catch (error) {
|
||||
logger.error(
|
||||
`Message._withSchemaVersion: error updating message ${message.id},
|
||||
`Message._withSchemaVersion: error updating message ${message.id},
|
||||
attempt ${message.schemaMigrationAttempts}:`,
|
||||
Errors.toLogFormat(error)
|
||||
);
|
||||
@@ -1121,20 +1121,7 @@ export async function migrateBodyAttachmentToDisk(
|
||||
export const isUserMessage = (message: MessageAttributesType): boolean =>
|
||||
message.type === 'incoming' || message.type === 'outgoing';
|
||||
|
||||
// NB: if adding more expiring message types, be sure to also update
|
||||
// getUnreadByConversationAndMarkRead &
|
||||
// getMessagesUnexpectedlyMissingExpirationStartTimestamp
|
||||
export const EXPIRING_MESSAGE_TYPES = new Set([
|
||||
'incoming',
|
||||
'outgoing',
|
||||
'poll-terminate',
|
||||
]);
|
||||
|
||||
export const isExpiringMessage = (message: MessageAttributesType): boolean => {
|
||||
if (!EXPIRING_MESSAGE_TYPES.has(message.type)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const { expireTimer } = message;
|
||||
|
||||
return typeof expireTimer === 'number' && expireTimer > 0;
|
||||
|
||||
Reference in New Issue
Block a user