MDL-64715 message: improve the front-end for the self-conversations

This commit is contained in:
Ryan Wyllie 2019-04-16 16:33:25 +08:00 committed by Sara Arjona
parent 734b198fd3
commit 69efd0337b
10 changed files with 144 additions and 163 deletions

File diff suppressed because one or more lines are too long

View file

@ -1 +1 @@
define([],function(){var a={ACTION_ACCEPT_CONTACT_REQUEST:'[data-action="accept-contact-request"]',ACTION_CANCEL_CONFIRM:'[data-action="cancel-confirm"]',ACTION_CANCEL_EDIT_MODE:'[data-action="cancel-edit-mode"]',ACTION_CONFIRM_ADD_CONTACT:'[data-action="confirm-add-contact"]',ACTION_CONFIRM_BLOCK:'[data-action="confirm-block"]',ACTION_CONFIRM_DELETE_SELECTED_MESSAGES:'[data-action="confirm-delete-selected-messages"]',ACTION_CONFIRM_DELETE_CONVERSATION:'[data-action="confirm-delete-conversation"]',ACTION_CONFIRM_FAVOURITE:'[data-action="confirm-favourite"]',ACTION_CONFIRM_MUTE:'[data-action="confirm-mute"]',ACTION_CONFIRM_UNFAVOURITE:'[data-action="confirm-unfavourite"]',ACTION_CONFIRM_REMOVE_CONTACT:'[data-action="confirm-remove-contact"]',ACTION_CONFIRM_UNBLOCK:'[data-action="confirm-unblock"]',ACTION_CONFIRM_UNMUTE:'[data-action="confirm-unmute"]',ACTION_DECLINE_CONTACT_REQUEST:'[data-action="decline-contact-request"]',ACTION_REQUEST_ADD_CONTACT:'[data-action="request-add-contact"]',ACTION_REQUEST_BLOCK:'[data-action="request-block"]',ACTION_REQUEST_DELETE_CONVERSATION:'[data-action="request-delete-conversation"]',ACTION_REQUEST_DELETE_SELECTED_MESSAGES:'[data-action="delete-selected-messages"]',ACTION_REQUEST_REMOVE_CONTACT:'[data-action="request-remove-contact"]',ACTION_REQUEST_UNBLOCK:'[data-action="request-unblock"]',ACTION_VIEW_CONTACT:'[data-action="view-contact"]',ACTION_VIEW_GROUP_INFO:'[data-action="view-group-info"]',CAN_RECEIVE_FOCUS:'input:not([type="hidden"]), a[href], button, textarea, select, [tabindex]',CONFIRM_DIALOGUE_BUTTON_TEXT:'[data-region="dialogue-button-text"]',CONFIRM_DIALOGUE_CANCEL_BUTTON:'[data-action="cancel-confirm"]',CONFIRM_DIALOGUE_CONTAINER:'[data-region="confirm-dialogue-container"]',CONFIRM_DIALOGUE_HEADER:'[data-region="dialogue-header"]',CONFIRM_DIALOGUE_TEXT:'[data-region="dialogue-text"]',CONTACT_REQUEST_SENT_MESSAGE_CONTAINER:'[data-region="contact-request-sent-message-container"]',CONTENT_PLACEHOLDER_CONTAINER:'[data-region="content-placeholder"]',CONTENT_CONTAINER:'[data-region="content-container"]',CONTENT_MESSAGES_CONTAINER:'[data-region="content-message-container"]',CONTENT_MESSAGES_FOOTER_CONTAINER:'[data-region="content-messages-footer-container"]',CONTENT_MESSAGES_FOOTER_EDIT_MODE_CONTAINER:'[data-region="content-messages-footer-edit-mode-container"]',CONTENT_MESSAGES_FOOTER_REQUIRE_CONTACT_CONTAINER:'[data-region="content-messages-footer-require-contact-container"]',CONTENT_MESSAGES_FOOTER_REQUIRE_UNBLOCK_CONTAINER:'[data-region="content-messages-footer-require-unblock-container"]',CONTENT_MESSAGES_FOOTER_UNABLE_TO_MESSAGE_CONTAINER:'[data-region="content-messages-footer-unable-to-message"]',DAY_MESSAGES_CONTAINER:'[data-region="day-messages-container"]',FAVOURITE_ICON_CONTAINER:'[data-region="favourite-icon-container"]',FOOTER_CONTAINER:'[data-region="content-messages-footer-container"]',HEADER:'[data-region="header-content"]',HEADER_EDIT_MODE:'[data-region="header-edit-mode"]',HEADER_PLACEHOLDER_CONTAINER:'[data-region="header-placeholder"]',LOADING_ICON_CONTAINER:'[data-region="loading-icon-container"]',MESSAGE:'[data-region="message"]',MESSAGE_NOT_SELECTED:'[data-region="message"][aria-checked="false"]',MESSAGE_NOT_SELECTED_ICON:'[data-region="not-selected-icon"]',MESSAGE_SELECTED_ICON:'[data-region="selected-icon"]',MESSAGES:'[data-region="content-message-container"]',MESSAGES_CONTAINER:'[data-region="content-message-container"]',MESSAGES_SELECTED_COUNT:'[data-region="message-selected-court"]',MESSAGE_TEXT_AREA:'[data-region="send-message-txt"]',MORE_MESSAGES_LOADING_ICON_CONTAINER:'[data-region="more-messages-loading-icon-container"]',MUTED_ICON_CONTAINER:'[data-region="muted-icon-container"]',PLACEHOLDER_CONTAINER:'[data-region="placeholder-container"]',SELF_CONVERSATION_MESSAGE_CONTAINER:'[data-region="self-conversation-message-container"]',SEND_MESSAGE_BUTTON:'[data-action="send-message"]',SEND_MESSAGE_ICON_CONTAINER:'[data-region="send-icon-container"]',TEXT:'[data-region="text"]',TITLE:'[data-region="title"]'},b={HEADER_PRIVATE:"core_message/message_drawer_view_conversation_header_content_type_private",HEADER_PRIVATE_NO_CONTROLS:"core_message/message_drawer_view_conversation_header_content_type_private_no_controls",HEADER_PUBLIC:"core_message/message_drawer_view_conversation_header_content_type_public",HEADER_SELF:"core_message/message_drawer_view_conversation_header_content_type_self",DAY:"core_message/message_drawer_view_conversation_body_day",MESSAGE:"core_message/message_drawer_view_conversation_body_message",MESSAGES:"core_message/message_drawer_view_conversation_body_messages"},c={PRIVATE:1,PUBLIC:2,SELF:3},d={PRIVATE:1,PUBLIC:2,FAVOURITE:null};return{SELECTORS:a,TEMPLATES:b,CONVERSATION_TYPES:c,CONVERSATION_CATEGORY_TYPES:d,NEWEST_MESSAGES_FIRST:!0,LOAD_MESSAGE_LIMIT:100,INITIAL_NEW_MESSAGE_POLL_TIMEOUT:1e3}});
define([],function(){var a={ACTION_ACCEPT_CONTACT_REQUEST:'[data-action="accept-contact-request"]',ACTION_CANCEL_CONFIRM:'[data-action="cancel-confirm"]',ACTION_CANCEL_EDIT_MODE:'[data-action="cancel-edit-mode"]',ACTION_CONFIRM_ADD_CONTACT:'[data-action="confirm-add-contact"]',ACTION_CONFIRM_BLOCK:'[data-action="confirm-block"]',ACTION_CONFIRM_DELETE_SELECTED_MESSAGES:'[data-action="confirm-delete-selected-messages"]',ACTION_CONFIRM_DELETE_CONVERSATION:'[data-action="confirm-delete-conversation"]',ACTION_CONFIRM_FAVOURITE:'[data-action="confirm-favourite"]',ACTION_CONFIRM_MUTE:'[data-action="confirm-mute"]',ACTION_CONFIRM_UNFAVOURITE:'[data-action="confirm-unfavourite"]',ACTION_CONFIRM_REMOVE_CONTACT:'[data-action="confirm-remove-contact"]',ACTION_CONFIRM_UNBLOCK:'[data-action="confirm-unblock"]',ACTION_CONFIRM_UNMUTE:'[data-action="confirm-unmute"]',ACTION_DECLINE_CONTACT_REQUEST:'[data-action="decline-contact-request"]',ACTION_REQUEST_ADD_CONTACT:'[data-action="request-add-contact"]',ACTION_REQUEST_BLOCK:'[data-action="request-block"]',ACTION_REQUEST_DELETE_CONVERSATION:'[data-action="request-delete-conversation"]',ACTION_REQUEST_DELETE_SELECTED_MESSAGES:'[data-action="delete-selected-messages"]',ACTION_REQUEST_REMOVE_CONTACT:'[data-action="request-remove-contact"]',ACTION_REQUEST_UNBLOCK:'[data-action="request-unblock"]',ACTION_VIEW_CONTACT:'[data-action="view-contact"]',ACTION_VIEW_GROUP_INFO:'[data-action="view-group-info"]',CAN_RECEIVE_FOCUS:'input:not([type="hidden"]), a[href], button, textarea, select, [tabindex]',CONFIRM_DIALOGUE_BUTTON_TEXT:'[data-region="dialogue-button-text"]',CONFIRM_DIALOGUE_CANCEL_BUTTON:'[data-action="cancel-confirm"]',CONFIRM_DIALOGUE_CONTAINER:'[data-region="confirm-dialogue-container"]',CONFIRM_DIALOGUE_HEADER:'[data-region="dialogue-header"]',CONFIRM_DIALOGUE_TEXT:'[data-region="dialogue-text"]',CONTACT_REQUEST_SENT_MESSAGE_CONTAINER:'[data-region="contact-request-sent-message-container"]',CONTENT_PLACEHOLDER_CONTAINER:'[data-region="content-placeholder"]',CONTENT_CONTAINER:'[data-region="content-container"]',CONTENT_MESSAGES_CONTAINER:'[data-region="content-message-container"]',CONTENT_MESSAGES_FOOTER_CONTAINER:'[data-region="content-messages-footer-container"]',CONTENT_MESSAGES_FOOTER_EDIT_MODE_CONTAINER:'[data-region="content-messages-footer-edit-mode-container"]',CONTENT_MESSAGES_FOOTER_REQUIRE_CONTACT_CONTAINER:'[data-region="content-messages-footer-require-contact-container"]',CONTENT_MESSAGES_FOOTER_REQUIRE_UNBLOCK_CONTAINER:'[data-region="content-messages-footer-require-unblock-container"]',CONTENT_MESSAGES_FOOTER_UNABLE_TO_MESSAGE_CONTAINER:'[data-region="content-messages-footer-unable-to-message"]',DAY_MESSAGES_CONTAINER:'[data-region="day-messages-container"]',FAVOURITE_ICON_CONTAINER:'[data-region="favourite-icon-container"]',FOOTER_CONTAINER:'[data-region="content-messages-footer-container"]',HEADER:'[data-region="header-content"]',HEADER_EDIT_MODE:'[data-region="header-edit-mode"]',HEADER_PLACEHOLDER_CONTAINER:'[data-region="header-placeholder"]',LOADING_ICON_CONTAINER:'[data-region="loading-icon-container"]',MESSAGE:'[data-region="message"]',MESSAGE_NOT_SELECTED:'[data-region="message"][aria-checked="false"]',MESSAGE_NOT_SELECTED_ICON:'[data-region="not-selected-icon"]',MESSAGE_SELECTED_ICON:'[data-region="selected-icon"]',MESSAGES:'[data-region="content-message-container"]',MESSAGES_CONTAINER:'[data-region="content-message-container"]',MESSAGES_SELECTED_COUNT:'[data-region="message-selected-court"]',MESSAGE_TEXT_AREA:'[data-region="send-message-txt"]',MORE_MESSAGES_LOADING_ICON_CONTAINER:'[data-region="more-messages-loading-icon-container"]',MUTED_ICON_CONTAINER:'[data-region="muted-icon-container"]',PLACEHOLDER_CONTAINER:'[data-region="placeholder-container"]',SELF_CONVERSATION_MESSAGE_CONTAINER:'[data-region="self-conversation-message-container"]',SEND_MESSAGE_BUTTON:'[data-action="send-message"]',SEND_MESSAGE_ICON_CONTAINER:'[data-region="send-icon-container"]',TEXT:'[data-region="text"]',TITLE:'[data-region="title"]'},b={HEADER_PRIVATE:"core_message/message_drawer_view_conversation_header_content_type_private",HEADER_PRIVATE_NO_CONTROLS:"core_message/message_drawer_view_conversation_header_content_type_private_no_controls",HEADER_PUBLIC:"core_message/message_drawer_view_conversation_header_content_type_public",HEADER_SELF:"core_message/message_drawer_view_conversation_header_content_type_self",DAY:"core_message/message_drawer_view_conversation_body_day",MESSAGE:"core_message/message_drawer_view_conversation_body_message",MESSAGES:"core_message/message_drawer_view_conversation_body_messages"},c={PRIVATE:1,PUBLIC:2,SELF:3};return{SELECTORS:a,TEMPLATES:b,CONVERSATION_TYPES:c,NEWEST_MESSAGES_FIRST:!0,LOAD_MESSAGE_LIMIT:100,INITIAL_NEW_MESSAGE_POLL_TIMEOUT:1e3}});

