invite actually working

This commit is contained in:
Seth Call 2020-04-04 17:51:36 -05:00
parent f4e4b4dd16
commit 0294761079
20 changed files with 174 additions and 45 deletions

View File

@ -389,4 +389,5 @@ onboarder_limit.sql
onboarding_emails.sql
limit_counter_reminders.sql
amazon_v2.sql
store_backend_details_rate_session.sql
store_backend_details_rate_session.sql
invited_user_receiver.sql

View File

@ -0,0 +1 @@
ALTER TABLE invited_users ADD COLUMN receiver_id VARCHAR(64) REFERENCES users(id);

View File

@ -43,7 +43,7 @@
run into trouble and need help, please reach out to us. We will be glad to do everything we can
to answer your questions and get you the help you need. You can visit our <a href="https://forum.jamkazam.com/showthread.php?tid=69" style="color:#fc0">Forum</a> to
to answer your questions and get you the help you need. You can visit our <a href="https://forum.jamkazam.com/showthread.php?tid=69" style="color:#fc0">helpful forums</a> to
find knowledge base articles and post questions that have not already been answered. You can

View File

@ -16,13 +16,18 @@ module JamRuby
validates :message, no_profanity: true
def to_s
return "#{self.id} => #{self.user.to_s}:#{self.friend.to_s}"
"#{self.id} => #{self.user.to_s}:#{self.friend.to_s}"
end
def self.save(id, user_id, friend_id, status, message)
def self.invited_path(invited_user, sender, message)
friend_request = self.save(nil, sender.id, invited_user.id, nil, message, supress_initial: true)
self.save(friend_request.id, sender.id, invited_user.id, 'accept', message, supress_initial: true)
end
def self.save(id, user_id, friend_id, status, message, supress_initial: false)
# new friend request
if id.nil?
friend_request = FriendRequest.new()
friend_request = FriendRequest.new
friend_request = validate_friend_request(friend_request, user_id, friend_id)
friend_request.user_id = user_id
friend_request.friend_id = friend_id
@ -30,8 +35,8 @@ module JamRuby
friend_request.save
# send notification
Notification.send_friend_request(friend_request.id, user_id, friend_id)
Notification.send_friend_request(friend_request.id, user_id, friend_id) unless supress_initial
else
ActiveRecord::Base.transaction do
friend_request = FriendRequest.find(id)

View File

@ -14,6 +14,7 @@ module JamRuby
### Who sent this invitatio?
# either admin_sender or user_sender is not null. If an administrator sends the invitation, then
belongs_to :sender , :inverse_of => :invited_users, :class_name => "JamRuby::User", :foreign_key => "sender_id"
belongs_to :receiver, :inverse_of => :receiver_users, :class_name => "JamRuby::User", :foreign_key => "receiver_id"
# who is the invitation sent to?
validates :email, format: {with: VALID_EMAIL_REGEX}, :if => lambda { |iu| iu.email_required? }
@ -33,6 +34,7 @@ module JamRuby
before_validation(:on => :create) do
self.invitation_code = SecureRandom.urlsafe_base64 if self.invitation_code.nil?
self.sender_id = nil if self.sender_id.blank? # this coercion was done just to make activeadmin work
self.receiver = User.find_by_email(self.email) unless self.email.nil?
end
FB_MEDIUM = 'facebook'

View File

@ -178,6 +178,7 @@ module JamRuby
# invited users
has_many :invited_users, :foreign_key => "sender_id", :class_name => "JamRuby::InvitedUser"
has_many :receiver_users, :foreign_key => "receiver_id", :class_name => "JamRuby::InvitedUser"
# crash dumps
has_many :crash_dumps, :foreign_key => "user_id", :class_name => "JamRuby::CrashDump"
@ -1526,19 +1527,6 @@ module JamRuby
user.signup_token = SecureRandom.urlsafe_base64
end
# now that the user is saved, let's
if invited_user.autofriend && !invited_user.sender.nil?
# hookup this user with the sender
Friendship.save_using_models(user, invited_user.sender)
end
invited_user.accept!
invited_user.save
if invited_user.errors.any?
raise ActiveRecord::Rollback
end
end
found_gift_card = nil
@ -1566,6 +1554,15 @@ module JamRuby
user.save
# now that the user is saved, let's
if invited_user && invited_user.autofriend && !invited_user.sender.nil?
# hookup this user with the sender
FriendRequest.invited_path(user, invited_user.sender, invited_user.note)
invited_user.accept!
invited_user.save
end
if found_gift_card
user.reload
ShoppingCart.apply_gifted_jamtracks(user)
@ -1613,6 +1610,11 @@ module JamRuby
else
user.email_needs_verification = false
end
if !invited_user.nil? && invited_user.accepted
invited_user.receiver = user
invited_user.save
end
end

View File

