LinkUp-P2P-Chat/chatBot/includes/TextMessage.js
2024-06-11 17:40:02 -04:00

27 lines
693 B
JavaScript

class TextMessage {
constructor(peerName, peerAvatar, topic, message, timestamp) {
this.peerName = peerName;
this.peerAvatar = peerAvatar;
this.topic = topic;
this.message = message;
this.timestamp = timestamp;
}
toJsonString() {
return JSON.stringify({
type: 'message',
name: this.peerName,
message: this.message,
avatar: this.peerAvatar,
topic: this.topic,
timestamp: this.timestamp
});
}
static new(bot, message) {
return new TextMessage(bot.botName, "", bot.currentTopic, message, Date.now());
}
}
export default TextMessage;