Skip to content

Commit

Permalink
Reply inline
Browse files Browse the repository at this point in the history
  • Loading branch information
akirk committed Apr 26, 2024
1 parent e1979b1 commit 41bbd38
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 156 deletions.
56 changes: 0 additions & 56 deletions feed-parsers/class-feed-parser-activitypub.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ public function __construct( Feed $friends_feed ) {

\add_filter( 'friends_reblog_button_label', array( $this, 'friends_reblog_button_label' ), 10, 2 );
\add_filter( 'friends_search_autocomplete', array( $this, 'friends_search_autocomplete' ), 10, 2 );
\add_action( 'wp_ajax_friends-in-reply-to-preview', array( $this, 'ajax_in_reply_to_preview' ) );

\add_filter( 'friends_reblog', array( $this, 'unqueue_activitypub_create' ), 9 );
\add_action( 'mastodon_api_reblog', array( $this, 'mastodon_api_reblog' ) );
Expand Down Expand Up @@ -1729,61 +1728,6 @@ public function friends_reblog_button_label( $button_label ) {
return $button_label;
}


/**
* Get metadata for in_reply_to_preview.
*
* @param string $url The url.
*
* @return array|WP_Error The in reply to metadata.
*/
public function get_activitypub_ajax_metadata( $url ) {
$meta = apply_filters( 'friends_get_activitypub_metadata', array(), $url );
if ( is_wp_error( $meta ) ) {
return $meta;
}

if ( ! $meta || ! isset( $meta['attributedTo'] ) ) {
return new \WP_Error( 'no-activitypub', 'No ActivityPub metadata found.' );
}

$html = force_balance_tags( wp_kses_post( $meta['content'] ) );

$webfinger = apply_filters( 'friends_get_activitypub_metadata', array(), $meta['attributedTo'] );
$mention = '';
if ( $webfinger && ! is_wp_error( $webfinger ) ) {
$mention = '@' . $webfinger['preferredUsername'] . '@' . wp_parse_url( $url, PHP_URL_HOST );
}

return array(
'url' => $url,
'html' => $html,
'author' => $meta['attributedTo'],
'mention' => $mention,
);
}

/**
* The Ajax function to fill the in-reply-to-preview.
*/
public function ajax_in_reply_to_preview() {
check_ajax_referer( 'friends-in-reply-to-preview' );
$url = wp_unslash( $_POST['url'] );

if ( ! wp_parse_url( $url ) ) {
wp_send_json_error();
exit;
}

$meta = $this->get_activitypub_ajax_metadata( $_POST['url'] );

if ( is_wp_error( $meta ) ) {
wp_send_json_error( $meta->get_error_message() );
exit;
}
wp_send_json_success( $meta );
}

public function friends_search_autocomplete( $results, $q ) {
$url = preg_match( '#^(https?:\/\/)?(?:w{3}\.)?[\w-]+(?:\.[\w-]+)+((?:\/[^\s\/]*)*)#i', $q, $m );
$url_with_path = isset( $m[2] ) && $m[2];
Expand Down
2 changes: 1 addition & 1 deletion friends.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion friends.css.map

Large diffs are not rendered by default.

63 changes: 4 additions & 59 deletions friends.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,11 +280,12 @@
}

const $this = $( this );
const content = $this.closest( 'article' ).find( '.comments-content' );
const commentsContent = $this.closest( 'article' ).find( '.comments-content' );
const content = commentsContent.find( '.comments-list' );
if ( content.data( 'loaded' ) ) {
content.toggle();
commentsContent.toggle();
} else {
content.show();
commentsContent.show();
wp.ajax.send( 'friends-load-comments', {
data: {
_ajax_nonce: $this.data( 'cnonce' ),
Expand Down Expand Up @@ -559,62 +560,6 @@
}
}

$document.on( 'click', '.activitypub_preview a', function () {
if ( ! $( this ).hasClass( 'mention' ) ) {
return true;
}
insertTextInGutenberg( getAcct( $( this ).attr( 'href' ) ) );
return false;
} );

$document.on( 'keyup', 'input.activitypub_preview_url', function () {
const input = $( this );
const form = input.closest( 'form' );
const preview = form.find( '.activitypub_preview' );
const url = input.val().trim();

if ( alreadySearching === url ) {
return;
}

preview.html( '<figcaption><a href=""></a></figcaption><blockquote>' );
preview.find( 'blockquote' ).text( friends.text_checking_url );
preview.find( 'a' ).attr( 'href', url ).text( url );
form.find( '.boost-link' ).attr( 'href', '?boost=' + escape( url ) );
form.find( '.reply-to-link' ).attr( 'href', '?in_reply_to=' + escape( url ) );

const searchIndicator = input
.closest( '.form-autocomplete-input' )
.find( '.form-icon' );

wp.ajax.send( 'friends-in-reply-to-preview', {
data: {
_ajax_nonce: input.data( 'nonce' ),
url,
},
beforeSend() {
searchIndicator.addClass( 'loading' );
alreadySearching = url;
},
success( results ) {
searchIndicator.removeClass( 'loading' );
if ( results ) {
preview.find( 'blockquote' ).html( results.html ).show();
input.closest( 'form' ).find( 'button' ).prop( 'disabled', false );
insertTextInGutenberg( getAcct( results.author ) );
} else {
preview.hide();
input.closest( 'form' ).find( 'button' ).prop( 'disabled', false );
}
},
error( results ) {
searchIndicator.removeClass( 'loading' );
input.closest( 'form' ).find( 'button' ).prop( 'disabled', true );
preview.find( 'blockquote' ).text( results ).show();
},
} );
} );

$document.on( 'click', '.quick-reply', function () {
$( '#quick-post-panel' ).addClass( 'open' );
$( '#quick-post-panel input#friends_in_reply_to' )
Expand Down
32 changes: 27 additions & 5 deletions friends.scss
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ div {
@import "node_modules/spectre.css/src/utilities/loading";
@import "node_modules/spectre.css/src/utilities/colors";
@import "node_modules/spectre.css/src/utilities/divider";
@import "node_modules/spectre.css/src/utilities/display";
@import "node_modules/spectre.css/src/utilities/position";

.friends-dropdown {
Expand Down Expand Up @@ -238,23 +239,31 @@ h2#page-title a.dashicons {

article {
.card-body {

img,
video {
max-width: 100% !important;
height: auto;
}
}

&.format-status {
div.teaser {
display: none;
}

border-bottom: 1px solid $dark-color;
padding-bottom: 2em;
margin-bottom: 2em;

header {
div.overflow, div.post-meta, div.teaser {

div.overflow,
div.post-meta,
div.teaser {
margin-top: .4em;
}

div.overflow {
.btn {
margin-top: -.5em;
Expand Down Expand Up @@ -362,6 +371,7 @@ h2#page-title a.dashicons {
}
}
}

.friends-sidebar-customize {
margin-left: 1.5rem;
color: #999;
Expand Down Expand Up @@ -392,6 +402,7 @@ h2#page-title a.dashicons {
&.open {
display: block;
}

p.description {
font-color: $dark-color;
font-size: .6rem;
Expand All @@ -404,8 +415,10 @@ h2#page-title a.dashicons {
margin-bottom: 1em;
max-height: 6em;
overflow-y: auto;

figcaption {
float: right;

a:any-link {
color: #999;
}
Expand Down Expand Up @@ -536,29 +549,35 @@ h2#page-title a.dashicons {
padding-bottom: 0;
margin-bottom: .5em;
width: 100%;

.overflow {
width: 6em;
margin-left: 1em;
}

div.teaser {
text-overflow: ellipsis;
width: calc(100% - 7em);
overflow: hidden;
white-space: nowrap;
display: inline-block;

@media (min-width: $off-canvas-breakpoint) {
width: calc(100% - 25em);
}
}

header {
padding-left: 0;
margin-bottom: 0;

div.post-meta {
max-width: 15em;
max-height: 1.5em;
overflow: hidden;
text-overflow: ellipsis;
}

div.avatar {
display: block;
}
Expand Down Expand Up @@ -674,19 +693,22 @@ h2#page-title a.dashicons {
.invisible {
font-size: 0;
line-height: 0;
display:inline-block;
display: inline-block;
width: 0;
height: 0;
position:absolute;
img, svg{
position: absolute;

img,
svg {
margin: 0 !important;
border: 0 !important;
padding: 0 !important;
width: 0 !important;
height: 0 !important
}
}
.ellipsis::after{

.ellipsis::after {
content: ""
}
}
2 changes: 1 addition & 1 deletion templates/frontend/error-message.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div class="card-body message">
<strong class="message"><?php echo wp_kses_post( $args['message'] ); ?></strong>
<?php if ( $args['error'] ) : ?>
<div class="error"><?php echo wp_kses_post( $args['error'] ); ?></div>
<blockquote class="error"><?php echo wp_kses_post( $args['error'] ); ?></blockquote>
<?php endif; ?>
</div>
</div>
12 changes: 11 additions & 1 deletion templates/frontend/parts/comments-content.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,14 @@
* @package Friends
*/

?><footer class="comments-content card-footer"></footer>
?><footer class="comments-content card-footer">
<div class="comments-list"></div>
<?php
comment_form(
array(
'title_reply' => __( 'Send a reply', 'friends' ),
'logged_in_as' => '',
)
);
?>
</footer>
2 changes: 1 addition & 1 deletion templates/frontend/parts/comments.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

$args['friends']->frontend->link(
get_comments_link(),
get_comments_number(),
__( 'Comments' ), // phpcs:ignore
array(
'class' => 'comments btn ml-1',
'dashicon_front' => 'admin-comments',
Expand Down
31 changes: 0 additions & 31 deletions templates/frontend/parts/footer-status.php

This file was deleted.

0 comments on commit 41bbd38

Please sign in to comment.