#25: Enable certain email notifications by default for new users.

Also fixes a bug with storing OAuth tokens for new users!
This commit is contained in:
Peter Deltchev 2016-12-30 13:23:52 -08:00
parent 7ebab328d4
commit 8c7fe0ea33
2 changed files with 19 additions and 1 deletions

View file

@ -26,6 +26,7 @@ use League\OAuth2\Client\Provider\Exception\IdentityProviderException;
use League\OAuth2\Client\Token\AccessToken; use League\OAuth2\Client\Token\AccessToken;
use Log; use Log;
use Poniverse\Lib\Client; use Poniverse\Lib\Client;
use Poniverse\Ponyfm\Models\Activity;
use Poniverse\Ponyfm\Models\User; use Poniverse\Ponyfm\Models\User;
use Auth; use Auth;
use DB; use DB;
@ -106,12 +107,17 @@ class AuthController extends Controller
// Check by login name to see if they already have an account // Check by login name to see if they already have an account
$user = User::findOrCreate($poniverseUser->username, $poniverseUser->display_name, $poniverseUser->email); $user = User::findOrCreate($poniverseUser->username, $poniverseUser->display_name, $poniverseUser->email);
if (!$user->wasRecentlyCreated) { if ($user->wasRecentlyCreated) {
// We need to insert a new token row :O // We need to insert a new token row :O
$setData['user_id'] = $user->id; $setData['user_id'] = $user->id;
$setData['external_user_id'] = $poniverseUser->id; $setData['external_user_id'] = $poniverseUser->id;
$setData['service'] = 'poniverse'; $setData['service'] = 'poniverse';
DB::table('oauth2_tokens')->insert($setData); DB::table('oauth2_tokens')->insert($setData);
// Subscribe the user to default email notifications
foreach (Activity::DEFAULT_EMAIL_TYPES as $activityType) {
$user->emailSubscriptions()->create(['activity_type' => $activityType]);
}
} }

View file

@ -79,6 +79,18 @@ class Activity extends Model
const TYPE_NEW_COMMENT = 6; const TYPE_NEW_COMMENT = 6;
const TYPE_CONTENT_FAVOURITED = 7; const TYPE_CONTENT_FAVOURITED = 7;
/**
* Activity types to subscribe new users to email notifications for.
*/
const DEFAULT_EMAIL_TYPES = [
Activity::TYPE_PUBLISHED_TRACK,
Activity::TYPE_PUBLISHED_ALBUM,
Activity::TYPE_PUBLISHED_PLAYLIST,
Activity::TYPE_NEW_FOLLOWER,
Activity::TYPE_NEW_COMMENT,
Activity::TYPE_CONTENT_FAVOURITED,
];
/** /**
* These "target" constants are an implementation detail of this model and * These "target" constants are an implementation detail of this model and
* should not be used directly in other classes. They're used to efficiently * should not be used directly in other classes. They're used to efficiently