Permalink
Browse files

some refactoring

  • Loading branch information...
1 parent 4f98dc1 commit d5610242dcc3b5860d1ae7c73568e9dc816303ae Jen Fong-Adwent committed Dec 21, 2012
View
@@ -82,33 +82,3 @@ exports.getUserHash = function(req, nickname, channel, isOwner, callback) {
exports.generateRandomNick = function() {
return 'i_love_ie6_v' + (new Date().getTime()) + Math.floor(Math.random() * 100);
};
-
-// generates a secret key for rss feed access
-exports.generateRSSKey = function(client, emailHash, callback) {
- var rssKey = crypto.createHash('sha1').update(emailHash +
- (new Date().getTime()) + Math.floor(Math.random() * 100) +
- Math.floor(Math.random() * 100)).digest('hex');
-
- client.set('privateFeedKey:' + emailHash, rssKey, function(err, resp) {
- if (err) {
- return callback(err);
- }
-
- callback(null, rssKey);
- });
-};
-
-// finds whether the secret key matches a given email hash
-exports.isValidRSSKey = function(client, emailHash, rssKey, callback) {
- client.get('privateFeedKey:' + emailHash, function(err, validRssKey) {
- if (err) {
- return callback(err);
- }
-
- if (validRssKey === rssKey) {
- callback(null, true);
- } else {
- callback(null, false);
- }
- });
-};
@@ -1,7 +1,7 @@
'use strict';
var auth = require('../lib/authenticate');
-var content = require('../lib/web-remix');
+var content = require('../lib/utils');
var gravatar = require('gravatar');
var noodleRedis = require('../lib/noodle-redis');
View
@@ -3,8 +3,6 @@
// Redis helper commands
var MEDIA_IFRAME_MATCHER = /<iframe\s.+><\/iframe>/i;
var MEDIA_OBJECT_MATCHER = /<object\s.+><\/object>/i;
-var MEDIA_VIDEO_MATCHER = /<video\s.+>.+<\/video>/i;
-var MEDIA_AUDIO_MATCHER = /<audio\s.+>.+<\/audio>/i;
var MEDIA_IMAGE_MATCHER = /(\.jpg)|(\.jpeg)|(\.png)|(\.gif)/i;
var PRIVATE_MESSAGE_MATCH = /private-/i;
var PROFILE_MESSAGE_MATCH = /profile-/i;
@@ -13,7 +11,7 @@ var SLASH_MATCHER = /^(\/)\w?/i;
var RECENT_MESSAGE_LIMIT = 39; // limit recent messages to 40, starting at 0
var RECENT_MEDIA_LIMIT = 9; // limit recent media to 10, starting at 0
var RECENT_USER_LIMIT = 19; // limit recent users to 20, starting at 0
-var content = require('../lib/web-remix');
+var content = require('../lib/utils');
var messageMaker = require('../lib/message-maker');
var scaffold = require('../lib/scaffold');
var auth = require('../lib/authenticate');
@@ -23,14 +21,25 @@ var auth = require('../lib/authenticate');
* Returns: a list of active user hashes
*/
exports.getUserlist = function(client, channel, callback) {
- scaffold.getDataByKeys(client, 'channelUser', channel, function(err, userList) {
- if (err) {
- callback(err);
+ scaffold.getDataByKeys(client, 'channelUser', channel, callback);
+};
- } else {
- callback(null, userList);
+var getMessageType = function(req) {
+ var messageContent = req.body.message || '';
+ console.log(messageContent)
+ if (req.body) {
+ var nick = content.getNickName(messageContent);
+ if (nick.length > 0) {
+ return 'nick';
+
+ } else if (messageContent.match(ME_MATCH)) {
+ return 'activity';
+
+ } else if (messageContent.match(SLASH_MATCHER)) {
+ return 'dummy';
}
- });
+ }
+ return '';
};
/* Create a new message
@@ -39,26 +48,9 @@ exports.getUserlist = function(client, channel, callback) {
*/
exports.setRecentMessage = function(client, req, io, callback) {
var channel = escape(req.params.channel);
+ var messageType = getMessageType(req);
- var getMessageType = function(req) {
- var messageContent = req.body.message || '';
-
- if (req.body) {
- var nick = content.getNickName(messageContent);
- if (nick.length > 0) {
- return 'nick';
-
- } else if (messageContent.match(ME_MATCH)) {
- return 'activity';
-
- } else if (messageContent.match(SLASH_MATCHER)) {
- return 'dummy';
- }
- }
- return '';
- };
-
- messageMaker.getMessage(client, channel, req, io, getMessageType(req), function(err, message) {
+ messageMaker.getMessage(client, channel, req, io, messageType, function(err, message) {
if (err || (channel.match(PROFILE_MESSAGE_MATCH) &&
auth.setEmailHash(req.session.email) !== channel.split('-')[1])) {
@@ -73,8 +65,6 @@ exports.setRecentMessage = function(client, req, io, callback) {
// Add if this is a media item
if (message.message.match(MEDIA_IFRAME_MATCHER) ||
message.message.match(MEDIA_OBJECT_MATCHER) ||
- message.message.match(MEDIA_VIDEO_MATCHER) ||
- message.message.match(MEDIA_AUDIO_MATCHER) ||
(message.message.match(MEDIA_IMAGE_MATCHER) &&
message.message.indexOf('class="emoti"') === -1)) {
client.lpush('channelMedia:' + channel, jsonMessage);
@@ -94,50 +84,12 @@ exports.setRecentMessage = function(client, req, io, callback) {
* Returns: the message list if successful, error otherwise
*/
exports.getRecentMessages = function(client, channel, callback) {
- scaffold.getDataByList(client, 'channelMessages', channel, RECENT_MESSAGE_LIMIT, function(err, messageList) {
- if (err) {
- callback(err);
-
- } else {
- callback(null, messageList);
- }
- });
-};
-
-/* Get the last recent notifications
- * Requires: a db client connection and a web request
- * Returns: the notification list if successful, error otherwise
- */
-exports.getRecentNotifications = function(client, req, callback) {
- var emailHash = req.params.email;
-
- auth.isValidRSSKey(client, emailHash, req.params.rsskey, function(errRss, resp) {
- if (errRss || !resp) {
- callback(errRss);
-
- } else {
- scaffold.getDataByList(client, 'notifications', emailHash,
- RECENT_MESSAGE_LIMIT, function(err, messageList) {
- if (err) {
- return callback(err);
- }
-
- callback(null, messageList);
- });
- }
- });
+ scaffold.getDataByList(client, 'channelMessages', channel, RECENT_MESSAGE_LIMIT, callback);
};
// Get the last recent media items
exports.getRecentMedia = function(client, channel, callback) {
- scaffold.getDataByList(client, 'channelMedia', channel, RECENT_MEDIA_LIMIT, function(err, messageList) {
- if (err) {
- callback(err);
-
- } else {
- callback(null, messageList);
- }
- });
+ scaffold.getDataByList(client, 'channelMedia', channel, RECENT_MEDIA_LIMIT, callback);
};
/* Set the new nick for the channel user or reference the old nick
View
@@ -1,17 +0,0 @@
-'use strict';
-
-// Generate audio tag
-var SERVICE_AUDIO = /(mp3)|(ogg)$/i;
-
-exports.process = function(media, remix) {
- if (!remix.isMatched && media.match(SERVICE_AUDIO)) {
- var audioType = media.split('.');
- remix.isMatched = true;
-
- audioType = audioType[audioType.length - 1];
- remix.result = '<audio controls="controls" preload="none" autobuffer>' +
- '<source src="' + media + '" type="audio/' + audioType + '" /></audio>' +
- '<a href="' + media + '" target="_blank">' + media + '</a>';
- }
- return remix;
-};
View
@@ -1,15 +0,0 @@
-'use strict';
-
-// Generate image link
-var SERVICE_IMAGE = /\.((jpg)|(jpeg)|(png)|(gif))$/i;
-
-exports.process = function(media, remix) {
- if (!remix.isMatched && media.match(SERVICE_IMAGE) &&
- media !== '/images/heart.png') {
- remix.isMatched = true;
-
- remix.result = '<img src="' + media + '"><a href="' + media + '" ' +
- 'class="media-link" target="_blank">' + media + '</a>';
- }
- return remix;
-};
View
@@ -1,11 +0,0 @@
-'use strict';
-
-// Generate regular link
-exports.process = function (media, remix) {
- if (!remix.isMatched) {
- remix.isMatched = true;
-
- remix.result = '<a href="' + media + '" target="_blank">' + media + '</a>';
- }
- return remix;
-};
@@ -1,25 +0,0 @@
-'use strict';
-
-// Generate Mixcloud iframe
-var SERVICE_MIXCLOUD = /(mixcloud\.com\/\w+\/\w+)/i;
-
-exports.process = function(media, remix, options) {
- if (!remix.isMatched && media.match(SERVICE_MIXCLOUD)) {
- remix.isMatched = true;
-
- var mixcloudURL = escape(media);
-
- remix.result = '<object width="' + options.width + '" height="' +
- options.height + '"><param name="movie" value="http://www.mixcloud.com/media/swf/' +
- 'player/mixcloudLoader.swf?feed=' + mixcloudURL + '&embed_type=widget_standard"></param>' +
- '<param name="allowFullScreen" value="false"></param><param name="wmode" value="opaque">' +
- '</param><param name="allowscriptaccess" value="always"></param><embed src="//www.mixcloud.com/' +
- 'media/swf/player/mixcloudLoader.swf?feed=' + mixcloudURL + '&embed_type=widget_standard" ' +
- 'type="application/x-shockwave-flash" wmode="opaque" allowscriptaccess="always" ' +
- 'allowfullscreen="true" width="' + options.width + '" height="' + options.height + '">' +
- '</embed></object><div style="clear:both; height:3px;">' +
- '<div style="clear:both; height:3px;"></div></div><a href="' + mixcloudURL + '" ' +
- 'class="media-link" target="_blank">' + mixcloudURL + '</a>';
- }
- return remix;
-};
View
@@ -1,21 +0,0 @@
-'use strict';
-
-// Generate Rdio iframe
-var SERVICE_RDIO = /(((rdio\.com)|(rd\.io))\/\w\/\w+)/i;
-
-exports.process = function(media, remix, url) {
- if (!remix.isMatched && media.match(SERVICE_RDIO)) {
- var rdioId = url[url.length -1];
-
- try {
- remix.isMatched = true;
- remix.result = '<iframe class="rdio" width="450" height="80" ' +
- 'src="//rd.io/i/' + rdioId + '" frameborder="0"></iframe>' +
- '<a href="http://rd.io/x/' + rdioId + '" ' +
- 'class="media-link" target="_blank">http://rd.io/x/' + rdioId + '</a>';
- } catch(err) {
- return remix;
- }
- }
- return remix;
-};
@@ -1,27 +0,0 @@
-// Generate Soundcloud iframe
-var SERVICE_SOUNDCLOUD = /soundcloud/i;
-var request = require('request');
-
-exports.process = function(media, remix, url, callback) {
- if (!remix.isMatched && media.match(SERVICE_SOUNDCLOUD)) {
- request.get('http://soundcloud.com/oembed?format=json&url=' + media, function(error, resp, body) {
- if(error) {
- return media;
- }
-
- try {
- remix.isMatched = true;
- var jsonResp = JSON.parse(body);
-
- jsonResp.html = jsonResp.html.replace(/src="http:/, 'src="');
-
- remix.result = jsonResp.html + '<a href="' + media + '" class="media-link" target="_blank">' + media + '</a>';
- return callback(null, remix);
- } catch(error) {
- return callback(null, remix);
- }
- });
- } else {
- return callback(null, remix);
- }
-};
View
@@ -1,24 +0,0 @@
-'use strict';
-
-// Generate video tag
-var SERVICE_VIDEO = /(webm)|(ogv)|(mp4)$/i;
-
-exports.process = function(media, remix) {
- if (!remix.isMatched && media.match(SERVICE_VIDEO)) {
- var videoType = media.split('.');
- remix.isMatched = true;
- videoType = videoType[videoType.length - 1];
-
- var videoFormat = '';
- if(videoType === 'webm') {
- videoFormat = 'type="video/webm; codecs="theora, vorbis"';
- } else if(videoType === 'ogv') {
- videoFormat = 'type="video/ogg; codecs="vp8, vorbis"';
- }
-
- remix.result = '<video controls="controls" preload="none" autobuffer>' +
- '<source src="' + media + '" ' + videoFormat + ' /></video>' +
- '<a href="' + media + '" target="_blank">' + media + '</a>';
- }
- return remix;
-};
View
@@ -1,24 +0,0 @@
-'use strict';
-
-// Generate Vimeo iframe
-var SERVICE_VIMEO = /vimeo/i;
-
-exports.process = function(media, remix, url, options) {
- if (!remix.isMatched && media.match(SERVICE_VIMEO)) {
- var vimeoId = parseInt(url[url.length - 1], 10);
-
- if (!isNaN(vimeoId)) {
- remix.isMatched = true;
-
- remix.result = '<iframe src="//player.vimeo.com/video/' + vimeoId + '" ' +
- 'width="' + options.width + '" height="' + options.height + '" frameborder="0" ' +
- 'webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>' +
- '<a href="http://vimeo.com/' + vimeoId + '" ' +
- 'class="media-link" target="_blank">http://vimeo.com/' + vimeoId + '</a>';
-
- } else {
- return remix;
- }
- }
- return remix;
-};
@@ -1,27 +0,0 @@
-'use strict';
-
-// Generate Youtube iframe
-var SERVICE_YOUTUBE = /(youtube)|(youtu\.be)/i;
-
-exports.process = function(media, remix, url, options) {
- if (!remix.isMatched && media.match(SERVICE_YOUTUBE)) {
- var youtubeId = "";
-
- try {
- remix.isMatched = true;
- if (media.indexOf('youtu.be') > -1) {
- youtubeId = url[url.length - 1];
- } else {
- youtubeId = url[url.length - 1].split('v=')[1].split('&')[0];
- }
- remix.result = '<iframe width="' + options.width + '" height="' + options.height + '" ' +
- 'src="//www.youtube.com/embed/' + youtubeId + '?wmode=transparent" frameborder="0" ' +
- 'allowfullscreen></iframe><a href="//www.youtube.com/watch?v=' + youtubeId + '" ' +
- 'class="media-link" target="_blank">http://www.youtube.com/watch?v=' + youtubeId + '</a>';
-
- } catch(err) {
- return remix;
- }
- }
- return remix;
-};
Oops, something went wrong.

0 comments on commit d561024

Please sign in to comment.