Skip to content

Commit

Permalink
Fix current rate limit reset on another user and minor UI updates.
Browse files Browse the repository at this point in the history
  • Loading branch information
iamdharmesh committed Dec 18, 2024
1 parent eddffdc commit cd51aa2
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
5 changes: 5 additions & 0 deletions assets/css/admin-autoshare-for-twitter.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
Expand Down
21 changes: 17 additions & 4 deletions includes/core.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand All @@ -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;
}

Expand Down Expand Up @@ -314,7 +318,7 @@ function display_rate_monitor_dashboard_widget() {

if ( empty( $accounts ) ) {
printf(
'<p>%s</p>',
'<p class="autoshare-for-twitter-no-accounts">%s</p>',
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;
Expand Down Expand Up @@ -343,8 +347,10 @@ function display_rate_monitor_dashboard_widget() {
$users_rate_limits_markup .= sprintf(
'<div class="autoshare-for-twitter-rate-monitor__user">
<img src="%1$s" alt="%2$s" class="twitter-account-profile-image">
<h3>@%3$s</h3>
%4$s
<div class="autoshare-for-twitter-rate-monitor__user-info">
<h3>@%3$s</h3>
%4$s
</div>
</div>',
esc_url( $account['profile_image_url'] ),
esc_attr( $account['name'] ),
Expand Down Expand Up @@ -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(
'<p>%s</p>',
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,
Expand Down Expand Up @@ -512,4 +525,4 @@ function get_rate_limits_markup( $title, $remaining, $limit, $reset ) {
esc_html( $reset )
)
);
}
}
2 changes: 1 addition & 1 deletion src/js/components/TwitterAccounts.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<p>
{ __(
Expand Down

0 comments on commit cd51aa2

Please sign in to comment.