<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[BuddyPress][12116] branches/3.0/src/bp-templates/bp-nouveau: BP Nouveau Messages UI: Improve the Backbone router using pushState</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { white-space: pre-line; overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="http://buddypress.trac.wordpress.org/changeset/12116">12116</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"http://buddypress.trac.wordpress.org/changeset/12116","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>imath</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2018-05-24 05:17:07 +0000 (Thu, 24 May 2018)</dd>
</dl>
<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>BP Nouveau Messages UI: Improve the Backbone router using pushState
In order to be consistent with conditional template tags such as {{{bp_is_messages_compose_screen()}}}, the routes of the Backbone router have been updated to match Messages component canonical URLs
Props sbrajesh, djpaul
Fixes <a href="http://buddypress.trac.wordpress.org/ticket/7840">#7840</a> (Branch 3.0)</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#branches30srcbptemplatesbpnouveaubuddypresscommonjstemplatesmessagesindexphp">branches/3.0/src/bp-templates/bp-nouveau/buddypress/common/js-templates/messages/index.php</a></li>
<li><a href="#branches30srcbptemplatesbpnouveauincludesmessagesfunctionsphp">branches/3.0/src/bp-templates/bp-nouveau/includes/messages/functions.php</a></li>
<li><a href="#branches30srcbptemplatesbpnouveaujsbuddypressmessagesjs">branches/3.0/src/bp-templates/bp-nouveau/js/buddypress-messages.js</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="branches30srcbptemplatesbpnouveaubuddypresscommonjstemplatesmessagesindexphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: branches/3.0/src/bp-templates/bp-nouveau/buddypress/common/js-templates/messages/index.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- branches/3.0/src/bp-templates/bp-nouveau/buddypress/common/js-templates/messages/index.php 2018-05-24 05:13:57 UTC (rev 12115)
+++ branches/3.0/src/bp-templates/bp-nouveau/buddypress/common/js-templates/messages/index.php 2018-05-24 05:17:07 UTC (rev 12116)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -154,7 +154,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> <div class="thread-content" data-thread-id="{{data.id}}">
</span><span class="cx" style="display: block; padding: 0 10px"> <div class="thread-subject">
</span><span class="cx" style="display: block; padding: 0 10px"> <span class="thread-count">({{data.count}})</span>
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- <a class="subject" href="#view/{{data.id}}">{{data.subject}}</a>
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ <a class="subject" href="../view/{{data.id}}/">{{data.subject}}</a>
</ins><span class="cx" style="display: block; padding: 0 10px"> </div>
</span><span class="cx" style="display: block; padding: 0 10px"> <p class="excerpt">{{data.excerpt}}</p>
</span><span class="cx" style="display: block; padding: 0 10px"> </div>
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -203,7 +203,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> <# } #>
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- <a href="#view/{{data.id}}" class="message-action-view bp-tooltip bp-icons" data-bp-tooltip="<?php esc_attr_e( 'View full conversation and reply.', 'buddypress' ); ?>">
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ <a href="../view/{{data.id}}/" class="message-action-view bp-tooltip bp-icons" data-bp-action="view" data-bp-tooltip="<?php esc_attr_e( 'View full conversation and reply.', 'buddypress' ); ?>">
</ins><span class="cx" style="display: block; padding: 0 10px"> <span class="bp-screen-reader-text"><?php esc_html_e( 'View full conversation and reply.', 'buddypress' ); ?></span>
</span><span class="cx" style="display: block; padding: 0 10px"> </a>
</span><span class="cx" style="display: block; padding: 0 10px"> </div>
</span></span></pre></div>
<a id="branches30srcbptemplatesbpnouveauincludesmessagesfunctionsphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: branches/3.0/src/bp-templates/bp-nouveau/includes/messages/functions.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- branches/3.0/src/bp-templates/bp-nouveau/includes/messages/functions.php 2018-05-24 05:13:57 UTC (rev 12115)
+++ branches/3.0/src/bp-templates/bp-nouveau/includes/messages/functions.php 2018-05-24 05:17:07 UTC (rev 12116)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -114,6 +114,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'one' => __( '(and 1 other)', 'buddypress' ),
</span><span class="cx" style="display: block; padding: 0 10px"> 'more' => __( '(and %d others)', 'buddypress' ),
</span><span class="cx" style="display: block; padding: 0 10px"> ),
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'rootUrl' => trailingslashit( str_replace( home_url(), '', bp_displayed_user_domain() ) . bp_get_messages_slug() ),
</ins><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Star private messages.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -178,15 +179,10 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if ( 'notices' === $secondary_nav_item->slug ) {
</span><span class="cx" style="display: block; padding: 0 10px"> bp_core_remove_subnav_item( bp_get_messages_slug(), $secondary_nav_item->slug, 'members' );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- } else {
- $params = array( 'link' => '#' . $secondary_nav_item->slug );
-
- // Make sure Admins won't write a messages from the user's account.
- if ( 'compose' === $secondary_nav_item->slug ) {
- $params['user_has_access'] = bp_is_my_profile();
- }
-
- $bp->members->nav->edit_nav( $params, $secondary_nav_item->slug, bp_get_messages_slug() );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ } elseif ( 'compose' === $secondary_nav_item->slug ) {
+ $bp->members->nav->edit_nav( array(
+ 'user_has_access' => bp_is_my_profile()
+ ), $secondary_nav_item->slug, bp_get_messages_slug() );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -204,12 +200,10 @@
</span><span class="cx" style="display: block; padding: 0 10px"> foreach ( $admin_nav as $nav_iterator => $nav ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $nav_id = str_replace( 'my-account-messages-', '', $nav['id'] );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( 'my-account-messages' !== $nav_id ) {
- if ( 'notices' === $nav_id ) {
- $admin_nav[ $nav_iterator ]['href'] = esc_url( add_query_arg( array( 'page' => 'bp-notices' ), bp_get_admin_url( 'users.php' ) ) );
- } else {
- $admin_nav[ $nav_iterator ]['href'] = $user_messages_link . '#' . trim( $nav_id );
- }
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( 'notices' === $nav_id ) {
+ $admin_nav[ $nav_iterator ]['href'] = esc_url( add_query_arg( array(
+ 'page' => 'bp-notices'
+ ), bp_get_admin_url( 'users.php' ) ) );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span></span></pre></div>
<a id="branches30srcbptemplatesbpnouveaujsbuddypressmessagesjs"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: branches/3.0/src/bp-templates/bp-nouveau/js/buddypress-messages.js</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- branches/3.0/src/bp-templates/bp-nouveau/js/buddypress-messages.js 2018-05-24 05:13:57 UTC (rev 12115)
+++ branches/3.0/src/bp-templates/bp-nouveau/js/buddypress-messages.js 2018-05-24 05:17:07 UTC (rev 12116)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -37,7 +37,10 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> this.setupNav();
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- Backbone.history.start();
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ Backbone.history.start( {
+ pushState: true,
+ root: BP_Nouveau.messages.rootUrl
+ } );
</ins><span class="cx" style="display: block; padding: 0 10px"> },
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> setupNav: function() {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -69,11 +72,11 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Navigate back to current box
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- self.router.navigate( self.box, { trigger: true } );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ self.router.navigate( self.box + '/', { trigger: true } );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Otherwise load it
</span><span class="cx" style="display: block; padding: 0 10px"> } else {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- self.router.navigate( 'compose', { trigger: true } );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ self.router.navigate( 'compose/', { trigger: true } );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Other views are classic.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -82,7 +85,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> if ( self.box !== view_id || ! _.isUndefined( self.views.get( 'compose' ) ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> self.clearViews();
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- self.router.navigate( view_id, { trigger: true } );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ self.router.navigate( view_id + '/', { trigger: true } );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> } );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -616,7 +619,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> form.get( 'view' ).remove();
</span><span class="cx" style="display: block; padding: 0 10px"> bp.Nouveau.Messages.views.remove( { id: 'compose', view: form } );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- bp.Nouveau.Messages.router.navigate( 'sentbox', { trigger: true } );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ bp.Nouveau.Messages.router.navigate( 'sentbox/', { trigger: true } );
</ins><span class="cx" style="display: block; padding: 0 10px"> } ).fail( function( response ) {
</span><span class="cx" style="display: block; padding: 0 10px"> if ( response.feedback ) {
</span><span class="cx" style="display: block; padding: 0 10px"> bp.Nouveau.Messages.displayFeedback( response.feedback, response.type );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -712,8 +715,11 @@
</span><span class="cx" style="display: block; padding: 0 10px"> bp.Nouveau.Messages.removeFeedback();
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // If the click is done on an active conversation, open it.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( $( event.currentTarget ).closest( '.thread-item' ).hasClass( 'selected' ) ) {
- this.loadSingleView( event );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( target.closest( '.thread-item' ).hasClass( 'selected' ) ) {
+ bp.Nouveau.Messages.router.navigate(
+ 'view/' + target.closest( '.thread-content' ).data( 'thread-id' ) + '/',
+ { trigger: true }
+ );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Otherwise activate the conversation and display its preview.
</span><span class="cx" style="display: block; padding: 0 10px"> } else {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -721,15 +727,6 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $( '.message-action-view' ).focus();
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- },
-
- loadSingleView: function( event ) {
- event.preventDefault();
-
- bp.Nouveau.Messages.router.navigate(
- 'view/' + $( event.currentTarget ).closest( '.thread-content' ).data( 'thread-id' ),
- { trigger: true }
- );
</del><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> } );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -895,7 +892,17 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> mid = model.get( 'id' );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( 'star' === action || 'unstar' === action ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Open the full conversation
+ if ( 'view' === action ) {
+ bp.Nouveau.Messages.router.navigate(
+ 'view/' + mid + '/',
+ { trigger: true }
+ );
+
+ return;
+
+ // Star/Unstar actions needs to use a specific id and nonce.
+ } else if ( 'star' === action || 'unstar' === action ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> options.data = {
</span><span class="cx" style="display: block; padding: 0 10px"> 'star_nonce' : model.get( 'star_nonce' )
</span><span class="cx" style="display: block; padding: 0 10px"> };
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1323,11 +1330,11 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> bp.Nouveau.Messages.Router = Backbone.Router.extend( {
</span><span class="cx" style="display: block; padding: 0 10px"> routes: {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'compose' : 'composeMessage',
- 'view/:id': 'viewMessage',
- 'sentbox' : 'sentboxView',
- 'starred' : 'starredView',
- 'inbox' : 'inboxView',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'compose/' : 'composeMessage',
+ 'view/:id/': 'viewMessage',
+ 'sentbox/' : 'sentboxView',
+ 'starred/' : 'starredView',
+ 'inbox/' : 'inboxView',
</ins><span class="cx" style="display: block; padding: 0 10px"> '' : 'inboxView'
</span><span class="cx" style="display: block; padding: 0 10px"> },
</span><span class="cx" style="display: block; padding: 0 10px">
</span></span></pre>
</div>
</div>
</body>
</html>