diff options
author | TylerSchroederWM <75996872+TylerSchroederWM@users.noreply.github.com> | 2021-03-01 01:14:26 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-01 01:14:26 -0500 |
commit | e8b9c3781d41c08afe936faacd5141ec6fb75810 (patch) | |
tree | 970447f02230965596d28f0d05ac1273fb72ca9e /channels-lib.js | |
parent | f1e74394f211a48ed7b0cea04769acbb155d51e8 (diff) | |
download | ssb-logbook-master.tar.gz ssb-logbook-master.zip |
also removed stupid typo
Diffstat (limited to 'channels-lib.js')
-rw-r--r-- | channels-lib.js | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/channels-lib.js b/channels-lib.js index d150046..fbdc0c0 100644 --- a/channels-lib.js +++ b/channels-lib.js @@ -27,7 +27,8 @@ class StreamData { } class StreamController { - constructor(opts) { + constructor(client, opts) { + this.client = client, this.outputStream = Pushable(), this.streamData = { channelStream: new StreamData(), @@ -65,6 +66,7 @@ class StreamController { for(var msgIndex in newlySafeMessages) { debug("pushing safe message..."); this.outputStream.push(newlySafeMessages[msgIndex]); + this.requestBlobs(newlySafeMessages[msgIndex]); } }, this.finish = function() { @@ -73,8 +75,25 @@ class StreamController { } this.pushNewlySafeMessages(); this.outputStream.end(); + }, + this.requestBlobs = function(msg) { + if(msg.value && msg.value.content && msg.value.content.mentions && msg.value.content.mentions.type && msg.value.content.mentions.link && msg.value.content.mentions.type.includes("image")) { + this.client.blobs.has(msg.value.content.mentions.link, function(err, has) { + if(err) { + debug("[ERROR] ssb.blobs.has failed on the following message: " + JSON.stringify(msg)); + } + if(!err && !has) { + debug("Wanting blob with ID " + msg.value.content.mentions.link); + this.client.blobs.want(msg.value.content.mentions.link, {nowait: false}, function() { + this.client.blobs.get(msg.value.content.mentions.link, function() { + debug("Downloaded blob with ID " + msg.value.content.mentions.link); + }); + }); + } + }); + } } - }a + } } module.exports = { @@ -97,7 +116,7 @@ function getMessagesFrom(client, channelName, followedIds, opts, preserve, cb) { debug("Fetching messages from IDs in " + JSON.stringify(followedIds)); var channelTag = "#" + channelName; - var streamController = new StreamController(opts); + var streamController = new StreamController(client, opts); var hashtagStream = createHashtagStream(client, channelName); var channelStream = createChannelStream(client, channelName); var stream = many([hashtagStream, channelStream]); |