@@ -24,6 +24,9 @@ public func iconForSession(_ session: RecentAccountSession) -> (CGImage?, LocalA
2424 let platform = session . platform . lowercased ( )
2525 let device = session . deviceModel . lowercased ( )
2626 let systemVersion = session . systemVersion . lowercased ( )
27+ if session . isCurrent {
28+ return ( NSImage ( named : " Icon_Device_Apple " ) ! . precomposed ( ) , LocalAnimatedSticker . device_mac , NSColor ( rgb : 0x0079ff ) , nil )
29+ }
2730 if device . contains ( " xbox " ) {
2831 return ( NSImage ( named : " Icon_Device_Xbox " ) ! . precomposed ( ) , nil , NSColor ( rgb : 0x35c759 ) , nil )
2932 }
@@ -48,7 +51,7 @@ public func iconForSession(_ session: RecentAccountSession) -> (CGImage?, LocalA
4851 if platform . contains ( " android " ) {
4952 return ( NSImage ( named : " Icon_Device_Android " ) ! . precomposed ( ) , LocalAnimatedSticker . device_android , NSColor ( rgb : 0x35c759 ) , [ " Eye L.Eye L.Заливка 1 " , " Eye R.Eye R.Заливка 1 " ] )
5053 }
51- if ( platform . contains ( " macos " ) || systemVersion . contains ( " macos " ) ) && device . contains ( " mac " ) {
54+ if ( platform . contains ( " macos " ) || systemVersion . contains ( " macos " ) ) && ! device . contains ( " iphone " ) && ! device . contains ( " ipad " ) {
5255 return ( NSImage ( named : " Icon_Device_Apple " ) ! . precomposed ( ) , LocalAnimatedSticker . device_mac , NSColor ( rgb : 0x0079ff ) , nil )
5356 }
5457 if device . contains ( " ipad " ) {
@@ -83,12 +86,14 @@ private final class RecentSessionsControllerArguments {
8386 public let terminateOthers : ( ) -> Void
8487 public let toggleTtl : ( Int ) -> Void
8588 public let preview : ( RecentAccountSession , AnyHashable ) -> Void
86- public init ( context : any AccountContextProtocol , removeSession : @escaping ( Int64 ) -> Void , terminateOthers : @escaping ( ) -> Void , toggleTtl : @escaping ( Int ) -> Void , preview : @escaping ( RecentAccountSession , AnyHashable ) -> Void ) {
89+ public let rename : ( ) -> Void
90+ public init ( context : any AccountContextProtocol , removeSession : @escaping ( Int64 ) -> Void , terminateOthers : @escaping ( ) -> Void , toggleTtl : @escaping ( Int ) -> Void , preview : @escaping ( RecentAccountSession , AnyHashable ) -> Void , rename : @escaping ( ) -> Void ) {
8791 self . context = context
8892 self . removeSession = removeSession
8993 self . terminateOthers = terminateOthers
9094 self . toggleTtl = toggleTtl
9195 self . preview = preview
96+ self . rename = rename
9297 }
9398}
9499
@@ -113,7 +118,7 @@ public enum RecentSessionsEntryStableId: Hashable {
113118private enum RecentSessionsEntry : Comparable , Identifiable {
114119 case loading ( sectionId : Int )
115120 case currentSessionHeader ( sectionId : Int , viewType : GeneralViewType )
116- case currentSession ( sectionId : Int , RecentAccountSession , viewType : GeneralViewType )
121+ case currentSession ( sectionId : Int , RecentAccountSession , deviceModel : String ? , viewType : GeneralViewType )
117122 case terminateOtherSessions ( sectionId : Int , viewType : GeneralViewType )
118123 case currentSessionInfo ( sectionId : Int , viewType : GeneralViewType )
119124
@@ -193,7 +198,7 @@ private enum RecentSessionsEntry: Comparable, Identifiable {
193198 return sectionId
194199 case let . currentSessionHeader ( sectionId , _) :
195200 return sectionId
196- case let . currentSession ( sectionId , _, _) :
201+ case let . currentSession ( sectionId , _, _, _ ) :
197202 return sectionId
198203 case let . terminateOtherSessions ( sectionId , _) :
199204 return sectionId
@@ -222,7 +227,7 @@ private enum RecentSessionsEntry: Comparable, Identifiable {
222227 return ( sectionId * 1000 ) + stableIndex
223228 case let . currentSessionHeader ( sectionId , _) :
224229 return ( sectionId * 1000 ) + stableIndex
225- case let . currentSession ( sectionId , _, _) :
230+ case let . currentSession ( sectionId , _, _, _ ) :
226231 return ( sectionId * 1000 ) + stableIndex
227232 case let . terminateOtherSessions ( sectionId , _) :
228233 return ( sectionId * 1000 ) + stableIndex
@@ -253,9 +258,9 @@ private enum RecentSessionsEntry: Comparable, Identifiable {
253258 public func item ( _ arguments : RecentSessionsControllerArguments , initialSize : NSSize ) -> TableRowItem {
254259 switch self {
255260 case let . currentSessionHeader ( _, viewType ) :
256- return GeneralTextRowItem ( initialSize , stableId : stableId , text : strings ( ) . sessionsCurrentSessionHeader , viewType : viewType )
257- case let . currentSession ( _, session , viewType ) :
258- return RecentSessionRowItem ( initialSize , session : session , stableId : stableId , viewType : viewType , icon : iconForSession ( session ) , handler : {
261+ return GeneralTextRowItem ( initialSize , stableId : stableId , text : strings ( ) . sessionsCurrentSessionHeader , viewType : viewType , rightItem : InputDataGeneralTextRightData ( isLoading : false , text : . initialize ( string : " Rename " , color : theme . colors . accent , font : . medium ( . small ) ) , action : arguments . rename ) ) //TODOLANG
262+ case let . currentSession ( _, session , deviceModel , viewType ) :
263+ return RecentSessionRowItem ( initialSize , session : session , deviceModel : deviceModel , stableId : stableId , viewType : viewType , icon : iconForSession ( session ) , handler : {
259264 arguments . preview ( session , stableId )
260265 } )
261266 case let . terminateOtherSessions ( _, viewType ) :
@@ -356,7 +361,7 @@ private struct RecentSessionsControllerState: Equatable {
356361 }
357362}
358363
359- private func recentSessionsControllerEntries ( state : RecentSessionsControllerState , sessions : ActiveSessionsContextState ) -> [ RecentSessionsEntry ] {
364+ private func recentSessionsControllerEntries ( state : RecentSessionsControllerState , sessions : ActiveSessionsContextState , deviceModel : String ? ) -> [ RecentSessionsEntry ] {
360365 var entries : [ RecentSessionsEntry ] = [ ]
361366
362367
@@ -368,7 +373,7 @@ private func recentSessionsControllerEntries(state: RecentSessionsControllerStat
368373 entries . append ( . currentSessionHeader ( sectionId : sectionId , viewType : . textTopItem ) )
369374 if let index = sessions . sessions . firstIndex ( where : { $0 . hash == 0 } ) {
370375 existingSessionIds . insert ( sessions . sessions [ index ] . hash )
371- entries . append ( . currentSession ( sectionId : sectionId , sessions . sessions [ index ] , viewType : . firstItem ) )
376+ entries . append ( . currentSession ( sectionId : sectionId , sessions . sessions [ index ] , deviceModel : deviceModel , viewType : . firstItem ) )
372377 }
373378 entries . append ( . terminateOtherSessions ( sectionId : sectionId , viewType : existingSessionIds . isEmpty ? . singleItem : . lastItem ) )
374379 entries . append ( . currentSessionInfo ( sectionId : sectionId , viewType : . textBottomItem ) )
@@ -526,6 +531,9 @@ open class RecentSessionsController<Context: AccountContextProtocol>: TableViewC
526531 showModal ( with : SessionModalController ( context : context , session : session ) , for : context . window , morphSource : {
527532 ( self ? . genericView . item ( stableId : stableId ) ? . view as? GeneralContainableRowView ) ? . containerView
528533 } )
534+ } , rename : { [ weak self ] in
535+ let source = ( self ? . genericView . item ( stableId : RecentSessionsEntryStableId . index ( 2 ) ) ? . view as? RecentSessionRowView ) ? . titleView
536+ showModal ( with : RenameDeviceController ( context : context ) , for : context . window , morphSource : source . map { source in { [ weak source ] in source } } )
529537 } )
530538
531539 let sessionsSignal : Signal < ActiveSessionsContextState , NoError > = context . activeSessionsContext . state
@@ -534,10 +542,10 @@ open class RecentSessionsController<Context: AccountContextProtocol>: TableViewC
534542
535543 let previousSessions : Atomic < [ AppearanceWrapperEntry < RecentSessionsEntry > ] > = Atomic ( value : [ ] )
536544
537- let signal = combineLatest ( statePromise . get ( ) , sessionsPromise . get ( ) , appearanceSignal )
545+ let signal = combineLatest ( statePromise . get ( ) , sessionsPromise . get ( ) , renamedDeviceModel . get ( ) , appearanceSignal )
538546 |> deliverOnMainQueue
539- |> map { state , sessions , appearance -> TableUpdateTransition in
540- let entries = recentSessionsControllerEntries ( state : state , sessions : sessions ) . map { AppearanceWrapperEntry ( entry : $0 , appearance : appearance ) }
547+ |> map { state , sessions , deviceModel , appearance -> TableUpdateTransition in
548+ let entries = recentSessionsControllerEntries ( state : state , sessions : sessions , deviceModel : deviceModel ) . map { AppearanceWrapperEntry ( entry : $0 , appearance : appearance ) }
541549 return prepareSessions ( left : previousSessions . swap ( entries ) , right : entries , arguments : arguments , initialSize : initialSize . modify { $0 } )
542550 } |> afterDisposed {
543551 actionsDisposable . dispose ( )
0 commit comments