File diff suppressed because one or more lines are too long

View file

@ -1 +1 @@
define(["jquery","core/key_codes","core/pubsub","core/str","core_message/message_drawer_router","core_message/message_drawer_routes","core_message/message_drawer_events","core_message/message_drawer_view_overview_section","core_message/message_repository","core_message/message_drawer_view_conversation_constants"],function(a,b,c,d,e,f,g,h,i,j){var k={CONTACT_REQUEST_COUNT:'[data-region="contact-request-count"]',FAVOURITES:'[data-region="view-overview-favourites"]',GROUP_MESSAGES:'[data-region="view-overview-group-messages"]',MESSAGES:'[data-region="view-overview-messages"]',SEARCH_INPUT:'[data-region="view-overview-search-input"]',SECTION_TOGGLE_BUTTON:"[data-toggle]"},l=null,m=function(a){return null===l&&(l=i.getAllConversationCounts(a)),l},n=function(a,b){var c=0;return c=b===j.CONVERSATION_CATEGORY_TYPES.PRIVATE&&a.types[j.CONVERSATION_TYPES.SELF]?a.types[j.CONVERSATION_TYPES.PRIVATE]+a.types[j.CONVERSATION_TYPES.SELF]:b===j.CONVERSATION_CATEGORY_TYPES.FAVOURITE?a.favourites:a.types[b]},o=function(a){var b=a.some(function(a){var b=a[0];return h.isVisible(b)});if(!b){a.sort(function(a,b){var c=a[1],d=a[2],e=b[1],f=b[2];return d>0&&0==f?-1:0==d&&f>0?1:c>0&&0==e?-1:0==c&&e>0?1:0});var c=a[0][0],d=c.find(k.SECTION_TOGGLE_BUTTON);d.click()}},p=function(a){return a.find(k.SEARCH_INPUT)},q=function(a){return a.attr("data-user-id")},r=function(a){return function(){var b=a.find(k.CONTACT_REQUEST_COUNT),c=parseInt(b.text(),10);c=isNaN(c)?0:c-1,c<=0?b.addClass("hidden"):b.text(c)}},s=function(a,d){var h=p(d),i=[b.tab,b.shift,b.ctrl,b.alt];h.on("click",function(){e.go(a,f.VIEW_SEARCH)}),h.on("keydown",function(b){i.indexOf(b.keyCode)<0&&"Meta"!=b.key&&e.go(a,f.VIEW_SEARCH)}),c.subscribe(g.CONTACT_REQUEST_ACCEPTED,r(d)),c.subscribe(g.CONTACT_REQUEST_DECLINED,r(d))},t=function(a,b,c){b.attr("data-init")||(s(a,b),b.attr("data-init",!0)),p(b).val("");var d=q(c),e=m(d),f=[[c.find(k.FAVOURITES),j.CONVERSATION_CATEGORY_TYPES.FAVOURITE,!0],[c.find(k.GROUP_MESSAGES),j.CONVERSATION_CATEGORY_TYPES.PUBLIC,!1],[c.find(k.MESSAGES),j.CONVERSATION_CATEGORY_TYPES.PRIVATE,!1]];return f.forEach(function(b){var c=b[0],d=b[1],f=b[2],g=e.then(function(a){return n(a.total,d)}),i=e.then(function(a){return n(a.unread,d)});h.show(a,null,c,null,d,f,g,i)}),e.then(function(a){var b=f.map(function(b){var c=b[0],d=b[1],e=n(a.total,d),f=n(a.unread,d);return[c,e,f]});return o(b)})},u=function(){return d.get_string("messagedrawerviewoverview","core_message")};return{show:t,description:u}});
define(["jquery","core/key_codes","core/pubsub","core/str","core_message/message_drawer_router","core_message/message_drawer_routes","core_message/message_drawer_events","core_message/message_drawer_view_overview_section","core_message/message_repository","core_message/message_drawer_view_conversation_constants"],function(a,b,c,d,e,f,g,h,i,j){var k={CONTACT_REQUEST_COUNT:'[data-region="contact-request-count"]',FAVOURITES:'[data-region="view-overview-favourites"]',GROUP_MESSAGES:'[data-region="view-overview-group-messages"]',MESSAGES:'[data-region="view-overview-messages"]',SEARCH_INPUT:'[data-region="view-overview-search-input"]',SECTION_TOGGLE_BUTTON:"[data-toggle]"},l={PRIVATE:[j.CONVERSATION_TYPES.PRIVATE,j.CONVERSATION_TYPES.SELF],PUBLIC:[j.CONVERSATION_TYPES.PUBLIC],FAVOURITE:null},m=null,n=function(a){return null===m&&(m=i.getAllConversationCounts(a)),m},o=function(a,b,c){var d=0;return b&&b.length&&(d=b.reduce(function(b,c){return b+a.types[c]},d)),c&&(d+=a.favourites),d},p=function(a){var b=a.some(function(a){var b=a[0];return h.isVisible(b)});if(!b){a.sort(function(a,b){var c=a[1],d=a[2],e=b[1],f=b[2];return d>0&&0==f?-1:0==d&&f>0?1:c>0&&0==e?-1:0==c&&e>0?1:0});var c=a[0][0],d=c.find(k.SECTION_TOGGLE_BUTTON);d.click()}},q=function(a){return a.find(k.SEARCH_INPUT)},r=function(a){return a.attr("data-user-id")},s=function(a){return function(){var b=a.find(k.CONTACT_REQUEST_COUNT),c=parseInt(b.text(),10);c=isNaN(c)?0:c-1,c<=0?b.addClass("hidden"):b.text(c)}},t=function(a,d){var h=q(d),i=[b.tab,b.shift,b.ctrl,b.alt];h.on("click",function(){e.go(a,f.VIEW_SEARCH)}),h.on("keydown",function(b){i.indexOf(b.keyCode)<0&&"Meta"!=b.key&&e.go(a,f.VIEW_SEARCH)}),c.subscribe(g.CONTACT_REQUEST_ACCEPTED,s(d)),c.subscribe(g.CONTACT_REQUEST_DECLINED,s(d))},u=function(a,b,c){b.attr("data-init")||(t(a,b),b.attr("data-init",!0)),q(b).val("");var d=r(c),e=n(d),f=[[c.find(k.FAVOURITES),l.FAVOURITE,!0],[c.find(k.GROUP_MESSAGES),l.PUBLIC,!1],[c.find(k.MESSAGES),l.PRIVATE,!1]];return f.forEach(function(b){var c=b[0],d=b[1],f=b[2],g=e.then(function(a){return o(a.total,d,f)}),i=e.then(function(a){return o(a.unread,d,f)});h.show(a,null,c,null,d,f,g,i)}),e.then(function(a){var b=f.map(function(b){var c=b[0],d=b[1],e=b[2],f=o(a.total,d,e),g=o(a.unread,d,e);return[c,f,g]});return p(b)})},v=function(){return d.get_string("messagedrawerviewoverview","core_message")};return{show:u,description:v}});

