feat(follow): follow & unfollow in userinfo page

This commit is contained in:
OldHawk
2018-01-04 12:14:43 +08:00
parent 7c95d3a547
commit 95422aaaec
10 changed files with 157 additions and 9 deletions

View File

@@ -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');
}
};
}
}());