fix call messages and data extraction messages with their expiration info and refactor

pull/731/head
Ryan ZHAO 4 months ago
parent e85ec08b36
commit 43e2983f49

@ -221,15 +221,14 @@ public final class SessionCall: CurrentCallProtocol, WebRTCSessionDelegate {
let webRTCSession: WebRTCSession = self.webRTCSession
let timestampMs: Int64 = SnodeAPI.currentOffsetTimestampMs()
let disappearingMessagesConfiguration = try? thread.disappearingMessagesConfiguration.fetchOne(db)
let disappearingMessagesConfiguration = try? thread.disappearingMessagesConfiguration.fetchOne(db)?.forcedWithDisappearAfterReadIfNeeded()
let message: CallMessage = CallMessage(
uuid: self.uuid,
kind: .preOffer,
sdps: [],
sentTimestampMs: UInt64(timestampMs)
)
message.expiresInSeconds = disappearingMessagesConfiguration?.durationSeconds
message.expiresStartedAtMs = disappearingMessagesConfiguration?.type == .disappearAfterSend ? Double(timestampMs) : nil
.with(disappearingMessagesConfiguration)
let interaction: Interaction? = try? Interaction(
messageUuid: self.uuid,
@ -241,7 +240,6 @@ public final class SessionCall: CurrentCallProtocol, WebRTCSessionDelegate {
expiresInSeconds: message.expiresInSeconds,
expiresStartedAtMs: message.expiresStartedAtMs
)
.withDisappearingMessagesConfiguration(config: disappearingMessagesConfiguration)
.inserted(db)
self.callInteractionId = interaction?.id

@ -2093,8 +2093,10 @@ extension ConversationVC:
cellViewModel.authorId
)
)
unsendRequest.expiresInSeconds = cellViewModel.expiresInSeconds
unsendRequest.expiresStartedAtMs = cellViewModel.expiresStartedAtMs
.with(
expiresInSeconds: cellViewModel.expiresInSeconds,
expiresStartedAtMs: cellViewModel.expiresStartedAtMs
)
// For incoming interactions or interactions with no serverHash just delete them locally
guard cellViewModel.variant == .standardOutgoing, let serverHash: String = serverHash else {
@ -2512,6 +2514,10 @@ extension ConversationVC:
message: DataExtractionNotification(
kind: kind,
sentTimestamp: UInt64(SnodeAPI.currentOffsetTimestampMs())
)
.with(DisappearingMessagesConfiguration
.fetchOne(db, id: threadId)?
.forcedWithDisappearAfterReadIfNeeded()
),
interactionId: nil,
threadId: threadId,

@ -499,9 +499,8 @@ class ThreadDisappearingMessagesSettingsViewModel: SessionTableViewModel, Naviga
syncTarget: nil,
duration: duration
)
expirationTimerUpdateMessage.sentTimestamp = UInt64(currentTimestampMs)
expirationTimerUpdateMessage.expiresInSeconds = updatedConfig.durationSeconds
expirationTimerUpdateMessage.expiresStartedAtMs = updatedConfig.type == .disappearAfterSend ? Double(currentTimestampMs) : nil
.with(sentTimestamp: UInt64(currentTimestampMs))
.with(updatedConfig)
try MessageSender.send(
db,

@ -558,6 +558,10 @@ class MediaPageViewController: UIPageViewController, UIPageViewControllerDataSou
timestamp: UInt64(currentViewController.galleryItem.interactionTimestampMs)
),
sentTimestamp: UInt64(SnodeAPI.currentOffsetTimestampMs())
)
.with(DisappearingMessagesConfiguration
.fetchOne(db, id: threadId)?
.forcedWithDisappearAfterReadIfNeeded()
),
interactionId: nil, // Show no interaction for the current user
threadId: threadId,

@ -57,6 +57,8 @@
<true/>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
<key>NSExceptionDomains</key>
<dict>
<key>seed1.getsession.org</key>

@ -184,6 +184,10 @@ public final class WebRTCSession : NSObject, RTCPeerConnectionDelegate {
kind: .offer,
sdps: [ sdp.sdp ],
sentTimestampMs: UInt64(SnodeAPI.currentOffsetTimestampMs())
)
.with(try? thread.disappearingMessagesConfiguration
.fetchOne(db)?
.forcedWithDisappearAfterReadIfNeeded()
),
to: try Message.Destination
.from(db, threadId: thread.id, threadVariant: thread.variant),
@ -254,6 +258,10 @@ public final class WebRTCSession : NSObject, RTCPeerConnectionDelegate {
uuid: uuid,
kind: .answer,
sdps: [ sdp.sdp ]
)
.with(try? thread.disappearingMessagesConfiguration
.fetchOne(db)?
.forcedWithDisappearAfterReadIfNeeded()
),
to: try Message.Destination
.from(db, threadId: thread.id, threadVariant: thread.variant),
@ -316,6 +324,10 @@ public final class WebRTCSession : NSObject, RTCPeerConnectionDelegate {
sdpMids: candidates.map { $0.sdpMid! }
),
sdps: candidates.map { $0.sdp }
)
.with(try? thread.disappearingMessagesConfiguration
.fetchOne(db)?
.forcedWithDisappearAfterReadIfNeeded()
),
to: try Message.Destination
.from(db, threadId: thread.id, threadVariant: thread.variant),
@ -347,6 +359,10 @@ public final class WebRTCSession : NSObject, RTCPeerConnectionDelegate {
uuid: self.uuid,
kind: .endCall,
sdps: []
)
.with(try? thread.disappearingMessagesConfiguration
.fetchOne(db)?
.forcedWithDisappearAfterReadIfNeeded()
),
to: try Message.Destination.from(db, threadId: thread.id, threadVariant: thread.variant),
namespace: try Message.Destination

