handleUnknownDevices

This commit is contained in:
David A Roberts 2017-02-14 11:57:21 +00:00
parent 95ddd678db
commit 28cb4fe513

View File

@ -17,6 +17,12 @@ class Matrix extends Adapter
super super
@robot.logger.info "Constructor" @robot.logger.info "Constructor"
handleUnknownDevices: (err) ->
for stranger, devices of err.devices
for device, _ of devices
@robot.logger.info "Acknowledging #{stranger}'s device #{device}"
@client.setDeviceKnown(stranger, device)
send: (envelope, strings...) -> send: (envelope, strings...) ->
for str in strings for str in strings
@robot.logger.info "Sending to #{envelope.room}: #{str}" @robot.logger.info "Sending to #{envelope.room}: #{str}"
@ -25,18 +31,15 @@ class Matrix extends Adapter
else else
@client.sendNotice(envelope.room, str).catch (err) => @client.sendNotice(envelope.room, str).catch (err) =>
if err.name == 'UnknownDeviceError' if err.name == 'UnknownDeviceError'
for stranger, devices of err.devices @handleUnknownDevices err
for device, _ of devices
@robot.logger.info "Acknowledging #{stranger}'s device #{device}"
@client.setDeviceKnown(stranger, device)
@client.sendNotice(envelope.room, str) @client.sendNotice(envelope.room, str)
emote: (envelope, strings...) -> emote: (envelope, strings...) ->
for str in strings for str in strings
@client.sendMessage envelope.room, { @client.sendEmoteMessage(envelope.room, str).catch (err) =>
msgtype: "m.emote", if err.name == 'UnknownDeviceError'
body: str @handleUnknownDevices err
} @client.sendEmoteMessage(envelope.room, str)
reply: (envelope, strings...) -> reply: (envelope, strings...) ->
for str in strings for str in strings
@ -60,7 +63,10 @@ class Matrix extends Adapter
dims.type = 'jpeg' if dims.type == 'jpg' dims.type = 'jpeg' if dims.type == 'jpg'
info = { mimetype: "image/#{dims.type}", h: dims.height, w: dims.width, size: body.length } info = { mimetype: "image/#{dims.type}", h: dims.height, w: dims.width, size: body.length }
@client.uploadContent(body, name: url, type: info.mimetype, rawResponse: false, onlyContentUri: true).done (content_uri) => @client.uploadContent(body, name: url, type: info.mimetype, rawResponse: false, onlyContentUri: true).done (content_uri) =>
@client.sendImageMessage(envelope.room, content_uri, info, url) @client.sendImageMessage(envelope.room, content_uri, info, url).catch (err) =>
if err.name == 'UnknownDeviceError'
@handleUnknownDevices err
@client.sendImageMessage(envelope.room, content_uri, info, url)
catch error catch error
@robot.logger.info error.message @robot.logger.info error.message
@send envelope, " #{url}" @send envelope, " #{url}"