2020-10-26 08:10:02 +00:00
|
|
|
const {ElemJS, ejs} = require("../basic")
|
2020-10-31 17:20:56 +00:00
|
|
|
const {dateFormatter} = require("../date-formatter")
|
2020-11-25 06:54:09 +00:00
|
|
|
const {SubscribeSet} = require("../store/subscribe_set.js")
|
2020-10-26 08:10:02 +00:00
|
|
|
|
2020-10-26 21:58:38 +00:00
|
|
|
class MatrixEvent extends ElemJS {
|
2020-10-26 08:10:02 +00:00
|
|
|
constructor(data) {
|
|
|
|
super("div")
|
|
|
|
this.data = null
|
|
|
|
this.group = null
|
|
|
|
this.editedAt = null
|
2020-11-25 06:54:09 +00:00
|
|
|
this.readBy = new SubscribeSet()
|
2020-10-26 08:10:02 +00:00
|
|
|
this.update(data)
|
|
|
|
}
|
|
|
|
|
|
|
|
// predicates
|
|
|
|
|
|
|
|
canGroup() {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
// operations
|
|
|
|
|
|
|
|
setGroup(group) {
|
|
|
|
this.group = group
|
|
|
|
}
|
|
|
|
|
|
|
|
setEdited(time) {
|
|
|
|
this.editedAt = time
|
|
|
|
this.render()
|
|
|
|
}
|
|
|
|
|
|
|
|
update(data) {
|
|
|
|
this.data = data
|
|
|
|
this.render()
|
|
|
|
}
|
|
|
|
|
|
|
|
removeEvent() {
|
|
|
|
if (this.group) this.group.removeEvent(this)
|
|
|
|
else this.remove()
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
this.element.classList[this.data.pending ? "add" : "remove"]("c-message--pending")
|
|
|
|
if (this.editedAt) {
|
|
|
|
this.child(ejs("span").class("c-message__edited").text("(edited)").attribute("title", "at " + dateFormatter.format(this.editedAt)))
|
|
|
|
}
|
2020-10-29 09:42:17 +00:00
|
|
|
return this
|
2020-10-26 08:10:02 +00:00
|
|
|
}
|
2020-10-29 09:42:17 +00:00
|
|
|
|
2020-11-05 03:44:22 +00:00
|
|
|
static canRender(eventData) {
|
2020-10-26 08:10:02 +00:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-26 13:48:30 +00:00
|
|
|
class GroupableEvent extends MatrixEvent {
|
|
|
|
constructor(data) {
|
|
|
|
super(data)
|
|
|
|
this.class("c-message")
|
|
|
|
}
|
|
|
|
|
|
|
|
canGroup() {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class UngroupableEvent extends MatrixEvent {
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
GroupableEvent,
|
|
|
|
UngroupableEvent
|
|
|
|
}
|