From 9843b362d4c2bddaebc82a29e99656856e12f9a9 Mon Sep 17 00:00:00 2001 From: Emmanuel Prochasson Date: Wed, 24 Jul 2013 12:12:57 +0800 Subject: [PATCH] Add a friendlist widget. Tweak the session variable. Add indexes to collection. Code cleaning, a bit. --- .gitignore | 3 +- TODO | 4 +- client/css/less/newsfeed.lessimport | 25 --------- ...ine-user.lessimport => widgets.lessimport} | 27 +++++++--- client/css/style.less | 3 +- client/helpers/router.js | 54 +++++++++++++++---- client/main.js | 23 ++++---- client/views/home/home.html | 3 ++ .../includes/notifications/notifications.js | 4 +- client/views/mailbox/compose/compose.html | 16 ------ client/views/mailbox/compose/compose.js | 29 ---------- client/views/mailbox/conversation.html | 2 +- client/views/mailbox/conversation.js | 4 +- .../views/profile/includes/modal_message.html | 2 +- .../views/search/includes/search_results.js | 2 - client/views/search/search.js | 0 client/views/widgets/friends/friends.html | 20 +++++++ client/views/widgets/friends/friends.js | 19 +++++++ lib/collections/conversations.js | 4 +- lib/collections/friends.js | 4 +- server/friends.js | 3 +- server/presence.js | 12 +++-- server/publications.js | 1 + 23 files changed, 150 insertions(+), 114 deletions(-) delete mode 100644 client/css/less/newsfeed.lessimport rename client/css/less/{online-user.lessimport => widgets.lessimport} (82%) delete mode 100644 client/views/mailbox/compose/compose.html delete mode 100644 client/views/mailbox/compose/compose.js delete mode 100644 client/views/search/search.js create mode 100644 client/views/widgets/friends/friends.html create mode 100644 client/views/widgets/friends/friends.js diff --git a/.gitignore b/.gitignore index fce6837..76bf93c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .idea/ -main.config.js \ No newline at end of file +main.config.js +.directory \ No newline at end of file diff --git a/TODO b/TODO index 23c8464..7edfebe 100644 --- a/TODO +++ b/TODO @@ -5,4 +5,6 @@ Complete Lexicon... Email validation at subscription. Check input security (not too long, invalid characters, injection...). Profile picture update field allow empty images. Also, show the image uploaded, allow for image resize. Improve.. -Profile edition. \ No newline at end of file +Profile edition. +Add possibility to comment on activity. +Add a friendlist page. diff --git a/client/css/less/newsfeed.lessimport b/client/css/less/newsfeed.lessimport deleted file mode 100644 index 06aa33d..0000000 --- a/client/css/less/newsfeed.lessimport +++ /dev/null @@ -1,25 +0,0 @@ -.newsfeed{ - .border-radius(3px); - border: 1px @blueLessLight solid; - - ul { - margin-left: 0; - list-style: none; - border-top: 1px @blueLessLight solid; - border-bottom: 1px @blueLessLight solid; - } - ul li{ - width: 100%; - } - ul li img{ - height: 30px; - widht: 30px; - float: left; - margin-right:3px; - } - h2{ - font-size:1.1em; - line-height: normal; - text-align: center; - } -} diff --git a/client/css/less/online-user.lessimport b/client/css/less/widgets.lessimport similarity index 82% rename from client/css/less/online-user.lessimport rename to client/css/less/widgets.lessimport index 9e91bbc..2eec3ac 100644 --- a/client/css/less/online-user.lessimport +++ b/client/css/less/widgets.lessimport @@ -1,8 +1,12 @@ - -.online-user{ +.widget{ .border-radius(3px); border: 1px @blueLessLight solid; + h2{ + font-size:1.1em; + line-height: normal; + text-align: center; + } ul { margin-left: 0; list-style: none; @@ -12,6 +16,12 @@ ul li{ width: 100%; } + margin-bottom: 5px; +} + + +.online-user{ + ul li img{ height: 30px; widht: 30px; @@ -31,9 +41,14 @@ background: @blueLessLight; text-decoration: none; } - h2{ - font-size:1.1em; - line-height: normal; - text-align: center; +} + + +.newsfeed{ + ul li img{ + height: 30px; + widht: 30px; + float: left; + margin-right:3px; } } diff --git a/client/css/style.less b/client/css/style.less index 0d30e21..342c505 100644 --- a/client/css/style.less +++ b/client/css/style.less @@ -5,8 +5,7 @@ @import "/.meteor/meteorite/packages/bootstrap-themes/lib/themes/cerulean/cerulean.lessimport"; -@import "less/online-user.lessimport"; -@import "less/newsfeed.lessimport"; +@import "less/widgets.lessimport"; @import "less/map.lessimport"; @import "less/slider.lessimport"; @import "less/search.lessimport"; diff --git a/client/helpers/router.js b/client/helpers/router.js index 5b43012..9d3db92 100644 --- a/client/helpers/router.js +++ b/client/helpers/router.js @@ -1,3 +1,12 @@ +// Is there a better way to do that? +var resetSession = function(){ + console.log('resetting session'); + Session.set('currentConversation', null); + Session.set('currentUserProfile', null); + Session.set('currentQuery', null); + Session.set('searchQueryDone', null); +}; + Meteor.Router.add({ '/': { as: 'home', @@ -7,31 +16,56 @@ Meteor.Router.add({ } else{ return 'front' } - } + }, + and: resetSession + }, + '/mailbox': { + as:'mailbox', + to: function(){ + return 'mailbox'; + }, + and: resetSession }, - '/mailbox/compose': 'compose', - '/mailbox': 'mailbox', '/mailbox/:_id':{ as: 'conversation', to: 'conversation', and: function(id){ + resetSession(); Session.set('currentConversation', id); } }, - '/settings': 'settings', + '/settings': { + as:'settings', + to: 'setting', + and: resetSession + }, '/profile': { as: 'profile', to: 'profile', - and: function(){ Session.set('currentUserProfile', null)} + and: function(){ + resetSession(); + Session.set('currentUserProfile', null) + } }, '/profile/edit': 'editProfile', '/profile/:_id': { as: 'profile', to: 'profile', - and: function(id){ Session.set('currentUserProfile', id);} + and: function(id){ + resetSession(); + Session.set('currentUserProfile', id); + } + }, + '/profile_done': { + as: 'profile_done', + to: 'profile_done', + and: resetSession + }, + '/search': { + to: 'search', + as: 'search', + and: resetSession }, - '/profile_done': 'profile_done', - '/search': 'search', '*': 'p404' }); @@ -55,4 +89,6 @@ Meteor.Router.filters({ } }); -Meteor.Router.filter('requireLogin', {except: 'front'}); \ No newline at end of file + +Meteor.Router.filter('requireLogin', {except: 'front'}); + diff --git a/client/main.js b/client/main.js index b63456b..821974e 100644 --- a/client/main.js +++ b/client/main.js @@ -16,23 +16,28 @@ Meteor.startup(function(){ // My conversations conversationsHandle = Meteor.subscribeWithPagination('myConversations', 3); - oneConversationHandle = Meteor.subscribeWithPagination('oneConversation', function(){ - return Session.get('currentConversation') || null; - }, Messages.messagePerPage); - // Questions for the profile form. Meteor.subscribe('questions'); + } + }); + Deps.autorun(function(){ + if(Session.get('currentConversation')){ + oneConversationHandle = Meteor.subscribeWithPagination('oneConversation', function(){ + return Session.get('currentConversation') || null; + }, Messages.messagePerPage); } }); // When visiting someone's profile Deps.autorun(function () { - userProfileHandle = Meteor.subscribe("userProfile", Session.get("currentUserProfile")); - userPictureHandle = Meteor.subscribe("oneUserPictures", Session.get("currentUserProfile")); - userActivitiesHandle = Meteor.subscribeWithPagination("oneUserActivities", function(){ - return Session.get("currentUserProfile") || null; - }, Activities.activitiesPerPage); + if(Session.get('currentUserProfile')){ + userProfileHandle = Meteor.subscribe("userProfile", Session.get("currentUserProfile")); + userPictureHandle = Meteor.subscribe("oneUserPictures", Session.get("currentUserProfile")); + userActivitiesHandle = Meteor.subscribeWithPagination("oneUserActivities", Session.get("currentUserProfile"), function(){ + return Session.get("currentUserProfile") || null; + }, Activities.activitiesPerPage); + } }); Deps.autorun(function(){ diff --git a/client/views/home/home.html b/client/views/home/home.html index 7f42bdb..9149924 100644 --- a/client/views/home/home.html +++ b/client/views/home/home.html @@ -5,6 +5,9 @@
{{> online_friends}} + + {{> friends}}
+ \ No newline at end of file diff --git a/client/views/includes/notifications/notifications.js b/client/views/includes/notifications/notifications.js index 06c09b0..14fa4c1 100644 --- a/client/views/includes/notifications/notifications.js +++ b/client/views/includes/notifications/notifications.js @@ -45,7 +45,6 @@ Template.notification.helpers({ }); - Template.notification_friend_request.helpers({ user: function(){ return getUser(this.from) @@ -60,13 +59,14 @@ Template.notification_accepted_friend_request.helpers({ Template.notification_friend_request.events({ 'click button.accept': function(e){ e.preventDefault(); + var self = this; Meteor.call('addAsFriend', this.from, function(err,res){ if(err){ Errors.modal(err); } else { // Remove the notification. - Notifications.remove(this._id); + Notifications.remove(self._id); Errors.notification('Friend request confirmed!'); } }); diff --git a/client/views/mailbox/compose/compose.html b/client/views/mailbox/compose/compose.html deleted file mode 100644 index 6814d2c..0000000 --- a/client/views/mailbox/compose/compose.html +++ /dev/null @@ -1,16 +0,0 @@ - \ No newline at end of file diff --git a/client/views/mailbox/compose/compose.js b/client/views/mailbox/compose/compose.js deleted file mode 100644 index 084e231..0000000 --- a/client/views/mailbox/compose/compose.js +++ /dev/null @@ -1,29 +0,0 @@ -Template.compose.helpers({ - friendsList: function(){ - if(Meteor.user()){ - return Meteor.users.find({ _id: {$ne : Meteor.userId()}}, {reactive: false}); - } else { - return {}; - } - } -}); - -Template.compose.events({ - 'submit form': function(e){ - e.preventDefault(); - var values = { - to: $('select[name="to"]').val(), - body: $('textarea[name="body"]').val() - }; - if(values.to && values.body){ - Meteor.call('sendMessage', values, function(err, res){ - console.log(err, res); - if(err){ - Errors.modal(err); - } else { - Errors.notification({text: __('message.message_sent')}); - } - }) - } - } -}); \ No newline at end of file diff --git a/client/views/mailbox/conversation.html b/client/views/mailbox/conversation.html index cb96121..1b415da 100644 --- a/client/views/mailbox/conversation.html +++ b/client/views/mailbox/conversation.html @@ -6,7 +6,7 @@

Active conversations

{{> conversation_list}}
-

Conversation with {{conversationWith}}

+

Conversation with {{conversationWith.profile.name}}

diff --git a/client/views/mailbox/conversation.js b/client/views/mailbox/conversation.js index f445854..a4d4d1c 100644 --- a/client/views/mailbox/conversation.js +++ b/client/views/mailbox/conversation.js @@ -39,8 +39,8 @@ Template.conversation.helpers({ if(!conversation){ return ''; } - var user = Meteor.users.findOne(conversation.with); - return user.profile && user.profile.name; + return Meteor.users.findOne(conversation.with); + } }); diff --git a/client/views/profile/includes/modal_message.html b/client/views/profile/includes/modal_message.html index ffc264e..bc1e05e 100644 --- a/client/views/profile/includes/modal_message.html +++ b/client/views/profile/includes/modal_message.html @@ -1,5 +1,5 @@