@ -112,6 +112,14 @@ public extension DisappearingMessagesConfiguration {
type: (isEnabled == false) ? .unknown : (type ?? self.type)
)
}
func forcedWithDisappearAfterReadIfNeeded() -> DisappearingMessagesConfiguration {
if self.isEnabled {
return self.with(type: .disappearAfterRead)
}
return self
}
}
// MARK: - Convenience

@ -17,7 +17,8 @@ public final class CallMessage: ControlMessage {
/// See https://developer.mozilla.org/en-US/docs/Glossary/SDP for more information.
public var sdps: [String]
public override var ttl: UInt64 { 5 * 60 * 1000 } // 5 minutes
public override var isSelfSendValid: Bool {
switch kind {
case .answer, .endCall: return true

@ -685,9 +685,26 @@ public extension Message {
// MARK: - Mutation
internal extension Message {
func with(sentTimestamp: UInt64) -> Message {
public extension Message {
func with(sentTimestamp: UInt64) -> Self {
self.sentTimestamp = sentTimestamp
return self
}
func with(_ disappearingMessagesConfiguration: DisappearingMessagesConfiguration?) -> Self {
self.expiresInSeconds = disappearingMessagesConfiguration?.durationSeconds
if disappearingMessagesConfiguration?.type == .disappearAfterSend, let sentTimestamp = self.sentTimestamp {
self.expiresStartedAtMs = Double(sentTimestamp)
}
return self
}
func with(
expiresInSeconds: TimeInterval?,
expiresStartedAtMs: Double? = nil
) -> Self {
self.expiresInSeconds = expiresInSeconds
self.expiresStartedAtMs = expiresStartedAtMs
return self
}
}

@ -260,6 +260,10 @@ public extension VisibleMessage {
},
reaction: nil // Reactions are custom messages sent separately
)
.with(
expiresInSeconds: interaction.expiresInSeconds,
expiresStartedAtMs: interaction.expiresStartedAtMs
)
visibleMessage.expiresInSeconds = interaction.expiresInSeconds
visibleMessage.expiresStartedAtMs = interaction.expiresStartedAtMs

@ -228,9 +228,10 @@ extension MessageReceiver {
timestampMs: (messageSentTimestamp * 1000),
userPublicKey: getUserHexEncodedPublicKey(db),
openGroup: nil
)
),
expiresInSeconds: message.expiresInSeconds,
expiresStartedAtMs: message.expiresStartedAtMs
)
.withDisappearAfterReadIfNeeded(db) // Should follow local timer with disappear after read
.inserted(db)
MessageSender.sendImmediate(
@ -242,6 +243,10 @@ extension MessageReceiver {
kind: .endCall,
sdps: [],
sentTimestampMs: nil // Explicitly nil as it's a separate message from above
)
.with(try? thread.disappearingMessagesConfiguration
.fetchOne(db)?
.forcedWithDisappearAfterReadIfNeeded()
),
to: try Message.Destination.from(db, threadId: thread.id, threadVariant: thread.variant),
namespace: try Message.Destination
@ -302,9 +307,10 @@ extension MessageReceiver {
timestampMs: (timestampMs * 1000),
userPublicKey: currentUserPublicKey,
openGroup: nil
)
),
expiresInSeconds: message.expiresInSeconds,
expiresStartedAtMs: message.expiresStartedAtMs
)
.withDisappearAfterReadIfNeeded(db) // Should follow local timer with disappear after read
.inserted(db)
}
}

@ -39,9 +39,10 @@ extension MessageReceiver {
timestampMs: (timestampMs * 1000),
userPublicKey: getUserHexEncodedPublicKey(db),
openGroup: nil
)
),
expiresInSeconds: message.expiresInSeconds,
expiresStartedAtMs: message.expiresStartedAtMs
)
.withDisappearAfterReadIfNeeded(db) // Should follow local timer with disappear after read
.inserted(db)
}
}

Loading…
Cancel
Save