-
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.
Revamp friendship. Need to find a way to make the list of online frie…
…nd reactive.
- Loading branch information
1 parent
ac1d4a3
commit 10bff07
Showing
9 changed files
with
120 additions
and
14 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
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
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,2 +1,8 @@ | ||
// Activities between users | ||
Activities = new Meteor.Collection('activities'); | ||
Activities = new Meteor.Collection('activities'); | ||
|
||
Activities.deny({ | ||
update: function(){return true}, | ||
remove: function(){return true}, | ||
insert: function(){return true} | ||
}); |
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,7 @@ | ||
Friends = new Meteor.Collection('friends'); | ||
|
||
Friends.deny({ | ||
update: function(){return true}, | ||
remove: function(){return true}, | ||
insert: function(){return true} | ||
}); |
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,3 @@ | ||
Activities.sendFriendRequest = function(target){ | ||
|
||
}; |
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,50 @@ | ||
Meteor.methods({ | ||
addAsFriend: function(target){ | ||
target = Meteor.users.findOne(target); | ||
if(!target){ | ||
throw new Meteor.Error(404, 'Person not found'); | ||
} | ||
if(_.contains(target.blacklist, this.userId)){ | ||
throw new Meteor.Error(300, 'Blocked'); | ||
} | ||
|
||
var id; | ||
if(id = Friends.findOne({me: this.userId, target: target._id})){ | ||
// Already friend. | ||
return id; | ||
} | ||
|
||
var fields = { | ||
me: this.userId, // That's me | ||
target: target._id, // That's the person I'm becoming friend with. | ||
live: 1, // Link is alive. | ||
reciprocal: 0, // Connection goes both way | ||
timestamp: new Date().getTime() | ||
}; | ||
|
||
// Answering a friend request. | ||
if(Friends.findOne({me: target._id, target: this.userId, live: 1})){ | ||
fields.reciprocal = 1; | ||
Friends.update({me: target._id, target: this.userId}, {$set: {reciprocal: 1}}); | ||
} | ||
|
||
id = Friends.insert(fields); | ||
|
||
return Activities.sendFriendRequest(this.userId, target._id) && id; | ||
}, | ||
removeFriend: function(target){ | ||
// Just kill the link, keep the connection. | ||
target = Meteor.users.findOne(target); | ||
if(!target){ | ||
throw new Meteor.Error(404, 'Person not found'); | ||
} | ||
|
||
Friends.remove({target: target._id, me: this.userId}); | ||
Friends.remove({me: target._id, target: this.userId}); | ||
|
||
// Friends.update({target: target._id, me: this.userId}, {$set: {live: 0, reciprocal: 0}}); | ||
// Friends.update({me: target._id, target: this.userId}, {$set: {live: 0, reciprocal: 0}}); | ||
|
||
return true; | ||
} | ||
}); |
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