Desktop: - Search lists chats whose own name matches first, so a named group isn't pushed out of the top 8 by chats that merely include a member. Android (Rabbit R1) app, 0.2.0: - Pull the chat list past its top for a search box (name, person, number, then group members; archived chats too; Back clears it). - Swipe right to left marks a chat unread / read over a magenta band; left to right still archives (SwipeActions replaces SwipeArchive). - Google Voice chats don't offer voice notes in the paperclip bubble. - Chats open with their newest 60 messages, then the full history; marking read (and the Google Voice network call) waits until they're on screen. Cached pictures show at once, and one slow download no longer blocks the other images. Fixed a contacts reload race. - Sandbox data gains filler chats, a named group and a 4,000-message chat. Also: the Android app, Google Voice support, media, export, emoji and the other work since the first commit, and a CLAUDE.md carrying the privacy rule.
83 lines
3.4 KiB
TypeScript
83 lines
3.4 KiB
TypeScript
import fs from 'node:fs'
|
|
import os from 'node:os'
|
|
import path from 'node:path'
|
|
import { afterEach, beforeEach, describe, expect, it } from 'vitest'
|
|
import { MessageDb } from '../src/main/db'
|
|
import { sendWithRetry } from '../src/main/send'
|
|
import { VoipMsError } from '../src/main/voipms'
|
|
|
|
let dir: string
|
|
let db: MessageDb
|
|
let tempId: number
|
|
|
|
const timeout = (): Error => new DOMException('The operation was aborted due to timeout', 'TimeoutError')
|
|
const offline = (): Error => Object.assign(new TypeError('fetch failed'), { cause: { code: 'ENOTFOUND' } })
|
|
const sleep = async (): Promise<void> => undefined
|
|
|
|
// An attempt that plays back `results` in order (errors are thrown).
|
|
function attempts(...results: Array<number | Error>) {
|
|
const fn = async (): Promise<number> => {
|
|
fn.calls++
|
|
const r = results.shift()!
|
|
if (r instanceof Error) throw r
|
|
return r
|
|
}
|
|
fn.calls = 0
|
|
return fn
|
|
}
|
|
|
|
beforeEach(() => {
|
|
dir = fs.mkdtempSync(path.join(os.tmpdir(), 'voipms-send-'))
|
|
db = new MessageDb(path.join(dir, 'messages.db'))
|
|
tempId = db.insertPending({ did: '5550001111', contact: 'a', direction: 'out', body: 'breakfast?', ts: 1000 })
|
|
})
|
|
afterEach(() => {
|
|
db.close()
|
|
fs.rmSync(dir, { recursive: true, force: true })
|
|
})
|
|
|
|
describe('sendWithRetry', () => {
|
|
it('confirms a message that sends first time', async () => {
|
|
await sendWithRetry(tempId, { db, attempt: attempts(77), checkSent: async () => undefined, sleep })
|
|
expect(db.getMessage(77)?.status).toBe('delivered')
|
|
})
|
|
|
|
it('does not resend after a timeout when the listing shows it went out', async () => {
|
|
const attempt = attempts(timeout(), 99)
|
|
const checkSent = async (): Promise<void> => void db.reconcileSent(db.upsertMessages([{ id: 88, did: '5550001111', contact: 'a', direction: 'out', body: 'breakfast?', ts: 2000 }]))
|
|
await sendWithRetry(tempId, { db, attempt, checkSent, sleep })
|
|
expect(attempt.calls).toBe(1)
|
|
expect(db.getConversationMessages('5550001111', 'a').map((m) => m.id)).toEqual([88])
|
|
})
|
|
|
|
it('resends after a timeout once the listing shows it did not go out', async () => {
|
|
const attempt = attempts(timeout(), 99)
|
|
let checks = 0
|
|
await sendWithRetry(tempId, { db, attempt, checkSent: async () => void checks++, sleep })
|
|
expect(checks).toBe(2)
|
|
expect(attempt.calls).toBe(2)
|
|
expect(db.getConversationMessages('5550001111', 'a').map((m) => m.id)).toEqual([99])
|
|
})
|
|
|
|
it('resends right away when the request never left', async () => {
|
|
const attempt = attempts(offline(), 99)
|
|
await sendWithRetry(tempId, { db, attempt, checkSent: async () => undefined, sleep })
|
|
expect(attempt.calls).toBe(2)
|
|
expect(db.getMessage(99)?.status).toBe('delivered')
|
|
})
|
|
|
|
it('gives up after three attempts and says why', async () => {
|
|
const attempt = attempts(offline(), offline(), offline(), 99)
|
|
await sendWithRetry(tempId, { db, attempt, checkSent: async () => undefined, sleep })
|
|
expect(attempt.calls).toBe(3)
|
|
expect(db.getMessage(tempId)).toMatchObject({ status: 'failed', error: expect.stringMatching(/internet connection/) })
|
|
})
|
|
|
|
it('does not retry a rejection', async () => {
|
|
const attempt = attempts(new VoipMsError('invalid_dst'), 99)
|
|
await sendWithRetry(tempId, { db, attempt, checkSent: async () => undefined, sleep })
|
|
expect(attempt.calls).toBe(1)
|
|
expect(db.getMessage(tempId)).toMatchObject({ status: 'failed', error: 'Invalid destination number.' })
|
|
})
|
|
})
|