#25: Built out email unsubscription UI and further tweaked the email template.

This commit is contained in:
Peter Deltchev 2016-12-28 07:07:28 -08:00
parent b6b3f036cc
commit b7088ccfb7
11 changed files with 120 additions and 9 deletions

View file

@ -21,9 +21,11 @@
namespace Poniverse\Ponyfm\Http\Controllers;
use App;
use Auth;
use DB;
use Poniverse\Ponyfm\Models\Email;
use Poniverse\Ponyfm\Models\EmailSubscription;
use View;
class NotificationsController extends Controller {
@ -45,9 +47,24 @@ class NotificationsController extends Controller {
}
public function getEmailUnsubscribe($subscriptionKey) {
/** @var EmailSubscription $subscription */
$subscription = EmailSubscription::findOrFail($subscriptionKey);
$subscription->delete();
return 'Unsubscribed!';
if (Auth::check() && $subscription->user->id === Auth::user()->id) {
return redirect(route('account:settings', [
'slug' => $subscription->user->slug,
'unsubscribedMessageKey' => $subscription->activity_type
]), 303);
} else {
return redirect(route('email:confirm-unsubscribed', [
'unsubscribedUser' => $subscription->user->display_name,
'unsubscribedMessageKey' => $subscription->activity_type
]), 303);
}
}
public function getEmailUnsubscribePage() {
return View::make('shared.null');
}
}

View file

@ -127,8 +127,10 @@ abstract class BaseNotification extends Mailable {
->text("emails.plaintext.notifications.{$templateName}")
->with(array_merge($extraVariables, [
'notificationUrl' => $this->generateNotificationUrl(),
'unsubscribeUrl' => $this->generateUnsubscribeUrl(),
'thumbnailUrl' => $this->activityRecord->thumbnail_url
'unsubscribeUrl' => $this->generateUnsubscribeUrl(),
'thumbnailUrl' => $this->activityRecord->thumbnail_url,
'recipientName' => $this->emailRecord->getUser()->display_name,
'accountSettingsUrl' => $this->emailRecord->getUser()->getSettingsUrl(),
]));
}
}

View file

@ -338,6 +338,11 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon
return Gravatar::getUrl($email, Image::$ImageTypes[$type]['width']);
}
public function getSettingsUrl()
{
return route('account:settings', ['slug' => $this->slug]);
}
/**
* Get the token value for the "remember me" session.
*

View file

@ -44,6 +44,10 @@
</div>
</div>
<div class="col-md-8" ng-if="::settings.can_manage_notifications">
<div class="alert alert-warning" ng-if="unsubscribeMessage">
<p>{{ ::unsubscribeMessage }}</p>
</div>
<h3>Notification settings</h3>
<p>On-site notifications are always on. That way, you can always see
what you&#39;ve missed whenever you log on to Pony.fm!</p>

View file

@ -0,0 +1,3 @@
<div class="alert alert-warning" ng-if="unsubscribeMessage">
<p>{{ ::unsubscribeMessage }}</p>
</div>

View file

@ -307,8 +307,12 @@ ponyfm.config [
templateUrl: '/templates/admin/announcement-show.html'
controller: 'admin-announcement-edit'
# Homepage
state.state 'notifications-email-unsubscribed',
url: '/notifications/email/unsubscribed',
controller: 'notifications-email-unsubscribed',
templateUrl: '/templates/home/email-unsubscribed.html'
# Homepage
if window.pfm.auth.isLogged
state.state 'home',
url: '/'

View file

@ -15,11 +15,12 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
module.exports = angular.module('ponyfm').controller "account-settings", [
'$scope', 'auth', '$state'
($scope, auth, $state) ->
'$scope', 'auth', '$state', 'activity-types',
($scope, auth, $state, activityTypes) ->
$scope.settings = {}
$scope.errors = {}
$scope.isDirty = false
$scope.unsubscribeMessage = activityTypes.getUnsubscribeMessage()
$scope.touchModel = () ->
$scope.isDirty = true

View file

@ -0,0 +1,24 @@
# Pony.fm - A community for pony fan music.
# Copyright (C) 2016 Peter Deltchev
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
module.exports = angular.module('ponyfm').controller "notifications-email-unsubscribed", [
'$scope', 'activity-types',
($scope, activityTypes) ->
console.log("boom")
$scope.unsubscribeMessage = activityTypes.getUnsubscribeMessage()
]

View file

@ -0,0 +1,50 @@
# Pony.fm - A community for pony fan music.
# Copyright (C) 2016 Peter Deltchev
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
module.exports = angular.module('ponyfm').factory('activity-types', [
'$location',
($location) ->
self =
getUnsubscribeMessage: () ->
if $location.search().unsubscribedMessageKey?
if $location.search().unsubscribedUser?
return self.generateUnsubscribeMessage(
$location.search().unsubscribedMessageKey,
$location.search().unsubscribedUser,
)
else
return self.generateUnsubscribeMessage($location.search().unsubscribedMessageKey)
else
return null
generateUnsubscribeMessage: (activityType, displayName = null) ->
# TODO: get these messages from the backend
switch parseInt(activityType)
when 1 then activityString = 'updates from the Pony.fm team'
when 2 then activityString = 'new tracks by users you follow'
when 3 then activityString = 'new albums by users you follow'
when 4 then activityString = 'new playlists by users you follow'
when 5 then activityString = 'when you get new followers'
when 6 then activityString = 'when someone leaves you a comment'
when 7 then activityString = 'when something of yours is favourited'
else throw "#{activityType} is an invalid activity type!"
if displayName
return "#{displayName} - you've been unsubscribed from email notifications for #{activityString}. You can re-enable them by logging in and going to your account settings."
else
return "You successfully unsubscribed from email notifications for #{activityString}. If you want, you can re-subscribe below."
return self
])

View file

@ -24,13 +24,13 @@
<row>
<columns large="6">
<h6>What&#39;s this?</h6>
<p><small>Pony.fm can now send you notifications via email! You can control what you get email notifications for in your <a href="#">account settings</a>.</small></p>
<p><small>Pony.fm can now send you notifications via email! You can control what you get email notifications for in your <a href="\{{ $accountSettingsUrl }}">account settings</a>.</small></p>
<p><small><a href="\{{ $unsubscribeUrl }}" target="_blank">Unsubscribe from this kind of email</a></small></p>
</columns>
<columns large="6">
<br>
<p><small>
Sent with &#9829;<br>
Sent with &#9829; to \{{ $recipientName }}<br>
<br>
Poniverse<br>
248-1641 Lonsdale Avenue<br>

View file

@ -80,6 +80,7 @@ Route::get('notifications', 'AccountController@getNotifications');
Route::group(['prefix' => 'notifications/email'], function() {
Route::get('/unsubscribe/{subscriptionKey}', 'NotificationsController@getEmailUnsubscribe')->name('email:unsubscribe');
Route::get('/unsubscribed', 'NotificationsController@getEmailUnsubscribePage')->name('email:confirm-unsubscribed');
Route::get('/click/{emailKey}', 'NotificationsController@getEmailClick')->name('email:click');
});
@ -246,7 +247,7 @@ Route::group(['prefix' => '{slug}'], function () {
Route::get('/uploader', 'UploaderController@getIndex');
Route::get('/', 'AccountController@getIndex');
Route::get('/', 'AccountController@getIndex')->name('account:settings');
});
});