Skip to content

Commit

Permalink
Add lot of stuff. Super broken
Browse files Browse the repository at this point in the history
  • Loading branch information
eprochasson committed Jul 11, 2013
1 parent 8184921 commit 3ff8f55
Show file tree
Hide file tree
Showing 20 changed files with 440 additions and 8 deletions.
1 change: 1 addition & 0 deletions .meteor/packages
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ momentjs
collectionFS
imagemagick
loadpicker
page-js-ie-support
4 changes: 3 additions & 1 deletion client/helpers/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ Meteor.Router.add({
}
}
},
'/mailbox/compose': 'compose',
'/mailbox': 'mailbox',
'/settings': 'settings',
'/profile': {
as: 'profile',
to: 'profile',
Expand All @@ -20,7 +23,6 @@ Meteor.Router.add({
to: 'profile',
and: function(id){ Session.set('currentUserProfile', id);}
},
'/settings': 'settings',
'*': 'p404'
});

Expand Down
14 changes: 13 additions & 1 deletion client/main.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
Meteor.subscribe('questions');
// 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');

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

// My conversations
Meteor.subscribe('myConversations');


// 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');
3 changes: 3 additions & 0 deletions client/views/includes/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
<li class="{{activeRouteClass 'settings'}}">
<a href="{{settingsPath}}">Settings</a>
</li>
<li class="{{activeRouteClass 'mailbox'}}">
<a href="{{mailboxPath}}"><i class="icon-envelope"></i></a>
</li>

</ul>
{{/if}}
Expand Down
16 changes: 16 additions & 0 deletions client/views/mailbox/compose/compose.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<template name="compose">

Compose new email
<form>
<select name="to">
<option value=""></option>
{{#each friendsList}}
<option value="{{_id}}" selected>{{profile.name}}</option>
{{/each}}
</select>
<textarea name="body" placeholder="Type your message here"> bla lakj d</textarea>

<button class="btn btn-submit">Send!</button>
</form>

</template>
21 changes: 21 additions & 0 deletions client/views/mailbox/compose/compose.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Template.compose.helpers({
friendsList: function(){
var me = Meteor.users.findOne(Meteor.userId());
return Meteor.users.find({_id : {$in : me.friends}}, {reactive: false});
}
});

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);
})
}
}
});
11 changes: 11 additions & 0 deletions client/views/mailbox/mailbox.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<template name="mailbox">

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

