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.
		
		
		
		
		
			
		
			
	
	
		
			77 lines
		
	
	
		
			2.2 KiB
		
	
	
	
		
			Swift
		
	
		
		
			
		
	
	
			77 lines
		
	
	
		
			2.2 KiB
		
	
	
	
		
			Swift
		
	
| 
											8 years ago
										 | // | ||
| 
											8 years ago
										 | //  Copyright (c) 2018 Open Whisper Systems. All rights reserved. | ||
| 
											8 years ago
										 | // | ||
|  | 
 | ||
|  | import Foundation | ||
| 
											8 years ago
										 | import JSQMessagesViewController | ||
|  | import SignalServiceKit | ||
| 
											8 years ago
										 | import SignalMessaging | ||
| 
											8 years ago
										 | 
 | ||
|  | @objc | ||
| 
											8 years ago
										 | public class OWSMessagesBubbleImageFactory: NSObject { | ||
| 
											8 years ago
										 | 
 | ||
| 
											8 years ago
										 |     static let shared = OWSMessagesBubbleImageFactory() | ||
|  | 
 | ||
| 
											8 years ago
										 |     private let jsqFactory = JSQMessagesBubbleImageFactory()! | ||
| 
											8 years ago
										 | 
 | ||
| 
											8 years ago
										 |     // TODO: UIView is a little bit expensive to instantiate. | ||
|  |     //       Can we cache this value? | ||
| 
											8 years ago
										 |     private lazy var isRTL: Bool = { | ||
| 
											8 years ago
										 |         return UIView().isRTL() | ||
| 
											8 years ago
										 |     }() | ||
| 
											8 years ago
										 | 
 | ||
| 
											8 years ago
										 |     public lazy var incoming: JSQMessagesBubbleImage = { | ||
| 
											8 years ago
										 |         let color = UIColor.jsq_messageBubbleLightGray()! | ||
| 
											8 years ago
										 |         return self.incoming(color: color) | ||
|  |     }() | ||
| 
											8 years ago
										 | 
 | ||
| 
											8 years ago
										 |     public lazy var outgoing: JSQMessagesBubbleImage = { | ||
| 
											8 years ago
										 |         let color = UIColor.ows_materialBlue | ||
| 
											8 years ago
										 |         return self.outgoing(color: color) | ||
|  |     }() | ||
| 
											8 years ago
										 | 
 | ||
| 
											8 years ago
										 |     public lazy var currentlyOutgoing: JSQMessagesBubbleImage = { | ||
| 
											8 years ago
										 |         let color = UIColor.ows_fadedBlue | ||
| 
											8 years ago
										 |         return self.outgoing(color: color) | ||
|  |     }() | ||
| 
											8 years ago
										 | 
 | ||
| 
											8 years ago
										 |     public lazy var outgoingFailed: JSQMessagesBubbleImage = { | ||
| 
											8 years ago
										 |         let color = UIColor.gray | ||
| 
											8 years ago
										 |         return self.outgoing(color: color) | ||
|  |     }() | ||
| 
											8 years ago
										 | 
 | ||
| 
											8 years ago
										 |     public func bubble(message: TSMessage) -> JSQMessagesBubbleImage { | ||
|  |         if message is TSIncomingMessage { | ||
|  |             return self.incoming | ||
|  |         } else if let outgoingMessage = message as? TSOutgoingMessage { | ||
|  |             switch outgoingMessage.messageState { | ||
|  |             case .unsent: | ||
|  |                 return outgoingFailed | ||
|  |             case .attemptingOut: | ||
|  |                 return currentlyOutgoing | ||
|  |             default: | ||
|  |                 return outgoing | ||
|  |             } | ||
|  |         } else { | ||
|  |             owsFail("Unexpected message type: \(message)") | ||
|  |             return outgoing | ||
|  |         } | ||
|  |     } | ||
|  | 
 | ||
|  |     private func outgoing(color: UIColor) -> JSQMessagesBubbleImage { | ||
| 
											8 years ago
										 |         if isRTL { | ||
|  |             return jsqFactory.incomingMessagesBubbleImage(with: color) | ||
|  |         } else { | ||
|  |             return jsqFactory.outgoingMessagesBubbleImage(with: color) | ||
|  |         } | ||
|  |     } | ||
|  | 
 | ||
| 
											8 years ago
										 |     private func incoming(color: UIColor) -> JSQMessagesBubbleImage { | ||
| 
											8 years ago
										 |         if isRTL { | ||
|  |             return jsqFactory.outgoingMessagesBubbleImage(with: color) | ||
|  |         } else { | ||
|  |             return jsqFactory.incomingMessagesBubbleImage(with: color) | ||
|  |         } | ||
|  |     } | ||
|  | } |