File diff suppressed because one or more lines are too long

View file

@ -120,7 +120,7 @@ function(
* @return {Number} Userid.
*/
var getOtherUserId = function() {
if (!viewState || (viewState.type != CONVERSATION_TYPES.PRIVATE && viewState.type != CONVERSATION_TYPES.SELF)) {
if (!viewState || viewState.type == CONVERSATION_TYPES.PUBLIC) {
return null;
}
@ -149,7 +149,7 @@ function(
if (!carry) {
var state = stateCache[id].state;
if (state.type == CONVERSATION_TYPES.PRIVATE || state.type == CONVERSATION_TYPES.SELF) {
if (state.type != CONVERSATION_TYPES.PUBLIC) {
if (userId in state.members) {
// We've found a cached conversation for this user!
carry = state.id;
@ -274,6 +274,9 @@ function(
*/
var loadEmptyPrivateConversation = function(loggedInUserProfile, otherUserId) {
var loggedInUserId = loggedInUserProfile.id;
// If the other user id is the same as the logged in user then this is a self
// conversation.
var conversationType = loggedInUserId == otherUserId ? CONVERSATION_TYPES.SELF : CONVERSATION_TYPES.PRIVATE;
var newState = StateManager.setLoadingMembers(viewState, true);
newState = StateManager.setLoadingMessages(newState, true);
return render(newState)
@ -288,57 +291,16 @@ function(
}
})
.then(function(profile) {
var newState = StateManager.addMembers(viewState, [profile, loggedInUserProfile]);
// If the conversation is a self conversation then the profile loaded is the
// logged in user so only add that to the members array.
var members = conversationType == CONVERSATION_TYPES.SELF ? [profile] : [profile, loggedInUserProfile];
var newState = StateManager.addMembers(viewState, members);
newState = StateManager.setLoadingMembers(newState, false);
newState = StateManager.setLoadingMessages(newState, false);
newState = StateManager.setName(newState, profile.fullname);
newState = StateManager.setType(newState, CONVERSATION_TYPES.PRIVATE);
newState = StateManager.setType(newState, conversationType);
newState = StateManager.setImageUrl(newState, profile.profileimageurl);
newState = StateManager.setTotalMemberCount(newState, 2);
return render(newState)
.then(function() {
return profile;
});
})
.catch(function(error) {
var newState = StateManager.setLoadingMembers(viewState, false);
render(newState);
Notification.exception(error);
});
};
/**
* Load up an empty self-conversation for the logged in user.
* Sets all of the conversation details based on the current user.
*
* A conversation isn't created until the user sends the first message.
*
* @param {Object} loggedInUserProfile The logged in user profile.
* @return {Object} Profile returned from repository.
*/
var loadEmptySelfConversation = function(loggedInUserProfile) {
var loggedInUserId = loggedInUserProfile.id;
var newState = StateManager.setLoadingMembers(viewState, true);
newState = StateManager.setLoadingMessages(newState, true);
return render(newState)
.then(function() {
return Repository.getMemberInfo(loggedInUserId, [loggedInUserId], true, true);
})
.then(function(profiles) {
if (profiles.length) {
return profiles[0];
} else {
throw new Error('Unable to load other user profile');
}
})
.then(function(profile) {
var newState = StateManager.addMembers(viewState, [profile, loggedInUserProfile]);
newState = StateManager.setLoadingMembers(newState, false);
newState = StateManager.setLoadingMessages(newState, false);
newState = StateManager.setName(newState, profile.fullname);
newState = StateManager.setType(newState, CONVERSATION_TYPES.SELF);
newState = StateManager.setImageUrl(newState, profile.profileimageurl);
newState = StateManager.setTotalMemberCount(newState, 1);
newState = StateManager.setTotalMemberCount(newState, members.length);
return render(newState)
.then(function() {
return profile;
@ -373,7 +335,8 @@ function(
var name = conversation.name;
var imageUrl = conversation.imageurl;
if (conversation.type == CONVERSATION_TYPES.PRIVATE || conversation.type == CONVERSATION_TYPES.SELF) {
if (conversation.type != CONVERSATION_TYPES.PUBLIC) {
name = name || otherUser ? otherUser.fullname : '';
imageUrl = imageUrl || otherUser ? otherUser.profileimageurl : '';
}
@ -1076,8 +1039,7 @@ function(
var newConversationId = null;
return render(newState)
.then(function() {
if (!conversationId &&
(viewState.type == CONVERSATION_TYPES.PRIVATE || viewState.type == CONVERSATION_TYPES.SELF)) {
if (!conversationId && (viewState.type != CONVERSATION_TYPES.PUBLIC)) {
// If it's a new private conversation then we need to use the old
// web service function to create the conversation.
var otherUserId = getOtherUserId();
@ -1539,10 +1501,10 @@ function(
var resetNoConversation = function(body, loggedInUserProfile, otherUserId) {
// Always reset the state back to the initial state so that the
// state manager and patcher can work correctly.
if (loggedInUserProfile.id != otherUserId) {
// This is a private conversation between two users.
return resetState(body, null, loggedInUserProfile)
.then(function() {
if (loggedInUserProfile.id != otherUserId) {
// Private conversation between two different users.
return Repository.getConversationBetweenUsers(
loggedInUserProfile.id,
otherUserId,
@ -1553,7 +1515,17 @@ function(
LOAD_MESSAGE_LIMIT,
0,
NEWEST_FIRST
)
);
} else {
// Self conversation.
return Repository.getSelfConversation(
loggedInUserProfile.id,
LOAD_MESSAGE_LIMIT,
0,
NEWEST_FIRST
);
}
})
.then(function(conversation) {
// Looks like we have a conversation after all! Let's use that.
return resetByConversation(body, conversation, loggedInUserProfile);
@ -1562,27 +1534,6 @@ function(
// Can't find a conversation. Oh well. Just load up a blank one.
return loadEmptyPrivateConversation(loggedInUserProfile, otherUserId);
});
});
} else {
// This is a self-conversation.
return resetState(body, null, loggedInUserProfile)
.then(function() {
return Repository.getSelfConversation(
loggedInUserProfile.id,
LOAD_MESSAGE_LIMIT,
0,
NEWEST_FIRST
)
.then(function(conversation) {
// Looks like we have a conversation after all! Let's use that.
return resetByConversation(body, conversation, loggedInUserProfile);
})
.catch(function() {
// Can't find a conversation. Oh well. Just load up a blank one.
return loadEmptySelfConversation(loggedInUserProfile);
});
});
}
};
/**

View file

@ -102,19 +102,10 @@ define([], function() {
SELF: 3
};
// Categories displayed in the message drawer. Some methods (such as filterCountsByType) are expecting their value
// will be the same as the defined in the CONVERSATION_TYPES, except for the favourite.
var CONVERSATION_CATEGORY_TYPES = {
PRIVATE: 1,
PUBLIC: 2,
FAVOURITE: null
};
return {
SELECTORS: SELECTORS,
TEMPLATES: TEMPLATES,
CONVERSATION_TYPES: CONVERSATION_TYPES,
CONVERSATION_CATEGORY_TYPES: CONVERSATION_CATEGORY_TYPES,
NEWEST_MESSAGES_FIRST: true,
LOAD_MESSAGE_LIMIT: 100,
INITIAL_NEW_MESSAGE_POLL_TIMEOUT: 1000

View file

@ -322,7 +322,7 @@ function(
* @return {Object} patch
*/
var buildHeaderPatchTypeSelf = function(state, newState) {
var shouldRenderHeader = (state.name === null);
var shouldRenderHeader = (state.name === null && newState.name !== null);
if (shouldRenderHeader) {
return {
@ -1150,7 +1150,11 @@ function(
* @return {bool}
*/
var buildSelfConversationMessage = function(state, newState) {
if (state.type != newState.type) {
return (newState.type == Constants.CONVERSATION_TYPES.SELF);
}
return null;
};
/**

View file

@ -55,6 +55,14 @@ function(
SECTION_TOGGLE_BUTTON: '[data-toggle]'
};
// Categories displayed in the message drawer. Some methods (such as filterCountsByType) are expecting their value
// will be the same as the defined in the CONVERSATION_TYPES, except for the favourite.
var OVERVIEW_SECTION_TYPES = {
PRIVATE: [Constants.CONVERSATION_TYPES.PRIVATE, Constants.CONVERSATION_TYPES.SELF],
PUBLIC: [Constants.CONVERSATION_TYPES.PUBLIC],
FAVOURITE: null
};
var loadAllCountsPromise = null;
/**
@ -81,18 +89,23 @@ function(
* This is used on the result returned by the loadAllCounts function.
*
* @param {Object} counts Conversation counts indexed by conversation type.
* @param {String|null} type The conversation type (null for favourites only).
* @param {Array|null} types The conversation types handlded by this section (null for all conversation types).
* @param {bool} includeFavourites If this section includes favourites
* @return {Number}
*/
var filterCountsByType = function(counts, type) {
var filterCountsByTypes = function(counts, types, includeFavourites) {
var total = 0;
if (type === Constants.CONVERSATION_CATEGORY_TYPES.PRIVATE && counts.types[Constants.CONVERSATION_TYPES.SELF]) {
// As private and self conversations are displayed together, we need to add the counts for the self-conversations
// to the private ones, when there is any self-conversation.
total = counts.types[Constants.CONVERSATION_TYPES.PRIVATE] + counts.types[Constants.CONVERSATION_TYPES.SELF];
} else {
total = type === Constants.CONVERSATION_CATEGORY_TYPES.FAVOURITE ? counts.favourites : counts.types[type];
if (types && types.length) {
total = types.reduce(function(carry, type) {
return carry + counts.types[type];
}, total);
}
if (includeFavourites) {
total += counts.favourites;
}
return total;
};
@ -230,34 +243,35 @@ function(
var sections = [
// Favourite conversations section.
[body.find(SELECTORS.FAVOURITES), Constants.CONVERSATION_CATEGORY_TYPES.FAVOURITE, true],
[body.find(SELECTORS.FAVOURITES), OVERVIEW_SECTION_TYPES.FAVOURITE, true],
// Group conversations section.
[body.find(SELECTORS.GROUP_MESSAGES), Constants.CONVERSATION_CATEGORY_TYPES.PUBLIC, false],
[body.find(SELECTORS.GROUP_MESSAGES), OVERVIEW_SECTION_TYPES.PUBLIC, false],
// Private conversations section.
[body.find(SELECTORS.MESSAGES), Constants.CONVERSATION_CATEGORY_TYPES.PRIVATE, false]
[body.find(SELECTORS.MESSAGES), OVERVIEW_SECTION_TYPES.PRIVATE, false]
];
sections.forEach(function(args) {
var sectionRoot = args[0];
var sectionType = args[1];
var sectionTypes = args[1];
var includeFavourites = args[2];
var totalCountPromise = allCounts.then(function(result) {
return filterCountsByType(result.total, sectionType);
return filterCountsByTypes(result.total, sectionTypes, includeFavourites);
});
var unreadCountPromise = allCounts.then(function(result) {
return filterCountsByType(result.unread, sectionType);
return filterCountsByTypes(result.unread, sectionTypes, includeFavourites);
});
Section.show(namespace, null, sectionRoot, null, sectionType, includeFavourites,
Section.show(namespace, null, sectionRoot, null, sectionTypes, includeFavourites,
totalCountPromise, unreadCountPromise);
});
return allCounts.then(function(result) {
var sectionParams = sections.map(function(section) {
var sectionRoot = section[0];
var sectionType = section[1];
var totalCount = filterCountsByType(result.total, sectionType);
var unreadCount = filterCountsByType(result.unread, sectionType);
var sectionTypes = section[1];
var includeFavourites = section[2];
var totalCount = filterCountsByTypes(result.total, sectionTypes, includeFavourites);
var unreadCount = filterCountsByTypes(result.unread, sectionTypes, includeFavourites);
return [sectionRoot, totalCount, unreadCount];
});

View file

@ -233,12 +233,34 @@ function(
/**
* Build the callback to load conversations.
*
* @param {Number} type The conversation type.
* @param {Array|null} types The conversation types for this section.
* @param {bool} includeFavourites Include/exclude favourites.
* @param {Number} offset Result offset
* @return {Function}
*/
var getLoadCallback = function(type, includeFavourites, offset) {
var getLoadCallback = function(types, includeFavourites, offset) {
// Note: This function is a bit messy because we've added the concept of loading
// multiple conversations types (e.g. private + self) at once but haven't properly
// updated the web service to accept an array of types. Instead we've added a new
// parameter for the self type which means we can only ever load self + other type.
// This should be improved to make it more extensible in the future. Adding new params
// for each type isn't very scalable.
var type = null;
// Include self conversations in the results by default.
var includeSelfConversations = true;
if (types && types.length) {
// Just get the conversation types that aren't "self" for now.
var nonSelfConversationTypes = types.filter(function(candidate) {
return candidate != MessageDrawerViewConversationContants.CONVERSATION_TYPES.SELF;
});
// If we're specifically asking for a list of types that doesn't include the self
// conversations then we don't need to include them.
includeSelfConversations = types.length != nonSelfConversationTypes.length;
// As mentioned above the webservice is currently limited to loading one type at a
// time (plus self conversations) so let's hope we never change this.
type = nonSelfConversationTypes[0];
}
return function(root, userId) {
return MessageRepository.getConversations(
userId,
@ -246,7 +268,7 @@ function(
LOAD_LIMIT + 1,
offset,
includeFavourites,
true // Always merge self-conversations with private conversations, to display them together.
includeSelfConversations
)
.then(function(response) {
var conversations = response.conversations;
@ -531,11 +553,27 @@ function(
* @param {String} namespace Unique identifier for the Routes
* @param {Object} root The section container element.
* @param {Function} loadCallback The callback to load items.
* @param {Number} type The conversation type for this section
* @param {Array|null} type The conversation types for this section
* @param {bool} includeFavourites If this section includes favourites
*/
var registerEventListeners = function(namespace, root, loadCallback, type, includeFavourites) {
var registerEventListeners = function(namespace, root, loadCallback, types, includeFavourites) {
var listRoot = LazyLoadList.getRoot(root);
var conversationBelongsToThisSection = function(conversation) {
// Make sure the type is an int so that the index of check matches correctly.
var conversationType = parseInt(conversation.type, 10);
if (
// If the conversation type isn't one this section cares about then we can ignore it.
(types && types.indexOf(conversationType) < 0) ||
// If this is the favourites section and the conversation isn't a favourite then ignore it.
(includeFavourites && !conversation.isFavourite) ||
// If this section doesn't include favourites and the conversation is a favourite then ignore it.
(!includeFavourites && conversation.isFavourite)
) {
return false;
}
return true;
};
// Set the minimum height of the section to the height of the toggle. This
// smooths out the collapse animation.
@ -583,16 +621,7 @@ function(
});
PubSub.subscribe(MessageDrawerEvents.CONVERSATION_NEW_LAST_MESSAGE, function(conversation) {
// Self-conversations could be displayed as private conversations when they are not starred. So we need to exclude
// them from the following check to make sure last messages are updated properly for them.
if (
(type && conversation.type == MessageDrawerViewConversationContants.CONVERSATION_TYPES.SELF &&
type != MessageDrawerViewConversationContants.CONVERSATION_TYPES.PRIVATE && !conversation.isFavourite) ||
(type && conversation.type != MessageDrawerViewConversationContants.CONVERSATION_TYPES.SELF &&
type != conversation.type) ||
(includeFavourites && !conversation.isFavourite) ||
(!includeFavourites && conversation.isFavourite)
) {
if (!conversationBelongsToThisSection(conversation)) {
return;
}
@ -621,16 +650,12 @@ function(
PubSub.subscribe(MessageDrawerEvents.CONVERSATION_SET_FAVOURITE, function(conversation) {
var conversationElement = null;
if (includeFavourites && (!type || type == conversation.type)) {
if (conversationBelongsToThisSection(conversation)) {
conversationElement = getConversationElement(root, conversation.id);
if (!conversationElement.length) {
createNewConversation(root, conversation);
}
} else if (type == conversation.type ||
(type == MessageDrawerViewConversationContants.CONVERSATION_TYPES.PRIVATE &&
conversation.type == MessageDrawerViewConversationContants.CONVERSATION_TYPES.SELF)) {
// Self-conversations are displayed in the private conversations section, so they should be removed from
// there when they are favourited.
} else {
conversationElement = getConversationElement(root, conversation.id);
if (conversationElement.length) {
deleteConversation(root, conversationElement);
@ -640,20 +665,16 @@ function(
PubSub.subscribe(MessageDrawerEvents.CONVERSATION_UNSET_FAVOURITE, function(conversation) {
var conversationElement = null;
if (includeFavourites) {
conversationElement = getConversationElement(root, conversation.id);
if (conversationElement.length) {
deleteConversation(root, conversationElement);
}
} else if (type == conversation.type ||
(type == MessageDrawerViewConversationContants.CONVERSATION_TYPES.PRIVATE &&
conversation.type == MessageDrawerViewConversationContants.CONVERSATION_TYPES.SELF)) {
// Self-conversations are displayed in the private conversations section, so they should be added
// there when they are unfavourited.
if (conversationBelongsToThisSection(conversation)) {
conversationElement = getConversationElement(root, conversation.id);
if (!conversationElement.length) {
createNewConversation(root, conversation);
}
} else {
conversationElement = getConversationElement(root, conversation.id);
if (conversationElement.length) {
deleteConversation(root, conversationElement);
}
}
});
@ -675,17 +696,17 @@ function(
* @param {Object} header The header container element.
* @param {Object} body The section container element.
* @param {Object} footer The footer container element.
* @param {Number} type The conversation type for this section
* @param {Array} types The conversation types that show in this section
* @param {bool} includeFavourites If this section includes favourites
* @param {Object} totalCountPromise Resolves wth the total conversations count
* @param {Object} unreadCountPromise Resolves wth the unread conversations count
*/
var show = function(namespace, header, body, footer, type, includeFavourites, totalCountPromise, unreadCountPromise) {
var show = function(namespace, header, body, footer, types, includeFavourites, totalCountPromise, unreadCountPromise) {
var root = $(body);
if (!root.attr('data-init')) {
var loadCallback = getLoadCallback(type, includeFavourites, 0);
registerEventListeners(namespace, root, loadCallback, type, includeFavourites);
var loadCallback = getLoadCallback(types, includeFavourites, 0);
registerEventListeners(namespace, root, loadCallback, types, includeFavourites);
if (isVisible(root)) {
setExpanded(root);