@@ -323,6 +323,7 @@ extension AdamantChatsProvider {
323323 SecureStore . remove ( StoreKey . chatProvider. receivedLastHeight)
324324 SecureStore . remove ( StoreKey . chatProvider. readedLastHeight)
325325 SecureStore . remove ( StoreKey . chatProvider. markedChatsAsUnread)
326+ UserDefaultsManager . chatPositions = nil
326327 UserDefaultsManager . lastReceivedId = nil
327328
328329 // Set State
@@ -796,16 +797,30 @@ extension AdamantChatsProvider {
796797 return transaction
797798 }
798799
799- @MainActor func removeChatPosition( for address: String ) {
800- chatPositon. removeValue ( forKey: address)
800+ func removeChatPosition( for address: String ) {
801+ var positions = UserDefaultsManager . chatPositions ?? [ : ]
802+ positions. removeValue ( forKey: address)
803+ UserDefaultsManager . chatPositions = positions
801804 }
802-
803- @MainActor func setChatPositon( for address: String , position: CGFloat ? , collectionHeight: CGFloat ? ) {
804- chatPositon [ address] = ( position, collectionHeight) as? ( CGFloat , CGFloat )
805+
806+ func setChatPositon( for address: String , position: CGFloat ? , collectionHeight: CGFloat ? ) {
807+ var positions = UserDefaultsManager . chatPositions ?? [ : ]
808+ if let position = position, let collectionHeight = collectionHeight {
809+ positions [ address] = [ Double ( position) , Double ( collectionHeight) ]
810+ } else {
811+ positions. removeValue ( forKey: address)
812+ }
813+ UserDefaultsManager . chatPositions = positions
805814 }
806-
807- @MainActor func getChatPositon( for address: String ) -> ( CGFloat , CGFloat ) ? {
808- return chatPositon [ address]
815+
816+ func getChatPositon( for address: String ) -> ( CGFloat , CGFloat ) ? {
817+ guard
818+ let values = UserDefaultsManager . chatPositions ? [ address] ,
819+ values. count == 2
820+ else {
821+ return nil
822+ }
823+ return ( CGFloat ( values [ 0 ] ) , CGFloat ( values [ 1 ] ) )
809824 }
810825
811826 /// Logic:
0 commit comments