mirror of
https://github.com/lingble/chatwoot.git
synced 2025-11-20 21:15:01 +00:00
feat: Retry failed messages within 24h (#12436)
Fixes [CW-5540](https://linear.app/chatwoot/issue/CW-5540/feat-allow-retry-a-failed-message-sendout), https://github.com/chatwoot/chatwoot/issues/12333 ## Type of change - [x] New feature (non-breaking change which adds functionality) ## How Has This Been Tested? ### Screenshot <img width="196" height="113" alt="image" src="https://github.com/user-attachments/assets/8b4a1aa9-c75c-4169-b4a2-e89148647e91" /> ## Checklist: - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my code - [x] I have commented on my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [x] My changes generate no new warnings - [x] I have added tests that prove my fix is effective or that my feature works - [x] New and existing unit tests pass locally with my changes - [ ] Any dependent changes have been merged and published in downstream modules --------- Co-authored-by: Muhsin Keloth <muhsinkeramam@gmail.com>
This commit is contained in:
@@ -3,6 +3,7 @@ import {
|
||||
isSameYear,
|
||||
fromUnixTime,
|
||||
formatDistanceToNow,
|
||||
differenceInDays,
|
||||
} from 'date-fns';
|
||||
|
||||
/**
|
||||
@@ -91,3 +92,25 @@ export const shortTimestamp = (time, withAgo = false) => {
|
||||
.replace(' years ago', `y${suffix}`);
|
||||
return convertToShortTime;
|
||||
};
|
||||
|
||||
/**
|
||||
* Calculates the difference in days between now and a given timestamp.
|
||||
* @param {Date} now - Current date/time.
|
||||
* @param {number} timestampInSeconds - Unix timestamp in seconds.
|
||||
* @returns {number} Number of days difference.
|
||||
*/
|
||||
export const getDayDifferenceFromNow = (now, timestampInSeconds) => {
|
||||
const date = new Date(timestampInSeconds * 1000);
|
||||
return differenceInDays(now, date);
|
||||
};
|
||||
|
||||
/**
|
||||
* Checks if more than 24 hours have passed since a given timestamp.
|
||||
* Useful for determining if retry/refresh actions should be disabled.
|
||||
* @param {number} timestamp - Unix timestamp.
|
||||
* @returns {boolean} True if more than 24 hours have passed.
|
||||
*/
|
||||
export const hasOneDayPassed = timestamp => {
|
||||
if (!timestamp) return true; // Defensive check
|
||||
return getDayDifferenceFromNow(new Date(), timestamp) >= 1;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user