From cd51aa2d9cfed07dbd2679163cab2522958b1220 Mon Sep 17 00:00:00 2001 From: Dharmesh Patel Date: Wed, 18 Dec 2024 11:10:13 +0530 Subject: [PATCH] Fix current rate limit reset on another user and minor UI updates. --- assets/css/admin-autoshare-for-twitter.css | 5 +++++ includes/core.php | 21 +++++++++++++++++---- src/js/components/TwitterAccounts.js | 2 +- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/assets/css/admin-autoshare-for-twitter.css b/assets/css/admin-autoshare-for-twitter.css index 00ae27e2..4b4f372d 100644 --- a/assets/css/admin-autoshare-for-twitter.css +++ b/assets/css/admin-autoshare-for-twitter.css @@ -271,6 +271,10 @@ tbody .autoshare-for-twitter-status-logo--disabled::before { margin-top: 0px; } +.autoshare-for-twitter-no-accounts { + padding: 0px 12px 12px 12px; +} + .autoshare-for-twitter-rate-monitor__users { border-top: 1px solid #f0f0f1; } @@ -294,6 +298,7 @@ tbody .autoshare-for-twitter-status-logo--disabled::before { margin-right: 10px; } +.autoshare-for-twitter-rate-monitor__user-info p, .autoshare-for-twitter-rate-monitor__rate p { margin-bottom: 0; margin-top: 0; diff --git a/includes/core.php b/includes/core.php index 8f3703a9..9bf4f2cd 100644 --- a/includes/core.php +++ b/includes/core.php @@ -275,6 +275,7 @@ function update_account_rate_limits( $response, $update_data, $post, $account_id ); foreach ( $accounts as $key => $account ) { + $current_rate_limits = ( isset( $account['rate_limits'] ) && is_array( $account['rate_limits'] ) ) ? $account['rate_limits'] : array(); // Update the "global" and app rate limits on all accounts. $account_rate_limits = array_merge( $rate_limits, $app_rate_limits ); @@ -284,6 +285,9 @@ function update_account_rate_limits( $response, $update_data, $post, $account_id $account_rate_limits = array_merge( $user_rate_limits, $account_rate_limits ); } + // Merge the current rate limits with the new rate limits. + $account_rate_limits = array_merge( $current_rate_limits, $account_rate_limits ); + $accounts[ $key ]['rate_limits'] = $account_rate_limits; } @@ -314,7 +318,7 @@ function display_rate_monitor_dashboard_widget() { if ( empty( $accounts ) ) { printf( - '

%s

', + '

%s

', esc_html__( 'No X/Twitter accounts are connected. Please connect at least one X/Twitter account to continue using Autopost for X.', 'autoshare-for-twitter' ) ); return; @@ -343,8 +347,10 @@ function display_rate_monitor_dashboard_widget() { $users_rate_limits_markup .= sprintf( '
-

@%3$s

- %4$s +
', esc_url( $account['profile_image_url'] ), esc_attr( $account['name'] ), @@ -451,6 +457,13 @@ function get_user_rate_limits_markup( $rate_limits ) { $limit = isset( $rate_limits['user_limit_24hour_limit'] ) ? $rate_limits['user_limit_24hour_limit'] : ''; $reset = isset( $rate_limits['user_limit_24hour_reset'] ) ? $rate_limits['user_limit_24hour_reset'] : ''; + if ( empty( $remaining ) && empty( $limit ) && empty( $reset ) ) { + return sprintf( + '

%s

', + esc_html__( 'No X/Twitter rate limit available yet. Make a post to X/Twitter first.', 'autoshare-for-twitter' ) + ); + } + return get_rate_limits_markup( __( 'User 24-Hour Limit:', 'autoshare-for-twitter' ), $remaining, @@ -512,4 +525,4 @@ function get_rate_limits_markup( $title, $remaining, $limit, $reset ) { esc_html( $reset ) ) ); -} \ No newline at end of file +} diff --git a/src/js/components/TwitterAccounts.js b/src/js/components/TwitterAccounts.js index 1fcdca6d..8b77f9ac 100644 --- a/src/js/components/TwitterAccounts.js +++ b/src/js/components/TwitterAccounts.js @@ -105,7 +105,7 @@ function TwitterAccount( props ) { * @return {JSX.Element} The account rate limits. */ function TwitterUserRateLimits( { rate_limits: rateLimits } ) { - if ( ! rateLimits ) { + if ( ! rateLimits || ! rateLimits.user_limit_24hour_limit ) { return (

{ __(