Skip to content

Commit

Permalink
Moved user presence to an extra collection. Fix Invisible mode. Show …
Browse files Browse the repository at this point in the history
…conversation
  • Loading branch information
eprochasson committed Jul 12, 2013
1 parent abcaf05 commit ac1d4a3
Show file tree
Hide file tree
Showing 11 changed files with 168 additions and 97 deletions.
9 changes: 2 additions & 7 deletions TODO
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
Make sure logout users are redirected to the front page, always.

Browse users
Setting page

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.


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

myFriends and myOnlineFriends are redundant.
Move images to S3.
11 changes: 2 additions & 9 deletions client/helpers/presence.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Meteor.startup(function(){
// update presences every interval
presenceTick = Meteor.setInterval(function() {
Meteor.Presence.update();
}, Presence.checkInterval || 1000);
}, Presences.checkInterval || 1000);
});

Meteor.Presence = {
Expand All @@ -18,14 +18,7 @@ Meteor.Presence = {
Meteor.autorun(function(){
Session.get('last-presence-at'); // Just to hit the context.

var settings = Session.get('settings')||{};
var invisible = settings.invisible;
if(invisible == undefined){
// Default to true, to avoid "blinking" on other clients
// (otherwise, invisible users get set online for a short time, before being updated to invisible)
invisible = true;
}
Meteor.call('setUserPresence', invisible, function(err,res){
Meteor.call('setUserPresence', function(err,res){
if(err){
console.log('setUserPresence: huho');
}
Expand Down
4 changes: 4 additions & 0 deletions client/lexicon/lexicon.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,7 @@ Meteor.i18nMessages.question = {
dob: 'Date of Birth',
dob_help: 'Select your date of birth'
};

Meteor.i18nMessages.messages = {
you: 'you'
};
49 changes: 25 additions & 24 deletions client/main.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,33 @@
// All my data
Meteor.subscribe('myData', function(){
Session.set('settings', Meteor.user().settings||{});
});
// My own picture.
Meteor.subscribe('myPictures');
Meteor.startup(function(){
// All my data
Meteor.subscribe('myData', function(){
Session.set('settings', Meteor.user().settings||{});
});
// My own picture.
Meteor.subscribe('myPictures');

// Online friends widget.
Meteor.subscribe('myOnlineFriends');
// Online friends widget.
Meteor.subscribe('myOnlineFriends');

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

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

var currentConversation = function(){
return Session.get('currentConversation') || null;
};
oneConversationHandle = Meteor.subscribeWithPagination('oneConversation', function(){
return Session.get('currentConversation') || null;
}, Messages.messagePerPage);

oneConversationHandle = Meteor.subscribeWithPagination('oneConversation', currentConversation, 4);
// When visiting someone's profile
Deps.autorun(function () {
userProfileHandle = Meteor.subscribe("oneUserProfile", Session.get("currentUserProfile"));
userPictureHandle = Meteor.subscribe("oneUserPictures", Session.get("currentUserProfile"));
});

// When visiting someone's profile
Deps.autorun(function () {
userProfileHandle = Meteor.subscribe("oneUserProfile", Session.get("currentUserProfile"));
userPictureHandle = Meteor.subscribe("oneUserPictures", Session.get("currentUserProfile"));
});
// Questions for the profile form.
Meteor.subscribe('questions');

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

Meteor.subscribe('showFuckingEveryone');
});
19 changes: 13 additions & 6 deletions client/views/mailbox/conversation.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
<template name="conversation">

yoyo
<ul>
{{#each messages}}
<li>To:{{to}}, From:{{from}}</li>
{{/each}}
</ul>
<ul>
{{#each messages}}
{{> message}}
{{/each}}
</ul>

</template>

<template name="message">
<li>
<p>From:{{sender}}. to:{{receiver}}, {{timestamp}}</p>
<p>{{body}}</p>
</li>
</template>
28 changes: 26 additions & 2 deletions client/views/mailbox/conversation.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,31 @@
Template.conversation.helpers({
messages: function(){
console.log('message');
//
var conversation = Conversations.findOne(Session.get('currentConversation'));
if(!conversation){
return;
}

return Messages.find({}, {sort: {timestamp: -1}});
return Messages.find(
{
$or: [
{from: Meteor.userId(), to: conversation.with},
{to: Meteor.userId(), from: conversation.with}
]
},
{sort: {sent: -1}}
);
}
});
Template.message.helpers({
timestamp: function(){
return moment(this.sent).fromNow();
},
sender: function(){
console.log(this);
return this.from == Meteor.userId()? __('messages.you') : Meteor.users.findOne(this.from)['profile'].name;
},
receiver: function(){
return this.to == Meteor.userId()? __('messages.you') : Meteor.users.findOne(this.to)['profile'].name;
}
});
13 changes: 9 additions & 4 deletions client/views/widgets/online_friends.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
Template.online_friends.helpers({
friends: function(){
var friends = Meteor.user().friends || [];
return Meteor.users.find({'profile.online': 1, _id: {$in: friends}});
var friends = Presences.find({});
var ids = [];
friends.forEach(function(f){
ids.push(f.user);
});

return Meteor.users.find({_id: {$in: ids}}, {sort:{'profile.name': 1}});
},
count: function(){
var friends = Meteor.user().friends || [];
return Meteor.users.find({'profile.online': 1, _id: {$in: friends}}).count();
// Presence subscription only show online users...
return Presences.find({}).count() + 1;
}
});
9 changes: 9 additions & 0 deletions lib/collections/presences.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Presences = new Meteor.Collection('presences');


// Can't touch me
Presences.deny({
insert: function(){ return true; },
update: function(){ return true; },
remove: function(){ return true; }
});
18 changes: 9 additions & 9 deletions main.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ if(Meteor.isClient){
filePickerKey = "Av2HCAqJSM2aHdX5yKTZtz";
}


/*
Users
Users configuration
*/
// What fields are public for everyone
Meteor.user.publicProfileInformation = {
Expand All @@ -29,15 +30,13 @@ Meteor.user.privateProfileInformation = {

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


/*
Messages
Messages configuration
*/
// Duration to measure velocity (default 2 minutes).
Messages.velocityCaliber = 30*1000;
Expand All @@ -47,9 +46,11 @@ Messages.onlineMaxVelocity = 15;
Messages.offlineMaxVelocity = 5;
// Cooldown penalty (def: 1 minute)
Messages.cooldownPenalty = 10*1000;
// How many messages to display per page.
Messages.messagePerPage = 2;

/*
User posted Pictures.
User posted Pictures configuration
*/
// Fields people can change
Pictures.authorizedFields = ['main'];
Expand All @@ -59,10 +60,9 @@ Pictures.maxFileSize = 1024*1024;
Pictures.maxFilePerUser = -1;

/*
Check user presence
Check user presence configuration
*/
Presence = {};
// How often do we update presence (ms)
Presence.checkInterval = 2000;
Presences.checkInterval = 2000;
// How long before a user is considered out (ms).
Presence.TimeOut = 10000;
Presences.TimeOut = 10000;
26 changes: 20 additions & 6 deletions server/presence.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,29 @@

//Check user presence
Meteor.methods({
setUserPresence: function(invisible){
// We record user presence regardless of their online status.
return Meteor.users.update(Meteor.userId(), {$set: {lastseen: new Date().getTime(), 'profile.online': 0+!invisible, 'settings.invisible': invisible}});
setUserPresence: function(){
if(!Presences.findOne({user: Meteor.userId()})){
return Presences.insert({
user: Meteor.userId(),
lastseen: new Date().getTime(),
online: 1
})
} else {
return Presences.update(
{user: Meteor.userId()},
{$set: {lastseen: new Date().getTime(), 'online': 1}}
);
}
},
setInvisible: function(invisible){
return Presences.update({user: this.userId}, {$set: {invisible: Boolean(invisible)}}) &&
Meteor.users.findOne(this.userId, {$set: {'settings.invisible': Boolean(invisible)}});
}
});

Meteor.startup(function(){
// Update user not connected.
// Update user not connected.
Meteor.setInterval(function(){
Meteor.users.update({lastseen: {$lt:(new Date().getTime() - Presence.TimeOut)}}, {$set: {'profile.online': 0}});
}, Presence.checkInterval || 1000);
Presences.update({lastseen: {$lt:(new Date().getTime() - Presences.TimeOut)}}, {$set: {'online': 0}});
}, Presences.checkInterval || 1000);
});
Loading

0 comments on commit ac1d4a3

Please sign in to comment.