mirror of https://github.com/oxen-io/session-ios
				
				
				
			
			You cannot select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
	
	
		
			51 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			Swift
		
	
		
		
			
		
	
	
			51 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			Swift
		
	
| 
											8 years ago
										 | // | ||
|  | //  Copyright (c) 2018 Open Whisper Systems. All rights reserved. | ||
|  | // | ||
|  | 
 | ||
|  | import Foundation | ||
|  | 
 | ||
|  | @objc | ||
|  | public class ThreadViewModel: NSObject { | ||
| 
											8 years ago
										 |     @objc public let hasUnreadMessages: Bool | ||
|  |     @objc public let lastMessageDate: Date | ||
|  |     @objc public let isGroupThread: Bool | ||
|  |     @objc public let threadRecord: TSThread | ||
|  |     @objc public let unreadCount: UInt | ||
|  |     @objc public let contactIdentifier: String? | ||
|  |     @objc public let name: String | ||
|  |     @objc public let isMuted: Bool | ||
| 
											8 years ago
										 |     var isContactThread: Bool { | ||
|  |         return !isGroupThread | ||
|  |     } | ||
|  | 
 | ||
| 
											8 years ago
										 |     @objc public let lastMessageText: String? | ||
| 
											8 years ago
										 | 
 | ||
| 
											8 years ago
										 |     @objc | ||
|  |     public init(thread: TSThread, transaction: YapDatabaseReadTransaction) { | ||
| 
											8 years ago
										 |         self.threadRecord = thread | ||
|  |         self.lastMessageDate = thread.lastMessageDate() | ||
|  |         self.isGroupThread = thread.isGroupThread() | ||
|  |         self.name = thread.name() | ||
|  |         self.isMuted = thread.isMuted | ||
|  |         self.lastMessageText = thread.lastMessageText(transaction: transaction) | ||
|  | 
 | ||
|  |         if let contactThread = thread as? TSContactThread { | ||
|  |             self.contactIdentifier = contactThread.contactIdentifier() | ||
|  |         } else { | ||
|  |             self.contactIdentifier = nil | ||
|  |         } | ||
|  | 
 | ||
|  |         self.unreadCount = thread.unreadMessageCount(transaction: transaction) | ||
|  |         self.hasUnreadMessages = unreadCount > 0 | ||
|  |     } | ||
| 
											8 years ago
										 | 
 | ||
|  |     @objc | ||
|  |     override public func isEqual(_ object: Any?) -> Bool { | ||
|  |         guard let otherThread = object as? ThreadViewModel else { | ||
|  |             return super.isEqual(object) | ||
|  |         } | ||
|  | 
 | ||
|  |         return threadRecord.isEqual(otherThread.threadRecord) | ||
|  |     } | ||
| 
											8 years ago
										 | } |