<!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][13179] trunk/src: Add a new "Recycle" tab to the Avatar UI</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/13179">13179</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/13179","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>2021-12-11 18:52:01 +0000 (Sat, 11 Dec 2021)</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'>Add a new "Recycle" tab to the Avatar UI

Thanks to this tab users can manage their avatars history. They can choose to:
- reuse a previously uploaded avatar as their current profile photo,
- permanently delete an avatar from their avatars history.

Props vapvarun, oztaser

See <a href="http://buddypress.trac.wordpress.org/ticket/8581">#8581</a></pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcbpcorebpcoreattachmentsphp">trunk/src/bp-core/bp-core-attachments.php</a></li>
<li><a href="#trunksrcbpcorecssavatarrtlcss">trunk/src/bp-core/css/avatar-rtl.css</a></li>
<li><a href="#trunksrcbpcorecssavatarcss">trunk/src/bp-core/css/avatar.css</a></li>
<li><a href="#trunksrcbpcorejsavatarjs">trunk/src/bp-core/js/avatar.js</a></li>
<li><a href="#trunksrcbptemplatesbplegacybuddypressassets_attachmentsavatarsindexphp">trunk/src/bp-templates/bp-legacy/buddypress/assets/_attachments/avatars/index.php</a></li>
<li><a href="#trunksrcbptemplatesbpnouveaubuddypressassets_attachmentsavatarsindexphp">trunk/src/bp-templates/bp-nouveau/buddypress/assets/_attachments/avatars/index.php</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunksrcbptemplatesbplegacybuddypressassets_attachmentsavatarsrecyclephp">trunk/src/bp-templates/bp-legacy/buddypress/assets/_attachments/avatars/recycle.php</a></li>
<li><a href="#trunksrcbptemplatesbpnouveaubuddypressassets_attachmentsavatarsrecyclephp">trunk/src/bp-templates/bp-nouveau/buddypress/assets/_attachments/avatars/recycle.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcbpcorebpcoreattachmentsphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/bp-core/bp-core-attachments.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/bp-core/bp-core-attachments.php 2021-12-11 14:13:14 UTC (rev 13178)
+++ trunk/src/bp-core/bp-core-attachments.php   2021-12-11 18:52:01 UTC (rev 13179)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -409,24 +409,28 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        // It's an avatar, we need to crop it.
</span><span class="cx" style="display: block; padding: 0 10px">        if ( 'avatar' === $type ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $created = bp_core_avatar_handle_crop( array(
-                       'object'        => $r['object'],
-                       'avatar_dir'    => trim( dirname( $attachment_data['subdir'] ), '/' ),
-                       'item_id'       => (int) $r['item_id'],
-                       'original_file' => trailingslashit( $attachment_data['subdir'] ) . $image_file_name,
-                       'crop_w'        => $r['crop_w'],
-                       'crop_h'        => $r['crop_h'],
-                       'crop_x'        => $r['crop_x'],
-                       'crop_y'        => $r['crop_y']
-               ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $created = bp_core_avatar_handle_crop(
+                       array(
+                               'object'        => $r['object'],
+                               'avatar_dir'    => trim( dirname( $attachment_data['subdir'] ), '/' ),
+                               'item_id'       => (int) $r['item_id'],
+                               'original_file' => trailingslashit( $attachment_data['subdir'] ) . $image_file_name,
+                               'crop_w'        => $r['crop_w'],
+                               'crop_h'        => $r['crop_h'],
+                               'crop_x'        => $r['crop_x'],
+                               'crop_y'        => $r['crop_y']
+                       )
+               );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        // It's a cover image we need to fit it to feature's dimensions.
</span><span class="cx" style="display: block; padding: 0 10px">        } elseif ( 'cover_image' === $type ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $cover_image = bp_attachments_cover_image_generate_file( array(
-                       'file'            => $image_file_path,
-                       'component'       => $r['component'],
-                       'cover_image_dir' => $attachment_data['path']
-               ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $cover_image = bp_attachments_cover_image_generate_file(
+                       array(
+                               'file'            => $image_file_path,
+                               'component'       => $r['component'],
+                               'cover_image_dir' => $attachment_data['path']
+                       )
+               );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $created = ! empty( $cover_image['cover_file'] );
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -787,23 +791,58 @@
</span><span class="cx" style="display: block; padding: 0 10px">                // Avatar only need 1 file and 1 only!
</span><span class="cx" style="display: block; padding: 0 10px">                $defaults['multi_selection'] = false;
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                // Does the object already has an avatar set.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         // Does the object already has an avatar set?
</ins><span class="cx" style="display: block; padding: 0 10px">                 $has_avatar = $defaults['multipart_params']['bp_params']['has_avatar'];
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                // What is the object the avatar belongs to.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         // What is the object the avatar belongs to?
</ins><span class="cx" style="display: block; padding: 0 10px">                 $object = $defaults['multipart_params']['bp_params']['object'];
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                // Get The item id.
+               $item_id = $defaults['multipart_params']['bp_params']['item_id'];
+
</ins><span class="cx" style="display: block; padding: 0 10px">                 // Init the Avatar nav.
</span><span class="cx" style="display: block; padding: 0 10px">                $avatar_nav = array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        'upload' => array( 'id' => 'upload', 'caption' => __( 'Upload', 'buddypress' ), 'order' => 0  ),
-
-                       // The delete view will only show if the object has an avatar.
-                       'delete' => array( 'id' => 'delete', 'caption' => __( 'Delete', 'buddypress' ), 'order' => 100, 'hide' => (int) ! $has_avatar ),
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 'upload'  => array(
+                               'id'      => 'upload',
+                               'caption' => __( 'Upload', 'buddypress' ),
+                               'order'   => 0
+                       ),
+                       'delete'  => array(
+                               'id'      => 'delete',
+                               'caption' => __( 'Delete', 'buddypress' ),
+                               'order'   => 100,
+                               'hide'    => (int) ! $has_avatar
+                       ),
</ins><span class="cx" style="display: block; padding: 0 10px">                 );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                if ( 'user' === $object ) {
+                       // Look inside history to see if the user previously uploaded avatars.
+                       $avatars_history = bp_avatar_get_avatars_history( $item_id, $object );
+
+                       if ( $avatars_history ) {
+                               ksort( $avatars_history );
+                               $settings['history']       = array_values( $avatars_history );
+                               $settings['historyNonces'] = array(
+                                       'recylePrevious' => wp_create_nonce( 'bp_avatar_recycle_previous' ),
+                                       'deletePrevious' => wp_create_nonce( 'bp_avatar_delete_previous' ),
+                               );
+
+                               $avatar_nav['recycle'] = array(
+                                       'id'      => 'recycle',
+                                       'caption' => __( 'Recycle', 'buddypress' ),
+                                       'order'   => 20,
+                                       'hide'    => (int) empty( $avatars_history ),
+                               );
+                       }
+               }
+
</ins><span class="cx" style="display: block; padding: 0 10px">                 // Create the Camera Nav if the WebCam capture feature is enabled.
</span><span class="cx" style="display: block; padding: 0 10px">                if ( bp_avatar_use_webcam() && 'user' === $object ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        $avatar_nav['camera'] = array( 'id' => 'camera', 'caption' => __( 'Take Photo', 'buddypress' ), 'order' => 10 );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 $avatar_nav['camera'] = array(
+                               'id'      => 'camera',
+                               'caption' => __( 'Take Photo', 'buddypress' ),
+                               'order'   => 10
+                       );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                        // Set warning messages.
</span><span class="cx" style="display: block; padding: 0 10px">                        $strings['camera_warnings'] = array(
</span></span></pre></div>
<a id="trunksrcbpcorecssavatarrtlcss"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/bp-core/css/avatar-rtl.css</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/bp-core/css/avatar-rtl.css      2021-12-11 14:13:14 UTC (rev 13178)
+++ trunk/src/bp-core/css/avatar-rtl.css        2021-12-11 18:52:01 UTC (rev 13179)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -397,6 +397,53 @@
</span><span class="cx" style="display: block; padding: 0 10px">        line-height: inherit;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+.avatars-history {
+       display: flex;
+       flex-direction: row;
+}
+
+.avatar-history-list {
+       order: 1;
+       width: 80%;
+       max-height: 250px;
+       overflow-y: auto;
+}
+
+.avatar-history-list label {
+       display: block;
+       margin: 0 auto;
+       width: 60px;
+}
+
+.avatar-history-table td .avatar {
+       vertical-align: middle;
+}
+
+.avatar-history-table td .avatar.selected {
+       border: solid 4px #065288;
+}
+
+.avatar-history-actions {
+       order: 2;
+       margin-right: 1em;
+       text-align: center;
+}
+
+.avatar-history-actions p.warning {
+       text-align: right;
+}
+
+.avatar-history-actions button.delete:not(.disabled):hover {
+       background-color: #800;
+       color: #fff;
+}
+
+.avatar-history-actions button.delete:not(.disabled) {
+       background-color: #fdc;
+       border: 1px solid #a00;
+       color: #800;
+}
+
</ins><span class="cx" style="display: block; padding: 0 10px"> @media screen and (min-width: 810px) {
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        .wp-admin #TB_window .bp-avatar #bp-webcam-avatar #avatar-to-crop {
</span></span></pre></div>
<a id="trunksrcbpcorecssavatarcss"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/bp-core/css/avatar.css</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/bp-core/css/avatar.css  2021-12-11 14:13:14 UTC (rev 13178)
+++ trunk/src/bp-core/css/avatar.css    2021-12-11 18:52:01 UTC (rev 13179)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -397,6 +397,53 @@
</span><span class="cx" style="display: block; padding: 0 10px">        line-height: inherit;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+.avatars-history {
+       display: flex;
+       flex-direction: row;
+}
+
+.avatar-history-list {
+       order: 1;
+       width: 80%;
+       max-height: 250px;
+       overflow-y: auto;
+}
+
+.avatar-history-list label {
+       display: block;
+       margin: 0 auto;
+       width: 60px;
+}
+
+.avatar-history-table td .avatar {
+       vertical-align: middle;
+}
+
+.avatar-history-table td .avatar.selected {
+       border: solid 4px #065288;
+}
+
+.avatar-history-actions {
+       order: 2;
+       margin-left: 1em;
+       text-align: center;
+}
+
+.avatar-history-actions p.warning {
+       text-align: left;
+}
+
+.avatar-history-actions button.delete:not(.disabled):hover {
+       background-color: #800;
+       color: #fff;
+}
+
+.avatar-history-actions button.delete:not(.disabled) {
+       background-color: #fdc;
+       border: 1px solid #a00;
+       color: #800;
+}
+
</ins><span class="cx" style="display: block; padding: 0 10px"> @media screen and (min-width: 810px) {
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        .wp-admin #TB_window .bp-avatar #bp-webcam-avatar #avatar-to-crop {
</span></span></pre></div>
<a id="trunksrcbpcorejsavatarjs"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/bp-core/js/avatar.js</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/bp-core/js/avatar.js    2021-12-11 14:13:14 UTC (rev 13178)
+++ trunk/src/bp-core/js/avatar.js      2021-12-11 18:52:01 UTC (rev 13179)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -39,6 +39,9 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        // The Avatar Attachment object.
</span><span class="cx" style="display: block; padding: 0 10px">                        this.Attachment = new Backbone.Model();
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                        // The Avatars history.
+                       this.historicAvatars = null;
+
</ins><span class="cx" style="display: block; padding: 0 10px">                         // Wait till the queue is reset.
</span><span class="cx" style="display: block; padding: 0 10px">                        bp.Uploader.filesQueue.on( 'reset', this.cropView, this );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -115,6 +118,10 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                case 'delete':
</span><span class="cx" style="display: block; padding: 0 10px">                                        this.deleteView();
</span><span class="cx" style="display: block; padding: 0 10px">                                        break;
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+                               case 'recycle':
+                                       this.recycleView();
+                                       break;
</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">@@ -303,7 +310,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">-                deleteView:function() {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         deleteView: function() {
</ins><span class="cx" style="display: block; padding: 0 10px">                         // Create the delete model.
</span><span class="cx" style="display: block; padding: 0 10px">                        var delete_model = new Backbone.Model( _.pick( BP_Uploader.settings.defaults.multipart_params.bp_params,
</span><span class="cx" style="display: block; padding: 0 10px">                                'object',
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -332,7 +339,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                this.views.remove( { id: 'delete', view: deleteView } );
</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">-                        // Remove the avatar !
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 // Remove the avatar!
</ins><span class="cx" style="display: block; padding: 0 10px">                         bp.ajax.post( 'bp_avatar_delete', {
</span><span class="cx" style="display: block; padding: 0 10px">                                json:          true,
</span><span class="cx" style="display: block; padding: 0 10px">                                item_id:       model.get( 'item_id' ),
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -407,6 +414,126 @@
</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">                        this.warning.inject( '.bp-avatar-status' );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                },
+
+               recycleView: function() {
+                       if ( ! this.historicAvatars ) {
+                               this.historicAvatars = new Backbone.Collection( BP_Uploader.settings.history );
+                       }
+
+                       // Create the recycle view.
+                       var recycleView = new bp.Views.RecycleAvatar( { collection: this.historicAvatars } );
+
+                       // Add it to views.
+                       this.views.add( { id: 'recycle', view: recycleView } );
+
+                       // Display it.
+                       recycleView.inject( '.bp-avatar' );
+               },
+
+               recycleHistoricAvatar: function( model ) {
+                       var self = this;
+                       model.set( 'selected', false );
+
+                       // Recycle the avatar.
+                       bp.ajax.post( 'bp_avatar_recycle_previous', {
+                               json: true,
+                               item_id: BP_Uploader.settings.defaults.multipart_params.bp_params.item_id,
+                               avatar_id: model.get( 'id' ),
+                               object: BP_Uploader.settings.defaults.multipart_params.bp_params.object,
+                               nonce: BP_Uploader.settings.historyNonces.recylePrevious
+                       } ).done( function( response ) {
+                               if ( response.historicalAvatar ) {
+                                       model.collection.add( response.historicalAvatar );
+                               }
+
+                               model.collection.remove( model );
+
+                               if ( response.feedback_code ) {
+                                       var avatarStatus = new bp.Views.AvatarStatus( {
+                                               value : BP_Uploader.strings.feedback_messages[ response.feedback_code ],
+                                               type : 'success'
+                                       } );
+
+                                       self.views.add( {
+                                               id   : 'status',
+                                               view : avatarStatus
+                                       } );
+
+                                       avatarStatus.inject( '.bp-avatar-status' );
+                               }
+
+                               // Update each avatars of the page.
+                               $( '.' + BP_Uploader.settings.defaults.multipart_params.bp_params.object + '-' + response.item_id + '-avatar' ).each( function() {
+                                       $( this ).prop( 'src', response.avatar );
+                               } );
+
+                       } ).fail( function( response ) {
+                               var error_message = BP_Uploader.strings.default_error;
+                               if ( response && response.message ) {
+                                       error_message = response.message;
+                               }
+
+                               var avatarStatus = new bp.Views.AvatarStatus( {
+                                       value : error_message,
+                                       type : 'error'
+                               } );
+
+                               self.views.add( {
+                                       id   : 'status',
+                                       view : avatarStatus
+                               } );
+
+                               avatarStatus.inject( '.bp-avatar-status' );
+                       } );
+               },
+
+               deletePreviousAvatar: function( model ) {
+                       var self = this;
+                       model.set( 'selected', false );
+
+                       // Recycle the avatar.
+                       bp.ajax.post( 'bp_avatar_delete_previous', {
+                               json: true,
+                               item_id: BP_Uploader.settings.defaults.multipart_params.bp_params.item_id,
+                               avatar_id: model.get( 'id' ),
+                               object: BP_Uploader.settings.defaults.multipart_params.bp_params.object,
+                               nonce: BP_Uploader.settings.historyNonces.deletePrevious
+                       } ).done( function( response ) {
+                               model.collection.remove( model );
+
+                               if ( response.feedback_code ) {
+                                       var avatarStatus = new bp.Views.AvatarStatus( {
+                                               value : BP_Uploader.strings.feedback_messages[ response.feedback_code ],
+                                               type : 'success'
+                                       } );
+
+                                       self.views.add( {
+                                               id   : 'status',
+                                               view : avatarStatus
+                                       } );
+
+                                       avatarStatus.inject( '.bp-avatar-status' );
+                               }
+
+                       } ).fail( function( response ) {
+                               var error_message = BP_Uploader.strings.default_error;
+                               if ( response && response.message ) {
+                                       error_message = response.message;
+                               }
+
+                               var avatarStatus = new bp.Views.AvatarStatus( {
+                                       value : error_message,
+                                       type : 'error'
+                               } );
+
+                               self.views.add( {
+                                       id   : 'status',
+                                       view : avatarStatus
+                               } );
+
+                               avatarStatus.inject( '.bp-avatar-status' );
+                       } );
</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">@@ -677,6 +804,95 @@
</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><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+        bp.Views.HistoryAvatarsItem = bp.View.extend( {
+               tagName: 'tr',
+               className: 'historic-avatar',
+               template: bp.template( 'bp-avatar-recycle-history-item' ),
+
+               events: {
+                       'change input[name="avatar_id"]': 'selectAvatar'
+               },
+
+               initialize: function() {
+                       this.model.on( 'change:selected', this.toggleSelection, this );
+                       this.model.on( 'remove', this.clearView, this );
+               },
+
+               toggleSelection: function( model, selected ) {
+                       if ( true === selected ) {
+                               this.$el.parent().find( '#' + model.get( 'id' ) ).addClass( 'selected' );
+                       } else {
+                               this.$el.parent().find( '#' + model.get( 'id' ) ).removeClass( 'selected' );
+                               this.$el.parent().find( '#avatar_' + model.get( 'id' ) ).prop( 'checked', false );
+                       }
+               },
+
+               selectAvatar: function( event ) {
+                       event.preventDefault();
+
+                       if ( event.currentTarget.checked ) {
+                               var self = this;
+
+                               _.each( this.model.collection.models, function( model ) {
+                                       self.$el.parent().find( '#' + model.id ).removeClass( 'selected' );
+                                       model.set( 'selected', false, { silent: true } );
+                               } );
+
+                               this.model.set( 'selected', true );
+                       }
+               },
+
+               clearView: function() {
+                       this.views.view.remove();
+               }
+       } );
+
+       bp.Views.RecycleAvatar = bp.View.extend( {
+               tagName: 'div',
+               id: 'bp-avatars-history-container',
+               template: bp.template( 'bp-avatar-recycle' ),
+
+               events: {
+                       'click button.avatar-history-action': 'doAvatarAction'
+               },
+
+               initialize: function() {
+                       _.each( this.collection.models, function( model ) {
+                               this.views.add( '#bp-avatars-history-list', new bp.Views.HistoryAvatarsItem( { model: model } ) );
+                       }, this );
+
+                       this.collection.on( 'change:selected', this.updateButtonStatus, this );
+                       this.collection.on( 'add', this.addView, this );
+               },
+
+               addView: function( model ) {
+                       this.views.add( '#bp-avatars-history-list', new bp.Views.HistoryAvatarsItem( { model: model } ) );
+               },
+
+               updateButtonStatus: function( model ) {
+                       if ( true === model.get( 'selected' ) ) {
+                               this.$el.find( 'button.disabled' ).removeClass( 'disabled' );
+                       }
+               },
+
+               doAvatarAction: function( event ) {
+                       event.preventDefault();
+                       var buttonClasses = event.currentTarget.classList,
+                           selected = this.collection.findWhere( { selected: true } );
+
+                       if ( ! buttonClasses.contains( 'disabled' ) && selected ) {
+                               // Make sure it's not possible to fire 2 actions at the same time.
+                               this.$el.find( 'button.avatar-history-action' ).addClass( 'disabled' );
+
+                               if ( buttonClasses.contains( 'recycle' ) ) {
+                                       bp.Avatar.recycleHistoricAvatar( selected );
+                               } else if ( buttonClasses.contains( 'delete' ) ) {
+                                       bp.Avatar.deletePreviousAvatar( selected );
+                               }
+                       }
+               }
+       } );
+
</ins><span class="cx" style="display: block; padding: 0 10px">         bp.Avatar.start();
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px"> })( window.bp, jQuery );
</span></span></pre></div>
<a id="trunksrcbptemplatesbplegacybuddypressassets_attachmentsavatarsindexphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/bp-templates/bp-legacy/buddypress/assets/_attachments/avatars/index.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/bp-templates/bp-legacy/buddypress/assets/_attachments/avatars/index.php 2021-12-11 14:13:14 UTC (rev 13178)
+++ trunk/src/bp-templates/bp-legacy/buddypress/assets/_attachments/avatars/index.php   2021-12-11 18:52:01 UTC (rev 13179)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -33,6 +33,8 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px"> <?php bp_attachments_get_template_part( 'avatars/camera' ); ?>
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php bp_attachments_get_template_part( 'avatars/recycle' ); ?>
+
</ins><span class="cx" style="display: block; padding: 0 10px"> <script id="tmpl-bp-avatar-delete" type="text/html">
</span><span class="cx" style="display: block; padding: 0 10px">        <# if ( 'user' === data.object ) { #>
</span><span class="cx" style="display: block; padding: 0 10px">                <p><?php _e( "If you'd like to delete your current profile photo but not upload a new one, please use the delete profile photo button.", 'buddypress' ); ?></p>
</span></span></pre></div>
<a id="trunksrcbptemplatesbplegacybuddypressassets_attachmentsavatarsrecyclephp"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: trunk/src/bp-templates/bp-legacy/buddypress/assets/_attachments/avatars/recycle.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/bp-templates/bp-legacy/buddypress/assets/_attachments/avatars/recycle.php                               (rev 0)
+++ trunk/src/bp-templates/bp-legacy/buddypress/assets/_attachments/avatars/recycle.php 2021-12-11 18:52:01 UTC (rev 13179)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,46 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+/**
+ * BuddyPress Avatars recycle template.
+ *
+ * This template is used to create the recycle Backbone views.
+ *
+ * @since 10.0.0
+ * @version 10.0.0
+ */
+?>
+<script id="tmpl-bp-avatar-recycle" type="text/html">
+       <div class="avatars-history">
+               <div class="avatar-history-list">
+                       <table class="avatar-history-table">
+                               <thead>
+                                       <tr>
+                                               <th><?php esc_html_e( 'Profile photo', 'buddypress' ); ?></th>
+                                               <th><?php esc_html_e( 'Uploaded on', 'buddypress' ); ?></th>
+                                       </tr>
+                               </thead>
+                               <tbody id="bp-avatars-history-list"></tbody>
+                       </table>
+               </div>
+               <div class="avatar-history-actions">
+                       <p class="warning"><?php esc_html_e( 'Click on a profile photo from your history to recycle it as your current profile photo or delete it.', 'buddypress' ); ?></p>
+                       <button class="avatar-history-action recycle disabled">
+                               <?php esc_html_e( 'Recycle', 'buddypress' ); ?>
+                       </button>
+                       <button class="avatar-history-action delete disabled">
+                               <?php esc_html_e( 'Delete', 'buddypress' ); ?>
+                       </button>
+               </div>
+       </div>
+</script>
+
+<script id="tmpl-bp-avatar-recycle-history-item" type="text/html">
+       <td>
+               <label for="avatar_{{data.id}}">
+                       <input type="radio" name="avatar_id" value="{{data.id}}" id="avatar_{{data.id}}" class="bp-screen-reader-text"/>
+                       <img src="{{{data.url}}}" id="{{data.id}}" class="avatar" width="<?php echo esc_attr( bp_core_avatar_thumb_width() ); ?>" height="<?php echo esc_attr( bp_core_avatar_thumb_height() ); ?>"/>
+               </label>
+       </td>
+       <td>
+               <span class="time">{{data.date}}</span>
+       </td>
+</script>
</ins><span class="cx" style="display: block; padding: 0 10px">Property changes on: trunk/src/bp-templates/bp-legacy/buddypress/assets/_attachments/avatars/recycle.php
</span><span class="cx" style="display: block; padding: 0 10px">___________________________________________________________________
</span></span></pre></div>
<a id="svneolstyle"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: svn:eol-style</h4></div>
<ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+native
</ins><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of property
</span><a id="trunksrcbptemplatesbpnouveaubuddypressassets_attachmentsavatarsindexphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/bp-templates/bp-nouveau/buddypress/assets/_attachments/avatars/index.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/bp-templates/bp-nouveau/buddypress/assets/_attachments/avatars/index.php        2021-12-11 14:13:14 UTC (rev 13178)
+++ trunk/src/bp-templates/bp-nouveau/buddypress/assets/_attachments/avatars/index.php  2021-12-11 18:52:01 UTC (rev 13179)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -30,6 +30,8 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px"> <?php bp_attachments_get_template_part( 'avatars/camera' ); ?>
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php bp_attachments_get_template_part( 'avatars/recycle' ); ?>
+
</ins><span class="cx" style="display: block; padding: 0 10px"> <script id="tmpl-bp-avatar-delete" type="text/html">
</span><span class="cx" style="display: block; padding: 0 10px">        <# if ( 'user' === data.object ) { #>
</span><span class="cx" style="display: block; padding: 0 10px">                <p><?php esc_html_e( "If you'd like to delete your current profile photo, use the delete profile photo button.", 'buddypress' ); ?></p>
</span></span></pre></div>
<a id="trunksrcbptemplatesbpnouveaubuddypressassets_attachmentsavatarsrecyclephp"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: trunk/src/bp-templates/bp-nouveau/buddypress/assets/_attachments/avatars/recycle.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/bp-templates/bp-nouveau/buddypress/assets/_attachments/avatars/recycle.php                              (rev 0)
+++ trunk/src/bp-templates/bp-nouveau/buddypress/assets/_attachments/avatars/recycle.php        2021-12-11 18:52:01 UTC (rev 13179)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,46 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+/**
+ * BuddyPress Avatars recycle template.
+ *
+ * This template is used to create the recycle Backbone views.
+ *
+ * @since 10.0.0
+ * @version 10.0.0
+ */
+?>
+<script id="tmpl-bp-avatar-recycle" type="text/html">
+       <div class="avatars-history">
+               <div class="avatar-history-list">
+                       <table class="avatar-history-table">
+                               <thead>
+                                       <tr>
+                                               <th><?php esc_html_e( 'Profile photo', 'buddypress' ); ?></th>
+                                               <th><?php esc_html_e( 'Uploaded on', 'buddypress' ); ?></th>
+                                       </tr>
+                               </thead>
+                               <tbody id="bp-avatars-history-list"></tbody>
+                       </table>
+               </div>
+               <div class="avatar-history-actions">
+                       <p class="warning"><?php esc_html_e( 'Click on a profile photo from your history to recycle it as your current profile photo or delete it.', 'buddypress' ); ?></p>
+                       <button class="avatar-history-action recycle disabled">
+                               <?php esc_html_e( 'Recycle', 'buddypress' ); ?>
+                       </button>
+                       <button class="avatar-history-action delete disabled">
+                               <?php esc_html_e( 'Delete', 'buddypress' ); ?>
+                       </button>
+               </div>
+       </div>
+</script>
+
+<script id="tmpl-bp-avatar-recycle-history-item" type="text/html">
+       <td>
+               <label for="avatar_{{data.id}}">
+                       <input type="radio" name="avatar_id" value="{{data.id}}" id="avatar_{{data.id}}" class="bp-screen-reader-text"/>
+                       <img src="{{{data.url}}}" id="{{data.id}}" class="avatar" width="<?php echo esc_attr( bp_core_avatar_thumb_width() ); ?>" height="<?php echo esc_attr( bp_core_avatar_thumb_height() ); ?>"/>
+               </label>
+       </td>
+       <td>
+               <span class="time">{{data.date}}</span>
+       </td>
+</script>
</ins><span class="cx" style="display: block; padding: 0 10px">Property changes on: trunk/src/bp-templates/bp-nouveau/buddypress/assets/_attachments/avatars/recycle.php
</span><span class="cx" style="display: block; padding: 0 10px">___________________________________________________________________
</span></span></pre></div>
<a id="svneolstyle"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: svn:eol-style</h4></div>
<ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+native
</ins><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of property
</span></div>

</body>
</html>