lib/app.jsView |
---|
7 | 7 … | var multicb = require('multicb') |
8 | 8 … | var paramap = require('pull-paramap') |
9 | 9 … | var Contacts = require('ssb-contact') |
10 | 10 … | var About = require('./about') |
| 11 … | +var Follows = require('./follows') |
11 | 12 … | var Serve = require('./serve') |
12 | 13 … | var Render = require('./render') |
13 | 14 … | var Git = require('./git') |
14 | 15 … | var cat = require('pull-cat') |
48 | 49 … | this.reverseNameCache = lru(500) |
49 | 50 … | this.reverseEmojiNameCache = lru(500) |
50 | 51 … | this.getBlobSize = memo({cache: this.blobSizeCache = lru(100)}, |
51 | 52 … | sbot.blobs.size.bind(sbot.blobs)) |
52 | | - this.getFollows = memo(this._getFollows.bind(this)) |
53 | 53 … | this.getVotes = memo({cache: lru(100)}, this._getVotes.bind(this)) |
54 | 54 … | |
55 | 55 … | this.unboxMsg = this.unboxMsg.bind(this) |
56 | 56 … | |
57 | 57 … | this.render = new Render(this, this.opts) |
58 | 58 … | this.git = new Git(this) |
59 | 59 … | this.contacts = new Contacts(this.sbot) |
| 60 … | + this.follows = new Follows(this.sbot, this.contacts) |
60 | 61 … | |
61 | 62 … | this.monitorBlobWants() |
62 | 63 … | } |
63 | 64 … | |
689 | 690 … | if (filter === 'all' |
690 | 691 … | || author === myId |
691 | 692 … | || author === opts.feed |
692 | 693 … | || msg.key === opts.msgId) return cb(null, show) |
693 | | - self.getFollows(myId, function (err, follows) { |
| 694 … | + self.follows.getFollows(myId, function (err, follows) { |
694 | 695 … | if (err) return cb(err) |
695 | 696 … | if (follows[author]) return cb(null, show) |
696 | 697 … | self.getVotes(msg.key, function (err, votes) { |
697 | 698 … | if (err) return cb(err) |
706 | 707 … | } |
707 | 708 … | |
708 | 709 … | App.prototype.isFollowing = function (src, dest, cb) { |
709 | 710 … | var self = this |
710 | | - self.getFollows(src, function (err, follows) { |
| 711 … | + self.follows.getFollows(src, function (err, follows) { |
711 | 712 … | if (err) return cb(err) |
712 | 713 … | return cb(null, follows[dest]) |
713 | 714 … | }) |
714 | 715 … | } |
715 | 716 … | |
716 | | -App.prototype._getFollows = function (id, cb) { |
717 | | - var follows = {} |
718 | | - function ready(err) { |
719 | | - if (!cb) return |
720 | | - var _cb = cb |
721 | | - cb = null |
722 | | - _cb(err, follows) |
723 | | - } |
724 | | - pull( |
725 | | - this.sbot.links2.read({ |
726 | | - live: true, |
727 | | - query: [ |
728 | | - {$filter: { |
729 | | - source: id, |
730 | | - rel: [{$prefix: 'contact'}] |
731 | | - }}, |
732 | | - {$map: { |
733 | | - following: ['rel', 1], |
734 | | - feed: 'dest' |
735 | | - }} |
736 | | - ] |
737 | | - }), |
738 | | - pull.drain(function (link) { |
739 | | - if (link.sync) return ready() |
740 | | - follows[link.feed] = link.following |
741 | | - }, ready) |
742 | | - ) |
743 | | -} |
744 | | - |
745 | 717 … | App.prototype._getVotes = function (id, cb) { |
746 | 718 … | var votes = {} |
747 | 719 … | pull( |
748 | 720 … | this.sbot.links2.read({ |