Fixed a couple more issues

Fixed an issue with the Emoji generation
Fixed the SessionThread 'isPinned' property
Fixed an issue when migrating from a pre 2.3.0 version to the latest version
This commit is contained in:
Morgan Pretty 2023-09-21 15:55:26 +10:00
parent cdf918194a
commit 52836cff91
16 changed files with 37 additions and 42 deletions

View File

@ -279,10 +279,10 @@ extension EmojiGenerator {
} }
} }
func switchString(with variableName: String = "rawValue") -> String { func switchString(with variableName: String = "rawValue", size: UInt32) -> String {
switch self { switch self {
case .firstScalar: return "rawValue.unicodeScalars.map({ $0.value }).first" case .firstScalar: return "rawValue.unicodeScalars.map({ $0.value }).first.map({ $0 / \(size) })"
case .scalarSum: return "rawValue.unicodeScalars.map({ $0.value }).reduce(0, +)" case .scalarSum: return "(rawValue.unicodeScalars.map({ $0.value }).reduce(0, +) / \(size))"
} }
} }
} }
@ -323,7 +323,7 @@ extension EmojiGenerator {
fileHandle.writeLine("init?(rawValue: String) {") fileHandle.writeLine("init?(rawValue: String) {")
fileHandle.indent { fileHandle.indent {
fileHandle.writeLine("guard rawValue.isSingleEmoji else { return nil }") fileHandle.writeLine("guard rawValue.isSingleEmoji else { return nil }")
fileHandle.writeLine("switch \(chunkType.switchString()) {") fileHandle.writeLine("switch \(chunkType.switchString(size: chunkSize)) {")
fileHandle.indent { fileHandle.indent {
chunkedEmojiInfo.forEach { chunk, _ in chunkedEmojiInfo.forEach { chunk, _ in
fileHandle.writeLine("case \(chunk): self = EmojiWithSkinTones.emojiFrom\(chunk)(rawValue)") fileHandle.writeLine("case \(chunk): self = EmojiWithSkinTones.emojiFrom\(chunk)(rawValue)")

View File

@ -4,7 +4,7 @@
extension EmojiWithSkinTones { extension EmojiWithSkinTones {
init?(rawValue: String) { init?(rawValue: String) {
guard rawValue.isSingleEmoji else { return nil } guard rawValue.isSingleEmoji else { return nil }
switch rawValue.unicodeScalars.map({ $0.value }).reduce(0, +) { switch (rawValue.unicodeScalars.map({ $0.value }).reduce(0, +) / 100) {
case 89: self = EmojiWithSkinTones.emojiFrom89(rawValue) case 89: self = EmojiWithSkinTones.emojiFrom89(rawValue)
case 91: self = EmojiWithSkinTones.emojiFrom91(rawValue) case 91: self = EmojiWithSkinTones.emojiFrom91(rawValue)
case 92: self = EmojiWithSkinTones.emojiFrom92(rawValue) case 92: self = EmojiWithSkinTones.emojiFrom92(rawValue)

View File

@ -82,7 +82,7 @@ public struct SessionApp {
) )
} }
/// The thread should generally exist at the time of calling this method, but on the off change it doesn't then we need to `fetchOrCreate` it and /// The thread should generally exist at the time of calling this method, but on the off chance it doesn't then we need to `fetchOrCreate` it and
/// should do it on a background thread just in case something is keeping the DBWrite thread busy as in the past this could cause the app to hang /// should do it on a background thread just in case something is keeping the DBWrite thread busy as in the past this could cause the app to hang
guard threadInfo?.threadExists == true else { guard threadInfo?.threadExists == true else {
DispatchQueue.global(qos: .userInitiated).async { DispatchQueue.global(qos: .userInitiated).async {

View File

@ -100,8 +100,7 @@ enum MockDataGenerator {
.compactMap { _ in stringContent.randomElement(using: &dmThreadRandomGenerator) } .compactMap { _ in stringContent.randomElement(using: &dmThreadRandomGenerator) }
.joined(), .joined(),
lastNameUpdate: Date().timeIntervalSince1970, lastNameUpdate: Date().timeIntervalSince1970,
lastProfilePictureUpdate: Date().timeIntervalSince1970, lastProfilePictureUpdate: Date().timeIntervalSince1970
lastBlocksCommunityMessageRequests: 0
) )
.saved(db) .saved(db)
@ -182,8 +181,7 @@ enum MockDataGenerator {
.compactMap { _ in stringContent.randomElement(using: &cgThreadRandomGenerator) } .compactMap { _ in stringContent.randomElement(using: &cgThreadRandomGenerator) }
.joined(), .joined(),
lastNameUpdate: Date().timeIntervalSince1970, lastNameUpdate: Date().timeIntervalSince1970,
lastProfilePictureUpdate: Date().timeIntervalSince1970, lastProfilePictureUpdate: Date().timeIntervalSince1970
lastBlocksCommunityMessageRequests: 0
) )
.saved(db) .saved(db)
@ -313,8 +311,7 @@ enum MockDataGenerator {
.compactMap { _ in stringContent.randomElement(using: &ogThreadRandomGenerator) } .compactMap { _ in stringContent.randomElement(using: &ogThreadRandomGenerator) }
.joined(), .joined(),
lastNameUpdate: Date().timeIntervalSince1970, lastNameUpdate: Date().timeIntervalSince1970,
lastProfilePictureUpdate: Date().timeIntervalSince1970, lastProfilePictureUpdate: Date().timeIntervalSince1970
lastBlocksCommunityMessageRequests: 0
) )
.saved(db) .saved(db)

View File

@ -65,7 +65,7 @@ enum _001_InitialSetupMigration: Migration {
t.column(.variant, .integer).notNull() t.column(.variant, .integer).notNull()
t.column(.creationDateTimestamp, .double).notNull() t.column(.creationDateTimestamp, .double).notNull()
t.column(.shouldBeVisible, .boolean).notNull() t.column(.shouldBeVisible, .boolean).notNull()
t.column(.isPinned, .boolean).notNull() t.deprecatedColumn(name: "isPinned", .boolean).notNull()
t.column(.messageDraft, .text) t.column(.messageDraft, .text)
t.column(.notificationSound, .integer) t.column(.notificationSound, .integer)
t.column(.mutedUntilTimestamp, .double) t.column(.mutedUntilTimestamp, .double)

View File

@ -422,8 +422,7 @@ enum _003_YDBToGRDBMigration: Migration {
profilePictureUrl: legacyContact.profilePictureURL, profilePictureUrl: legacyContact.profilePictureURL,
profilePictureFileName: legacyContact.profilePictureFileName, profilePictureFileName: legacyContact.profilePictureFileName,
profileEncryptionKey: legacyContact.profileEncryptionKey?.keyData, profileEncryptionKey: legacyContact.profileEncryptionKey?.keyData,
lastProfilePictureUpdate: 0, lastProfilePictureUpdate: 0
lastBlocksCommunityMessageRequests: 0
).migrationSafeInsert(db) ).migrationSafeInsert(db)
/// **Note:** The blow "shouldForce" flags are here to allow us to avoid having to run legacy migrations they /// **Note:** The blow "shouldForce" flags are here to allow us to avoid having to run legacy migrations they
@ -646,8 +645,7 @@ enum _003_YDBToGRDBMigration: Migration {
id: profileId, id: profileId,
name: profileId, name: profileId,
lastNameUpdate: 0, lastNameUpdate: 0,
lastProfilePictureUpdate: 0, lastProfilePictureUpdate: 0
lastBlocksCommunityMessageRequests: 0
).migrationSafeSave(db) ).migrationSafeSave(db)
} }
@ -1061,8 +1059,7 @@ enum _003_YDBToGRDBMigration: Migration {
id: quotedMessage.authorId, id: quotedMessage.authorId,
name: quotedMessage.authorId, name: quotedMessage.authorId,
lastNameUpdate: 0, lastNameUpdate: 0,
lastProfilePictureUpdate: 0, lastProfilePictureUpdate: 0
lastBlocksCommunityMessageRequests: 0
).migrationSafeSave(db) ).migrationSafeSave(db)
} }

View File

@ -180,7 +180,7 @@ enum _013_SessionUtilChanges: Migration {
// Migrate the 'isPinned' value to 'pinnedPriority' // Migrate the 'isPinned' value to 'pinnedPriority'
try SessionThread try SessionThread
.filter(SessionThread.Columns.isPinned == true) .filter(sql: "isPinned = true")
.updateAll( .updateAll(
db, db,
SessionThread.Columns.pinnedPriority.set(to: 1) SessionThread.Columns.pinnedPriority.set(to: 1)

View File

@ -60,7 +60,7 @@ public struct Profile: Codable, Identifiable, Equatable, Hashable, FetchableReco
public let blocksCommunityMessageRequests: Bool? public let blocksCommunityMessageRequests: Bool?
/// The timestamp (in seconds since epoch) that the `blocksCommunityMessageRequests` setting was last updated /// The timestamp (in seconds since epoch) that the `blocksCommunityMessageRequests` setting was last updated
public let lastBlocksCommunityMessageRequests: TimeInterval public let lastBlocksCommunityMessageRequests: TimeInterval?
// MARK: - Initialization // MARK: - Initialization
@ -74,7 +74,7 @@ public struct Profile: Codable, Identifiable, Equatable, Hashable, FetchableReco
profileEncryptionKey: Data? = nil, profileEncryptionKey: Data? = nil,
lastProfilePictureUpdate: TimeInterval, lastProfilePictureUpdate: TimeInterval,
blocksCommunityMessageRequests: Bool? = nil, blocksCommunityMessageRequests: Bool? = nil,
lastBlocksCommunityMessageRequests: TimeInterval lastBlocksCommunityMessageRequests: TimeInterval? = nil
) { ) {
self.id = id self.id = id
self.name = name self.name = name
@ -129,7 +129,7 @@ public extension Profile {
profileEncryptionKey: profileKey, profileEncryptionKey: profileKey,
lastProfilePictureUpdate: try container.decode(TimeInterval.self, forKey: .lastProfilePictureUpdate), lastProfilePictureUpdate: try container.decode(TimeInterval.self, forKey: .lastProfilePictureUpdate),
blocksCommunityMessageRequests: try? container.decode(Bool.self, forKey: .blocksCommunityMessageRequests), blocksCommunityMessageRequests: try? container.decode(Bool.self, forKey: .blocksCommunityMessageRequests),
lastBlocksCommunityMessageRequests: try container.decode(TimeInterval.self, forKey: .lastBlocksCommunityMessageRequests) lastBlocksCommunityMessageRequests: try? container.decode(TimeInterval.self, forKey: .lastBlocksCommunityMessageRequests)
) )
} }
@ -145,7 +145,7 @@ public extension Profile {
try container.encodeIfPresent(profileEncryptionKey, forKey: .profileEncryptionKey) try container.encodeIfPresent(profileEncryptionKey, forKey: .profileEncryptionKey)
try container.encode(lastProfilePictureUpdate, forKey: .lastProfilePictureUpdate) try container.encode(lastProfilePictureUpdate, forKey: .lastProfilePictureUpdate)
try container.encodeIfPresent(blocksCommunityMessageRequests, forKey: .blocksCommunityMessageRequests) try container.encodeIfPresent(blocksCommunityMessageRequests, forKey: .blocksCommunityMessageRequests)
try container.encode(lastBlocksCommunityMessageRequests, forKey: .lastBlocksCommunityMessageRequests) try container.encodeIfPresent(lastBlocksCommunityMessageRequests, forKey: .lastBlocksCommunityMessageRequests)
} }
} }
@ -263,7 +263,7 @@ public extension Profile {
profileEncryptionKey: nil, profileEncryptionKey: nil,
lastProfilePictureUpdate: 0, lastProfilePictureUpdate: 0,
blocksCommunityMessageRequests: nil, blocksCommunityMessageRequests: nil,
lastBlocksCommunityMessageRequests: 0 lastBlocksCommunityMessageRequests: nil
) )
} }

