That fuck shit the fascists are using
1package org.tm.archive.database;
2
3import androidx.annotation.NonNull;
4
5import org.signal.core.util.logging.Log;
6import org.tm.archive.recipients.RecipientId;
7import org.tm.archive.util.LRUCache;
8
9import java.util.HashMap;
10import java.util.Map;
11
12public class EarlyDeliveryReceiptCache {
13
14 private static final String TAG = Log.tag(EarlyDeliveryReceiptCache.class);
15
16 private final LRUCache<Long, Map<RecipientId, Receipt>> cache = new LRUCache<>(100);
17
18 public synchronized void increment(long targetTimestamp, @NonNull RecipientId receiptAuthor, long receiptSentTimestamp) {
19 Map<RecipientId, Receipt> receipts = cache.get(targetTimestamp);
20
21 if (receipts == null) {
22 receipts = new HashMap<>();
23 }
24
25 Receipt receipt = receipts.get(receiptAuthor);
26
27 if (receipt != null) {
28 receipt.count++;
29 receipt.timestamp = receiptSentTimestamp;
30 } else {
31 receipt = new Receipt(1, receiptSentTimestamp);
32 }
33 receipts.put(receiptAuthor, receipt);
34
35 cache.put(targetTimestamp, receipts);
36 }
37
38 public synchronized Map<RecipientId, Receipt> remove(long timestamp) {
39 Map<RecipientId, Receipt> receipts = cache.remove(timestamp);
40 return receipts != null ? receipts : new HashMap<>();
41 }
42
43 public static class Receipt {
44 private long count;
45 private long timestamp;
46
47 private Receipt(long count, long timestamp) {
48 this.count = count;
49 this.timestamp = timestamp;
50 }
51
52 public long getCount() {
53 return count;
54 }
55
56 public long getTimestamp() {
57 return timestamp;
58 }
59 }
60}