Permalink
Browse files

Step 17.21: Update users publication to publish Facebook friends

  • Loading branch information...
darkbasic committed Jun 11, 2017
1 parent cf0262e commit e81cef1af3caef4f36a58870f90c6bf3b9623c16
Showing with 13 additions and 0 deletions.
  1. +13 −0 api/server/publications.ts
View
@@ -3,6 +3,7 @@ import { Users } from './collections/users';
import { Messages } from './collections/messages';
import { Chats } from './collections/chats';
import { Pictures } from './collections/pictures';
import { facebookService } from "./services/facebook";
Meteor.publishComposite('users', function(
pattern: string,
@@ -14,18 +15,30 @@ Meteor.publishComposite('users', function(
let selector = {};
var facebookFriendsIds: string[] = [];
if (Users.collection.findOne({'_id': this.userId}).services.facebook) {
//FIXME: add definitions for the promise Meteor package
//TODO: handle error: token may be expired
const accessToken = (<any>Promise).await(facebookService.getAccessToken(this.userId));
//TODO: handle error: user may have denied permissions
const facebookFriends = (<any>Promise).await(facebookService.getFriends(accessToken));
facebookFriendsIds = facebookFriends.map((friend) => friend.id);
}
if (pattern) {
selector = {
'profile.name': { $regex: pattern, $options: 'i' },
$or: [
{'phone.number': {$in: contacts}},
{'services.facebook.id': {$in: facebookFriendsIds}},
{'profile.name': {$in: ['Ethan Gonzalez', 'Bryan Wallace', 'Avery Stewart', 'Katie Peterson', 'Ray Edwards']}}
]
};
} else {
selector = {
$or: [
{'phone.number': {$in: contacts}},
{'services.facebook.id': {$in: facebookFriendsIds}},
{'profile.name': {$in: ['Ethan Gonzalez', 'Bryan Wallace', 'Avery Stewart', 'Katie Peterson', 'Ray Edwards']}}
]
}

0 comments on commit e81cef1

Please sign in to comment.