summaryrefslogtreecommitdiff
path: root/bucky
diff options
context:
space:
mode:
Diffstat (limited to 'bucky')
-rw-r--r--bucky/app/api.js25
-rw-r--r--bucky/app/bucky.js64
-rw-r--r--bucky/app/pages.js11
-rw-r--r--bucky/db/index.js36
4 files changed, 133 insertions, 3 deletions
diff --git a/bucky/app/api.js b/bucky/app/api.js
index 75cdbd7..d2472c3 100644
--- a/bucky/app/api.js
+++ b/bucky/app/api.js
@@ -34,6 +34,19 @@ function route (app){
function(req, res){
res.json(util.sanitizeUser(res.user))
})
+ app.get("/api/users",
+ middleware.ensureAuthenticated,
+ bucky.ensureUserlist,
+ bucky.ensureUserThreadCounts,
+ bucky.ensureUserFileCounts,
+ bucky.ensureUserCommentCounts,
+ bucky.ensureUserStatistics,
+ function(req, res) {
+ res.json({
+ users: res.users,
+ userStats: res.userStats,
+ })
+ })
app.get("/api/profile/:username",
middleware.ensureAuthenticated,
bucky.ensureUser,
@@ -153,6 +166,16 @@ function route (app){
function(req, res){
res.send({ status: 'ok' })
})
+ app.get("/api/thread/:id/bury",
+ middleware.ensureAuthenticated,
+ bucky.ensureThread,
+ privacy.checkThreadPrivacy,
+ bucky.buryThread,
+ function(req, res){
+ res.json({
+ thread: res.thread,
+ })
+ })
/* comments */
@@ -259,9 +282,11 @@ function route (app){
middleware.ensureAuthenticated,
bucky.ensureKeywords,
bucky.ensureThreadGroups,
+ bucky.ensureLatestKeywordThreads,
function(req, res){
res.json({
keywords: res.keywords,
+ threads: res.threads,
threadGroups: res.threadGroups,
})
})
diff --git a/bucky/app/bucky.js b/bucky/app/bucky.js
index 8d9839f..ab153f9 100644
--- a/bucky/app/bucky.js
+++ b/bucky/app/bucky.js
@@ -227,6 +227,10 @@ var bucky = module.exports = {
next()
})
},
+ buryThread: function (req, res, next){
+ res.thread.set('lastmodified', util.now() - (14 * 86400))
+ res.thread.save().then( () => next() )
+ },
// ensureInterestedUsers: function(req, res, next){
// // given a thread, find people who might be interested in it
// // - other people who have been in threads with you
@@ -296,6 +300,12 @@ var bucky = module.exports = {
next()
})
},
+ ensureLatestKeywordThreads: function (req, res, next){
+ db.getLatestKeywordThreads().then(function(threads){
+ res.threads = threads
+ next()
+ })
+ },
ensureThreadGroups: function (req, res, next){
db.getThreadGroups().then(function(threadGroups){
res.threadGroups = threadGroups
@@ -571,6 +581,60 @@ var bucky = module.exports = {
}
})
},
+ ensureUserlist: function (req, res, next){
+ db.getUsers().then(function(users){
+ if (! users) {
+ return res.sendStatus(404)
+ }
+ res.users = users
+ next()
+ })
+ },
+ ensureUserThreadCounts: function (req, res, next) {
+ db.getUserThreadCounts().then(function(counts){
+ if (!counts) {
+ return res.sendStatus(404)
+ }
+ res.threadCounts = counts
+ next()
+ })
+ },
+ ensureUserCommentCounts: function (req, res, next) {
+ db.getUserCommentCounts().then(function(counts){
+ if (!counts) {
+ return res.sendStatus(404)
+ }
+ res.commentCounts = counts
+ next()
+ })
+ },
+ ensureUserFileCounts: function (req, res, next) {
+ db.getUserFileCounts().then(function(counts){
+ if (!counts) {
+ return res.sendStatus(404)
+ }
+ res.fileCounts = counts
+ next()
+ })
+ },
+ ensureUserStatistics: function (req, res, next) {
+ var stats = {}
+ res.threadCounts.forEach(function(user){
+ stats[user.username] = stats[user.username] || {}
+ stats[user.username].threads = user.count
+ })
+ res.commentCounts.forEach(function(user){
+ stats[user.username] = stats[user.username] || {}
+ stats[user.username].comments = user.count
+ })
+ res.fileCounts.forEach(function(user){
+ stats[user.username] = stats[user.username] || {}
+ stats[user.username].files = user.count
+ stats[user.username].fileSize = user.size
+ })
+ res.userStats = stats
+ next()
+ },
sanitizeUser: function(req, res, next) {
res.user = util.sanitizeUser(res.user)
next()
diff --git a/bucky/app/pages.js b/bucky/app/pages.js
index 7f666be..5d8551e 100644
--- a/bucky/app/pages.js
+++ b/bucky/app/pages.js
@@ -73,6 +73,17 @@ function route (app){
res.render("pages/profile_form", {title: "edit your profile"})
})
+ app.get("/users",
+ middleware.ensureAuthenticated,
+ function(req, res){
+ res.render("pages/users", {})
+ })
+ app.get("/users/all",
+ middleware.ensureAuthenticated,
+ function(req, res){
+ res.render("pages/users", {})
+ })
+
app.get("/search/",
middleware.ensureAuthenticated,
function(req, res){
diff --git a/bucky/db/index.js b/bucky/db/index.js
index f454c92..312ca13 100644
--- a/bucky/db/index.js
+++ b/bucky/db/index.js
@@ -55,8 +55,13 @@ db.createUser = function(data){
}
db.getUsers = function () {
return User.query(function(qb){
- qb.orderBy("id", "desc")
- }).fetchAll()
+ qb.orderBy("username", "asc")
+ }).fetchAll({
+ columns: [
+ "id", "username", "realname", "firstseen", "lastseen",
+ "location", "website", "avatar",
+ ]
+ })
}
db.getUser = function(id) {
var model = new User({'id': id})
@@ -143,6 +148,15 @@ db.getThreadUsers = function(thread_id){
db.getUserThreadIds = function(user_id){
return ThreadUser.query("where", "user_id", "=", user_id).fetch()
}
+db.getUserThreadCounts = function(ids){
+ return knex.column('username').count('* as count').select().from('threads').groupBy('username')
+}
+db.getUserCommentCounts = function(ids){
+ return knex.column('username').count('* as count').select().from('comments').groupBy('username')
+}
+db.getUserFileCounts = function(ids){
+ return knex.column('username').sum('size as size').count('* as count').select().from('files').groupBy('username')
+}
/* FILES */
@@ -281,8 +295,24 @@ db.getKeyword = function (keyword) {
return Keyword.query("where", "keyword", "=", keyword).fetch()
}
db.getThreadGroups = function (keyword) {
- return knex.column('keyword').sum('viewed').as('viewed').count('*').as('count').column('id').column('title').column('lastmodified').column('privacy').select().from('threads').groupBy('keyword')
+ return (
+ knex.column('keyword')
+ .sum('viewed').as('viewed')
+ .count('*').as('count')
+ .select().from('threads').groupBy('keyword')
+ )
+}
+db.getLatestKeywordThreads = function (keyword) {
+ var ids = knex('threads').max('id').groupBy('keyword')
+ return (
+ knex.select('id', 'keyword', 'title', 'lastmodified', 'privacy').from('threads').where('id', 'in', ids)
+ )
}
+ // .column('id')
+ // .column('title')
+ // .column('lastmodified')
+ // .column('privacy')
+
db.createKeyword = function(data){
return new db.Keyword(data).save()
}