<!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][13114] trunk/src: Make sure deleting an activity comment also deletes its children</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/13114">13114</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/13114","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-09-24 01:54:39 +0000 (Fri, 24 Sep 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'>Make sure deleting an activity comment also deletes its children
This commit also takes care of redirecting the user to the activity single view when clicking on the comment button and there is no comment form available for the corresponding activity. This case can happen on a single member's activity stream when the main activity is an activity comment.
Props yesbutmaybeno
Fixes <a href="http://buddypress.trac.wordpress.org/ticket/8415">#8415</a></pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcbpactivitybpactivitytemplatephp">trunk/src/bp-activity/bp-activity-template.php</a></li>
<li><a href="#trunksrcbptemplatesbplegacyjsbuddypressjs">trunk/src/bp-templates/bp-legacy/js/buddypress.js</a></li>
<li><a href="#trunksrcbptemplatesbpnouveaubuddypressactivitycommentphp">trunk/src/bp-templates/bp-nouveau/buddypress/activity/comment.php</a></li>
<li><a href="#trunksrcbptemplatesbpnouveaubuddypressactivityentryphp">trunk/src/bp-templates/bp-nouveau/buddypress/activity/entry.php</a></li>
<li><a href="#trunksrcbptemplatesbpnouveauincludesactivityajaxphp">trunk/src/bp-templates/bp-nouveau/includes/activity/ajax.php</a></li>
<li><a href="#trunksrcbptemplatesbpnouveauincludesactivitytemplatetagsphp">trunk/src/bp-templates/bp-nouveau/includes/activity/template-tags.php</a></li>
<li><a href="#trunksrcbptemplatesbpnouveaujsbuddypressactivityjs">trunk/src/bp-templates/bp-nouveau/js/buddypress-activity.js</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcbpactivitybpactivitytemplatephp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/bp-activity/bp-activity-template.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/bp-activity/bp-activity-template.php 2021-09-24 01:18:04 UTC (rev 13113)
+++ trunk/src/bp-activity/bp-activity-template.php 2021-09-24 01:54:39 UTC (rev 13114)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2677,6 +2677,8 @@
</span><span class="cx" style="display: block; padding: 0 10px"> // Determine if we're on a single activity page, and customize accordingly.
</span><span class="cx" style="display: block; padding: 0 10px"> if ( bp_is_activity_component() && is_numeric( bp_current_action() ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $class = 'delete-activity-single';
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ } elseif ( 'activity_comment' === bp_get_activity_type() ) {
+ $class = 'acomment-delete';
</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"> $link = '<a href="' . esc_url( $url ) . '" class="button item-button bp-secondary-action ' . $class . ' confirm" rel="nofollow">' . __( 'Delete', 'buddypress' ) . '</a>';
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2713,11 +2715,18 @@
</span><span class="cx" style="display: block; padding: 0 10px"> function bp_get_activity_delete_url() {
</span><span class="cx" style="display: block; padding: 0 10px"> global $activities_template;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $url = trailingslashit( bp_get_root_domain() . '/' . bp_get_activity_root_slug() . '/delete/' . $activities_template->activity->id );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $activity_id = 0;
+ if ( isset( $activities_template->activity->id ) ) {
+ $activity_id = (int) $activities_template->activity->id;
+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $url = trailingslashit( bp_get_root_domain() . '/' . bp_get_activity_root_slug() . '/delete/' . $activity_id );
+
</ins><span class="cx" style="display: block; padding: 0 10px"> // Determine if we're on a single activity page, and customize accordingly.
</span><span class="cx" style="display: block; padding: 0 10px"> if ( bp_is_activity_component() && is_numeric( bp_current_action() ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $url = add_query_arg( array( 'redirect_to' => wp_get_referer() ), $url );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ } elseif ( 'activity_comment' === bp_get_activity_type() ) {
+ $url = add_query_arg( 'cid', $activity_id, $url );
</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"> $url = wp_nonce_url( $url, 'bp_activity_delete_link' );
</span></span></pre></div>
<a id="trunksrcbptemplatesbplegacyjsbuddypressjs"></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/js/buddypress.js</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/bp-templates/bp-legacy/js/buddypress.js 2021-09-24 01:18:04 UTC (rev 13113)
+++ trunk/src/bp-templates/bp-legacy/js/buddypress.js 2021-09-24 01:54:39 UTC (rev 13114)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -557,6 +557,16 @@
</span><span class="cx" style="display: block; padding: 0 10px"> c_id = target.attr('href').substr( 10, target.attr('href').length );
</span><span class="cx" style="display: block; padding: 0 10px"> form = jq( '#ac-form-' + a_id );
</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 ( ! form.length ) {
+ var viewDiscussionLink = target.closest( 'li.activity' ).find( '.activity-meta a.view' ).prop( 'href' );
+
+ if ( viewDiscussionLink ) {
+ window.location.href = viewDiscussionLink;
+ }
+
+ return false;
+ }
+
</ins><span class="cx" style="display: block; padding: 0 10px"> form.css( 'display', 'none' );
</span><span class="cx" style="display: block; padding: 0 10px"> form.removeClass('root');
</span><span class="cx" style="display: block; padding: 0 10px"> jq('.ac-form').hide();
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -671,9 +681,10 @@
</span><span class="cx" style="display: block; padding: 0 10px"> /* Deleting an activity comment */
</span><span class="cx" style="display: block; padding: 0 10px"> if ( target.hasClass('acomment-delete') ) {
</span><span class="cx" style="display: block; padding: 0 10px"> link_href = target.attr('href');
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- comment_li = target.parent().parent();
- form = comment_li.parents('div.activity-comments').children('form');
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ comment_li = target.closest( 'li' );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ form = comment_li.find( 'form.ac-form' );
+
</ins><span class="cx" style="display: block; padding: 0 10px"> nonce = link_href.split('_wpnonce=');
</span><span class="cx" style="display: block; padding: 0 10px"> nonce = nonce[1];
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -687,7 +698,9 @@
</span><span class="cx" style="display: block; padding: 0 10px"> jq('.activity-comments ul .error').remove();
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /* Reset the form position */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- comment_li.parents('.activity-comments').append(form);
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( form && form.length ) {
+ comment_li.closest( '.activity-comments' ).append( form );
+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> jq.post( ajaxurl, {
</span><span class="cx" style="display: block; padding: 0 10px"> action: 'delete_activity_comment',
</span></span></pre></div>
<a id="trunksrcbptemplatesbpnouveaubuddypressactivitycommentphp"></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/activity/comment.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/bp-templates/bp-nouveau/buddypress/activity/comment.php 2021-09-24 01:18:04 UTC (rev 13113)
+++ trunk/src/bp-templates/bp-nouveau/buddypress/activity/comment.php 2021-09-24 01:54:39 UTC (rev 13114)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -6,12 +6,12 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * each activity.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 3.0.0
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @version 7.0.0
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @version 10.0.0
</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"> bp_nouveau_activity_hook( 'before', 'comment' ); ?>
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-<li id="acomment-<?php bp_activity_comment_id(); ?>" class="comment-item" data-bp-activity-comment-id="<?php bp_activity_comment_id(); ?>">
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<li id="acomment-<?php bp_activity_comment_id(); ?>" class="comment-item" <?php bp_nouveau_activity_data_attribute_id(); ?>>
</ins><span class="cx" style="display: block; padding: 0 10px"> <div class="acomment-avatar item-avatar">
</span><span class="cx" style="display: block; padding: 0 10px"> <a href="<?php bp_activity_comment_user_link(); ?>">
</span><span class="cx" style="display: block; padding: 0 10px"> <?php
</span></span></pre></div>
<a id="trunksrcbptemplatesbpnouveaubuddypressactivityentryphp"></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/activity/entry.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/bp-templates/bp-nouveau/buddypress/activity/entry.php 2021-09-24 01:18:04 UTC (rev 13113)
+++ trunk/src/bp-templates/bp-nouveau/buddypress/activity/entry.php 2021-09-24 01:54:39 UTC (rev 13114)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -6,12 +6,12 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * each activity.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 3.0.0
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @version 3.0.0
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @version 10.0.0
</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"> bp_nouveau_activity_hook( 'before', 'entry' ); ?>
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-<li class="<?php bp_activity_css_class(); ?>" id="activity-<?php bp_activity_id(); ?>" data-bp-activity-id="<?php bp_activity_id(); ?>" data-bp-timestamp="<?php bp_nouveau_activity_timestamp(); ?>">
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<li class="<?php bp_activity_css_class(); ?>" id="activity-<?php bp_activity_id(); ?>" <?php bp_nouveau_activity_data_attribute_id(); ?> data-bp-timestamp="<?php bp_nouveau_activity_timestamp(); ?>">
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> <div class="activity-avatar item-avatar">
</span><span class="cx" style="display: block; padding: 0 10px">
</span></span></pre></div>
<a id="trunksrcbptemplatesbpnouveauincludesactivityajaxphp"></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/includes/activity/ajax.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/bp-templates/bp-nouveau/includes/activity/ajax.php 2021-09-24 01:18:04 UTC (rev 13113)
+++ trunk/src/bp-templates/bp-nouveau/includes/activity/ajax.php 2021-09-24 01:54:39 UTC (rev 13114)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -3,7 +3,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * Activity Ajax functions
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 3.0.0
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @version 8.1.0
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @version 10.0.0
</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"> // Exit if accessed directly.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -232,8 +232,21 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Deleting an activity comment.
</span><span class="cx" style="display: block; padding: 0 10px"> if ( ! empty( $_POST['is_comment'] ) ) {
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Get replies before they are deleted.
+ $replies = (array) BP_Activity_Activity::get_child_comments( $activity->id );
+ $reply_ids = wp_list_pluck( $replies, 'id' );
+
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( ! bp_activity_delete_comment( $activity->item_id, $activity->id ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> wp_send_json_error( $response );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ // The comment and its replies has been deleted successfully.
+ } else {
+ $response = array(
+ 'deleted' => array_merge(
+ array( $activity->id ),
+ $reply_ids
+ ),
+ );
</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"> // Deleting an activity.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -240,6 +253,12 @@
</span><span class="cx" style="display: block; padding: 0 10px"> } else {
</span><span class="cx" style="display: block; padding: 0 10px"> if ( ! bp_activity_delete( array( 'id' => $activity->id, 'user_id' => $activity->user_id ) ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> wp_send_json_error( $response );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ // The activity has been deleted successfully.
+ } else {
+ $response = array(
+ 'deleted' => array( $activity->id ),
+ );
</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">@@ -246,9 +265,6 @@
</span><span class="cx" style="display: block; padding: 0 10px"> /** This action is documented in bp-activity/bp-activity-actions.php */
</span><span class="cx" style="display: block; padding: 0 10px"> do_action( 'bp_activity_action_delete_activity', $activity->id, $activity->user_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">- // The activity has been deleted successfully
- $response = array( 'deleted' => $activity->id );
-
</del><span class="cx" style="display: block; padding: 0 10px"> // If on a single activity redirect to user's home.
</span><span class="cx" style="display: block; padding: 0 10px"> if ( ! empty( $_POST['is_single'] ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $response['redirect'] = bp_core_get_user_domain( $activity->user_id );
</span></span></pre></div>
<a id="trunksrcbptemplatesbpnouveauincludesactivitytemplatetagsphp"></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/includes/activity/template-tags.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/bp-templates/bp-nouveau/includes/activity/template-tags.php 2021-09-24 01:18:04 UTC (rev 13113)
+++ trunk/src/bp-templates/bp-nouveau/includes/activity/template-tags.php 2021-09-24 01:54:39 UTC (rev 13114)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -3,7 +3,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * Activity Template tags
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 3.0.0
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @version 8.1.0
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @version 10.0.0
</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"> // Exit if accessed directly.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -147,6 +147,30 @@
</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">+ * Output the `data-bp-activity-id` or `data-bp-activity-comment-id` attribute
+ * according to the activity type.
+ *
+ * @since 10.0.0
+ */
+function bp_nouveau_activity_data_attribute_id() {
+ $attribute = 'data-bp-%1$s-id="%2$s"';
+ $type = 'activity';
+ $id = (int) bp_get_activity_id();
+ $comment_id = (int) bp_get_activity_comment_id();
+
+ if ( 'activity_comment' === bp_get_activity_type() || $comment_id ) {
+ $type = 'activity-comment';
+
+
+ if ( $comment_id ) {
+ $id = $comment_id;
+ }
+ }
+
+ printf( $attribute, $type, $id );
+}
+
+/**
</ins><span class="cx" style="display: block; padding: 0 10px"> * Checks if an activity of the loop has some content.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 3.0.0
</span></span></pre></div>
<a id="trunksrcbptemplatesbpnouveaujsbuddypressactivityjs"></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/js/buddypress-activity.js</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/bp-templates/bp-nouveau/js/buddypress-activity.js 2021-09-24 01:18:04 UTC (rev 13113)
+++ trunk/src/bp-templates/bp-nouveau/js/buddypress-activity.js 2021-09-24 01:54:39 UTC (rev 13114)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1,7 +1,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> /* jshint browser: true */
</span><span class="cx" style="display: block; padding: 0 10px"> /* global BP_Nouveau */
</span><span class="cx" style="display: block; padding: 0 10px"> /* @since 3.0.0 */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-/* @version 8.0.0 */
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+/* @version 10.0.0 */
</ins><span class="cx" style="display: block; padding: 0 10px"> window.bp = window.bp || {};
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> ( function( bp, $ ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -556,6 +556,11 @@
</span><span class="cx" style="display: block; padding: 0 10px"> li_parent = activity_comment_li;
</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">+ // Move the form if needed
+ if ( activity_comment_li.find( 'form' ).length ) {
+ activity_item.find( '.activity-comments' ).append( activity_comment_li.find( 'form' ) );
+ }
+
</ins><span class="cx" style="display: block; padding: 0 10px"> parent.ajax( ajaxData, 'activity' ).done( function( response ) {
</span><span class="cx" style="display: block; padding: 0 10px"> target.removeClass( 'loading' );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -570,15 +575,19 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if ( activity_comment_id ) {
</span><span class="cx" style="display: block; padding: 0 10px"> deleted_comments_count = 1;
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( response.data.deleted ) {
+ deleted_comments_count = response.data.deleted.length;
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // Move the form if needed
- activity_item.append( activity_comment_li.find( 'form' ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ response.data.deleted.forEach( function( cid ) {
+ $( '[data-bp-activity-comment-id="' + cid + '"]' ).remove();
+ } );
+ } else {
+ // Count child comments if there are some
+ $.each( activity_comment_li.find( 'li' ), function() {
+ deleted_comments_count += 1;
+ } );
+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // Count child comments if there are some
- $.each( activity_comment_li.find( 'li' ), function() {
- deleted_comments_count += 1;
- } );
-
</del><span class="cx" style="display: block; padding: 0 10px"> // Update the button count
</span><span class="cx" style="display: block; padding: 0 10px"> comment_count_span = activity_item.find( '.acomment-reply span.comment-count' );
</span><span class="cx" style="display: block; padding: 0 10px"> comment_count = Number( comment_count_span.html() - deleted_comments_count );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -660,6 +669,16 @@
</span><span class="cx" style="display: block; padding: 0 10px"> // Stop event propagation
</span><span class="cx" style="display: block; padding: 0 10px"> event.preventDefault();
</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 ( ! form.length ) {
+ var viewDiscussionLink = target.closest( 'li.activity' ).find( '.activity-meta a.view' ).prop( 'href' );
+
+ if ( viewDiscussionLink ) {
+ window.location.href = viewDiscussionLink;
+ }
+
+ return false;
+ }
+
</ins><span class="cx" style="display: block; padding: 0 10px"> // If the comment count span inside the link is clicked
</span><span class="cx" style="display: block; padding: 0 10px"> if ( target.parent().hasClass( 'acomment-reply' ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> comment_link = target.parent();
</span></span></pre>
</div>
</div>
</body>
</html>