Last active
December 20, 2015 14:39
-
-
Save gr2m/6148091 to your computer and use it in GitHub Desktop.
a Hoodie messaging worker (dreamcode yet) that allows to send messages between users
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = function(hoodie) { | |
hoodie.task.on('new:message', handleNewMessage); | |
function handleNewMessage(originDb, message) { | |
// move new message to the recipients | |
var recipient = message.to; | |
hoodie.account.find('user', recipient, function(error, user) { | |
if (error) { | |
return hoodie.task.error(originDb, message, error) | |
} | |
var targetDb = "user/" + user.ownerHash; | |
hoodie.database(targetDb).add('message', message, handleError); | |
hoodie.task.success(originDb, message, {sentAt: new Date}, handleError); | |
}) | |
} | |
funciont handleError() {} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The frontend code API would look like this: