mirror of
https://github.com/taobataoma/meanTorrent.git
synced 2026-09-08 21:39:59 +02:00
feat(follow): follow & unfollow in userinfo page
This commit is contained in:
@@ -5,10 +5,11 @@
|
||||
.module('users')
|
||||
.controller('UserInfoController', UserInfoController);
|
||||
|
||||
UserInfoController.$inject = ['$scope', '$state', 'Authentication', 'userResolve', 'ScoreLevelService', '$timeout', 'MeanTorrentConfig',
|
||||
'DebugConsoleService'];
|
||||
UserInfoController.$inject = ['$scope', '$rootScope', '$state', 'Authentication', 'userResolve', 'ScoreLevelService', '$timeout', 'MeanTorrentConfig', 'UsersService',
|
||||
'DebugConsoleService', 'NotifycationService'];
|
||||
|
||||
function UserInfoController($scope, $state, Authentication, user, ScoreLevelService, $timeout, MeanTorrentConfig, mtDebug) {
|
||||
function UserInfoController($scope, $rootScope, $state, Authentication, user, ScoreLevelService, $timeout, MeanTorrentConfig, UsersService,
|
||||
mtDebug, NotifycationService) {
|
||||
var vm = this;
|
||||
|
||||
vm.authentication = Authentication;
|
||||
@@ -35,5 +36,57 @@
|
||||
function isContextUserSelf() {
|
||||
return vm.user.username === vm.authentication.user.username;
|
||||
}
|
||||
|
||||
/**
|
||||
* inMyFollowing
|
||||
* @returns {boolean}
|
||||
*/
|
||||
vm.inMyFollowing = function () {
|
||||
return vm.authentication.user.following.indexOf(vm.user._id) >= 0 ? true : false;
|
||||
};
|
||||
|
||||
/**
|
||||
* followTo
|
||||
*/
|
||||
vm.followTo = function () {
|
||||
UsersService.userFollowTo({
|
||||
userId: vm.user._id
|
||||
}).then(onSuccess)
|
||||
.catch(onError);
|
||||
|
||||
function onSuccess(response) {
|
||||
mtDebug.info(response);
|
||||
vm.authentication.user = Authentication.user = response;
|
||||
$rootScope.$broadcast('user-follow-changed', response);
|
||||
|
||||
NotifycationService.showSuccessNotify('FOLLOW_SUCCESSFULLY');
|
||||
}
|
||||
|
||||
function onError(response) {
|
||||
NotifycationService.showErrorNotify(response.data.message, 'FOLLOW_ERROR');
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* unFollowTo
|
||||
*/
|
||||
vm.unFollowTo = function () {
|
||||
UsersService.userUnfollowTo({
|
||||
userId: vm.user._id
|
||||
}).then(onSuccess)
|
||||
.catch(onError);
|
||||
|
||||
function onSuccess(response) {
|
||||
mtDebug.info(response);
|
||||
vm.authentication.user = Authentication.user = response;
|
||||
$rootScope.$broadcast('user-follow-changed', response);
|
||||
|
||||
NotifycationService.showSuccessNotify('UNFOLLOW_SUCCESSFULLY');
|
||||
}
|
||||
|
||||
function onError(response) {
|
||||
NotifycationService.showErrorNotify(response.data.message, 'UNFOLLOW_ERROR');
|
||||
}
|
||||
};
|
||||
}
|
||||
}());
|
||||
|
||||
Reference in New Issue
Block a user