v0.5.1: bubble for Android 0.5.1 — no double sends when a text with an emoji is cut off mid-send
voip.ms's listing drops emoji, so a send whose reply was lost (here the laptop slept 8 s after Send) never matched its own copy in the listing and went out a second time. Match with the emoji taken out (exact match first), and after an uncertain send only send again once a listing check actually got through; if none can, mark it failed with a note instead.
This commit is contained in:
@@ -26,7 +26,12 @@ final class Sender {
|
||||
|
||||
private static final int MAX_ATTEMPTS = 3;
|
||||
private static final long[] RETRY_DELAYS = {3000, 10_000};
|
||||
private static final long[] CHECK_DELAYS = {5000, 15_000};
|
||||
// After a send that may have gone out (no reply), look for it in the listing
|
||||
// before sending again. Two looks that got through are enough; the later
|
||||
// ones are for a network that's still coming back.
|
||||
private static final long[] CHECK_DELAYS = {5000, 15_000, 30_000, 60_000, 120_000};
|
||||
private static final int CHECKS_NEEDED = 2;
|
||||
static final String UNCHECKED = "This may have gone out, but there was no connection to check. Retry if it didn't arrive.";
|
||||
|
||||
/** A photo already saved into files/media. */
|
||||
static final class Photo {
|
||||
@@ -158,10 +163,18 @@ final class Sender {
|
||||
if (store.getMessage(tempId) == null) return null; // a check found it already sent
|
||||
String kind = classify(e, gv);
|
||||
if (kind.equals("unknown")) {
|
||||
// Never send again without having seen that it isn't in the listing.
|
||||
int looked = 0;
|
||||
for (long ms : CHECK_DELAYS) {
|
||||
sleep(ms);
|
||||
Sync.poll(c);
|
||||
if ((gv ? Sync.gvError : Sync.voipError) == null) looked++;
|
||||
if (store.getMessage(tempId) == null) return null;
|
||||
if (looked >= CHECKS_NEEDED) break;
|
||||
}
|
||||
if (looked == 0) {
|
||||
store.markFailed(tempId, UNCHECKED);
|
||||
return UNCHECKED;
|
||||
}
|
||||
}
|
||||
if (kind.equals("fatal") || n >= MAX_ATTEMPTS) {
|
||||
|
||||
@@ -217,14 +217,35 @@ final class Store {
|
||||
sorted.sort(Comparator.comparingLong(a -> a.ts));
|
||||
for (Msg m : sorted) {
|
||||
if (m.in() || m.id < 0) continue;
|
||||
try (Cursor c = db.rawQuery("SELECT id FROM messages WHERE id < 0 AND status IN ('pending','failed') AND direction = 'out'"
|
||||
+ " AND did = ? AND contact = ? AND body = ? AND ts BETWEEN ? AND ? ORDER BY ts, id DESC LIMIT 1",
|
||||
new String[] {m.did, m.contact, m.body, String.valueOf(m.ts - MATCH_AFTER), String.valueOf(m.ts + MATCH_BEFORE)})) {
|
||||
if (c.moveToFirst()) confirmPending(c.getLong(0), m.id);
|
||||
// voip.ms's listing drops emoji, so an exact match first, then one without them.
|
||||
long exact = 0, loose = 0;
|
||||
String key = withoutEmoji(m.body);
|
||||
try (Cursor c = db.rawQuery("SELECT id, body FROM messages WHERE id < 0 AND status IN ('pending','failed') AND direction = 'out'"
|
||||
+ " AND did = ? AND contact = ? AND ts BETWEEN ? AND ? ORDER BY ts, id DESC",
|
||||
new String[] {m.did, m.contact, String.valueOf(m.ts - MATCH_AFTER), String.valueOf(m.ts + MATCH_BEFORE)})) {
|
||||
while (c.moveToNext() && exact == 0) {
|
||||
String body = c.getString(1) == null ? "" : c.getString(1);
|
||||
if (body.equals(m.body)) exact = c.getLong(0);
|
||||
else if (loose == 0 && withoutEmoji(body).equals(key)) loose = c.getLong(0);
|
||||
}
|
||||
}
|
||||
long id = exact != 0 ? exact : loose;
|
||||
if (id != 0) confirmPending(id, m.id);
|
||||
}
|
||||
}
|
||||
|
||||
/** A text with its emoji (and their joiners and variation selectors) taken out, trimmed. */
|
||||
static String withoutEmoji(String s) {
|
||||
if (s == null) return "";
|
||||
StringBuilder out = new StringBuilder();
|
||||
s.codePoints().forEach(c -> {
|
||||
boolean emoji = c >= 0x1F000 || (c >= 0x2600 && c <= 0x27BF) || (c >= 0x2300 && c <= 0x23FF) || (c >= 0x2B00 && c <= 0x2BFF)
|
||||
|| (c >= 0xFE00 && c <= 0xFE0F) || c == 0x200D || c == 0x20E3;
|
||||
if (!emoji) out.appendCodePoint(c);
|
||||
});
|
||||
return out.toString().trim();
|
||||
}
|
||||
|
||||
void deleteMessage(long id) {
|
||||
db.execSQL("DELETE FROM messages WHERE id = ?", new Object[] {id});
|
||||
}
|
||||
|
||||
+2
-2
@@ -26,8 +26,8 @@ import sys
|
||||
import zipfile
|
||||
from pathlib import Path
|
||||
|
||||
VERSION_NAME = "0.5.0"
|
||||
VERSION_CODE = 5
|
||||
VERSION_NAME = "0.5.1"
|
||||
VERSION_CODE = 6
|
||||
|
||||
PACKAGE = "me.teafry.voipmessages"
|
||||
DEV_PACKAGE = PACKAGE + ".dev"
|
||||
|
||||
Reference in New Issue
Block a user