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:
+22
-4
@@ -47,6 +47,20 @@ const MESSAGE_COLS = 'id, did, contact, direction, body, ts, kind, status, media
|
||||
const MATCH_BEFORE = 2 * 60_000
|
||||
const MATCH_AFTER = 15 * 60_000
|
||||
|
||||
// A text with its emoji (and their joiners and variation selectors) taken
|
||||
// out, trimmed: what's left of it in voip.ms's listing.
|
||||
export function withoutEmoji(s: string): string {
|
||||
let out = ''
|
||||
for (const ch of s) {
|
||||
const c = ch.codePointAt(0)!
|
||||
const 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 += ch
|
||||
}
|
||||
return out.trim()
|
||||
}
|
||||
|
||||
function fromRow({ media_json, error, sender, ...m }: MessageRow): Message {
|
||||
return {
|
||||
...m,
|
||||
@@ -250,16 +264,20 @@ export class MessageDb {
|
||||
// Returns the local ids that were replaced.
|
||||
reconcileSent(added: NewMessage[]): number[] {
|
||||
const find = this.db.prepare(
|
||||
`SELECT id FROM messages
|
||||
`SELECT id, body 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`
|
||||
AND did = ? AND contact = ? AND ts BETWEEN ? AND ?
|
||||
ORDER BY ts, id DESC`
|
||||
)
|
||||
const claimed: number[] = []
|
||||
this.db.transaction(() => {
|
||||
for (const m of [...added].sort((a, b) => a.ts - b.ts || a.id - b.id)) {
|
||||
if (m.direction !== 'out' || m.id < 0) continue
|
||||
const row = find.get(m.did, m.contact, m.body, m.ts - MATCH_AFTER, m.ts + MATCH_BEFORE) as { id: number } | undefined
|
||||
const rows = find.all(m.did, m.contact, m.ts - MATCH_AFTER, m.ts + MATCH_BEFORE) as { id: number; body: string }[]
|
||||
// voip.ms's listing drops emoji ("…everything ❤️" comes back as
|
||||
// "…everything "), so an exact match first, then one without them.
|
||||
const key = withoutEmoji(m.body)
|
||||
const row = rows.find((r) => r.body === m.body) ?? rows.find((r) => withoutEmoji(r.body) === key)
|
||||
if (!row) continue
|
||||
this.confirmPending(row.id, m.id)
|
||||
claimed.push(row.id)
|
||||
|
||||
Reference in New Issue
Block a user