diff --git a/examples/parties/.meteor/packages b/examples/parties/.meteor/packages index 2fa7591d08..fae85f5ca5 100644 --- a/examples/parties/.meteor/packages +++ b/examples/parties/.meteor/packages @@ -8,3 +8,6 @@ accounts-ui accounts-password d3 bootstrap +email +accounts-facebook +accounts-twitter diff --git a/examples/parties/client/client.js b/examples/parties/client/client.js index 1537f290fb..214fdf6bd8 100644 --- a/examples/parties/client/client.js +++ b/examples/parties/client/client.js @@ -34,14 +34,12 @@ Template.details.creatorName = function () { var owner = Meteor.users.findOne(this.owner); if (owner._id === Meteor.userId()) return "me"; - // XXX this (not having 'emails' just be an array of string, for the - // common case) really kind of sucks - return owner.emails[0].address; + return displayName(owner); }; -Template.attendance.rsvpEmail = function () { +Template.attendance.rsvpName = function () { var user = Meteor.users.findOne(this.user); - return user.emails[0].address; + return displayName(user); }; Template.attendance.outstandingInvitations = function () { @@ -51,8 +49,8 @@ Template.attendance.outstandingInvitations = function () { return Meteor.users.find({_id: {$in: people}}); }; -Template.attendance.invitationEmail = function () { - return this.emails[0].address; +Template.attendance.invitationName = function () { + return displayName(this); }; Template.attendance.rsvpIs = function (what) { @@ -299,6 +297,6 @@ Template.inviteDialog.uninvited = function () { return Meteor.users.find({_id: {$nin: invited}}); }; -Template.inviteDialog.email = function () { - return this.emails[0].address; +Template.inviteDialog.displayName = function () { + return displayName(this); }; diff --git a/examples/parties/model.js b/examples/parties/model.js index 3e51d50093..1047b4ad10 100644 --- a/examples/parties/model.js +++ b/examples/parties/model.js @@ -21,7 +21,7 @@ Parties.allow({ } }); -var attending = function(party) { +var attending = function (party) { return _.reduce(party.rsvps, function (memo, rsvp) { if (rsvp.rsvp === 'yes') return memo + 1; @@ -38,6 +38,20 @@ Parties.deny({ } }); +var displayName = function (user) { + if (user.profile && user.profile.name) + return user.profile.name; + return user.emails[0].address; +}; + +var contactEmail = function (user) { + if (user.emails && user.emails.length) + return user.emails[0].address; + if (user.services.facebook && user.services.facebook.email) + return user.services.facebook.email; + return null; +}; + Meteor.methods({ // title, description, x, y, public // XXX limit a user to a certain number of parties @@ -78,8 +92,24 @@ Meteor.methods({ if (party.public) throw new Meteor.Error(400, "That party is public. No need to invite people."); - if (userId !== party.owner) + if (userId !== party.owner && ! _.contains(party.invited, userId)) { Parties.update(partyId, { $addToSet: { invited: userId } }); + + var from = contactEmail(Meteor.users.findOne(this.userId)); + var to = contactEmail(Meteor.users.findOne(userId)); + if (Meteor.isServer && to) { + Email.send({ + from: "noreply@example.com", + to: to, + replyTo: from || undefined, + subject: "PARTY: " + party.title, + text: +"Hey, I just invited you to '" + party.title + "' on All Tomorrow's Parties.\n" + +"\n" + +"Come check it out at: " + Meteor.absoluteUrl() + "\n" + }); + } + } }, rsvp: function (partyId, rsvp) { diff --git a/examples/parties/parties.html b/examples/parties/parties.html index a8544083a8..a78b07bcb4 100644 --- a/examples/parties/parties.html +++ b/examples/parties/parties.html @@ -101,7 +101,7 @@ {{#each uninvited}}
Invite - {{email}} + {{displayName}}
{{else}} Everyone on the site has been invited. @@ -180,7 +180,7 @@ {{#each rsvps}}
- {{rsvpEmail}} + {{rsvpName}} {{#if rsvpIs "yes"}} Going {{/if}} @@ -196,7 +196,7 @@ {{#unless public}} {{#each outstandingInvitations}}
- {{invitationEmail}} + {{invitationName}} Invited
{{/each}} diff --git a/examples/parties/server/server.js b/examples/parties/server/server.js index 23e0275238..6c61f68b78 100644 --- a/examples/parties/server/server.js +++ b/examples/parties/server/server.js @@ -1,7 +1,7 @@ // XXX autopublish warning is printed on each restart. super spammy! Meteor.publish("directory", function () { - return Meteor.users.find({}, {fields: {emails: 1}}); + return Meteor.users.find({}, {fields: {emails: 1, profile: 1}}); }); Meteor.publish("parties", function () {