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.
session-desktop/ts/session/messages/outgoing/content/TypingMessage.ts

53 lines
1.5 KiB
TypeScript

import { ContentMessage } from './ContentMessage';
import { SignalService } from '../../../../protobuf';
import { TextEncoder } from 'util';
import { MessageParams } from '../Message';
import { StringUtils } from '../../../utils';
interface TypingMessageParams extends MessageParams {
isTyping: boolean;
typingTimestamp?: number;
groupId?: string;
}
export class TypingMessage extends ContentMessage {
private readonly isTyping: boolean;
private readonly typingTimestamp?: number;
private readonly groupId?: string;
constructor(params: TypingMessageParams) {
5 years ago
super({ timestamp: params.timestamp, identifier: params.identifier });
this.isTyping = params.isTyping;
this.typingTimestamp = params.typingTimestamp;
this.groupId = params.groupId;
}
public ttl(): number {
return 60 * 1000; // 1 minute for typing indicators
}
protected 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();
if (this.groupId) {
5 years ago
typingMessage.groupId = new Uint8Array(
StringUtils.encode(this.groupId, 'utf8')
5 years ago
);
}
typingMessage.action = action;
typingMessage.timestamp = finalTimestamp;
return typingMessage;
}
}