Skip to content

Commit 286bf45

Browse files
committed
MOBILE-2103 chat: Show modal while sending
1 parent 1b98e81 commit 286bf45

File tree

1 file changed

+12
-16
lines changed
  • www/addons/mod/chat/controllers

1 file changed

+12
-16
lines changed

www/addons/mod/chat/controllers/chat.js

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ angular.module('mm.addons.mod_chat')
6464
$mmaModChat.getChatUsers($scope.chatsid).then(function(data) {
6565
$scope.chatUsers = data.users;
6666
}).catch(function(error) {
67-
showError(error, 'mma.mod_chat.errorwhilegettingchatusers');
67+
$mmUtil.showErrorModalDefault(error, 'mma.mod_chat.errorwhilegettingchatusers', true);
6868
}).finally(function() {
6969
$scope.usersLoaded = true;
7070
});
@@ -104,16 +104,6 @@ angular.module('mm.addons.mod_chat')
104104
});
105105
}
106106

107-
// Show error modal.
108-
function showError(error, defaultMessage) {
109-
if (typeof error === 'string') {
110-
$mmUtil.showErrorModal(error);
111-
} else {
112-
$mmUtil.showErrorModal(defaultMessage, true);
113-
}
114-
return $q.reject();
115-
}
116-
117107
// Start the polling to get chat messages periodically.
118108
function startPolling() {
119109
// We already have the polling in place.
@@ -145,7 +135,8 @@ angular.module('mm.addons.mod_chat')
145135
$interval.cancel($scope.polling);
146136
$scope.polling = undefined;
147137
}
148-
return showError(error, 'mma.mod_chat.errorwhileretrievingmessages');
138+
$mmUtil.showErrorModalDefault(error, 'mma.mod_chat.errorwhileretrievingmessages', true);
139+
return $q.reject();
149140
});
150141
}).finally(function() {
151142
pollingRunning = false;
@@ -175,17 +166,20 @@ angular.module('mm.addons.mod_chat')
175166
}
176167
text = $mmText.replaceNewLines(text, '<br>');
177168

169+
var modal = $mmUtil.showModalLoading('mm.core.sending', true);
178170
$mmaModChat.sendMessage($scope.chatsid, text, beep).then(function() {
179171
if (beep === '') {
180172
$scope.newMessage.text = '';
181173
}
182174
getMessagesInterval(); // Update messages to show the sent message.
183-
}, function(error) {
175+
}).catch(function(error) {
184176
// Only close the keyboard if an error happens, we want the user to be able to send multiple
185177
// messages withoutthe keyboard being closed.
186178
$mmApp.closeKeyboard();
187179

188-
showError(error, 'mma.mod_chat.errorwhilesendingmessage');
180+
$mmUtil.showErrorModalDefault(error, 'mma.mod_chat.errorwhilesendingmessage', true);
181+
}).finally(function() {
182+
modal.dismiss();
189183
});
190184
};
191185

@@ -206,10 +200,12 @@ angular.module('mm.addons.mod_chat')
206200
return getMessages().then(function() {
207201
startPolling();
208202
}).catch(function(error) {
209-
return showError(error, 'mma.mod_chat.errorwhileretrievingmessages');
203+
$mmUtil.showErrorModalDefault(error, 'mma.mod_chat.errorwhileretrievingmessages', true);
204+
$ionicHistory.goBack();
205+
return $q.reject();
210206
});
211207
}, function(error) {
212-
showError(error, 'mma.mod_chat.errorwhileconnecting');
208+
$mmUtil.showErrorModalDefault(error, 'mma.mod_chat.errorwhileconnecting', true);
213209
$ionicHistory.goBack();
214210
}).finally(function() {
215211
$scope.loaded = true;

0 commit comments

Comments
 (0)