Skip to content

Commit

Permalink
0.4.0: Active sort, fetch comment tree structures by submission
Browse files Browse the repository at this point in the history
  • Loading branch information
go1dfish committed Jun 24, 2018
1 parent 44d3c1c commit 0d61942
Show file tree
Hide file tree
Showing 12 changed files with 186 additions and 124 deletions.
18 changes: 10 additions & 8 deletions dist/notabug.web.js

Large diffs are not rendered by default.

14 changes: 13 additions & 1 deletion lib/accessors.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getCollectionsArray = exports.getCollections = exports.getCollection = exports.getScore = exports.getVoteCount = exports.getTimestamp = undefined;
exports.getCollectionsArray = exports.getCollections = exports.getCollection = exports.getScore = exports.getOpId = exports.getVoteCount = exports.getLastActive = exports.getTimestamp = undefined;

var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };

Expand All @@ -23,12 +23,24 @@ var getTimestamp = exports.getTimestamp = function getTimestamp(peer) {
};
};

var getLastActive = exports.getLastActive = function getLastActive(peer) {
return function (id) {
return (0, _pathOr2.default)(peer.getTimestamp(id), ["things", id, "lastActive"], peer.getState());
};
};

var getVoteCount = exports.getVoteCount = function getVoteCount(peer) {
return function (id, type) {
return (0, _pathOr2.default)(0, ["things", id, "votes", type], peer.getState());
};
};

var getOpId = exports.getOpId = function getOpId(peer) {
return function (id) {
return (0, _pathOr2.default)(id, ["things", id, "opId"], peer.getState());
};
};

var getScore = exports.getScore = function getScore(peer) {
return function (id) {
return peer.getVoteCount(id, "up") - peer.getVoteCount(id, "down");
Expand Down
58 changes: 27 additions & 31 deletions lib/listing.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,10 @@ exports.unwatchListing = exports.watchListing = exports.getListingIds = exports.

var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };

var _compose = require("ramda/src/compose");

var _compose2 = _interopRequireDefault(_compose);

var _filter = require("ramda/src/filter");

var _filter2 = _interopRequireDefault(_filter);

var _identity = require("ramda/src/identity");

var _identity2 = _interopRequireDefault(_identity);

var _lte = require("ramda/src/lte");

var _lte2 = _interopRequireDefault(_lte);

var _slice = require("ramda/src/slice");

var _slice2 = _interopRequireDefault(_slice);
var _ramda = require("ramda");

var _etc = require("./etc");

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

var getListingSouls = exports.getListingSouls = function getListingSouls(peer) {
Expand All @@ -46,7 +26,7 @@ var getListingSouls = exports.getListingSouls = function getListingSouls(peer) {
var dayStrings = void 0;

if (replyToId) {
return [_etc.PREFIX + "/things/" + replyToId + "/comments"];
return [_etc.PREFIX + "/things/" + peer.getOpId(replyToId) + "/allcomments"];
} else if (url) {
return [_etc.PREFIX + "/urls/" + url];
} else if (domain) {
Expand All @@ -69,20 +49,36 @@ var getListingSouls = exports.getListingSouls = function getListingSouls(peer) {
};
};

var getReplies = function getReplies(peer, params) {
var _ref2 = params || {},
limit = _ref2.limit,
_ref2$sort = _ref2.sort,
sort = _ref2$sort === undefined ? "hot" : _ref2$sort,
replyToId = _ref2.replyToId,
_ref2$count = _ref2.count,
count = _ref2$count === undefined ? 0 : _ref2$count,
_ref2$threshold = _ref2.threshold,
threshold = _ref2$threshold === undefined ? null : _ref2$threshold;

return (0, _ramda.compose)(limit ? (0, _ramda.slice)(count, count + limit) : _ramda.identity, peer.sorts[sort], threshold === null ? _ramda.identity : (0, _ramda.filter)((0, _ramda.compose)((0, _ramda.lte)(threshold), peer.getScore)), Object.keys, (0, _ramda.pathOr)({}, ["things", replyToId, "replies"]))(peer.getState());
};

var getListingIds = exports.getListingIds = function getListingIds(peer) {
return function (params) {
var _ref2 = params || {},
limit = _ref2.limit,
_ref2$sort = _ref2.sort,
sort = _ref2$sort === undefined ? "hot" : _ref2$sort,
_ref2$count = _ref2.count,
count = _ref2$count === undefined ? 0 : _ref2$count,
_ref2$threshold = _ref2.threshold,
threshold = _ref2$threshold === undefined ? null : _ref2$threshold;
var _ref3 = params || {},
limit = _ref3.limit,
_ref3$sort = _ref3.sort,
sort = _ref3$sort === undefined ? "hot" : _ref3$sort,
_ref3$count = _ref3.count,
count = _ref3$count === undefined ? 0 : _ref3$count,
_ref3$threshold = _ref3.threshold,
threshold = _ref3$threshold === undefined ? null : _ref3$threshold;

if (!peer.sorts[sort]) throw new Error("Unknown sort: " + sort);

return (0, _compose2.default)(limit ? (0, _slice2.default)(count, count + limit) : _identity2.default, peer.sorts[sort], threshold === null ? _identity2.default : (0, _filter2.default)((0, _compose2.default)((0, _lte2.default)(threshold), peer.getScore)), peer.getCollectionsArray, peer.getListingSouls)(params);
if (params.replyToId) return getReplies(peer, params);

return (0, _ramda.compose)(limit ? (0, _ramda.slice)(count, count + limit) : _ramda.identity, peer.sorts[sort], threshold === null ? _ramda.identity : (0, _ramda.filter)((0, _ramda.compose)((0, _ramda.lte)(threshold), peer.getScore)), peer.getCollectionsArray, peer.getListingSouls)(params);
};
};

Expand Down
2 changes: 1 addition & 1 deletion lib/notabug.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ var notabug = function notabug() {
if (persist) {
gunConfig.localStorage = false;
gunConfig.radisk = true;
gunConfig.until = gunConfig.until || 60000;
gunConfig.until = gunConfig.until || 1000;
} else {
gunConfig.radisk = false;
}
Expand Down
3 changes: 3 additions & 0 deletions lib/sorts.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ var sorts = exports.sorts = function sorts(peer) {
old: (0, _sortBy2.default)(function (id) {
return peer.getTimestamp(id);
}),
active: (0, _sortBy2.default)(function (id) {
return -1 * peer.getLastActive(id);
}),
top: (0, _sortBy2.default)(function (id) {
return -1 * peer.getScore(id);
}),
Expand Down
Loading

0 comments on commit 0d61942

Please sign in to comment.