mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 15:17:25 +01:00
Refactor chat related things into own service
This commit is contained in:
@@ -159,8 +159,8 @@ habitrpg.controller("GroupsCtrl", ['$scope', '$rootScope', 'Shared', 'Groups', '
|
||||
};
|
||||
}])
|
||||
|
||||
.controller("MemberModalCtrl", ['$scope', '$rootScope', 'Members', 'Shared', '$http', 'Notification', 'Groups', '$controller',
|
||||
function($scope, $rootScope, Members, Shared, $http, Notification, Groups, $controller) {
|
||||
.controller("MemberModalCtrl", ['$scope', '$rootScope', 'Members', 'Shared', '$http', 'Notification', 'Groups', 'Chat', '$controller',
|
||||
function($scope, $rootScope, Members, Shared, $http, Notification, Groups, Chat, $controller) {
|
||||
|
||||
$controller('RootCtrl', {$scope: $scope});
|
||||
|
||||
@@ -199,13 +199,13 @@ habitrpg.controller("GroupsCtrl", ['$scope', '$rootScope', 'Shared', 'Groups', '
|
||||
}
|
||||
$scope.reportAbuse = function(reporter, message, groupId) {
|
||||
message.flags[reporter._id] = true;
|
||||
Groups.Group.flagChatMessage({gid: groupId, messageId: message.id}, undefined, function(data){
|
||||
Chat.utils.flagChatMessage({gid: groupId, messageId: message.id}, undefined, function(data){
|
||||
Notification.text(window.env.t('abuseReported'));
|
||||
$scope.$close();
|
||||
});
|
||||
}
|
||||
$scope.clearFlagCount = function(message, groupId) {
|
||||
Groups.Group.clearFlagCount({gid: groupId, messageId: message.id}, undefined, function(data){
|
||||
Chat.utils.clearFlagCount({gid: groupId, messageId: message.id}, undefined, function(data){
|
||||
message.flagCount = 0;
|
||||
Notification.text("Flags cleared");
|
||||
$scope.$close();
|
||||
@@ -286,7 +286,7 @@ habitrpg.controller("GroupsCtrl", ['$scope', '$rootScope', 'Shared', 'Groups', '
|
||||
});
|
||||
}])
|
||||
|
||||
.controller('ChatCtrl', ['$scope', 'Groups', 'User', '$http', 'ApiUrl', 'Notification', 'Members', '$rootScope', function($scope, Groups, User, $http, ApiUrl, Notification, Members, $rootScope){
|
||||
.controller('ChatCtrl', ['$scope', 'Groups', 'Chat', 'User', '$http', 'ApiUrl', 'Notification', 'Members', '$rootScope', function($scope, Groups, Chat, User, $http, ApiUrl, Notification, Members, $rootScope){
|
||||
$scope.message = {content:''};
|
||||
$scope._sending = false;
|
||||
|
||||
@@ -312,7 +312,7 @@ habitrpg.controller("GroupsCtrl", ['$scope', '$rootScope', 'Shared', 'Groups', '
|
||||
if (_.isEmpty(message) || $scope._sending) return;
|
||||
$scope._sending = true;
|
||||
var previousMsg = (group.chat && group.chat[0]) ? group.chat[0].id : false;
|
||||
Groups.Group.postChat({gid: group._id, message:message, previousMsg: previousMsg}, undefined, function(data){
|
||||
Chat.utils.postChat({gid: group._id, message:message, previousMsg: previousMsg}, undefined, function(data){
|
||||
if(data.chat){
|
||||
group.chat = data.chat;
|
||||
}else if(data.message){
|
||||
@@ -329,7 +329,7 @@ habitrpg.controller("GroupsCtrl", ['$scope', '$rootScope', 'Shared', 'Groups', '
|
||||
if(message.uuid === User.user.id || (User.user.backer && User.user.contributor.admin)){
|
||||
var previousMsg = (group.chat && group.chat[0]) ? group.chat[0].id : false;
|
||||
if(confirm('Are you sure you want to delete this message?')){
|
||||
Groups.Group.deleteChatMessage({gid:group._id, messageId:message.id, previousMsg:previousMsg}, undefined, function(data){
|
||||
Chat.utils.deleteChatMessage({gid:group._id, messageId:message.id, previousMsg:previousMsg}, undefined, function(data){
|
||||
if(data.chat) group.chat = data.chat;
|
||||
|
||||
var i = _.findIndex(group.chat, {id: message.id});
|
||||
@@ -348,9 +348,7 @@ habitrpg.controller("GroupsCtrl", ['$scope', '$rootScope', 'Shared', 'Groups', '
|
||||
} else {
|
||||
message.likes[User.user._id] = true;
|
||||
}
|
||||
//Chat.Chat.like({gid:group._id,mid:message.id});
|
||||
|
||||
$http.post(ApiUrl.get() + '/api/v2/groups/' + group._id + '/chat/' + message.id + '/like');
|
||||
Chat.utils.like({ gid:group._id, messageId:message.id }, undefined);
|
||||
}
|
||||
|
||||
$scope.flagChatMessage = function(groupId,message) {
|
||||
@@ -390,7 +388,7 @@ habitrpg.controller("GroupsCtrl", ['$scope', '$rootScope', 'Shared', 'Groups', '
|
||||
$scope.sync = function(group){
|
||||
group.$get();
|
||||
//When the user clicks fetch recent messages we need to update that the user has seen the new messages
|
||||
Groups.seenMessage(group._id);
|
||||
Chat.seenMessage(group._id);
|
||||
}
|
||||
|
||||
// List of Ordering options for the party members list
|
||||
@@ -499,15 +497,15 @@ habitrpg.controller("GroupsCtrl", ['$scope', '$rootScope', 'Shared', 'Groups', '
|
||||
}
|
||||
])
|
||||
|
||||
.controller("PartyCtrl", ['$rootScope','$scope', 'Groups', 'User', 'Challenges', '$state', '$compile',
|
||||
function($rootScope,$scope, Groups, User, Challenges, $state, $compile) {
|
||||
.controller("PartyCtrl", ['$rootScope','$scope', 'Groups', 'Chat', 'User', 'Challenges', '$state', '$compile',
|
||||
function($rootScope,$scope, Groups, Chat, User, Challenges, $state, $compile) {
|
||||
|
||||
$scope.type = 'party';
|
||||
$scope.text = window.env.t('party');
|
||||
$scope.group = $rootScope.party = Groups.party();
|
||||
$scope.newGroup = new Groups.Group({type:'party'});
|
||||
|
||||
Groups.seenMessage($scope.group._id);
|
||||
Chat.seenMessage($scope.group._id);
|
||||
|
||||
$scope.create = function(group){
|
||||
group.$save(function(){
|
||||
|
||||
Reference in New Issue
Block a user