only send read receipts if bot is mentioned, or is unable to respond

This commit is contained in:
David A Roberts 2017-02-12 05:44:42 +00:00
parent 14c6b86e84
commit 5f7fd7a957

View File

@ -81,15 +81,15 @@ class Matrix extends Adapter
@robot.logger.info "Synced #{@client.getRooms().length} rooms" @robot.logger.info "Synced #{@client.getRooms().length} rooms"
@emit 'connected' @emit 'connected'
@client.on 'Room.timeline', (event, room, toStartOfTimeline) => @client.on 'Room.timeline', (event, room, toStartOfTimeline) =>
@client.sendReadReceipt(event) 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()
message = event.getContent().body
name = event.getSender() name = event.getSender()
user = @robot.brain.userForId name user = @robot.brain.userForId name
user.room = room.roomId user.room = room.roomId
if user.name != @user_id if user.name != @user_id
@robot.logger.info "Received message: '#{message}' in room: #{user.room}, from: #{user.name}." @robot.logger.info "Received message: #{JSON.stringify message} in room: #{user.room}, from: #{user.name}."
@receive new TextMessage user, message @receive new TextMessage user, message.body if message.msgtype == "m.text"
@client.sendReadReceipt(event) if message.msgtype != "m.text" or message.body.indexOf(@robot.name) != -1
@client.on 'RoomMember.membership', (event, member) => @client.on 'RoomMember.membership', (event, member) =>
if member.membership == 'invite' and member.userId == @user_id if member.membership == 'invite' and member.userId == @user_id
@client.joinRoom(member.roomId).done => @client.joinRoom(member.roomId).done =>