mirror of
https://github.com/oxen-io/session-android.git
synced 2023-12-14 02:53:01 +01:00
This was a holdover from Signal's origins as a pure SMS app. It causes problems, depends on undefined device specific behavior, and should no longer be necessary now that we have all the information we need to E164 all numbers. // FREEBIE
57 lines
1.6 KiB
Java
57 lines
1.6 KiB
Java
package org.thoughtcrime.securesms.database;
|
|
|
|
import android.support.annotation.NonNull;
|
|
import android.util.Log;
|
|
|
|
import org.thoughtcrime.securesms.util.LRUCache;
|
|
|
|
public class EarlyReceiptCache {
|
|
|
|
private static final String TAG = EarlyReceiptCache.class.getSimpleName();
|
|
|
|
private final LRUCache<Placeholder, Long> cache = new LRUCache<>(100);
|
|
|
|
public synchronized void increment(long timestamp, Address address) {
|
|
Log.w(TAG, this+"");
|
|
Log.w(TAG, String.format("Early receipt: %d,%s", timestamp, address));
|
|
Placeholder tuple = new Placeholder(timestamp, address);
|
|
Long count = cache.get(tuple);
|
|
|
|
if (count != null) {
|
|
cache.put(tuple, ++count);
|
|
} else {
|
|
cache.put(tuple, 1L);
|
|
}
|
|
}
|
|
|
|
public synchronized long remove(long timestamp, Address address) {
|
|
Long count = cache.remove(new Placeholder(timestamp, address));
|
|
Log.w(TAG, this+"");
|
|
Log.w(TAG, String.format("Checking early receipts (%d, %s): %d", timestamp, address, count));
|
|
return count != null ? count : 0;
|
|
}
|
|
|
|
private class Placeholder {
|
|
|
|
private final long timestamp;
|
|
private final @NonNull Address address;
|
|
|
|
private Placeholder(long timestamp, @NonNull Address address) {
|
|
this.timestamp = timestamp;
|
|
this.address = address;
|
|
}
|
|
|
|
@Override
|
|
public boolean equals(Object other) {
|
|
return other != null && other instanceof Placeholder &&
|
|
((Placeholder)other).timestamp == this.timestamp &&
|
|
((Placeholder)other).address.equals(this.address);
|
|
}
|
|
|
|
@Override
|
|
public int hashCode() {
|
|
return (int)timestamp ^ address.hashCode();
|
|
}
|
|
}
|
|
}
|