53 lines
1.4 KiB
JavaScript
53 lines
1.4 KiB
JavaScript
/**
|
|
* @description Base class for all messages
|
|
* @since 1.0
|
|
* @author MiTask
|
|
*/
|
|
class Message {
|
|
/**
|
|
* @since 1.0
|
|
* @author MiTask
|
|
* @constructor
|
|
* @param {String} messageType Type of the message (text, file, audio, icon)
|
|
* @param {String} peerName Peer username
|
|
* @param {String} peerAvatar Peer avatar URL
|
|
* @param {String} topic Chat room topic string
|
|
* @param {Number} timestamp UNIX Timestamp
|
|
*/
|
|
constructor(messageType, peerName, peerAvatar, topic, timestamp) {
|
|
this.type = messageType;
|
|
this.peerName = peerName;
|
|
this.peerAvatar = peerAvatar;
|
|
this.topic = topic;
|
|
this.timestamp = timestamp;
|
|
}
|
|
|
|
/**
|
|
* @since 1.0
|
|
* @author MiTask
|
|
* @returns {{name: String, topic: String, avatar: String, type: String, timestamp: Number}} JSON Object with all of the information about the message
|
|
*/
|
|
toJson() {
|
|
return {
|
|
type: this.type,
|
|
name: this.peerName,
|
|
avatar: this.peerAvatar,
|
|
topic: this.topic,
|
|
timestamp: this.timestamp
|
|
};
|
|
}
|
|
|
|
/**
|
|
* @since 1.0
|
|
* @author MiTask
|
|
* @returns {String} JSON String with all of the information about the message
|
|
*/
|
|
toJsonString() {
|
|
return JSON.stringify({
|
|
...this.toJson()
|
|
});
|
|
}
|
|
}
|
|
|
|
export default Message;
|