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
		
	
import { ContentMessage } from './ContentMessage';
 | 
						|
import { SignalService } from '../../../../protobuf';
 | 
						|
import { MessageParams } from '../Message';
 | 
						|
import { Constants } from '../../..';
 | 
						|
 | 
						|
interface TypingMessageParams extends MessageParams {
 | 
						|
  isTyping: boolean;
 | 
						|
  typingTimestamp?: number;
 | 
						|
}
 | 
						|
 | 
						|
export class TypingMessage extends ContentMessage {
 | 
						|
  public readonly isTyping: boolean;
 | 
						|
  public readonly typingTimestamp?: number;
 | 
						|
 | 
						|
  constructor(params: TypingMessageParams) {
 | 
						|
    super({ timestamp: params.timestamp, identifier: params.identifier });
 | 
						|
    this.isTyping = params.isTyping;
 | 
						|
    this.typingTimestamp = params.typingTimestamp;
 | 
						|
  }
 | 
						|
 | 
						|
  public ttl(): number {
 | 
						|
    return Constants.TTL_DEFAULT.TYPING_MESSAGE;
 | 
						|
  }
 | 
						|
 | 
						|
  public contentProto(): SignalService.Content {
 | 
						|
    return new SignalService.Content({
 | 
						|
      typingMessage: this.typingProto(),
 | 
						|
    });
 | 
						|
  }
 | 
						|
 | 
						|
  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();
 | 
						|
 | 
						|
    const typingMessage = new SignalService.TypingMessage();
 | 
						|
    typingMessage.action = action;
 | 
						|
    typingMessage.timestamp = finalTimestamp;
 | 
						|
 | 
						|
    return typingMessage;
 | 
						|
  }
 | 
						|
}
 |