@ -159,6 +159,12 @@
renderNoActionPossibleBtns();
})
})
.fail(function() {
// not logged in :(
var redirectPath= '?redirect-to=' + encodeURIComponent(JK.locationPath());
window.location.href = '/signin' + redirectPath;
return
})
}
function events() {

View File

@ -7,6 +7,7 @@
var waitForUserToStopTypingTimer;
var deferredFbInvite = null;
var facebookHelper = null;
var sendingEmails = false
function trackMetrics(emails, googleInviteCount) {
var allInvitations = emails.length; // all email invites, regardless of how they got in the form
@ -93,25 +94,35 @@
// send invitations one after another, so as not to 'spam' the server very heavily.
// this should be a bulk call, clearly
function sendEmails(e) {
if(sendingEmails) {
return;
}
var $button = $(e.target)
var emails = $('#txt-emails').val().split(',');
if(emails.length > 0) {
var max_email = <%= Rails.application.config.max_email_invites_per_request %>;
if (max_email < emails.length) {
app.notifyAlert('Too many emails', 'You can send up to '+max_email.toString()+' email invites. You have '+emails.length.toString());
return;
return;
}
var invalids = invalidEmails(emails);
if (0 < invalids.length) {
app.notifyAlert('Invalid emails', 'Please confirm email addresses');
} else {
sendingEmails = true
$button.addClass("disabled")
rest.createEmailInvitations(emails, $('#txt-message').val())
.fail(function(jqXHR) {
app.notifyServerError(jqXHR, 'Unable to Invite Users');
app.layout.closeDialog('inviteUsers');
sendingEmails = false
$button.removeClass("disabled")
})
.done(function() {
app.notifyAlert('Invites sent', 'You sent '+emails.length.toString()+' email invites');
app.layout.closeDialog('inviteUsers');
sendingEmails = false
$button.removeClass("disabled")
});
trackMetrics(emails, $('#txt-emails').data('google_invite_count'));
}
@ -229,6 +240,7 @@
}
function beforeShow() {
sendingEmails = false
registerEvents(true);
$('#invitation-dialog input[name=email-filter]').val('');

View File

@ -213,17 +213,17 @@
registerSourceDown();
// watch for Invite More Users events
$('#sidebar-div .btn-email-invitation').click(function() {
$('#sidebar-div .email-invitation-holder').click(function() {
invitationDialog.showEmailDialog();
return false;
});
$('#sidebar-div .btn-gmail-invitation').click(function() {
$('#sidebar-div .gmail-invitation-holder').click(function() {
invitationDialog.showGoogleDialog();
return false;
});
$('#sidebar-div .btn-facebook-invitation').click(function(evt) {
$('#sidebar-div .facebook-invitation-holder').click(function(evt) {
invitationDialog.showFacebookDialog(evt);
return false;
});

View File

@ -4,9 +4,9 @@
var congratulations = {};
congratulations.initialize = function initialize(musician, registrationType) {
congratulations.initialize = function initialize(musician, friend) {
if(musician) {
context.JK.Downloads.listClients(true);
context.JK.Downloads.listClients(true, friend);
}
}

View File

@ -114,14 +114,20 @@
$('body.web .spinner-large').remove();
}
function flashCongratulations() {
context.JK.flash('Congratulations!<br>Your account is ready.', {hide:10})
function flashCongratulations(friend) {
if(friend) {
context.JK.flash('Congratulations!<br>Soon you can play with ' + friend + '!', {hide:20})
}
else {
context.JK.flash('Congratulations!<br>Your account is ready.', {hide:20})
}
}
function listClients(congratulations) {
function listClients(congratulations, friend) {
isCongratulations = congratulations;
if(isCongratulations) {
flashCongratulations();
flashCongratulations(friend);
}
else {
//flashCongratulations();

View File

@ -115,6 +115,10 @@
ms-filter: "alpha(opacity=50)";
}
.email-invitation-holder, .gmail-invitation-holder, .facebook-invitation-holder {
cursor:pointer;
}
.avatar-small {
float:left;
padding:1px;

View File

@ -2,6 +2,7 @@
width:500px;
min-height:100px;
height:auto;
line-height:normal;
.dialog-inner {
color:white;

View File

@ -21,6 +21,12 @@ class ApiInvitedUsersController < ApiController
@invited_users = []
if (emails = params[:emails]).present?
emails = emails[0...Rails.application.config.max_email_invites_per_request].uniq
if emails.include?(current_user.email)
@responseobject = { :errors => { :email => ["can't be your own address"]}}
render :json => @responseobject, :status => :unprocessable_entity, layout: nil
return
end
msg = params[:note].blank? ? nil : params[:note].strip
@invited_users = emails.collect do |ee|
iu = InvitedUser.new
@ -29,6 +35,15 @@ class ApiInvitedUsersController < ApiController
iu.autofriend = true
iu.note = msg
iu.save
if iu.receiver
# automatically create friend request for an invitation to an existing user
FriendRequest.save(nil,
current_user.id,
iu.receiver.id,
nil,
msg)
end
iu
end
else

View File

@ -39,14 +39,30 @@ class UsersController < ApplicationController
def new
@no_user_dropdown = true
@invited_user = load_invited_user(params)
if @invited_user && @invited_user.email
user = User.find_by_email(@invited_user.email)
if user && (!current_user || current_user.id != user.id)
sign_in(user)
friend_request = FriendRequest.find_by_user_id_and_friend_id(@invited_user.sender_id, user.id)
if !friend_request
redirect_url = "/client#/home"
else
redirect_url = "/client#/home/accept-friend-request/d1=#{friend_request.id}"
end
redirect_to redirect_url
return
end
end
if current_user
if params["redirect-to"]
redirect_to params["redirect-to"]
else
redirect_to client_url
end
return
end
@ -78,13 +94,7 @@ class UsersController < ApplicationController
end
@affiliate_partner = load_affiliate_partner(params)
@invited_user = load_invited_user(params)
if !@invited_user.nil? && @invited_user.has_required_email? && @invited_user.accepted
# short-circuit out if this invitation is already accepted
render "already_signed_up", :layout => 'landing'
return
end
@signup_postback = load_postback(@invited_user, @fb_signup, @affiliate_partner)
load_location(request.remote_ip)
@ -187,7 +197,7 @@ class UsersController < ApplicationController
new_user(@user, signup_hint) # sets a cookie used for GA analytics (one-time new user stuff in JavaScript)
destination = @user.musician ? :congratulations_musician : :congratulations_fan
redirect_url = handle_signup_hint(@user, signup_hint, {:action => destination, :type => @user.user_authorization('facebook') ? 'Facebook' : 'Native'})
redirect_url = handle_signup_hint(@user, signup_hint, {:action => destination, friend: @invited_user.nil? ? nil : @invited_user.sender.name})
redirect_to redirect_url
end
end

View File

@ -60,7 +60,7 @@
</div>
<br clear="all"/>
<div class="invitation-button-holder">
<div class="left mr20">
<div class="left mr20 email-invitation-holder">
<div class="left">
<a class="btn-email-invitation">
<%= image_tag("content/icon_gmail.png", :size => "24x24", :align => "absmiddle") %>
@ -68,7 +68,7 @@
</div>
<div class="right mt5 ml5">E-mail</div>
</div>
<div class="left left">
<div class="left left gmail-invitation-holder">
<div class="left">
<a class="btn-gmail-invitation">
<%= image_tag("content/icon_google.png", :size => "24x24", :align => "absmiddle") %>
@ -76,7 +76,7 @@
</div>
<div class="right mt5 ml5">Google+</div>
</div>
<!--<div class="left left">
<!--<div class="left left facebook-invitation-holder">
<div class="left">
<a class="btn-facebook-invitation">
<%= image_tag("content/icon_facebook.png", :size => "24x24", :align => "absmiddle") %>

View File

@ -29,7 +29,21 @@
.dialog-content-scroller
%a{'user-id' => '{{data.user.id}}', hoveraction: '{{data.user.user_type}}', class: 'avatar-small'}
%img{src: '{{data.user.photo_url}}' }
%p.accept-friend-msg You are already friends with {{data.user.name}}.
%p.accept-friend-msg You are now friends with {{data.user.name}}!
%br
%br
%p
Click
%b friends
on the right sidebar, find their name, and hover over their name for actions like 'message'
%br
%br
%p
Or, you can also go straight to the
%a{href: "/client#/createSession", class: 'create-session-already-friends'} create session
page and click
%b QUICK START SOLO
to create a private session that only your friends can join!
%br{clear:'all'}
%br{clear:'all'}

View File

@ -14,11 +14,11 @@
p You need the JamKazam application to:
ul
li Play and control your JamTracks multi-track recordings
li Play music with others in real time on the JamKazam platform
li Make audio recordings and share them via Facebook or URL
li Make video recordings and share them via YouTube or URL
li Live broadcast your sessions to family, friends, and fans
li Play and control your JamTracks multi-track recordings
p.click-to-download Click the button below to download the JamKazam application installer.
.downloads-blurb

View File

@ -3,5 +3,5 @@
<%= render "users/downloads" %>
<script type="text/javascript">
$(function() { window.congratulations.initialize(true, jQuery.QueryString["type"]) })
$(function() { window.congratulations.initialize(true, jQuery.QueryString["friend"]) })
</script>

View File

@ -0,0 +1,50 @@
require 'spec_helper'
require 'thread'
def time_it(cat, &blk)
start = Time.now
blk.call
time = Time.now - start
puts("TIME: #{cat}: #{time}")
end
describe Router do
message_factory = MessageFactory.new
describe "heartbeats" do
it "hehe" do
time_it('strings') {
10000.times {
#heartbeat = message_factory.heartbeat()
#puts heartbeat.to_s
#heartbeat.to_s
blurp = "hello mr turkey how are you"
blurp.to_s
}
}
end
it "teehee" do
time_it('pb') {
10000.times {
heartbeat = message_factory.heartbeat()
heartbeat.to_s
#heartbeat.to_s
#blurp = "hello mr turkey how are you"
#blurp
}
}
end
end
end