From 7d9c09ac9f6d7fda50578af2eaad9647e0f8f905 Mon Sep 17 00:00:00 2001 From: Hubert Chathi Date: Tue, 27 Sep 2016 21:31:09 -0400 Subject: [PATCH 1/6] update to newer version of Matrix SDK --- package.json | 2 +- src/matrix.coffee | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 547edb6..1d57e9c 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "license": "MIT", "dependencies": { "parent-require": "^1.0.0", - "matrix-js-sdk": ">=0.3.0" + "matrix-js-sdk": "^0.6.0" }, "peerDependencies": { "hubot": ">=2.0" diff --git a/src/matrix.coffee b/src/matrix.coffee index bf29d46..964b8df 100644 --- a/src/matrix.coffee +++ b/src/matrix.coffee @@ -49,9 +49,11 @@ class Matrix extends Adapter baseUrl: process.env.HUBOT_MATRIX_HOST_SERVER || 'https://matrix.org' accessToken: @access_token userId: @user_id - @client.on 'syncComplete', => - @robot.logger.info "Synced #{@client.getRooms().length} rooms" - @emit 'connected' + @client.on 'sync', (state, prevState, data) => + switch state + when "PREPARED" + @robot.logger.info "Synced #{@client.getRooms().length} rooms" + @emit 'connected' @client.on 'Room.timeline', (event, room, toStartOfTimeline) => if event.getType() == 'm.room.message' and toStartOfTimeline == false message = event.getContent().body From e0acdabe537da5e29e256682c5c3e976f0403e6d Mon Sep 17 00:00:00 2001 From: Hubert Chathi Date: Tue, 27 Sep 2016 21:32:08 -0400 Subject: [PATCH 2/6] send m.notice instead of m.text --- src/matrix.coffee | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/matrix.coffee b/src/matrix.coffee index 964b8df..7157e5b 100644 --- a/src/matrix.coffee +++ b/src/matrix.coffee @@ -18,7 +18,10 @@ class Matrix extends Adapter if /^(f|ht)tps?:\/\//i.test(str) @sendImage envelope, str else - @client.sendTextMessage envelope.room, str + @client.sendMessage envelope.room, { + msgtype: "m.notice", + body: str + } reply: (envelope, strings...) -> for str in strings From 93dcce7fe4c9c08b200507312cc5812e51f7a9cf Mon Sep 17 00:00:00 2001 From: Hubert Chathi Date: Tue, 27 Sep 2016 21:33:29 -0400 Subject: [PATCH 3/6] add support for emote and topic setting --- src/matrix.coffee | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/matrix.coffee b/src/matrix.coffee index 7157e5b..a1a4de4 100644 --- a/src/matrix.coffee +++ b/src/matrix.coffee @@ -23,10 +23,23 @@ class Matrix extends Adapter body: str } + emote: (envelope, strings...) -> + for str in strings + @client.sendMessage envelope.room, { + msgtype: "m.emote", + body: str + } + reply: (envelope, strings...) -> for str in strings @send envelope, "#{envelope.user.name}: #{str}" + topic: (envelope, strings...) -> + for str in strings + @sendEvent envelope.room, "m.room.topic", { + topic: str + } + sendImage: (envelope, url) -> @client.uploadContent(stream: request url, name: url).done (murl) => @client.sendMessage envelope.room, { From f0a1f885ff8b4108c5342863091cdd38b594bce2 Mon Sep 17 00:00:00 2001 From: Hubert Chathi Date: Tue, 27 Sep 2016 21:43:30 -0400 Subject: [PATCH 4/6] ignore incoming m.notice messages as per spec --- package.json | 2 +- src/matrix.coffee | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 1d57e9c..cffd144 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "hubot-matrix", - "version": "1.1.0", + "version": "1.1.1", "description": "Matrix adapter for hubot", "main": "src/matrix.coffee", "scripts": { diff --git a/src/matrix.coffee b/src/matrix.coffee index a1a4de4..5a764be 100644 --- a/src/matrix.coffee +++ b/src/matrix.coffee @@ -71,7 +71,7 @@ class Matrix extends Adapter @robot.logger.info "Synced #{@client.getRooms().length} rooms" @emit 'connected' @client.on 'Room.timeline', (event, room, toStartOfTimeline) => - if event.getType() == 'm.room.message' and toStartOfTimeline == false + if event.getType() == 'm.room.message' and event.getContent().msgtype != "m.notice" and toStartOfTimeline == false message = event.getContent().body name = event.getSender() user = @robot.brain.userForId name From 547e20df88248c24c51f6f7976b870719c749812 Mon Sep 17 00:00:00 2001 From: Hubert Chathi Date: Tue, 27 Sep 2016 21:44:27 -0400 Subject: [PATCH 5/6] sent read receipts for events --- src/matrix.coffee | 1 + 1 file changed, 1 insertion(+) diff --git a/src/matrix.coffee b/src/matrix.coffee index 5a764be..3fe74d7 100644 --- a/src/matrix.coffee +++ b/src/matrix.coffee @@ -71,6 +71,7 @@ class Matrix extends Adapter @robot.logger.info "Synced #{@client.getRooms().length} rooms" @emit 'connected' @client.on 'Room.timeline', (event, room, toStartOfTimeline) => + @client.sendReadReceipt(event) if event.getType() == 'm.room.message' and event.getContent().msgtype != "m.notice" and toStartOfTimeline == false message = event.getContent().body name = event.getSender() From c509b5cde09e2d06244a5888ffe7e77f7e368a72 Mon Sep 17 00:00:00 2001 From: Hubert Chathi Date: Sat, 1 Oct 2016 13:39:41 -0400 Subject: [PATCH 6/6] call method on the right object --- src/matrix.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/matrix.coffee b/src/matrix.coffee index 3fe74d7..8060c43 100644 --- a/src/matrix.coffee +++ b/src/matrix.coffee @@ -36,7 +36,7 @@ class Matrix extends Adapter topic: (envelope, strings...) -> for str in strings - @sendEvent envelope.room, "m.room.topic", { + @client.sendEvent envelope.room, "m.room.topic", { topic: str }