-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8184921
commit 3ff8f55
Showing
20 changed files
with
440 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,3 +17,4 @@ momentjs | |
collectionFS | ||
imagemagick | ||
loadpicker | ||
page-js-ie-support |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}) | ||
} | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// Activities between users | ||
Activities = new Meteor.Collection('activities'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// Questions for user profile. | ||
Questions = new Meteor.Collection('questions'); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.