diff --git a/src/database.js b/src/database.js
index e182638..a3eeca7 100644
--- a/src/database.js
+++ b/src/database.js
@@ -251,6 +251,27 @@ async function getServerConfig() {
return ENDPOINT.findOne();
}
+async function getNewsFeed(user, numberOfPosts) {
+ verifyConnected();
+ return POST.find({
+ $or: [
+ {pid: user.followed_users},
+ {pid: user.pid}
+ ],
+ }).limit(numberOfPosts).sort({ created_at: -1});
+}
+
+async function getNewsFeedAfterTimestamp(user, numberOfPosts, post) {
+ verifyConnected();
+ return POST.find({
+ $or: [
+ {pid: user.followed_users},
+ {pid: user.pid}
+ ],
+ created_at: { $lt: post.created_at }
+ }).limit(numberOfPosts).sort({ created_at: -1});
+}
+
module.exports = {
connect,
getCommunities,
@@ -281,5 +302,7 @@ module.exports = {
getCommunityPostsAfterTimestamp,
getServerConfig,
pushNewNotificationByPID,
- pushNewNotificationToAll
+ pushNewNotificationToAll,
+ getNewsFeed,
+ getNewsFeedAfterTimestamp,
};
\ No newline at end of file
diff --git a/src/services/juxt-web/index.js b/src/services/juxt-web/index.js
index ae91ba8..678b3ff 100644
--- a/src/services/juxt-web/index.js
+++ b/src/services/juxt-web/index.js
@@ -37,6 +37,8 @@ ctr.use('/titles/show', routes.CTR_SHOW);
ctr.use('/communities', routes.CTR_COMMUNITIES);
ctr.use('/users', routes.CTR_USER);
ctr.use('/posts', routes.CTR_POST);
+ctr.use('/news', routes.CTR_NEWS);
+ctr.use('/activity-feed', routes.CTR_FEED);
ctr.use('/', routes.CTR_WEB);
admin.use('/', routes.WEB_ADMIN);
diff --git a/src/services/juxt-web/routes/ctr/feed.js b/src/services/juxt-web/routes/ctr/feed.js
new file mode 100644
index 0000000..c43ae31
--- /dev/null
+++ b/src/services/juxt-web/routes/ctr/feed.js
@@ -0,0 +1,86 @@
+var express = require('express');
+var xml = require('object-to-xml');
+const database = require('../../../../database');
+const util = require('../../../../authentication');
+var moment = require('moment');
+var router = express.Router();
+
+router.get('/', function (req, res) {
+ res.header('X-Nintendo-WhiteList','1|http,youtube.com,,2|https,youtube.com,,2|http,.youtube.com,,2|https,.youtube.com,,2|http,.ytimg.com,,2|https,.ytimg.com,,2|http,.googlevideo.com,,2|https,.googlevideo.com,,2|https,youtube.com,/embed/,6|https,youtube.com,/e/,6|https,youtube.com,/v/,6|https,www.youtube.com,/embed/,6|https,www.youtube.com,/e/,6|https,www.youtube.com,/v/,6|https,youtube.googleapis.com,/e/,6|https,youtube.googleapis.com,/v/,6|http,maps.googleapis.com,/maps/api/streetview,2|https,maps.googleapis.com,/maps/api/streetview,2|http,cbk0.google.com,/cbk,2|https,cbk0.google.com,/cbk,2|http,cbk1.google.com,/cbk,2|https,cbk1.google.com,/cbk,2|http,cbk2.google.com,/cbk,2|https,cbk2.google.com,/cbk,2|http,cbk3.google.com,/cbk,2|https,cbk3.google.com,/cbk,2|https,.cloudfront.net,,2|https,www.google-analytics.com,/,2|https,stats.g.doubleclick.net,,2|https,www.google.com,/ads/,2|https,ssl.google-analytics.com,,2|http,fonts.googleapis.com,,2||fonts.googleapis.com,,2');
+ database.connect().then(async e => {
+
+ let pid = util.data.processServiceToken(req.headers["x-nintendo-servicetoken"]);
+
+ if(pid === null)
+ pid = 1000000000;
+ let user = await database.getUserByPID(pid);
+ let communityMap = await util.data.getCommunityHash();
+ let posts = await database.getNewsFeed(user, 3);
+ res.render('ctr/feed.ejs', {
+ moment: moment,
+ user: user,
+ posts: posts,
+ communityMap: communityMap,
+ });
+ }).catch(error => {
+ console.log(error);
+ res.set("Content-Type", "application/xml");
+ res.statusCode = 400;
+ response = {
+ result: {
+ has_error: 1,
+ version: 1,
+ code: 400,
+ error_code: 15,
+ message: "SERVER_ERROR"
+ }
+ };
+ res.send("\n" + xml(response));
+ });
+});
+
+router.get('/loadposts', function (req, res) {
+ res.header('X-Nintendo-WhiteList','1|http,youtube.com,,2|https,youtube.com,,2|http,.youtube.com,,2|https,.youtube.com,,2|http,.ytimg.com,,2|https,.ytimg.com,,2|http,.googlevideo.com,,2|https,.googlevideo.com,,2|https,youtube.com,/embed/,6|https,youtube.com,/e/,6|https,youtube.com,/v/,6|https,www.youtube.com,/embed/,6|https,www.youtube.com,/e/,6|https,www.youtube.com,/v/,6|https,youtube.googleapis.com,/e/,6|https,youtube.googleapis.com,/v/,6|http,maps.googleapis.com,/maps/api/streetview,2|https,maps.googleapis.com,/maps/api/streetview,2|http,cbk0.google.com,/cbk,2|https,cbk0.google.com,/cbk,2|http,cbk1.google.com,/cbk,2|https,cbk1.google.com,/cbk,2|http,cbk2.google.com,/cbk,2|https,cbk2.google.com,/cbk,2|http,cbk3.google.com,/cbk,2|https,cbk3.google.com,/cbk,2|https,.cloudfront.net,,2|https,www.google-analytics.com,/,2|https,stats.g.doubleclick.net,,2|https,www.google.com,/ads/,2|https,ssl.google-analytics.com,,2|http,fonts.googleapis.com,,2|fonts.googleapis.com,,2|https,www.googletagmanager.com,,2');
+ database.connect().then(async e => {
+ let pid = util.data.processServiceToken(req.headers["x-nintendo-servicetoken"]);
+ let post = await database.getPostByID(req.query.postID);
+ if(pid === null)
+ pid = 1000000000;
+ let user = await database.getUserByPID(pid);
+ let communityMap = await util.data.getCommunityHash();
+ let posts;
+ if(post !== null)
+ posts = await database.getNewsFeedAfterTimestamp(user, 3, post);
+
+ if(posts.length > 0)
+ {
+ res.render('ctr/more_posts.ejs', {
+ communityMap: communityMap,
+ moment: moment,
+ database: database,
+ user: user,
+ newPosts: posts,
+ });
+ }
+ else
+ {
+ res.sendStatus(204);
+ }
+ }).catch(error => {
+ console.log(error);
+ res.set("Content-Type", "application/xml");
+ res.statusCode = 400;
+ response = {
+ result: {
+ has_error: 1,
+ version: 1,
+ code: 400,
+ error_code: 15,
+ message: "SERVER_ERROR"
+ }
+ };
+ res.send("\n" + xml(response));
+ });
+});
+
+module.exports = router;
diff --git a/src/services/juxt-web/routes/ctr/notifications.js b/src/services/juxt-web/routes/ctr/notifications.js
new file mode 100644
index 0000000..2446140
--- /dev/null
+++ b/src/services/juxt-web/routes/ctr/notifications.js
@@ -0,0 +1,44 @@
+var express = require('express');
+var xml = require('object-to-xml');
+const database = require('../../../../database');
+const util = require('../../../../authentication');
+var moment = require('moment');
+var router = express.Router();
+
+router.get('/', function (req, res) {
+ res.header('X-Nintendo-WhiteList','1|http,youtube.com,,2|https,youtube.com,,2|http,.youtube.com,,2|https,.youtube.com,,2|http,.ytimg.com,,2|https,.ytimg.com,,2|http,.googlevideo.com,,2|https,.googlevideo.com,,2|https,youtube.com,/embed/,6|https,youtube.com,/e/,6|https,youtube.com,/v/,6|https,www.youtube.com,/embed/,6|https,www.youtube.com,/e/,6|https,www.youtube.com,/v/,6|https,youtube.googleapis.com,/e/,6|https,youtube.googleapis.com,/v/,6|http,maps.googleapis.com,/maps/api/streetview,2|https,maps.googleapis.com,/maps/api/streetview,2|http,cbk0.google.com,/cbk,2|https,cbk0.google.com,/cbk,2|http,cbk1.google.com,/cbk,2|https,cbk1.google.com,/cbk,2|http,cbk2.google.com,/cbk,2|https,cbk2.google.com,/cbk,2|http,cbk3.google.com,/cbk,2|https,cbk3.google.com,/cbk,2|https,.cloudfront.net,,2|https,www.google-analytics.com,/,2|https,stats.g.doubleclick.net,,2|https,www.google.com,/ads/,2|https,ssl.google-analytics.com,,2|http,fonts.googleapis.com,,2||fonts.googleapis.com,,2');
+ database.connect().then(async e => {
+
+ //let paramPackData = util.data.decodeParamPack(req.headers["x-nintendo-parampack"]);
+ let pid = util.data.processServiceToken(req.headers["x-nintendo-servicetoken"]);
+
+ if(pid === null)
+ pid = 1000000000;
+ let user = await database.getUserByPID(pid);
+ res.render('ctr/notifications.ejs', {
+ moment: moment,
+ user: user,
+ });
+ user.notification_list.filter(noti => noti.read === false).forEach(function(notification) {
+ notification.read = true;
+ });
+ user.markModified('notification_list');
+ user.save();
+ }).catch(error => {
+ console.log(error);
+ res.set("Content-Type", "application/xml");
+ res.statusCode = 400;
+ response = {
+ result: {
+ has_error: 1,
+ version: 1,
+ code: 400,
+ error_code: 15,
+ message: "SERVER_ERROR"
+ }
+ };
+ res.send("\n" + xml(response));
+ });
+});
+
+module.exports = router;
diff --git a/src/services/juxt-web/routes/ctr/posts.js b/src/services/juxt-web/routes/ctr/posts.js
index ecf7bc3..eaf7a00 100644
--- a/src/services/juxt-web/routes/ctr/posts.js
+++ b/src/services/juxt-web/routes/ctr/posts.js
@@ -104,7 +104,7 @@ router.post('/new', upload.none(), async function (req, res, next) {
};
const newPost = new POST(document);
newPost.save();
- res.redirect('/communities/' + community.community_id);
+ res.redirect('/communities/' + community.community_id + '/new');
}
}
catch (e)
diff --git a/src/services/juxt-web/routes/ctr/userpage.js b/src/services/juxt-web/routes/ctr/userpage.js
index 6254325..6eb634c 100644
--- a/src/services/juxt-web/routes/ctr/userpage.js
+++ b/src/services/juxt-web/routes/ctr/userpage.js
@@ -89,7 +89,7 @@ router.get('/show', function (req, res) {
database.connect().then(async e => {
let user = await database.getUserByPID(userID);
let newPosts = await database.getPostsByUserID(user.pid);
- let numPosts = await database.getNumberPostsByUserID(user.pid);
+ let numPosts = await database.getNumberUserPostsByID(user.pid);
if(isAJAX) {
res.render('ctr/user_page_ajax.ejs', {
// EJS variable and server-side variable
diff --git a/src/services/juxt-web/routes/index.js b/src/services/juxt-web/routes/index.js
index 8206197..dccde16 100644
--- a/src/services/juxt-web/routes/index.js
+++ b/src/services/juxt-web/routes/index.js
@@ -12,6 +12,8 @@ module.exports = {
CTR_COMMUNITIES: require('./ctr/communities'),
CTR_USER: require('./ctr/userpage'),
CTR_POST: require('./ctr/posts'),
+ CTR_FEED: require('./ctr/feed'),
+ CTR_NEWS: require('./ctr/notifications'),
WEB_ADMIN: require('./admin/home'),
WEB_API: require('./admin/api'),
};
\ No newline at end of file
diff --git a/src/services/juxt-web/routes/portal/feed.js b/src/services/juxt-web/routes/portal/feed.js
index e6d20af..524a4d7 100644
--- a/src/services/juxt-web/routes/portal/feed.js
+++ b/src/services/juxt-web/routes/portal/feed.js
@@ -15,9 +15,13 @@ router.get('/', function (req, res) {
if(pid === null)
pid = 1000000000;
let user = await database.getUserByPID(pid);
+ let communityMap = await util.data.getCommunityHash();
+ let posts = await database.getNewsFeed(user, 3);
res.render('portal/feed.ejs', {
moment: moment,
user: user,
+ posts: posts,
+ communityMap: communityMap,
});
user.notification_list.filter(noti => noti.read === false).forEach(function(notification) {
notification.read = true;
@@ -41,4 +45,48 @@ router.get('/', function (req, res) {
});
});
+router.get('/loadposts', function (req, res) {
+ res.header('X-Nintendo-WhiteList','1|http,youtube.com,,2|https,youtube.com,,2|http,.youtube.com,,2|https,.youtube.com,,2|http,.ytimg.com,,2|https,.ytimg.com,,2|http,.googlevideo.com,,2|https,.googlevideo.com,,2|https,youtube.com,/embed/,6|https,youtube.com,/e/,6|https,youtube.com,/v/,6|https,www.youtube.com,/embed/,6|https,www.youtube.com,/e/,6|https,www.youtube.com,/v/,6|https,youtube.googleapis.com,/e/,6|https,youtube.googleapis.com,/v/,6|http,maps.googleapis.com,/maps/api/streetview,2|https,maps.googleapis.com,/maps/api/streetview,2|http,cbk0.google.com,/cbk,2|https,cbk0.google.com,/cbk,2|http,cbk1.google.com,/cbk,2|https,cbk1.google.com,/cbk,2|http,cbk2.google.com,/cbk,2|https,cbk2.google.com,/cbk,2|http,cbk3.google.com,/cbk,2|https,cbk3.google.com,/cbk,2|https,.cloudfront.net,,2|https,www.google-analytics.com,/,2|https,stats.g.doubleclick.net,,2|https,www.google.com,/ads/,2|https,ssl.google-analytics.com,,2|http,fonts.googleapis.com,,2|fonts.googleapis.com,,2|https,www.googletagmanager.com,,2');
+ database.connect().then(async e => {
+ let pid = util.data.processServiceToken(req.headers["x-nintendo-servicetoken"]);
+ let post = await database.getPostByID(req.query.postID);
+ if(pid === null)
+ pid = 1000000000;
+ let user = await database.getUserByPID(pid);
+ let communityMap = await util.data.getCommunityHash();
+ let posts;
+ if(post !== null)
+ posts = await database.getNewsFeedAfterTimestamp(user, 3, post);
+
+ if(posts.length > 0)
+ {
+ res.render('portal/more_posts.ejs', {
+ communityMap: communityMap,
+ moment: moment,
+ database: database,
+ user: user,
+ newPosts: posts,
+ });
+ }
+ else
+ {
+ res.sendStatus(204);
+ }
+ }).catch(error => {
+ console.log(error);
+ res.set("Content-Type", "application/xml");
+ res.statusCode = 400;
+ response = {
+ result: {
+ has_error: 1,
+ version: 1,
+ code: 400,
+ error_code: 15,
+ message: "SERVER_ERROR"
+ }
+ };
+ res.send("\n" + xml(response));
+ });
+});
+
module.exports = router;
diff --git a/src/services/juxt-web/routes/portal/posts.js b/src/services/juxt-web/routes/portal/posts.js
index ecf7bc3..eaf7a00 100644
--- a/src/services/juxt-web/routes/portal/posts.js
+++ b/src/services/juxt-web/routes/portal/posts.js
@@ -104,7 +104,7 @@ router.post('/new', upload.none(), async function (req, res, next) {
};
const newPost = new POST(document);
newPost.save();
- res.redirect('/communities/' + community.community_id);
+ res.redirect('/communities/' + community.community_id + '/new');
}
}
catch (e)
diff --git a/src/webfiles/ctr/all_communities.ejs b/src/webfiles/ctr/all_communities.ejs
new file mode 100644
index 0000000..3415261
--- /dev/null
+++ b/src/webfiles/ctr/all_communities.ejs
@@ -0,0 +1,60 @@
+
+
+
+
+ 3DS Testing
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ <% for(var i = 0; i < communities.length; i++) {%>
+ <% if(i === communities.length - 1) { %>
+
+
+
+
+
+ <% } else { %>
+
+
+
+
+
+ <% }} %>
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/webfiles/ctr/communities.ejs b/src/webfiles/ctr/communities.ejs
index c3c7b48..f945eac 100644
--- a/src/webfiles/ctr/communities.ejs
+++ b/src/webfiles/ctr/communities.ejs
@@ -25,6 +25,9 @@
+
<% for(var i = 0; i < popularCommunities.length; i++) {%>
diff --git a/src/webfiles/ctr/community.ejs b/src/webfiles/ctr/community.ejs
index e218ac8..3f8a458 100644
--- a/src/webfiles/ctr/community.ejs
+++ b/src/webfiles/ctr/community.ejs
@@ -12,13 +12,110 @@
style="background: url('<%=community.CTR_browser_header%>')"<%}%>>