View File

@ -27,7 +27,7 @@ public struct SessionThread: Codable, Identifiable, Equatable, FetchableRecord,
case variant case variant
case creationDateTimestamp case creationDateTimestamp
case shouldBeVisible case shouldBeVisible
case isPinned @available(*, deprecated, message: "use 'pinnedPriority > 0' instead") case isPinned
case messageDraft case messageDraft
case notificationSound case notificationSound
case mutedUntilTimestamp case mutedUntilTimestamp
@ -61,8 +61,8 @@ public struct SessionThread: Codable, Identifiable, Equatable, FetchableRecord,
public let shouldBeVisible: Bool public let shouldBeVisible: Bool
/// A flag indicating whether the thread is pinned /// A flag indicating whether the thread is pinned
// @available(*, unavailable, message: "use 'pinnedPriority' instead") @available(*, deprecated, message: "use 'pinnedPriority > 0' instead")
public let isPinned: Bool = false private let isPinned: Bool = false
/// The value the user started entering into the input field before they left the conversation screen /// The value the user started entering into the input field before they left the conversation screen
public let messageDraft: String? public let messageDraft: String?

View File

@ -564,8 +564,7 @@ private extension SessionUtil {
count: ProfileManager.avatarAES256KeyByteLength count: ProfileManager.avatarAES256KeyByteLength
) )
), ),
lastProfilePictureUpdate: (TimeInterval(latestConfigSentTimestampMs) / 1000), lastProfilePictureUpdate: (TimeInterval(latestConfigSentTimestampMs) / 1000)
lastBlocksCommunityMessageRequests: 0
) )
result[contactId] = ContactData( result[contactId] = ContactData(

View File

@ -517,7 +517,7 @@ public struct ProfileManager {
} }
// Blocks community message requets flag // Blocks community message requets flag
if let blocksCommunityMessageRequests: Bool = blocksCommunityMessageRequests, sentTimestamp > profile.lastBlocksCommunityMessageRequests { if let blocksCommunityMessageRequests: Bool = blocksCommunityMessageRequests, sentTimestamp > (profile.lastBlocksCommunityMessageRequests ?? 0) {
profileChanges.append(Profile.Columns.blocksCommunityMessageRequests.set(to: blocksCommunityMessageRequests)) profileChanges.append(Profile.Columns.blocksCommunityMessageRequests.set(to: blocksCommunityMessageRequests))
profileChanges.append(Profile.Columns.lastBlocksCommunityMessageRequests.set(to: sentTimestamp)) profileChanges.append(Profile.Columns.lastBlocksCommunityMessageRequests.set(to: sentTimestamp))
} }

View File

@ -61,16 +61,14 @@ class ThreadSettingsViewModelSpec: QuickSpec {
id: "05\(TestConstants.publicKey)", id: "05\(TestConstants.publicKey)",
name: "TestMe", name: "TestMe",
lastNameUpdate: 0, lastNameUpdate: 0,
lastProfilePictureUpdate: 0, lastProfilePictureUpdate: 0
lastBlocksCommunityMessageRequests: 0
).insert(db) ).insert(db)
try Profile( try Profile(
id: "TestId", id: "TestId",
name: "TestUser", name: "TestUser",
lastNameUpdate: 0, lastNameUpdate: 0,
lastProfilePictureUpdate: 0, lastProfilePictureUpdate: 0
lastBlocksCommunityMessageRequests: 0
).insert(db) ).insert(db)
} }
viewModel = ThreadSettingsViewModel( viewModel = ThreadSettingsViewModel(

View File

@ -82,11 +82,11 @@ internal enum Theme_ClassicDark: ThemeColors {
.alert_buttonBackground: .classicDark1, .alert_buttonBackground: .classicDark1,
// ConversationButton // ConversationButton
.conversationButton_background: .classicDark1, .conversationButton_background: .classicDark0,
.conversationButton_unreadBackground: .classicDark2, .conversationButton_unreadBackground: .classicDark1,
.conversationButton_unreadStripBackground: .primary, .conversationButton_unreadStripBackground: .primary,
.conversationButton_unreadBubbleBackground: .classicDark3, .conversationButton_unreadBubbleBackground: .primary,
.conversationButton_unreadBubbleText: .classicDark6, .conversationButton_unreadBubbleText: .classicDark0,
.conversationButton_swipeDestructive: .dangerDark, .conversationButton_swipeDestructive: .dangerDark,
.conversationButton_swipeSecondary: .classicDark2, .conversationButton_swipeSecondary: .classicDark2,
.conversationButton_swipeTertiary: Theme.PrimaryColor.orange.color, .conversationButton_swipeTertiary: Theme.PrimaryColor.orange.color,

View File

@ -85,7 +85,7 @@ internal enum Theme_ClassicLight: ThemeColors {
.conversationButton_background: .classicLight6, .conversationButton_background: .classicLight6,
.conversationButton_unreadBackground: .classicLight6, .conversationButton_unreadBackground: .classicLight6,
.conversationButton_unreadStripBackground: .primary, .conversationButton_unreadStripBackground: .primary,
.conversationButton_unreadBubbleBackground: .classicLight3, .conversationButton_unreadBubbleBackground: .primary,
.conversationButton_unreadBubbleText: .classicLight0, .conversationButton_unreadBubbleText: .classicLight0,
.conversationButton_swipeDestructive: .dangerLight, .conversationButton_swipeDestructive: .dangerLight,
.conversationButton_swipeSecondary: .classicLight1, .conversationButton_swipeSecondary: .classicLight1,

View File

@ -82,8 +82,8 @@ internal enum Theme_OceanDark: ThemeColors {
.alert_buttonBackground: .oceanDark3, .alert_buttonBackground: .oceanDark3,
// ConversationButton // ConversationButton
.conversationButton_background: .oceanDark3, .conversationButton_background: .oceanDark2,
.conversationButton_unreadBackground: .oceanDark4, .conversationButton_unreadBackground: .oceanDark3,
.conversationButton_unreadStripBackground: .primary, .conversationButton_unreadStripBackground: .primary,
.conversationButton_unreadBubbleBackground: .primary, .conversationButton_unreadBubbleBackground: .primary,
.conversationButton_unreadBubbleText: .oceanDark0, .conversationButton_unreadBubbleText: .oceanDark0,

View File

@ -16,6 +16,10 @@ public class TypedTableDefinition<T> where T: TableRecord, T: ColumnExpressible
return definition.column(key.name, type) return definition.column(key.name, type)
} }
@discardableResult public func deprecatedColumn(name: String, _ type: Database.ColumnType? = nil) -> ColumnDefinition {
return definition.column(name, type)
}
public func primaryKey(_ columns: [T.Columns], onConflict: Database.ConflictResolution? = nil) { public func primaryKey(_ columns: [T.Columns], onConflict: Database.ConflictResolution? = nil) {
definition.primaryKey(columns.map { $0.name }, onConflict: onConflict) definition.primaryKey(columns.map { $0.name }, onConflict: onConflict)
} }