<ul>
{{#each conversations}}
<li>{{lastMessage}} with {{userInfo}}</li>
{{/each}}
</ul>

</template>
9 changes: 9 additions & 0 deletions client/views/mailbox/mailbox.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Template.mailbox.helpers({
conversations: function(){
return Conversations.find({owner: Meteor.userId()});
},
userInfo: function(){

return this.with;
}
});
2 changes: 2 additions & 0 deletions lib/collections/activities.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Activities between users
Activities = new Meteor.Collection('activities');
15 changes: 15 additions & 0 deletions lib/collections/conversations.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Conversations = new Meteor.Collection('conversations');

// Record who's talking with who, and the last message.
// All managed server side with message posting.
Conversations.allow({
insert: function(userId, doc){
return false;
},
update: function(userId, doc){
return false;
},
remove: function(){
return false;
}
});
38 changes: 38 additions & 0 deletions lib/collections/message.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
Messages = new Meteor.Collection('messages');

Messages.allow({
insert: function(userId, doc){
// Check that the message is emitted by userId
if(!(doc.from === userId)){
return false;
}

// Check that the emitter exists
var target ;
if(!(target = Meteor.user.findOne(doc.to))){
return false;
}
// Check that the emitter is not blacklisted to the receiver.
if(_.contains(target.blacklist, userId)){
return false;
}

// check that the message is not empty
if(doc.body.length == 0){
return false;
}

// All good. Let's go.
return true;
},
update: function(userId, fields){
return userId == fields.to; // Can only update message /received/
}
});

Messages.deny({
update: function(userId, fields){
// only field that can be updated is the 'viewed' field.
return (_.without(fields, 'viewed')).length > 0;
}
});
69 changes: 69 additions & 0 deletions lib/collections/pictures.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
Pictures = new CollectionFS('pictures', {autopublish: false});

var isValidImage = function(type){
return _.contains(['image/png','image/jpeg','image/gif'], type);
};

Pictures.allow({
insert: function(userId, myFile) {
var valid = true;
// Is a valid image
valid = valid && isValidImage(myFile.contentType);
// Is not too big.
valid = valid && myFile.length < (this.maxFileSize || 1024*1024);
// User quota is ok.
valid = valid && (!this.maxFilePerUser || (this.maxFilePerUser == -1) || Pictures.find({owner: userId}).count() < this.maxFilePerUser);
// User owns the file -- don't know how it could not, but that's in the doc.
valid = valid && userId && myFile.owner === userId;
return valid;
},
update: function(userId, file, fields, modifier) {
var valid = true, authorized = this.authorizedFields || [];
// Fields are authorized for modification
if(authorized){
valid = valid && _.every(fields, function(f){_.contains(authorized, f)});
}
// Check that user owns the image...
valid = valid && file.owner === userId;

return valid;
},
remove: function(userId, files) { return false; }
});

Pictures.fileHandlers({
save: function(options){
if (options.fileRecord.length > 5000000 || !isValidImage(options.fileRecord.contentType)){
return null;
}
return { blob: options.blob, fileRecord: options.fileRecord };
},
thumbnail50x50: function(options){
if (isValidImage(options.fileRecord.contentType)){
var destination = options.destination();
Imagemagick.resize({
srcData: options.blob,
dstPath: destination.serverFilename,
width: 50,
height: 50
});
return destination.fileData;
} else {
return null;
}
},
thumbnail150x150: function(options){
if (isValidImage(options.fileRecord.contentType)){
var destination = options.destination();
Imagemagick.resize({
srcData: options.blob,
dstPath: destination.serverFilename,
width: 150,
height: 150
});
return destination.fileData;
} else {
return null;
}
}
});
3 changes: 3 additions & 0 deletions lib/collections/questions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Questions for user profile.
Questions = new Meteor.Collection('questions');

12 changes: 12 additions & 0 deletions main.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,18 @@ if(Meteor.isClient){
filePickerKey = "Av2HCAqJSM2aHdX5yKTZtz";
}

/*
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;
// If target is offline
Messages.offlineMaxVelocity = 5;
// Cooldown penalty (def: 1 minute)
Messages.cooldownPenalty = 10*1000;

/*
User posted Pictures.
Expand Down
56 changes: 55 additions & 1 deletion server/fixtures.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,58 @@ if(Questions.find().count() == 0){
required: true
});
}

if(Meteor.users.find({}).count() <= 2){
Meteor.users.insert({
"createdAt": 1372216131137,
"emails": [
{
"address": "whatever",
"verified": false
}
],
"friends": [
"L7SLCm9mJyetnb3oD"
],
"invisible": false,
"lastseen": 1373524657763,
"online": 1,
"profile": {
"dob": "08-11-1982",
"gender": "Female",
"name": "Fake User 1",
"online": 0
},
"services": {
},
"settings": {
"invisible": false
},
"visible": 1
});
Meteor.users.insert({
"createdAt": 1372216131137,
"emails": [
{
"address": "whatever2",
"verified": false
}
],
"friends": [
"L7SLCm9mJyetnb3oD"
],
"invisible": false,
"lastseen": 1373524657763,
"online": 1,
"profile": {
"dob": "08-11-1992",
"gender": "Male",
"name": "Fake User 2",
"online": 0
},
"services": { },
"settings": {
"invisible": false
},
"visible": 1
});
}
Loading

0 comments on commit 3ff8f55

Please sign in to comment.