Merge branch 'dev' into disappearing-message-redesign

pull/731/head
ryanzhao 2 years ago
commit d415ea5781

@ -553,16 +553,34 @@ extension ConversationVC:
let insertedInteraction: Interaction = try optimisticData.interaction.inserted(db)
self?.viewModel.associate(optimisticMessageId: optimisticData.id, to: insertedInteraction.id)
// If there is a LinkPreview and it doesn't match an existing one then add it now
if
let linkPreviewDraft: LinkPreviewDraft = optimisticData.linkPreviewDraft,
(try? insertedInteraction.linkPreview.isEmpty(db)) == true
{
try LinkPreview(
url: linkPreviewDraft.urlString,
title: linkPreviewDraft.title,
attachmentId: try optimisticData.linkPreviewAttachment?.inserted(db).id
).insert(db)
// If there is a LinkPreview draft then check the state of any existing link previews and
// insert a new one if needed
if let linkPreviewDraft: LinkPreviewDraft = optimisticData.linkPreviewDraft {
let invalidLinkPreviewAttachmentStates: [Attachment.State] = [
.failedDownload, .pendingDownload, .downloading, .failedUpload, .invalid
]
let linkPreviewAttachmentId: String? = try? insertedInteraction.linkPreview
.select(.attachmentId)
.asRequest(of: String.self)
.fetchOne(db)
let linkPreviewAttachmentState: Attachment.State = linkPreviewAttachmentId
.map {
try? Attachment
.filter(id: $0)
.select(.state)
.asRequest(of: Attachment.State.self)
.fetchOne(db)
}
.defaulting(to: .invalid)
// If we don't have a "valid" existing link preview then upsert a new one
if invalidLinkPreviewAttachmentStates.contains(linkPreviewAttachmentState) {
try LinkPreview(
url: linkPreviewDraft.urlString,
title: linkPreviewDraft.title,
attachmentId: try optimisticData.linkPreviewAttachment?.inserted(db).id
).save(db)
}
}
// If there is a Quote the insert it now

@ -609,6 +609,10 @@ final class ConversationVC: BaseVC, SessionUtilRespondingViewController, Convers
let threadId: String = viewModel.threadData.threadId
if
(
self.navigationController == nil ||
self.navigationController?.viewControllers.contains(self) == false
) &&
viewModel.threadData.threadIsNoteToSelf == false &&
viewModel.threadData.threadShouldBeVisible == false &&
!SessionUtil.conversationInConfig(

@ -265,6 +265,24 @@ public class ConversationViewModel: OWSAudioPlayerDelegate {
.allCases
.filter { $0 != .wasRead }
),
PagedData.ObservedChanges(
table: Attachment.self,
columns: [.state],
joinToPagedType: {
let interaction: TypedTableAlias<Interaction> = TypedTableAlias()
let linkPreview: TypedTableAlias<LinkPreview> = TypedTableAlias()
let linkPreviewAttachment: TypedTableAlias<Attachment> = TypedTableAlias()
return SQL("""
LEFT JOIN \(LinkPreview.self) ON (
\(linkPreview[.url]) = \(interaction[.linkPreviewUrl]) AND
\(Interaction.linkPreviewFilterLiteral())
)
LEFT JOIN \(linkPreviewAttachment) ON \(linkPreviewAttachment[.id]) = \(linkPreview[.attachmentId])
"""
)
}()
),
PagedData.ObservedChanges(
table: Contact.self,
columns: [.isTrusted],

@ -467,7 +467,6 @@ final class VisibleMessageCell: MessageCell, TappableLabelDelegate {
subview.removeFromSuperview()
}
albumView = nil
albumView = nil
bodyTappableLabel = nil
// Handle the deleted state first (it's much simpler than the others)

@ -85,7 +85,36 @@ public enum SyncPushTokensJob: JobExecutor {
Logger.info("Re-registering for remote notifications.")
PushRegistrationManager.shared.requestPushTokens()
.flatMap { (pushToken: String, voipToken: String) -> AnyPublisher<Void, Error> in
PushNotificationAPI
/// For our `subscribe` endpoint we only want to call it if:
/// It's been longer than `SyncPushTokensJob.maxFrequency` since the last subscription;
/// The token has changed; or
/// We want to force an update
let timeSinceLastSubscription: TimeInterval = dependencies.dateNow
.timeIntervalSince(
dependencies.standardUserDefaults[.lastPushNotificationSync]
.defaulting(to: Date.distantPast)
)
let uploadOnlyIfStale: Bool? = {
guard
let detailsData: Data = job.details,
let details: Details = try? JSONDecoder().decode(Details.self, from: detailsData)
else { return nil }
return details.uploadOnlyIfStale
}()
guard
timeSinceLastSubscription >= SyncPushTokensJob.maxFrequency ||
dependencies.storage[.lastRecordedPushToken] != pushToken ||
uploadOnlyIfStale == false
else {
SNLog("[SyncPushTokensJob] OS subscription completed, skipping server subscription due to frequency")
return Just(())
.setFailureType(to: Error.self)
.eraseToAnyPublisher()
}
return PushNotificationAPI
.subscribe(
token: Data(hex: pushToken),
isForcedUpdate: true,

@ -77,7 +77,7 @@ public struct LinkPreview: Codable, Equatable, Hashable, FetchableRecord, Persis
// MARK: - Protobuf
public extension LinkPreview {
init?(_ db: Database, proto: SNProtoDataMessage, body: String?, sentTimestampMs: TimeInterval) throws {
init?(_ db: Database, proto: SNProtoDataMessage, sentTimestampMs: TimeInterval) throws {
guard let previewProto = proto.preview.first else { throw LinkPreviewError.noPreview }
guard URL(string: previewProto.url) != nil else { throw LinkPreviewError.invalidInput }
guard LinkPreview.isValidLinkUrl(previewProto.url) else { throw LinkPreviewError.invalidInput }
@ -86,9 +86,7 @@ public extension LinkPreview {
let timestamp: TimeInterval = LinkPreview.timestampFor(sentTimestampMs: sentTimestampMs)
let maybeLinkPreview: LinkPreview? = try? LinkPreview
.filter(LinkPreview.Columns.url == previewProto.url)
.filter(LinkPreview.Columns.timestamp == LinkPreview.timestampFor(
sentTimestampMs: Double(proto.timestamp)
))
.filter(LinkPreview.Columns.timestamp == timestamp)
.fetchOne(db)
if let linkPreview: LinkPreview = maybeLinkPreview {

@ -282,7 +282,6 @@ extension MessageReceiver {
let linkPreview: LinkPreview? = try? LinkPreview(
db,
proto: dataMessage,
body: message.text,
sentTimestampMs: (messageSentTimestamp * 1000)
)?.saved(db)

@ -8,6 +8,8 @@ extension PushNotificationAPI {
case accountId = "@"
case hash = "#"
case namespace = "n"
case createdTimestampMs = "t"
case expirationTimestampMs = "z"
case dataLength = "l"
case dataTooLong = "B"
}
@ -21,6 +23,12 @@ extension PushNotificationAPI {
/// The swarm namespace in which this message arrived.
let namespace: Int
/// The swarm timestamp when the message was created (unix epoch milliseconds)
let createdTimestampMs: Int64
/// The message's swarm expiry timestamp (unix epoch milliseconds)
let expirationTimestampMs: Int64
/// The length of the message data. This is always included, even if the message content
/// itself was too large to fit into the push notification.
let dataLength: Int
@ -40,6 +48,8 @@ extension PushNotificationAPI.NotificationMetadata {
accountId: try container.decode(String.self, forKey: .accountId),
hash: try container.decode(String.self, forKey: .hash),
namespace: try container.decode(Int.self, forKey: .namespace),
createdTimestampMs: try container.decode(Int64.self, forKey: .createdTimestampMs),
expirationTimestampMs: try container.decode(Int64.self, forKey: .expirationTimestampMs),
dataLength: try container.decode(Int.self, forKey: .dataLength),
dataTooLong: ((try? container.decode(Int.self, forKey: .dataTooLong) != 0) ?? false)
)

Loading…
Cancel
Save