From 73308186d248460c56fbca052b2c3bb8b6dc492f Mon Sep 17 00:00:00 2001 From: f0x Date: Wed, 17 Apr 2019 19:57:25 +0200 Subject: [PATCH] message sending with local echo --- app.js | 9 +++++++-- components/chat.js | 6 ++++-- components/events/text.js | 11 ++++++----- components/input.js | 26 +++++++++++++++++++++++++- public/scss/style.scss | 6 +++++- 5 files changed, 47 insertions(+), 11 deletions(-) diff --git a/app.js b/app.js index 64ee5e1..be34cd4 100644 --- a/app.js +++ b/app.js @@ -72,7 +72,12 @@ let App = create({ } else if (state == "PREPARED") { } }) - client.on("event", (event) => { + client.on("Room.localEchoUpdated", (event) => { + let rooms = {} + client.getRooms().forEach((room) => { + rooms[room.roomId] = room + }) + this.setState({rooms: rooms}) }) client.startClient() }, @@ -88,7 +93,7 @@ let App = create({
- +
) diff --git a/components/chat.js b/components/chat.js index f488f60..f0b63f9 100644 --- a/components/chat.js +++ b/components/chat.js @@ -82,12 +82,14 @@ let chat = create({ // if the sender is the same, add it to the 'current' messageGroup, if not, // push the old one to 'groups' and start with a new array. - console.log("GROUPING EVENTS", room.timeline.length) let events = [] if (room.timeline.length > 0) { room.timeline.forEach((timeline) => { - console.log("TIMELINE", timeline); let event = timeline.event; + if (event.user_id != null) { // localecho messages + event.sender = event.user_id + event.local = true + } if (event.sender != messageGroups.sender) { messageGroups.sender = event.sender if (messageGroups.current.length != 0) { diff --git a/components/events/text.js b/components/events/text.js index bd8c986..40c1bbd 100644 --- a/components/events/text.js +++ b/components/events/text.js @@ -11,13 +11,14 @@ let Event = create({ render: function() { let event = this.props.event; - // let eventBody = event.content.body.split("\n").map((line, id) => { - // return {line}
- // }) - let eventBody = riot.sanitize(event.content.body) - return
+ let eventClass = "event" + if (event.local) { + eventClass += " local" + } + + return
{ + // only send on plain 'enter' + if (e.key == "Enter" && !e.shiftKey && !e.altKey && !e.ctrlKey) { + this.send(e) + } + }) + this.setState({ref: ref}) + } + }, + + send: function(e) { + let content = { + "body": e.target.value, + "msgtype": "m.text" + } + this.props.client.sendEvent(this.props.roomId, "m.room.message", content, (err, res) => { + console.log(err) + }) + e.target.value = "" + }, + render: function() { return
- +
} }) diff --git a/public/scss/style.scss b/public/scss/style.scss index 8d2c9bb..b9536a0 100644 --- a/public/scss/style.scss +++ b/public/scss/style.scss @@ -4,7 +4,7 @@ $bg1: hsla(228, 12%, 18%, 1); $bg2: hsla(228, 12%, 30%, 1); $bg3: hsla(228, 12%, 36%, 1); $bg4: hsla(228, 12%, 60%, 1); -$bg6: hsla(228, 12%, 100%, 1); +$bg5: hsla(228, 12%, 100%, 1); $red: #CC6666; $amber: #DE935F; @@ -295,6 +295,10 @@ body { grid-area: content; padding-left: $spacing * 1.2; + .local { + color: $bg4; + } + .body { /* debug */ //border: 1px solid $red;