Formatting for sent messages
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
Cadence Ember 2020-11-24 18:58:27 +13:00
parent 0960ca7e97
commit 03c7501bf1
Signed by: cadence
GPG key ID: BC1C2C61CF521B17
4 changed files with 52 additions and 10 deletions

35
package-lock.json generated
View file

@ -998,6 +998,20 @@
"resolved": "https://registry.npmjs.org/@types/color-name/-/color-name-1.1.1.tgz", "resolved": "https://registry.npmjs.org/@types/color-name/-/color-name-1.1.1.tgz",
"integrity": "sha512-rr+OQyAjxze7GgWrSaJwydHStIhHq2lvY3BOC2Mj7KnzI7XK0Uw1TOOdI9lDoajEbSWLiYgoo4f1R51erQfhPQ==" "integrity": "sha512-rr+OQyAjxze7GgWrSaJwydHStIhHq2lvY3BOC2Mj7KnzI7XK0Uw1TOOdI9lDoajEbSWLiYgoo4f1R51erQfhPQ=="
}, },
"@types/prop-types": {
"version": "15.7.3",
"resolved": "https://registry.npmjs.org/@types/prop-types/-/prop-types-15.7.3.tgz",
"integrity": "sha512-KfRL3PuHmqQLOG+2tGpRO26Ctg+Cq1E01D2DMriKEATHgWLfeNDmq9e29Q9WIky0dQ3NPkd1mzYH8Lm936Z9qw=="
},
"@types/react": {
"version": "17.0.0",
"resolved": "https://registry.npmjs.org/@types/react/-/react-17.0.0.tgz",
"integrity": "sha512-aj/L7RIMsRlWML3YB6KZiXB3fV2t41+5RBGYF8z+tAKU43Px8C3cYUZsDvf1/+Bm4FK21QWBrDutu8ZJ/70qOw==",
"requires": {
"@types/prop-types": "*",
"csstype": "^3.0.2"
}
},
"JSONStream": { "JSONStream": {
"version": "1.3.5", "version": "1.3.5",
"resolved": "https://registry.npmjs.org/JSONStream/-/JSONStream-1.3.5.tgz", "resolved": "https://registry.npmjs.org/JSONStream/-/JSONStream-1.3.5.tgz",
@ -1693,6 +1707,11 @@
"randomfill": "^1.0.3" "randomfill": "^1.0.3"
} }
}, },
"csstype": {
"version": "3.0.5",
"resolved": "https://registry.npmjs.org/csstype/-/csstype-3.0.5.tgz",
"integrity": "sha512-uVDi8LpBUKQj6sdxNaTetL6FpeCqTjOvAQuQUa/qAqq8oOd4ivkbhgnqayl0dnPal8Tb/yB1tF+gOvCBiicaiQ=="
},
"dash-ast": { "dash-ast": {
"version": "1.0.0", "version": "1.0.0",
"resolved": "https://registry.npmjs.org/dash-ast/-/dash-ast-1.0.0.tgz", "resolved": "https://registry.npmjs.org/dash-ast/-/dash-ast-1.0.0.tgz",
@ -1771,6 +1790,14 @@
} }
} }
}, },
"discord-markdown": {
"version": "git+https://git.sr.ht/~cadence/nodejs-discord-markdown#e5d0a953764cd8e8e0f7ea84c93a882fe16f6e3d",
"from": "git+https://git.sr.ht/~cadence/nodejs-discord-markdown#e5d0a953764cd8e8e0f7ea84c93a882fe16f6e3d",
"requires": {
"highlight.js": "^10.3.2",
"simple-markdown": "^0.7.2"
}
},
"doctypes": { "doctypes": {
"version": "1.1.0", "version": "1.1.0",
"resolved": "https://registry.npmjs.org/doctypes/-/doctypes-1.1.0.tgz", "resolved": "https://registry.npmjs.org/doctypes/-/doctypes-1.1.0.tgz",
@ -3126,6 +3153,14 @@
"resolved": "https://registry.npmjs.org/simple-concat/-/simple-concat-1.0.1.tgz", "resolved": "https://registry.npmjs.org/simple-concat/-/simple-concat-1.0.1.tgz",
"integrity": "sha512-cSFtAPtRhljv69IK0hTVZQ+OfE9nePi/rtJmw5UjHeVyVroEqJXP1sFztKUy1qU+xvz3u/sfYJLa947b7nAN2Q==" "integrity": "sha512-cSFtAPtRhljv69IK0hTVZQ+OfE9nePi/rtJmw5UjHeVyVroEqJXP1sFztKUy1qU+xvz3u/sfYJLa947b7nAN2Q=="
}, },
"simple-markdown": {
"version": "0.7.2",
"resolved": "https://registry.npmjs.org/simple-markdown/-/simple-markdown-0.7.2.tgz",
"integrity": "sha512-XfCvqqzMyzRj4L7eIxJgGaQ2Gaxr20GhTFMB+1yuY8q3xffjzmOg4Q5tC0kcaJPV42NNUHCQDaRK6jzi3/RhrA==",
"requires": {
"@types/react": ">=16.0.0"
}
},
"source-map": { "source-map": {
"version": "0.5.7", "version": "0.5.7",
"resolved": "https://registry.npmjs.org/source-map/-/source-map-0.5.7.tgz", "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.5.7.tgz",

View file

@ -16,6 +16,7 @@
"@babel/preset-env": "^7.11.0", "@babel/preset-env": "^7.11.0",
"browserify": "^17.0.0", "browserify": "^17.0.0",
"chalk": "^4.1.0", "chalk": "^4.1.0",
"discord-markdown": "git+https://git.sr.ht/~cadence/nodejs-discord-markdown#e5d0a953764cd8e8e0f7ea84c93a882fe16f6e3d",
"dompurify": "^2.2.0", "dompurify": "^2.2.0",
"highlight.js": "^10.3.2", "highlight.js": "^10.3.2",
"http-server": "^0.12.3", "http-server": "^0.12.3",

View file

@ -2,13 +2,16 @@ const {q} = require("./basic.js")
const {store} = require("./store/store.js") const {store} = require("./store/store.js")
const lsm = require("./lsm.js") const lsm = require("./lsm.js")
const {chat} = require("./chat.js") const {chat} = require("./chat.js")
const {toHTML} = require("discord-markdown")
const input = q("#c-chat-textarea") const input = q("#c-chat-textarea")
class TypingManager { class TypingManager {
constructor() { constructor() {
this.time = 20000 // how long to appear to type for /** How long to appear to type for. */
this.margin = 5000 // how long before the end of the timeout to send the request again this.time = 20000
/** How long before the end of the timeout to send the request again. */
this.margin = 5000
/** The room that we're typing in. We can semantically only type in one room at a time. */ /** The room that we're typing in. We can semantically only type in one room at a time. */
this.typingRoom = null this.typingRoom = null
this.timeout = null this.timeout = null
@ -95,5 +98,12 @@ function fixHeight() {
function send(body) { function send(body) {
if (!store.activeRoom.exists()) return if (!store.activeRoom.exists()) return
if (!body.trim().length) return if (!body.trim().length) return
return store.activeRoom.value().timeline.send(body) const content = {
msgtype: "m.text",
format: "org.matrix.custom.html",
body,
formatted_body: toHTML(body),
"chat.carbon.input_body": body
}
return store.activeRoom.value().timeline.send("m.room.message", content)
} }

View file

@ -324,17 +324,13 @@ class Timeline extends Subscribable {
this.broadcast("afterScrollbackLoad") this.broadcast("afterScrollbackLoad")
} }
send(body) { send(type, content) {
const tx = getTxnId() const tx = getTxnId()
const id = `pending$${tx}` const id = `pending$${tx}`
this.pending.add(id) this.pending.add(id)
const content = { content["chat.carbon.message.pending_id"] = id
msgtype: "m.text",
body,
"chat.carbon.message.pending_id": id
}
const fakeEvent = { const fakeEvent = {
type: "m.room.message", type,
origin_server_ts: Date.now(), origin_server_ts: Date.now(),
event_id: id, event_id: id,
sender: lsm.get("mx_user_id"), sender: lsm.get("mx_user_id"),