mirror of
https://github.com/moodle/moodle.git
synced 2025-01-29 19:50:14 +01:00
MDL-66607 message: Add pendingJS checks
This commit is contained in:
parent
efeaa51edc
commit
56bcfae31f
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -59,6 +59,7 @@ define(
|
||||
'core/backoff_timer',
|
||||
'core/custom_interaction_events',
|
||||
'core/notification',
|
||||
'core/pending',
|
||||
'core/pubsub',
|
||||
'core/str',
|
||||
'core_message/message_repository',
|
||||
@ -78,6 +79,7 @@ function(
|
||||
BackOffTimer,
|
||||
CustomEvents,
|
||||
Notification,
|
||||
Pending,
|
||||
PubSub,
|
||||
Str,
|
||||
Repository,
|
||||
@ -615,12 +617,18 @@ function(
|
||||
*/
|
||||
var markConversationAsRead = function(conversationId) {
|
||||
var loggedInUserId = viewState.loggedInUserId;
|
||||
var pendingPromise = new Pending('core_message/message_drawer_view_conversation:markConversationAsRead');
|
||||
|
||||
return Repository.markAllConversationMessagesAsRead(loggedInUserId, conversationId)
|
||||
.then(function() {
|
||||
var newState = StateManager.markMessagesAsRead(viewState, viewState.messages);
|
||||
PubSub.publish(MessageDrawerEvents.CONVERSATION_READ, conversationId);
|
||||
return render(newState);
|
||||
})
|
||||
.then(function(result) {
|
||||
pendingPromise.resolve();
|
||||
|
||||
return result;
|
||||
});
|
||||
};
|
||||
|
||||
@ -645,6 +653,8 @@ function(
|
||||
*/
|
||||
var blockUser = function(userId) {
|
||||
var newState = StateManager.setLoadingConfirmAction(viewState, true);
|
||||
var pendingPromise = new Pending('core_message/message_drawer_view_conversation:blockUser');
|
||||
|
||||
render(newState);
|
||||
|
||||
return Repository.blockUser(viewState.loggedInUserId, userId)
|
||||
@ -654,6 +664,11 @@ function(
|
||||
newState = StateManager.setLoadingConfirmAction(newState, false);
|
||||
PubSub.publish(MessageDrawerEvents.CONTACT_BLOCKED, userId);
|
||||
return render(newState);
|
||||
})
|
||||
.then(function(result) {
|
||||
pendingPromise.resolve();
|
||||
|
||||
return result;
|
||||
});
|
||||
};
|
||||
|
||||
@ -678,6 +693,7 @@ function(
|
||||
*/
|
||||
var unblockUser = function(userId) {
|
||||
var newState = StateManager.setLoadingConfirmAction(viewState, true);
|
||||
var pendingPromise = new Pending('core_message/message_drawer_view_conversation:unblockUser');
|
||||
render(newState);
|
||||
|
||||
return Repository.unblockUser(viewState.loggedInUserId, userId)
|
||||
@ -687,6 +703,11 @@ function(
|
||||
newState = StateManager.setLoadingConfirmAction(newState, false);
|
||||
PubSub.publish(MessageDrawerEvents.CONTACT_UNBLOCKED, userId);
|
||||
return render(newState);
|
||||
})
|
||||
.then(function(result) {
|
||||
pendingPromise.resolve();
|
||||
|
||||
return result;
|
||||
});
|
||||
};
|
||||
|
||||
@ -711,6 +732,7 @@ function(
|
||||
*/
|
||||
var removeContact = function(userId) {
|
||||
var newState = StateManager.setLoadingConfirmAction(viewState, true);
|
||||
var pendingPromise = new Pending('core_message/message_drawer_view_conversation:removeContact');
|
||||
render(newState);
|
||||
|
||||
return Repository.deleteContacts(viewState.loggedInUserId, [userId])
|
||||
@ -720,6 +742,11 @@ function(
|
||||
newState = StateManager.setLoadingConfirmAction(newState, false);
|
||||
PubSub.publish(MessageDrawerEvents.CONTACT_REMOVED, userId);
|
||||
return render(newState);
|
||||
})
|
||||
.then(function(result) {
|
||||
pendingPromise.resolve();
|
||||
|
||||
return result;
|
||||
});
|
||||
};
|
||||
|
||||
@ -744,6 +771,7 @@ function(
|
||||
*/
|
||||
var addContact = function(userId) {
|
||||
var newState = StateManager.setLoadingConfirmAction(viewState, true);
|
||||
var pendingPromise = new Pending('core_message/message_drawer_view_conversation:addContactRequests');
|
||||
render(newState);
|
||||
|
||||
return Repository.createContactRequest(viewState.loggedInUserId, userId)
|
||||
@ -759,6 +787,11 @@ function(
|
||||
newState = StateManager.addContactRequests(newState, [request]);
|
||||
newState = StateManager.setLoadingConfirmAction(newState, false);
|
||||
return render(newState);
|
||||
})
|
||||
.then(function(result) {
|
||||
pendingPromise.resolve();
|
||||
|
||||
return result;
|
||||
});
|
||||
};
|
||||
|
||||
@ -770,6 +803,7 @@ function(
|
||||
var setFavourite = function() {
|
||||
var userId = viewState.loggedInUserId;
|
||||
var conversationId = viewState.id;
|
||||
var pendingPromise = new Pending('core_message/message_drawer_view_conversation:setFavourite');
|
||||
|
||||
return Repository.setFavouriteConversations(userId, [conversationId])
|
||||
.then(function() {
|
||||
@ -781,6 +815,11 @@ function(
|
||||
MessageDrawerEvents.CONVERSATION_SET_FAVOURITE,
|
||||
formatConversationForEvent(viewState)
|
||||
);
|
||||
})
|
||||
.then(function(result) {
|
||||
pendingPromise.resolve();
|
||||
|
||||
return result;
|
||||
});
|
||||
};
|
||||
|
||||
@ -792,6 +831,7 @@ function(
|
||||
var unsetFavourite = function() {
|
||||
var userId = viewState.loggedInUserId;
|
||||
var conversationId = viewState.id;
|
||||
var pendingPromise = new Pending('core_message/message_drawer_view_conversation:unsetFavourite');
|
||||
|
||||
return Repository.unsetFavouriteConversations(userId, [conversationId])
|
||||
.then(function() {
|
||||
@ -803,6 +843,11 @@ function(
|
||||
MessageDrawerEvents.CONVERSATION_UNSET_FAVOURITE,
|
||||
formatConversationForEvent(viewState)
|
||||
);
|
||||
})
|
||||
.then(function(result) {
|
||||
pendingPromise.resolve();
|
||||
|
||||
return result;
|
||||
});
|
||||
};
|
||||
|
||||
@ -814,6 +859,7 @@ function(
|
||||
var setMuted = function() {
|
||||
var userId = viewState.loggedInUserId;
|
||||
var conversationId = viewState.id;
|
||||
var pendingPromise = new Pending('core_message/message_drawer_view_conversation:markConversationAsRead');
|
||||
|
||||
return Repository.setMutedConversations(userId, [conversationId])
|
||||
.then(function() {
|
||||
@ -825,6 +871,11 @@ function(
|
||||
MessageDrawerEvents.CONVERSATION_SET_MUTED,
|
||||
formatConversationForEvent(viewState)
|
||||
);
|
||||
})
|
||||
.then(function(result) {
|
||||
pendingPromise.resolve();
|
||||
|
||||
return result;
|
||||
});
|
||||
};
|
||||
|
||||
@ -870,6 +921,7 @@ function(
|
||||
* @return {Promise} Renderer promise.
|
||||
*/
|
||||
var deleteSelectedMessages = function() {
|
||||
var pendingPromise = new Pending('core_message/message_drawer_view_conversation:deleteSelectedMessages');
|
||||
var messageIds = viewState.pendingDeleteMessageIds;
|
||||
var sentMessages = viewState.messages.filter(function(message) {
|
||||
// If a message sendState is null then it means it was loaded from the server or if it's
|
||||
@ -882,6 +934,7 @@ function(
|
||||
|
||||
var deleteMessagesPromise = $.Deferred().resolve().promise();
|
||||
|
||||
|
||||
if (sentMessages.length) {
|
||||
// We only need to send a request to the server if we're trying to delete messages that
|
||||
// have successfully been sent.
|
||||
@ -923,6 +976,11 @@ function(
|
||||
isDeletingConversationContent = false;
|
||||
return render(newState);
|
||||
})
|
||||
.then(function(result) {
|
||||
pendingPromise.resolve();
|
||||
|
||||
return result;
|
||||
})
|
||||
.catch(Notification.exception);
|
||||
};
|
||||
|
||||
@ -945,6 +1003,7 @@ function(
|
||||
* @return {Promise} Renderer promise.
|
||||
*/
|
||||
var deleteConversation = function() {
|
||||
var pendingPromise = new Pending('core_message/message_drawer_view_conversation:markConversationAsRead');
|
||||
var newState = StateManager.setLoadingConfirmAction(viewState, true);
|
||||
render(newState);
|
||||
|
||||
@ -967,6 +1026,11 @@ function(
|
||||
isDeletingConversationContent = false;
|
||||
|
||||
return render(newState);
|
||||
})
|
||||
.then(function(result) {
|
||||
pendingPromise.resolve();
|
||||
|
||||
return result;
|
||||
});
|
||||
};
|
||||
|
||||
@ -994,6 +1058,8 @@ function(
|
||||
* @return {Promise} Renderer promise.
|
||||
*/
|
||||
var acceptContactRequest = function(userId) {
|
||||
var pendingPromise = new Pending('core_message/message_drawer_view_conversation:acceptContactRequest');
|
||||
|
||||
// Search the list of the logged in user's contact requests to find the
|
||||
// one from this user.
|
||||
var loggedInUserId = viewState.loggedInUserId;
|
||||
@ -1015,6 +1081,11 @@ function(
|
||||
PubSub.publish(MessageDrawerEvents.CONTACT_ADDED, viewState.members[userId]);
|
||||
PubSub.publish(MessageDrawerEvents.CONTACT_REQUEST_ACCEPTED, request);
|
||||
return;
|
||||
})
|
||||
.then(function(result) {
|
||||
pendingPromise.resolve();
|
||||
|
||||
return result;
|
||||
});
|
||||
};
|
||||
|
||||
@ -1025,6 +1096,8 @@ function(
|
||||
* @return {Promise} Renderer promise.
|
||||
*/
|
||||
var declineContactRequest = function(userId) {
|
||||
var pendingPromise = new Pending('core_message/message_drawer_view_conversation:declineContactRequest');
|
||||
|
||||
// Search the list of the logged in user's contact requests to find the
|
||||
// one from this user.
|
||||
var loggedInUserId = viewState.loggedInUserId;
|
||||
@ -1045,6 +1118,11 @@ function(
|
||||
.then(function() {
|
||||
PubSub.publish(MessageDrawerEvents.CONTACT_REQUEST_DECLINED, request);
|
||||
return;
|
||||
})
|
||||
.then(function(result) {
|
||||
pendingPromise.resolve();
|
||||
|
||||
return result;
|
||||
});
|
||||
};
|
||||
|
||||
@ -1065,6 +1143,8 @@ function(
|
||||
return;
|
||||
}
|
||||
|
||||
var pendingPromise = new Pending('core_message/message_drawer_view_conversation:processSendMessageBuffer');
|
||||
|
||||
// Flag that we're processing the queue.
|
||||
isSendingMessage = true;
|
||||
// Grab all of the messages in the buffer.
|
||||
@ -1152,6 +1232,11 @@ function(
|
||||
PubSub.publish(MessageDrawerEvents.CONVERSATION_NEW_LAST_MESSAGE, conversation);
|
||||
return;
|
||||
})
|
||||
.then(function(result) {
|
||||
pendingPromise.resolve();
|
||||
|
||||
return result;
|
||||
})
|
||||
.catch(function(e) {
|
||||
var errorMessage;
|
||||
if (e.message) {
|
||||
@ -1170,6 +1255,11 @@ function(
|
||||
};
|
||||
|
||||
errorMessage.then(handleFailedMessages)
|
||||
.then(function(result) {
|
||||
pendingPromise.resolve();
|
||||
|
||||
return result;
|
||||
})
|
||||
.catch(function(e) {
|
||||
// Hrmm, we can't even load the error messages string! We'll have to
|
||||
// hard code something in English here if we still haven't got a message
|
||||
|
Loading…
x
Reference in New Issue
Block a user