Skip to content

Commit

Permalink
Add a friendlist widget. Tweak the session variable. Add indexes to c…
Browse files Browse the repository at this point in the history
…ollection. Code cleaning, a bit.
  • Loading branch information
eprochasson committed Jul 24, 2013
1 parent 8c5db53 commit 9843b36
Show file tree
Hide file tree
Showing 23 changed files with 150 additions and 114 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.idea/
main.config.js
main.config.js
.directory
4 changes: 3 additions & 1 deletion TODO
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Profile edition.
Add possibility to comment on activity.
Add a friendlist page.
25 changes: 0 additions & 25 deletions client/css/less/newsfeed.lessimport

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -12,6 +16,12 @@
ul li{
width: 100%;
}
margin-bottom: 5px;
}


.online-user{

ul li img{
height: 30px;
widht: 30px;
Expand All @@ -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;
}
}
3 changes: 1 addition & 2 deletions client/css/style.less
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
54 changes: 45 additions & 9 deletions client/helpers/router.js
Original file line number Diff line number Diff line change
@@ -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',
Expand All @@ -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'
});

Expand All @@ -55,4 +89,6 @@ Meteor.Router.filters({
}
});

Meteor.Router.filter('requireLogin', {except: 'front'});

Meteor.Router.filter('requireLogin', {except: 'front'});

23 changes: 14 additions & 9 deletions client/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(){
Expand Down
3 changes: 3 additions & 0 deletions client/views/home/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
</div>
<div class="span3 pull-right">
{{> online_friends}}

{{> friends}}
</div>


</template>
4 changes: 2 additions & 2 deletions client/views/includes/notifications/notifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ Template.notification.helpers({
});



Template.notification_friend_request.helpers({
user: function(){
return getUser(this.from)
Expand All @@ -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!');
}
});
Expand Down
16 changes: 0 additions & 16 deletions client/views/mailbox/compose/compose.html

This file was deleted.

29 changes: 0 additions & 29 deletions client/views/mailbox/compose/compose.js

This file was deleted.

2 changes: 1 addition & 1 deletion client/views/mailbox/conversation.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ <h2 class="conversation_title">Active conversations</h2>
{{> conversation_list}}
</div>
<div class="span9 conversation">
<h2 class="conversation_title">Conversation with {{conversationWith}}</h2>
<h2 class="conversation_title">Conversation with <a href="{{profilePath}}/{{conversationWith._id}}">{{conversationWith.profile.name}}</a></h2>
<div class="row-fluid">
<div class="span10">
<textarea name="message"></textarea>
Expand Down
4 changes: 2 additions & 2 deletions client/views/mailbox/conversation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

}
});

Expand Down
2 changes: 1 addition & 1 deletion client/views/profile/includes/modal_message.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template name="modal_message">
<div id="modalMessage" class="modal fade" role="dialog" aria-hidden="true">
<div id="modalMessage" class="modal hide fade" role="dialog" aria-hidden="true">
<div class="modal-header">
Send a message to {{profile.name}}
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
Expand Down
2 changes: 0 additions & 2 deletions client/views/search/includes/search_results.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ Template.searchResults.helpers({

Template.search_one_user.helpers({
userOnline: function(){
console.log(this);
var online = Presences.findOne({user: this._id});
console.log(online);
if(!online){
return 0;
}
Expand Down
Empty file removed client/views/search/search.js
Empty file.
20 changes: 20 additions & 0 deletions client/views/widgets/friends/friends.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<template name="friends">
<div class="friends widget">
<h2>Your friends</h2>
<ul>
{{#each friends}}
{{> one_friend}}
{{/each}}
</ul>
</div>
</template>

<template name="one_friend">
<li>
<a href="{{profilePath}}/{{user._id}}">
<img width="30" height="30" src="{{thumbnail user.profile.picture 30 30 'crop'}}" />
{{user.profile.name}}
{{#if online}}<i class="icon-circle pull-right"> </i>{{/if}}
</a>
</li>
</template>
19 changes: 19 additions & 0 deletions client/views/widgets/friends/friends.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Template.friends.helpers({
friends: function(){
var id = Meteor.userId();
if(Session.get('currentUserProfile')){
id = Session.get('currentUserProfile');
}
if(!id){
return [];
}
return Friends.find({me: id, reciprocal: 1});
}
});

Template.one_friend.helpers({

user: function(){
return Meteor.users.findOne(this.target);
}
});
4 changes: 3 additions & 1 deletion lib/collections/conversations.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ Conversations.allow({
remove: function(){
return false;
}
});
});

Conversations._ensureIndex({with: 1, owner: 1}, {unique: 1});
Loading

0 comments on commit 9843b36

Please sign in to comment.