mirror of
https://github.com/signalapp/Signal-Android.git
synced 2025-12-09 01:30:27 +00:00
Support pinning of edited messages.
This commit is contained in:
committed by
jeffrey-signal
parent
fbbcf30737
commit
2d5a56a88a
@@ -1136,6 +1136,7 @@ open class MessageTable(context: Context?, databaseHelper: SignalDatabase) : Dat
|
||||
.run()
|
||||
|
||||
reactions.moveReactionsToNewMessage(newMessageId = messageId, previousId = targetMessage.id)
|
||||
movePinnedDetailsToNewMessage(newMessageId = messageId, previousId = targetMessage.id)
|
||||
|
||||
notifyConversationListeners(targetMessage.threadId)
|
||||
}
|
||||
@@ -3411,6 +3412,7 @@ open class MessageTable(context: Context?, databaseHelper: SignalDatabase) : Dat
|
||||
attachments.duplicateAttachmentsForMessage(messageId, message.messageToEdit, excludeIds)
|
||||
|
||||
reactions.moveReactionsToNewMessage(messageId, message.messageToEdit)
|
||||
movePinnedDetailsToNewMessage(newMessageId = messageId, previousId = message.messageToEdit)
|
||||
}
|
||||
|
||||
threads.updateLastSeenAndMarkSentAndLastScrolledSilenty(threadId, dateReceived)
|
||||
@@ -3652,7 +3654,7 @@ open class MessageTable(context: Context?, databaseHelper: SignalDatabase) : Dat
|
||||
PINNED_UNTIL to 0,
|
||||
PINNED_AT to 0
|
||||
)
|
||||
.where("$PINNED_AT > 0 AND $PINNED_AT <= ?", oldestPin)
|
||||
.where("$PINNED_AT > 0 AND $PINNED_AT <= ? AND $THREAD_ID = ?", oldestPin, threadId)
|
||||
.run()
|
||||
}
|
||||
}
|
||||
@@ -5281,6 +5283,49 @@ open class MessageTable(context: Context?, databaseHelper: SignalDatabase) : Dat
|
||||
}
|
||||
}
|
||||
|
||||
fun movePinnedDetailsToNewMessage(newMessageId: Long, previousId: Long) {
|
||||
writableDatabase.withinTransaction { db ->
|
||||
val (pinnedAt, pinnedUntil, pinningMessageId) = db
|
||||
.select(PINNED_AT, PINNED_UNTIL, PINNING_MESSAGE_ID)
|
||||
.from(TABLE_NAME)
|
||||
.where("$ID = ?", previousId)
|
||||
.run()
|
||||
.use { cursor ->
|
||||
if (cursor.moveToNext()) {
|
||||
Triple(cursor.requireLong(PINNED_AT), cursor.requireLong(PINNED_UNTIL), cursor.requireLong(PINNING_MESSAGE_ID))
|
||||
} else {
|
||||
Triple(0, 0, 0)
|
||||
}
|
||||
}
|
||||
|
||||
if (pinnedUntil == 0) {
|
||||
return
|
||||
}
|
||||
|
||||
// Remove pinned details from original message
|
||||
db
|
||||
.update(TABLE_NAME)
|
||||
.values(
|
||||
PINNED_AT to 0,
|
||||
PINNED_UNTIL to 0,
|
||||
PINNING_MESSAGE_ID to 0
|
||||
)
|
||||
.where("$ID = ?", previousId)
|
||||
.run()
|
||||
|
||||
// Add pinned details to edited message
|
||||
db
|
||||
.update(TABLE_NAME)
|
||||
.values(
|
||||
PINNED_AT to pinnedAt,
|
||||
PINNED_UNTIL to pinnedUntil,
|
||||
PINNING_MESSAGE_ID to pinningMessageId
|
||||
)
|
||||
.where("$ID = ?", newMessageId)
|
||||
.run()
|
||||
}
|
||||
}
|
||||
|
||||
fun getMessagesForNotificationState(stickyThreads: Collection<StickyThread>): Cursor {
|
||||
val stickyQuery = StringBuilder()
|
||||
|
||||
|
||||
@@ -1316,6 +1316,7 @@ object DataMessageProcessor {
|
||||
return null
|
||||
}
|
||||
|
||||
val targetMessageId = targetMessage.latestRevisionId?.id ?: targetMessage.id
|
||||
val duration = if (pinMessage.pinDurationForever == true) MessageTable.PIN_FOREVER else pinMessage.pinDurationSeconds!!.toLong()
|
||||
val pinnedMessage = IncomingMessage(
|
||||
type = MessageType.PINNED_MESSAGE,
|
||||
@@ -1327,7 +1328,7 @@ object DataMessageProcessor {
|
||||
groupId = groupId,
|
||||
isUnidentified = metadata.sealedSender,
|
||||
serverGuid = UuidUtil.getStringUUID(envelope.serverGuid, envelope.serverGuidBinary),
|
||||
messageExtras = MessageExtras(pinnedMessage = PinnedMessage(pinnedMessageId = targetMessage.id, targetAuthorAci = pinMessage.targetAuthorAciBinary!!, targetTimestamp = pinMessage.targetSentTimestamp!!, pinDurationInSeconds = duration))
|
||||
messageExtras = MessageExtras(pinnedMessage = PinnedMessage(pinnedMessageId = targetMessageId, targetAuthorAci = pinMessage.targetAuthorAciBinary!!, targetTimestamp = pinMessage.targetSentTimestamp!!, pinDurationInSeconds = duration))
|
||||
)
|
||||
|
||||
val insertResult: InsertResult? = SignalDatabase.messages.insertMessageInbox(pinnedMessage).orNull()
|
||||
@@ -1399,9 +1400,10 @@ object DataMessageProcessor {
|
||||
return null
|
||||
}
|
||||
|
||||
SignalDatabase.messages.unpinMessage(targetMessage.id, targetMessage.threadId)
|
||||
val targetMessageId = targetMessage.latestRevisionId?.id ?: targetMessage.id
|
||||
SignalDatabase.messages.unpinMessage(targetMessageId, targetMessage.threadId)
|
||||
|
||||
return MessageId(targetMessage.id)
|
||||
return MessageId(targetMessageId)
|
||||
}
|
||||
|
||||
fun notifyTypingStoppedFromIncomingMessage(context: Context, senderRecipient: Recipient, threadRecipientId: RecipientId, device: Int) {
|
||||
|
||||
@@ -1895,12 +1895,13 @@ object SyncMessageProcessor {
|
||||
return -1
|
||||
}
|
||||
|
||||
val targetMessageId = (targetMessage as? MmsMessageRecord)?.latestRevisionId?.id ?: targetMessage.id
|
||||
val duration = if (pinMessage.pinDurationForever == true) MessageTable.PIN_FOREVER else pinMessage.pinDurationSeconds!!.toLong()
|
||||
val outgoingMessage = OutgoingMessage.pinMessage(
|
||||
threadRecipient = recipient,
|
||||
sentTimeMillis = sent.timestamp!!,
|
||||
expiresIn = recipient.expiresInSeconds.seconds.inWholeMilliseconds,
|
||||
messageExtras = MessageExtras(pinnedMessage = PinnedMessage(pinnedMessageId = targetMessage.id, targetAuthorAci = pinMessage.targetAuthorAciBinary!!, targetTimestamp = pinMessage.targetSentTimestamp!!, pinDurationInSeconds = duration))
|
||||
messageExtras = MessageExtras(pinnedMessage = PinnedMessage(pinnedMessageId = targetMessageId, targetAuthorAci = pinMessage.targetAuthorAciBinary!!, targetTimestamp = pinMessage.targetSentTimestamp!!, pinDurationInSeconds = duration))
|
||||
)
|
||||
|
||||
val messageId = SignalDatabase.messages.insertMessageOutbox(outgoingMessage, threadId, false, GroupReceiptTable.STATUS_UNKNOWN, null).messageId
|
||||
|
||||
Reference in New Issue
Block a user