|
@ -1,3 +1,7 @@ |
|
|
|
|
|
const EventEmitter = require("events"); |
|
|
|
|
|
|
|
|
|
|
|
let linkSignal = null; |
|
|
|
|
|
|
|
|
module.exports = class { |
|
|
module.exports = class { |
|
|
onCreate(input) { |
|
|
onCreate(input) { |
|
|
this.state = { |
|
|
this.state = { |
|
@ -8,8 +12,11 @@ module.exports = class { |
|
|
modal: null, |
|
|
modal: null, |
|
|
removed: false, |
|
|
removed: false, |
|
|
multipart: false, |
|
|
multipart: false, |
|
|
|
|
|
anchored: false, |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
this.mounted = false; |
|
|
|
|
|
|
|
|
this.updatePost(input) |
|
|
this.updatePost(input) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -45,16 +52,52 @@ module.exports = class { |
|
|
this.updatePost(input) |
|
|
this.updatePost(input) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
onMount() { |
|
|
|
|
|
this.linkSignalCallback = () => { |
|
|
|
|
|
this.state.anchored = false |
|
|
|
|
|
} |
|
|
|
|
|
if (linkSignal == null) { |
|
|
|
|
|
linkSignal = new EventEmitter() |
|
|
|
|
|
linkSignal.setMaxListeners(10000) |
|
|
|
|
|
} |
|
|
|
|
|
linkSignal.on("signal", this.linkSignalCallback) |
|
|
|
|
|
|
|
|
|
|
|
this.state.anchored = window.location.hash.slice(1) === this.input.post.id; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
onUnmount() { |
|
|
|
|
|
linkSignal.removeListener("signal", this.linkSignalCallback) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
link() { |
|
|
|
|
|
linkSignal.emit("signal") |
|
|
|
|
|
this.state.anchored = true |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
updatePost(input) { |
|
|
updatePost(input) { |
|
|
this.state.shortName = input.post.nick.split("_").shift() |
|
|
this.state.shortName = input.post.nick.split("_").shift() |
|
|
this.state.name = input.post.nick |
|
|
this.state.name = input.post.nick |
|
|
this.state.nameSuffix = "" |
|
|
this.state.nameSuffix = "" |
|
|
|
|
|
|
|
|
this.state.text = input.post.text.replace(/\x02/g, "**").replace(/\x1D/g, "_") |
|
|
|
|
|
|
|
|
this.state.text = input.post.text.replace(/\x02/g, "**").replace(/\x1D/g, "_").trim(); |
|
|
|
|
|
|
|
|
|
|
|
if (this.state.text.startsWith("|")) { |
|
|
|
|
|
this.state.name = "" |
|
|
|
|
|
this.state.text = this.state.text.slice(1).trim(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
if (input.post.kind === "text" && !this.state.text.includes("\"")) { |
|
|
|
|
|
|
|
|
if (input.post.kind === "text" && !this.state.text.includes("\"") && !this.state.text.includes("|")) { |
|
|
|
|
|
const colonIndex = this.state.text.indexOf(": "); |
|
|
|
|
|
if (colonIndex != -1 && colonIndex < this.state.text.indexOf(" ")) { |
|
|
|
|
|
this.state.text = this.state.text.replace(": ", ": \"") + "\""; |
|
|
|
|
|
} else { |
|
|
this.state.text = '"' + this.state.text + '"' |
|
|
this.state.text = '"' + this.state.text + '"' |
|
|
} |
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (this.state.text.charAt(0) == this.state.text.charAt(0).toUpperCase()) { |
|
|
|
|
|
this.state.name = "" |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
if (!input.post.nick.startsWith("=")) { |
|
|
if (!input.post.nick.startsWith("=")) { |
|
|
const postNick = input.post.nick.replace("'s", "").replace("s'", "s") |
|
|
const postNick = input.post.nick.replace("'s", "").replace("s'", "s") |
|
|