Skip to content
This repository has been archived by the owner on Dec 1, 2017. It is now read-only.

Commit

Permalink
Disabling bugzilla, adding mentions.
Browse files Browse the repository at this point in the history
  • Loading branch information
simonwex committed Aug 8, 2012
1 parent 57a214e commit ad42a3e
Show file tree
Hide file tree
Showing 14 changed files with 575 additions and 181 deletions.
2 changes: 1 addition & 1 deletion app/feeds/daemon.js
Expand Up @@ -5,7 +5,7 @@
* You can obtain one at http://mozilla.org/MPL/2.0/. */

require('../../lib/extensions/number');
require('./bugzilla');
// require('./bugzilla');

var
maxStoryAge = (1).hours(),
Expand Down
71 changes: 70 additions & 1 deletion app/http/controllers/profile.js
Expand Up @@ -14,7 +14,35 @@ Redis = require('../../../lib/redis');
*/
exports.index = {
get: function(req, res){
res.render('profile/index', { user: req.user });
mysql.query(
"SELECT name FROM irc_channels",
function(err, rows){
if (err){
logger.error("Error retrieving IRC Channels in profile.js: " + err);
}

for(var i in rows){
rows[i].displayName = rows[i].name.substr(1);
}

mysql.query(
"SELECT title, url, verified FROM feeds WHERE user_id = ?",
[req.user.id],
function(err, feedRows){
mysql.query(
"SELECT token FROM watched_tokens WHERE user_id = ?",
[req.user.id],
function(err, tokens){
for(var i in tokens){
tokens[i] = tokens[i].token;
}
res.render('profile/index', { user: req.user, channels: rows, feeds: feedRows, watchedTokens: tokens});
}
);
}
);
}
);
},
put: function(req, res){
// Only allow the saving of nick and realName
Expand All @@ -32,6 +60,47 @@ exports.index = {
}
};

exports.watchedTokens = {
put: function(req, res){
console.log(req.body);
var tokens = req.body.tokens;
var values = [];
var placeholders = [];
for (var i in tokens){
//Validate
if (tokens[i].match(/^\w[\w\-\_]+$/)){
values.push(req.user.id)
values.push(tokens[i]);
placeholders.push('(?, ?)');
}
else {
res.send('"ERROR"', {status: 500});
return;
}
}

mysql.query(
"DELETE FROM watched_tokens WHERE user_id = ?",
[req.user.id],
function(err, result){
if (err)
logger.error("Error deleting old tokens");

mysql.query(
"INSERT INTO watched_tokens (user_id, token) VALUES " + placeholders.join(','),
values,
function(err, result){
if (err)
logger.error("Error inserting new tokens: " + err);

res.send('"OK"');
}
);
}
);
}
}

/*
* POST
*/
Expand Down
33 changes: 29 additions & 4 deletions app/http/controllers/site.js
Expand Up @@ -3,9 +3,10 @@
* You can obtain one at http://mozilla.org/MPL/2.0/. */

const
createRedisClient = require('../../../lib/redis'),

redis = require('../../../lib/redis'),
uuid = require('node-uuid'),
logger = require('../../../lib/logger'),
crypto = require('crypto'),
config = require('../../../lib/configuration');

/*
Expand All @@ -25,12 +26,36 @@ exports.authenticate = function(req, res) {

exports.signout = function(req, res){
if (req.user){
var redis = createRedisClient();
redis.publish('user.signout', req.user.id.toString(), function(err){
redis.pub.publish('user.signout', req.user.id.toString(), function(err){
if (err)
logger.error(err);
});
}
req.logout();
res.redirect('/');
};


exports.driver = function(req, res){
var storyId = null;

if ('story' in req.body){
storyId = req.user.email + ":" + uuid.v1()
var hash = crypto.createHash('md5').update(req.user.email).digest("hex");

var story = {
id: storyId,
people: req.user.email,
title: req.body.story.title,
href: req.body.story.url,
pubdate: new Date(),
image: {url: "http://www.gravatar.com/avatar/" + hash + "?s=30"}
};

redis.io.lpush("serializer:stories", JSON.stringify({'userIds': [req.user.id], 'story': story}), function (err, reply) {
if (err)
logger.error(err);
});
}
res.render('site/driver', {user: req.user, lastId: storyId});
}
16 changes: 7 additions & 9 deletions app/http/controllers/social.js
Expand Up @@ -25,23 +25,22 @@ exports.manifest = function(req, res){
res.render('social/manifest.json.ejs', { baseUrl: config.get("public_url"), providerSuffix: config.get("social_provider")['name_suffix'], layout: false });
};

exports.bugs = function(req, res){
mysql.query('SELECT * FROM stories WHERE user_id = ? AND durable = ? ORDER BY seen_at, published_at', [req.user.id, true], function(err, rows){
exports.mentions = function(req, res){
mysql.query('SELECT * FROM stories WHERE user_id = ? AND durable = ? ORDER BY seen_at, published_at limit 200', [req.user.id, true], function(err, rows){
if (err){
logger.error('Erorr getting stories');
}
var bugs = [];
var mentions = [];
for (var i in rows){
var story = JSON.parse(rows[i].data);
story.seen_at = rows[i].seen_at;
bugs.push(story);
mentions.push(story);
}
res.render('social/bugs', {user: req.user, bugs: bugs, layout: false});
res.render('social/mentions', {user: req.user, mentions: mentions, layout: false});
});
};

exports.markBugAsViewed = function(req, res){
console.log(req.body);
exports.markMentionAsViewed = function(req, res){
if (req.user){
mysql.query(
"UPDATE stories SET seen_at = NOW() WHERE user_id = ? and id = ?",
Expand All @@ -50,8 +49,7 @@ exports.markBugAsViewed = function(req, res){
if (err){
logger.error('Error marking story as read: ' + err);
}
var redis = createRedisClient();
redis.publish('notifications.bugzilla.read', req.body.id, function(err){
redis.publish('notifications.mention.read', req.user.id, function(err){
if (err)
logger.error(err);
});
Expand Down

0 comments on commit ad42a3e

Please sign in to comment.