feat: check contacts client version based on protobuf

pull/941/head
Ryan Zhao 2 years ago
parent 245682b40d
commit c247064fa8

@ -688,7 +688,7 @@ final class ConversationVC: BaseVC, ConversationSearchControllerDelegate, UITabl
}
if initialLoad || viewModel.threadData.contactLastKnownClientVersion != updatedThreadData.contactLastKnownClientVersion {
addOrRemoveOutdatedClientBanner(contactIsUsingOutdatedClient: updatedThreadData.contactLastKnownClientVersion == .preDisappearingMessagesRedesign)
addOrRemoveOutdatedClientBanner(contactIsUsingOutdatedClient: updatedThreadData.contactLastKnownClientVersion == .legacyDisappearingMessages)
}
if initialLoad || viewModel.threadData.threadIsBlocked != updatedThreadData.threadIsBlocked {

@ -79,7 +79,7 @@ public extension Contact {
isTrusted: Updatable<Bool> = .existing,
isApproved: Updatable<Bool> = .existing,
isBlocked: Updatable<Bool> = .existing,
lastKnownClientVersion: Updatable<SessionVersion.FeatureVersion?> = .existing,
lastKnownClientVersion: SessionVersion.FeatureVersion? = nil,
didApproveMe: Updatable<Bool> = .existing
) -> Contact {
return Contact(

@ -20,7 +20,7 @@ public final class ExpirationTimerUpdate: ControlMessage {
// MARK: - Initialization
public init(syncTarget: String?, duration: UInt32) {
public init(syncTarget: String?, duration: UInt32?) {
super.init()
self.syncTarget = syncTarget
@ -64,7 +64,7 @@ public final class ExpirationTimerUpdate: ControlMessage {
return ExpirationTimerUpdate(
syncTarget: dataMessageProto.syncTarget,
duration: proto.hasExpirationTimer ? proto.expirationTimer : 0
duration: proto.hasExpirationTimer ? proto.expirationTimer : dataMessageProto.expireTimer
)
}

@ -65,7 +65,6 @@ public class Message: Codable {
public func setDisappearingMessagesConfigurationIfNeeded(_ db: Database, on proto: SNProtoContent.SNProtoContentBuilder) throws {
guard
DisappearingMessagesConfiguration.isNewConfigurationEnabled,
let threadId: String = threadId,
let disappearingMessagesConfiguration = try? DisappearingMessagesConfiguration.fetchOne(db, id: threadId)
else { return }

@ -332,9 +332,22 @@ public enum MessageReceiver {
openGroupId: String?,
proto: SNProtoContent
) throws {
guard let sender: String = message.sender else { return }
// Check the contact's client version based on this received message
let contact: Contact = Contact.fetchOrCreate(db, id: sender)
let lastKnowClientVersion: SessionVersion.FeatureVersion = (
!proto.hasExpirationType &&
!proto.hasExpirationTimer &&
!proto.hasLastDisappearingMessageChangeTimestamp
) ? .legacyDisappearingMessages : .newDisappearingMessages
_ = try? contact
.with(lastKnownClientVersion: lastKnowClientVersion)
.saved(db)
guard
DisappearingMessagesConfiguration.isNewConfigurationEnabled,
let (threadId, _) = MessageReceiver.threadInfo(db, message: message, openGroupId: openGroupId),
let sender = message.sender,
proto.hasLastDisappearingMessageChangeTimestamp
else { return }

@ -5,7 +5,7 @@ import DifferenceKit
public class SessionVersion {
public enum FeatureVersion: Int, Codable, Equatable, Hashable {
case preDisappearingMessagesRedesign
case disappearingMessageRedesign
case legacyDisappearingMessages
case newDisappearingMessages
}
}

Loading…
Cancel
Save