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.
		
		
		
		
		
			
		
			
	
	
		
			44 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			TypeScript
		
	
		
		
			
		
	
	
			44 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			TypeScript
		
	
| 
											6 years ago
										 | import { SignalService } from '../../../../protobuf'; | ||
| 
											6 years ago
										 | import { MessageParams } from '../Message'; | ||
| 
											5 years ago
										 | import { Constants } from '../../..'; | ||
| 
											5 years ago
										 | import { ContentMessage } from '..'; | ||
| 
											6 years ago
										 | 
 | ||
| 
											6 years ago
										 | interface TypingMessageParams extends MessageParams { | ||
| 
											6 years ago
										 |   isTyping: boolean; | ||
| 
											6 years ago
										 |   typingTimestamp?: number; | ||
| 
											6 years ago
										 | } | ||
|  | 
 | ||
|  | export class TypingMessage extends ContentMessage { | ||
| 
											5 years ago
										 |   public readonly isTyping: boolean; | ||
|  |   public readonly typingTimestamp?: number; | ||
| 
											6 years ago
										 | 
 | ||
|  |   constructor(params: TypingMessageParams) { | ||
| 
											6 years ago
										 |     super({ timestamp: params.timestamp, identifier: params.identifier }); | ||
| 
											6 years ago
										 |     this.isTyping = params.isTyping; | ||
|  |     this.typingTimestamp = params.typingTimestamp; | ||
|  |   } | ||
| 
											6 years ago
										 | 
 | ||
| 
											6 years ago
										 |   public ttl(): number { | ||
| 
											5 years ago
										 |     return Constants.TTL_DEFAULT.TYPING_MESSAGE; | ||
| 
											6 years ago
										 |   } | ||
|  | 
 | ||
| 
											5 years ago
										 |   public contentProto(): SignalService.Content { | ||
| 
											6 years ago
										 |     return new SignalService.Content({ | ||
|  |       typingMessage: this.typingProto(), | ||
|  |     }); | ||
|  |   } | ||
|  | 
 | ||
| 
											6 years ago
										 |   protected typingProto(): SignalService.TypingMessage { | ||
|  |     const ACTION_ENUM = SignalService.TypingMessage.Action; | ||
|  | 
 | ||
|  |     const action = this.isTyping ? ACTION_ENUM.STARTED : ACTION_ENUM.STOPPED; | ||
|  |     const finalTimestamp = this.typingTimestamp || Date.now(); | ||
| 
											6 years ago
										 | 
 | ||
| 
											6 years ago
										 |     const typingMessage = new SignalService.TypingMessage(); | ||
|  |     typingMessage.action = action; | ||
|  |     typingMessage.timestamp = finalTimestamp; | ||
|  | 
 | ||
|  |     return typingMessage; | ||
|  |   } | ||
| 
											6 years ago
										 | } |