#1073 Add delay to email recovery command

- Add configurable cooldown period after sending an email for /email recovery
- Change ExpiringMap to remove expired entries (like ExpiringSet)
- Create method to translate durations via the messages file
This commit is contained in:
ljacqu
2017-02-25 22:41:49 +01:00
parent a4b440bcca
commit c197a330f3
11 changed files with 252 additions and 72 deletions
@@ -83,23 +83,22 @@ public class ExpiringSet<E> {
/**
* Returns the duration of the entry until it expires (provided it is not removed or re-added).
* If the entry does not exist, -1 is returned.
* If the entry does not exist, a duration of -1 seconds is returned.
*
* @param entry the entry whose duration before it expires should be returned
* @param unit the unit in which to return the duration
* @return duration the entry will remain in the set (if there are not modifications)
*/
public long getExpiration(E entry, TimeUnit unit) {
public Duration getExpiration(E entry) {
Long expiration = entries.get(entry);
if (expiration == null) {
return -1;
return new Duration(-1, TimeUnit.SECONDS);
}
long stillPresentMillis = expiration - System.currentTimeMillis();
if (stillPresentMillis < 0) {
entries.remove(entry);
return -1;
return new Duration(-1, TimeUnit.SECONDS);
}
return unit.convert(stillPresentMillis, TimeUnit.MILLISECONDS);
return Duration.createWithSuitableUnit(stillPresentMillis, TimeUnit.MILLISECONDS);
}
/**