Skip to content

Commit

Permalink
send email on invitation. Facebook/Twitter support.
Browse files Browse the repository at this point in the history
  • Loading branch information
gschmidt committed Oct 16, 2012
1 parent f119348 commit 5b32931
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 15 deletions.
3 changes: 3 additions & 0 deletions examples/parties/.meteor/packages
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ accounts-ui
accounts-password
d3
bootstrap
email
accounts-facebook
accounts-twitter
16 changes: 7 additions & 9 deletions examples/parties/client/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand All @@ -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) {
Expand Down Expand Up @@ -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);
};
34 changes: 32 additions & 2 deletions examples/parties/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions examples/parties/parties.html
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ <h3>Invite people</h3>
{{#each uninvited}}
<div class="invite-row">
<a href="#" class="btn invite">Invite</a>
{{email}}
{{displayName}}
</div>
{{else}}
Everyone on the site has been invited.
Expand Down Expand Up @@ -180,7 +180,7 @@ <h1 class="muted pagination-centered">

{{#each rsvps}}
<div>
{{rsvpEmail}}
{{rsvpName}}
{{#if rsvpIs "yes"}}
<span class="label label-success pull-right">Going</span>
{{/if}}
Expand All @@ -196,7 +196,7 @@ <h1 class="muted pagination-centered">
{{#unless public}}
{{#each outstandingInvitations}}
<div>
{{invitationEmail}}
{{invitationName}}
<span class="label label-inverse pull-right">Invited</span>
</div>
{{/each}}
Expand Down
2 changes: 1 addition & 1 deletion examples/parties/server/server.js
Original file line number Diff line number Diff line change
@@ -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 () {
Expand Down

0 comments on commit 5b32931

Please sign in to comment.