Skip to content

Commit

Permalink
Merge pull request #5 from hivepress/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
hivepress committed Jun 6, 2019
2 parents ddec780 + dc52245 commit bb40c52
Show file tree
Hide file tree
Showing 32 changed files with 538 additions and 389 deletions.
2 changes: 1 addition & 1 deletion assets/css/frontend.less
Expand Up @@ -16,7 +16,7 @@
}

&--view-block &__date,
&__sender {
&--view-block &__sender {
&:not(:last-child) {
margin-right: 0.5rem;
}
Expand Down
2 changes: 1 addition & 1 deletion assets/css/frontend.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion hivepress-messages.php
Expand Up @@ -2,7 +2,7 @@
/**
* Plugin Name: HivePress Messages
* Description: Private messages extension for HivePress plugin.
* Version: 1.1.0
* Version: 1.1.1
* Author: HivePress
* Author URI: https://hivepress.io/
* Text Domain: hivepress-messages
Expand Down
10 changes: 5 additions & 5 deletions includes/blocks/class-messages.php
Expand Up @@ -45,7 +45,7 @@ public function render() {
// Get messages.
$messages = [];

if ( 'select' === $this->template ) {
if ( 'thread' === $this->template ) {
$all_messages = wp_list_sort(
array_merge(
get_comments(
Expand Down Expand Up @@ -108,7 +108,7 @@ public function render() {

// Render messages.
if ( ! empty( $messages ) ) {
if ( 'select' === $this->template ) {
if ( 'thread' === $this->template ) {
$output .= '<table class="hp-table">';
} else {
$output .= '<div class="hp-grid">';
Expand All @@ -120,7 +120,7 @@ public function render() {
$message = Models\Message::get( $message_args->comment_ID );

if ( ! is_null( $message ) ) {
if ( 'select' === $this->template ) {
if ( 'thread' === $this->template ) {

// Set sender.
if ( $message->get_sender_id() === get_current_user_id() ) {
Expand All @@ -147,13 +147,13 @@ public function render() {
]
) )->render();

if ( 'select' !== $this->template ) {
if ( 'thread' !== $this->template ) {
$output .= '</div>';
}
}
}

if ( 'select' === $this->template ) {
if ( 'thread' === $this->template ) {
$output .= '</table>';
} else {
$output .= '</div>';
Expand Down
162 changes: 157 additions & 5 deletions includes/components/class-message.php
Expand Up @@ -27,7 +27,16 @@ public function __construct() {
// Delete messages.
add_action( 'delete_user', [ $this, 'delete_messages' ] );

if ( ! is_admin() ) {
if ( is_admin() ) {

// Hide messages.
add_filter( 'comments_clauses', [ $this, 'hide_messages' ] );
} else {

// Alter templates.
add_filter( 'hivepress/v1/templates/listing_view_block', [ $this, 'alter_listing_view_block' ] );
add_filter( 'hivepress/v1/templates/listing_view_page', [ $this, 'alter_listing_view_page' ] );
add_filter( 'hivepress/v1/templates/vendor_view_page', [ $this, 'alter_vendor_view_page' ] );

// Set page title.
add_filter( 'hivepress/v1/controllers/message/routes/view_messages', [ $this, 'set_page_title' ] );
Expand All @@ -49,14 +58,14 @@ public function delete_messages( $user_id ) {
get_comments(
[
'type' => 'hp_message',
'user_id' => get_current_user_id(),
'user_id' => $user_id,
'fields' => 'ids',
]
),
get_comments(
[
'type' => 'hp_message',
'karma' => get_current_user_id(),
'karma' => $user_id,
'fields' => 'ids',
]
)
Expand All @@ -68,6 +77,149 @@ public function delete_messages( $user_id ) {
}
}

/**
* Hides messages.
*
* @param array $query Query arguments.
* @return array
*/
public function hide_messages( $query ) {
global $pagenow;

if ( in_array( $pagenow, [ 'index.php', 'edit-comments.php' ], true ) ) {
$query['where'] .= ' AND comment_type != "hp_message"';
}

return $query;
}

/**
* Alters listing view block.
*
* @param array $template Template arguments.
* @return array
*/
public function alter_listing_view_block( $template ) {
return hp\merge_trees(
$template,
[
'blocks' => [
'listing_actions_primary' => [
'blocks' => [
'message_send_modal' => [
'type' => 'modal',
'model' => 'listing',
'caption' => esc_html__( 'Reply to Listing', 'hivepress-messages' ),

'blocks' => [
'message_send_form' => [
'type' => 'message_send_form',
'order' => 10,

'attributes' => [
'class' => [ 'hp-form--narrow' ],
],
],
],
],

'message_send_link' => [
'type' => 'element',
'filepath' => 'listing/view/block/message-send-link',
'order' => 10,
],
],
],
],
],
'blocks'
);
}

/**
* Alters listing view page.
*
* @param array $template Template arguments.
* @return array
*/
public function alter_listing_view_page( $template ) {
return hp\merge_trees(
$template,
[
'blocks' => [
'listing_actions_primary' => [
'blocks' => [
'message_send_modal' => [
'type' => 'modal',
'caption' => esc_html__( 'Reply to Listing', 'hivepress-messages' ),

'blocks' => [
'message_send_form' => [
'type' => 'message_send_form',
'order' => 10,

'attributes' => [
'class' => [ 'hp-form--narrow' ],
],
],
],
],

'message_send_button' => [
'type' => 'element',
'filepath' => 'listing/view/page/message-send-link',
'order' => 10,
],
],
],
],
],
'blocks'
);
}

/**
* Alters vendor view page.
*
* @param array $template Template arguments.
* @return array
*/
public function alter_vendor_view_page( $template ) {
return hp\merge_trees(
$template,
[
'blocks' => [
'vendor_actions_primary' => [
'blocks' => [
'message_send_modal' => [
'type' => 'modal',
'caption' => esc_html__( 'Send Message', 'hivepress-messages' ),

'blocks' => [
'message_send_form' => [
'type' => 'message_send_form',
'order' => 10,

'attributes' => [
'class' => [ 'hp-form--narrow' ],
],
],
],
],

'message_send_button' => [
'type' => 'element',
'filepath' => 'vendor/view/page/message-send-link',
'order' => 10,
],
],
],
],
],
'blocks'
);
}

/**
* Sets page title.
*
Expand Down Expand Up @@ -115,8 +267,8 @@ public function add_menu_items( $menu ) {
if ( ! empty( $message_ids ) ) {

// Add menu item.
$menu['items']['select_messages'] = [
'route' => 'message/select_messages',
$menu['items']['thread_messages'] = [
'route' => 'message/thread_messages',
'order' => 30,
];
}
Expand Down
50 changes: 0 additions & 50 deletions includes/configs/templates/listing-view-block.php

This file was deleted.

53 changes: 0 additions & 53 deletions includes/configs/templates/listing-view-page.php

This file was deleted.

0 comments on commit bb40c52

Please sign in to comment.