Skip to content

Commit

Permalink
Clean a bit of code. Start working on displaying conversation
Browse files Browse the repository at this point in the history
  • Loading branch information
eprochasson committed Jul 12, 2013
1 parent 280e388 commit abcaf05
Show file tree
Hide file tree
Showing 17 changed files with 373 additions and 93 deletions.
4 changes: 3 additions & 1 deletion .meteor/packages
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# 'meteor add' and 'meteor remove' will edit this file for you,
# but you can also edit it by hand.

insecure
preserve-inputs
accounts-ui-bootstrap-dropdown
bootstrap
Expand All @@ -18,3 +17,6 @@ collectionFS
imagemagick
loadpicker
page-js-ie-support
spin
publish-with-relations
paginated-subscription
7 changes: 5 additions & 2 deletions TODO
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ Make sure logout users are redirected to the front page, always.

Browse users
Setting page
Add a messaging system

Activities: what did one do, what can of activity can the others see.

Check user security: do not allow user to change all their profile.
Check user security: do not allow user to change all their profile.


myFriends and myOnlineFriends are redundant. Add pagination to myFriends, for the page that lists all friends.

1 change: 0 additions & 1 deletion client/helpers/presence.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ var presenceTick;
Meteor.startup(function(){
// update presences every interval
presenceTick = Meteor.setInterval(function() {
console.log('tick');
Meteor.Presence.update();
}, Presence.checkInterval || 1000);
});
Expand Down
7 changes: 7 additions & 0 deletions client/helpers/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ Meteor.Router.add({
},
'/mailbox/compose': 'compose',
'/mailbox': 'mailbox',
'/mailbox/:_id':{
as: 'conversation',
to: 'conversation',
and: function(id){
Session.set('currentConversation', id);
}
},
'/settings': 'settings',
'/profile': {
as: 'profile',
Expand Down
11 changes: 9 additions & 2 deletions client/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,16 @@ Meteor.subscribe('myPictures');
Meteor.subscribe('myOnlineFriends');

// The list of my friends.
Meteor.subscribe('myFriends');
Meteor.subscribe('myFriendList');

// My conversations
Meteor.subscribe('myConversations');
conversationsHandle = Meteor.subscribeWithPagination('myConversations', 3);

var currentConversation = function(){
return Session.get('currentConversation') || null;
};

oneConversationHandle = Meteor.subscribeWithPagination('oneConversation', currentConversation, 4);

// When visiting someone's profile
Deps.autorun(function () {
Expand All @@ -23,3 +28,5 @@ Deps.autorun(function () {

// Questions for the profile form.
Meteor.subscribe('questions');

Meteor.subscribe('showFuckingEveryone');
3 changes: 3 additions & 0 deletions client/views/includes/loading.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<template name="loading">
{{> spinner}}
</template>
9 changes: 9 additions & 0 deletions client/views/mailbox/conversation.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<template name="conversation">

yoyo
<ul>
{{#each messages}}
<li>To:{{to}}, From:{{from}}</li>
{{/each}}
</ul>
</template>
7 changes: 7 additions & 0 deletions client/views/mailbox/conversation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Template.conversation.helpers({
messages: function(){
console.log('message');

return Messages.find({}, {sort: {timestamp: -1}});
}
});
12 changes: 10 additions & 2 deletions client/views/mailbox/mailbox.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
<template name="mailbox">

<a href="{{composePath}}">Compose a new message</a>
<a href="{{composePath}}">Compose a new message</a>

<ul>
{{#each conversations}}
<li>{{lastMessage}} with {{userInfo}}</li>
<li><a href="{{conversationPath _id}}">{{lastMessage}} with {{userInfo.profile.name}} {{#if isMyFriend}}Yes{{else}}No{{/if}}</li>
{{/each}}
{{#if conversationReady}}
{{#unless allConversationsLoaded}}
<a class="load-more" href="#">Load more</a>
{{/unless}}
{{else}}
{{>spinner}}
{{/if}}

</ul>

</template>
21 changes: 19 additions & 2 deletions client/views/mailbox/mailbox.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,25 @@
Template.mailbox.helpers({
conversations: function(){
return Conversations.find({owner: Meteor.userId()});
return Conversations.find({owner: Meteor.userId()},{limit: conversationsHandle.limit()});
},
conversationReady: function(){
return ! conversationsHandle.loading();
},
allConversationsLoaded: function(){
return !conversationsHandle.loading() &&
Conversations.find({owner: Meteor.userId()}).count() < conversationsHandle.loaded()
},
userInfo: function(){
return this.with;
return Meteor.users.findOne(this.with);
},
isMyFriend: function(){
return _.contains(Meteor.user().friends, this.with);
}
});

Template.mailbox.events({
'click .load-more': function(e){
e.preventDefault();
conversationsHandle.loadNextPage();
}
});
2 changes: 1 addition & 1 deletion client/views/widgets/online_friends.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
</template>

<template name="online_friend">
<li><img src="{{picture.thumbnail50x50}}" /><a href="{{profilePath}}/{{_id}}">{{profile.name}}</a> is online (<a class="startChat" href="#">chat</a>)</a></li>
<li><img src="{{profile.picture.thumbnail50x50}}" /><a href="{{profilePath}}/{{_id}}">{{profile.name}}</a> is online (<a class="startChat" href="#">chat</a>)</a></li>
</template>
5 changes: 2 additions & 3 deletions client/views/widgets/online_friends.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
Template.online_friends.helpers({
friends: function(){
var friends = Meteor.user().friends || [];
return Meteor.users.find({'profile.online': 1, visible: 1, _id: {$in: friends}});
return Meteor.users.find({'profile.online': 1, _id: {$in: friends}});
},
count: function(){
// console.log(Meteor.user());
var friends = Meteor.user().friends || [];
return Meteor.users.find({'profile.online': 1, visible: 1, _id: {$in: friends}}).count();
return Meteor.users.find({'profile.online': 1, _id: {$in: friends}}).count();
}
});
29 changes: 27 additions & 2 deletions main.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,39 @@ if(Meteor.isClient){
filePickerKey = "Av2HCAqJSM2aHdX5yKTZtz";
}

/*
Users
*/
// What fields are public for everyone
Meteor.user.publicProfileInformation = {
// show selected information
'profile.name' : 1,
'profile.dob': 1,
'profile.gender': 1,
'profile.online': 1,
'profile.picture': 1
};
// What fields are reserved for friends only
Meteor.user.privateProfileInformation = {
'profile': 1 // show all profile
};

// What field I can see about myself
Meteor.user.myProfileInformation = {
// show more information
'profile': 1,
'friends': 1,
'settings': 1
};


/*
Messages
*/
// Duration to measure velocity (default 2 minutes).
//Messages.velocityCaliber = 60*1000*2;
Messages.velocityCaliber = 30*1000;
// If target user is online, how many messages per velocityCaliber millisecond can the emitter send
Messages.onlineMaxVelocity = 5;
Messages.onlineMaxVelocity = 15;
// If target is offline
Messages.offlineMaxVelocity = 5;
// Cooldown penalty (def: 1 minute)
Expand Down
Loading

0 comments on commit abcaf05

Please sign in to comment.