Skip to content

Commit

Permalink
sdk and matrix-lib changes to (hopefullly) eliminate matrix-related e…
Browse files Browse the repository at this point in the history
…rrors
  • Loading branch information
Chuck LeDuc Díaz committed Apr 29, 2020
1 parent 594f023 commit d816121
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 15 deletions.
1 change: 1 addition & 0 deletions .vscode/settings.json
Expand Up @@ -12,6 +12,7 @@
"keypair",
"labdev",
"lcov",
"maxonrow",
"nikola",
"nixt",
"onpong",
Expand Down
6 changes: 3 additions & 3 deletions package.json
Expand Up @@ -23,9 +23,9 @@
},
"homepage": "https://github.com/lorena-ssi/lorena-sdk#readme",
"dependencies": {
"@lorena-ssi/credential-lib": "^1.0.14",
"@lorena-ssi/did-resolver": "^0.2.2",
"@lorena-ssi/matrix-lib": "^1.0.11",
"@lorena-ssi/credential-lib": "^1.1.0",
"@lorena-ssi/did-resolver": "^0.2.3",
"@lorena-ssi/matrix-lib": "^1.0.13",
"@lorena-ssi/maxonrow-lib": "^1.2.0",
"@lorena-ssi/substrate-lib": "^3.0.0",
"@lorena-ssi/wallet-lib": "^1.1.0",
Expand Down
31 changes: 19 additions & 12 deletions src/index.js
Expand Up @@ -255,6 +255,7 @@ export default class Lorena extends EventEmitter {
default:
parsedElement = JSON.parse(element.payload.body)
parsedElement.roomId = element.roomId
debug(`loop element.roomId: ${element.roomId}`)
this.emit(`message:${parsedElement.recipe}`, parsedElement)
this.emit('message', parsedElement)
break
Expand All @@ -273,25 +274,31 @@ export default class Lorena extends EventEmitter {
* @returns {*} events
*/
async getMessages () {
let result = await this.matrix.events(this.nextBatch)
// If empty (try again)
if (result.events.length === 0) {
result = await this.matrix.events(this.nextBatch)
try {
const result = await this.matrix.events(this.nextBatch)
this.nextBatch = result.nextBatch
return (result.events)
} catch (e) {
// If there was an error, log it and return empty events for continuation
debug(e)
return []
}
this.nextBatch = result.nextBatch
return (result.events)
}

/**
* process Outgoing queue of messages
*/
async processQueue () {
if (this.queue.length > 0) {
const sendPayload = JSON.stringify(this.queue.pop())
await this.matrix.sendMessage(this.wallet.info.roomId, 'm.action', sendPayload)
}
if (this.queue.length === 0) {
this.processing = false
try {
if (this.queue.length > 0) {
const sendPayload = JSON.stringify(this.queue.pop())
await this.matrix.sendMessage(this.wallet.info.roomId, 'm.action', sendPayload)
}
if (this.queue.length === 0) {
this.processing = false
}
} catch (e) {
debug(e)
}
}

Expand Down

0 comments on commit d816121

Please sign in to comment.