Skip to content

Commit

Permalink
Some documentation. Fix the "friend list" widget thingy.
Browse files Browse the repository at this point in the history
  • Loading branch information
eprochasson committed Jul 24, 2013
1 parent 9843b36 commit 88afdf1
Show file tree
Hide file tree
Showing 12 changed files with 176 additions and 12 deletions.
147 changes: 147 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,153 @@ There is a lot left to do and little time. Among the list:
- Some design. Current one is pretty minimalist. The UI in general is pretty much only what [Boostrap](https://github.com/twitter/bootstrap) offers.
- Security might not be horrible, but it is certainly not good. User input are validated but not sanitized at the moment.

## API

API is a big word, but here are a few of the useful helpers/methods implemented in Socialite.

### Publications

#### myData

The current user data: full profile, settings and if the profile is completed (to be able to display the profile creation flow otherwise).

On-ready, sets the `settings` and `profileComplete` Session variable. to indicate that 1. the profile is loaded and allow for easy access of those information.

#### myPictures

All the current user Photos.

#### myNotification

Notification for the current user, with potential related users (if the notification is "friend request from A", we also publish a light version of A's information, to display with the notification.

#### myFriendlist

All my friends (from Friends) and the related users information (Meteor.users.

#### myNews

Information happening to me and my interactions with other users (from Activities).

#### myConversations

The list of my current conversations with people, friend or not (from Conversations) and their info (from Meteor.users).

#### questions

The list of questions.

#### oneConversation

Depends on the Session variable `currentConversation`. Get some of the messages (from Messages) for a given conversation.

#### userProfile

Depends on the Session variable `currentUserProfile` (set when visiting a user profile). Publish user information from Meteor.users.

#### oneUserPicture

Publish pictures (from Photos) for the user set in `currentUserProfile`. TODO: merge with `userProfile`.

#### oneUserActivities

Publish activities for a given user (from `currentUserProfile`). TODO: merge with `userProfile`.

#### searchResults

Publish a list of users (from Meteor.users) matching a search query. On-ready, set the `searchQueryDone` Session variable, for client side update of the template.
Publish related Presences objects to know the online status of users in the search results.

### Collections

Not really API stuff, but help to understand the architecture of the app.

#### Meteor.users

The default Meteor.users collection, with nit much change. The profile information are stored in the `profile` field of a user document.

#### Activities

Register the things happening to the users. Some are public (this can be tuned in the config file), some are for logging purpose only. The public activities are used to generate a user newsfeed.

Activities are meant to be updates on the server side through different user action on the site.

#### Comments

Meant to attach comment to different objects (Photos, ...). Implemented by not plugged to anything at the moment.

#### Conversations

Register who's talking to who, useful to list all the conversation for a given user (the mailbox). Denormalize the last message of the conversation, the last time something happened and if the current conversation has been read or not.

A conversation belong to one user and indicates the other participant. Hence, a conversation with A and B has two documents, one for A to B, and one for B to A. This allow for easy retrieving of one user's live conversations.

#### Messages

Register messages users send to each other. Each message is associated to both A to B and B to A conversation.

#### Friends

Register the asymetric relation between users. If A and B are friends, we record a relation from A to B and B to A. If A or B breaks the relationship, both relation are destroyed. If A sends a friend request to B, only the A to B relation is created. If B confirms, the relation B to A is added, and both relations are marked as "reciprocal". Only reciprocal relations are published.
Also denormalize the online status of users to their friends. When A is connected, it broadcast its online status to all its friend in the associated Friends document.

#### Notifications

Stuff that are to be shown in the navbar. Notifications include things like friend request, friend request confirmation. And that's basically it for now.

#### Photos

Pictures user can upload. The Photos collection is based on filepicker. A previous version (Pictures) used CollectionFS to store the picture locally. Store the url of a picture and the owner.

#### Presences

Record user presence, last time they were seen, if they are online and the time they spent on the site.

#### Questions

Stores the questions to be retrieve to create the form for the users. Questions define their template (how to render them), their type, their name (to associate the question and the field in a user profile) their validation (typically, what kind of options are available in a dropdown) and can easily be extended (check servers/helpers/forms.js).

Questions can be presented to a user using the general helper `make_question(name)`, name being the unique name of a question. When user submit a form containing a question, the validation associated with it is used.

### Methods

#### update_profile(values)

Updates the current user profile. It can only apply to the profile of the user calling it. `values` contains an Object where the keys are a Question id. This guarantee that a user can only add/update information of his profile from a predefined Question in the database. This method also validate the value according to the validation embedded with the Question.

A few values have special processing:
- the `location` field is used to create a mongo 2d index value (for proximity-based search)
- the `dob` (date of birth) field is copied in the `dobtime` field as a Unix timestamp for easier manipulation later on.

#### denormalizeProfilePicture(picture)

Set `profile.picture` to point to the url of the Photos document whose _id is `picture`. Basically tell that this picture is the user's current profile picture.

#### profile_completed()

Check that a user profile is complete. This can be tuned in the `main.config.js` file, variable `Meteor.profileCreation.requiredFieldForCompletion`. Check that all the fields are defined. If yes, sets the `profile_complete` and `visible` field of the current user to 1. The user is now visible to other user and can be searched for by other users.

#### sendComment

Unused.

#### validateInput(value, docid, validations)

Allow for client side validation of form input, using the Questions validation.

#### addAsFriend

#### removeFriend

#### sendMessage

#### uploadPhoto

#### setUserPresence

#### setInvisible


## License stuff

This project is licensed with the MIT license.
Expand Down
1 change: 1 addition & 0 deletions TODO
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ Profile picture update field allow empty images. Also, show the image uploaded,
Profile edition.
Add possibility to comment on activity.
Add a friendlist page.
Put user Profile and user Picture together
1 change: 0 additions & 1 deletion client/helpers/router.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// 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);
Expand Down
3 changes: 1 addition & 2 deletions client/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Meteor.startup(function(){
myNewsFeedHandle = Meteor.subscribeWithPagination('myNewsfeed', Newsfeed.activitiesPerPage);

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

// Questions for the profile form.
Meteor.subscribe('questions');
Expand Down Expand Up @@ -44,7 +44,6 @@ Meteor.startup(function(){
if(Session.get("searchQuery")){
searchHandle = Meteor.subscribe("searchResults", Session.get("searchQuery"), Meteor.users.searchResultsLimit, function(){
Session.set('searchQueryDone', Session.get('searchQuery'));
console.log('updating publication searchResults');
});
}
});
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 @@ -6,7 +6,10 @@
<div class="span3 pull-right">
{{> online_friends}}

<h2>Your friends</h2>
<div class="friends widget">
{{> friends}}
</div>
</div>


Expand Down
4 changes: 4 additions & 0 deletions client/views/profile/profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ <h1>{{profile.name}}</h1>
</tbody>
</table>
</div>
<h2>{{profile.name}}'s friends</h2>
<div class="friends">
{{> friends}}
</div>
</div>

{{> modal_picture}}
Expand Down
3 changes: 0 additions & 3 deletions client/views/widgets/friends/friends.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
<template name="friends">
<div class="friends widget">
<h2>Your friends</h2>
<ul>
{{#each friends}}
{{> one_friend}}
{{/each}}
</ul>
</div>
</template>

<template name="one_friend">
Expand Down
3 changes: 1 addition & 2 deletions client/views/widgets/friends/friends.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@ Template.friends.helpers({
if(!id){
return [];
}
return Friends.find({me: id, reciprocal: 1});
return Friends.find({me: id});
}
});

Template.one_friend.helpers({

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

Conversations._ensureIndex({with: 1, owner: 1}, {unique: 1});
if(Meteor.isServer){
Conversations._ensureIndex({with: 1, owner: 1}, {unique: 1});
}
4 changes: 3 additions & 1 deletion lib/collections/friends.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ Friends.deny({
insert: function(){return true}
});

Friends._ensureIndex({me:1,target:1}, {unique: true});
if(Meteor.isServer){
Friends._ensureIndex({me:1,target:1}, {unique: true});
}
Empty file removed server/config.js
Empty file.
15 changes: 13 additions & 2 deletions server/publications.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Meteor.publish("myConversations", function(limit) {
mappings: [{ // Publish people sending message as well, as they might not be in your friendlist.
key: 'with',
collection: Meteor.users,
options: {fields: Meteor.user.publicProfileInformation}
options: {fields: Meteor.users.publicProfileInformation}
}]
});
});
Expand Down Expand Up @@ -91,7 +91,7 @@ Meteor.publish("oneConversation", function(conversation, limit){
mappings: [{ // Publish people sending message as well, as they might not be in your friendlist.
key: 'from',
collection: Meteor.users,
options: {fields: Meteor.user.publicProfileInformation}
options: {fields: Meteor.users.publicProfileInformation}
}]
})
}
Expand Down Expand Up @@ -136,6 +136,17 @@ Meteor.publish("userProfile", function(targetId){
collection: Presences,
filter: { invisible: {$ne : 1} },
options: {fields: {'user':1, 'online':1}}
},{
key: 'me',
reverse: true,
collection: Friends,
filter: {reciprocal: 1, live: 1},
options: {fields: {me: 1, target: 1}},
mappings: [{
key: 'me',
collection: Meteor.users,
options: {fields: Meteor.users.publicProfileInformation}
}]
}]
});
}
Expand Down

0 comments on commit 88afdf1

Please sign in to comment.