v0.2.0: bubble for Android 0.2.0 — chat search, swipe for unread, faster chat opening
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.
This commit is contained in:
+226
@@ -81,6 +81,174 @@ describe('MessageDb', () => {
|
||||
expect(db.search('fail')).toEqual([])
|
||||
})
|
||||
|
||||
it('stores MMS media and previews it in the conversation list', () => {
|
||||
const url = 'https://voip.ms/media/x/media.jpeg'
|
||||
db.upsertMessages([{ ...msg(1, 'a', '', 1000), kind: 'mms', media: [{ url }] }])
|
||||
expect(db.getMessage(1)).toMatchObject({ kind: 'mms', media: [{ url }] })
|
||||
expect(db.getMessage(1)).not.toHaveProperty('media_json')
|
||||
expect(db.listConversations()[0]).toMatchObject({ lastKind: 'mms', lastBody: '', lastMedia: { url } })
|
||||
db.setMediaFile(1, 0, { file: 'abc.jpg', mime: 'image/jpeg' })
|
||||
expect(db.getMessage(1)?.media).toEqual([{ url, file: 'abc.jpg', mime: 'image/jpeg' }])
|
||||
db.upsertMessages([msg(2, 'a', 'plain', 2000)])
|
||||
expect(db.getMessage(2)).not.toHaveProperty('media')
|
||||
expect(db.listConversations()[0]).not.toHaveProperty('lastMedia')
|
||||
})
|
||||
|
||||
it('keeps local attachment files when a sent MMS was already synced', () => {
|
||||
const t = db.insertPending({ did: '5550001111', contact: 'a', direction: 'out', body: '', ts: 1, kind: 'mms', media: [{ file: 'local.jpg', mime: 'image/jpeg' }] })
|
||||
db.upsertMessages([{ ...msg(50, 'a', '', 2, 'out'), kind: 'mms', media: [{ url: 'https://x/m.jpeg' }] }])
|
||||
db.confirmPending(t, 50)
|
||||
expect(db.getMessage(t)).toBeUndefined()
|
||||
expect(db.getMessage(50)?.media).toEqual([{ url: 'https://x/m.jpeg', file: 'local.jpg', mime: 'image/jpeg' }])
|
||||
})
|
||||
|
||||
it('migrates v1 databases by restarting the history import', () => {
|
||||
db.set('backfill_done', '1')
|
||||
db.set('backfill_cursor', '2010-01-01')
|
||||
db.set('unread_floor', '123')
|
||||
// Recreate read_state as v1 had it (before the archive columns).
|
||||
db.db.exec(`DROP TABLE read_state;
|
||||
CREATE TABLE read_state (did TEXT NOT NULL, contact TEXT NOT NULL, last_read_ts INTEGER NOT NULL, PRIMARY KEY (did, contact))`)
|
||||
db.db.pragma('user_version = 1')
|
||||
db.close()
|
||||
db = new MessageDb(path.join(dir, 'messages.db'))
|
||||
expect(db.get('backfill_done')).toBeUndefined()
|
||||
expect(db.get('backfill_cursor')).toBeUndefined()
|
||||
expect(db.get('unread_floor')).toBe('123')
|
||||
db.upsertMessages([msg(1, 'a', 'hi', 1000)])
|
||||
db.setArchived('5550001111', 'a', true)
|
||||
expect(db.listConversations()[0].archived).toBe(true)
|
||||
})
|
||||
|
||||
it('archives conversations until a newer message arrives', () => {
|
||||
db.upsertMessages([msg(1, 'a', 'hi', 1000), msg(2, 'b', 'yo', 2000)])
|
||||
db.setArchived('5550001111', 'a', true, 5000)
|
||||
expect(db.listConversations().find((c) => c.contact === 'a')).toMatchObject({ archived: true })
|
||||
expect(db.listConversations().find((c) => c.contact === 'b')).toMatchObject({ archived: false })
|
||||
// Older history (e.g. from the backfill) doesn't unarchive.
|
||||
db.upsertMessages([msg(3, 'a', 'old', 4000)])
|
||||
expect(db.listConversations().find((c) => c.contact === 'a')?.archived).toBe(true)
|
||||
// A new message (incoming, or one we send) does.
|
||||
db.upsertMessages([msg(4, 'a', 'new', 6000)])
|
||||
expect(db.listConversations().find((c) => c.contact === 'a')?.archived).toBe(false)
|
||||
db.setArchived('5550001111', 'a', true, 7000)
|
||||
db.insertPending({ did: '5550001111', contact: 'a', direction: 'out', body: 'sent', ts: 8000 })
|
||||
expect(db.listConversations().find((c) => c.contact === 'a')?.archived).toBe(false)
|
||||
db.setArchived('5550001111', 'b', true)
|
||||
db.setArchived('5550001111', 'b', false)
|
||||
expect(db.listConversations().find((c) => c.contact === 'b')?.archived).toBe(false)
|
||||
})
|
||||
|
||||
it('marks conversations unread until opened', () => {
|
||||
db.upsertMessages([msg(1, 'a', 'hi', 1000)])
|
||||
db.markRead('5550001111', 'a')
|
||||
expect(db.listConversations()[0]).toMatchObject({ unread: 0, markedUnread: false })
|
||||
db.markUnread('5550001111', 'a')
|
||||
expect(db.listConversations()[0]).toMatchObject({ unread: 0, markedUnread: true })
|
||||
db.markRead('5550001111', 'a')
|
||||
expect(db.listConversations()[0].markedUnread).toBe(false)
|
||||
})
|
||||
|
||||
it('migrates to v4: shifts voip.ms times out of the DST hour, keeps local send times', () => {
|
||||
const summer = Date.UTC(2026, 8, 18, 7, 35, 47) // as voip.ms reported it
|
||||
const winter = Date.UTC(2026, 0, 20, 2, 44, 49)
|
||||
const local = Date.UTC(2026, 8, 18, 6, 35, 34) + 465 // stamped on send
|
||||
db.upsertMessages([
|
||||
{ ...msg(1, 'a', 'summer', summer), kind: 'mms' },
|
||||
msg(2, 'a', 'winter', winter),
|
||||
msg(3, 'a', 'sent here', local, 'out'),
|
||||
{ ...msg(4, 'a', '', summer), kind: 'mms', media: [{ url: 'u' }] }
|
||||
])
|
||||
db.db.pragma('user_version = 3')
|
||||
db.close()
|
||||
db = new MessageDb(path.join(dir, 'messages.db'))
|
||||
expect(db.getMessage(1)).toMatchObject({ ts: summer - 3_600_000, kind: 'sms' })
|
||||
expect(db.getMessage(2)?.ts).toBe(winter)
|
||||
expect(db.getMessage(3)?.ts).toBe(local)
|
||||
expect(db.getMessage(4)).toMatchObject({ ts: summer - 3_600_000, kind: 'mms' })
|
||||
})
|
||||
|
||||
it('migrates to v5: labels texts too long for one SMS as MMS', () => {
|
||||
db.upsertMessages([msg(1, 'a', 'x'.repeat(161), 1000), msg(2, 'a', 'x'.repeat(160), 2000), msg(3, 'a', '😀'.repeat(160), 3000)])
|
||||
db.db.pragma('user_version = 4')
|
||||
db.close()
|
||||
db = new MessageDb(path.join(dir, 'messages.db'))
|
||||
expect(db.getMessage(1)?.kind).toBe('mms')
|
||||
expect(db.getMessage(2)?.kind).toBe('sms')
|
||||
expect(db.getMessage(3)?.kind).toBe('sms')
|
||||
})
|
||||
|
||||
it('keeps a sent text-only MMS labelled MMS when the poll got there first', () => {
|
||||
const t = db.insertPending({ did: '5550001111', contact: 'a', direction: 'out', body: 'short mms', ts: 1, kind: 'mms' })
|
||||
db.upsertMessages([msg(60, 'a', 'short mms', 2, 'out')])
|
||||
db.confirmPending(t, 60)
|
||||
expect(db.getMessage(t)).toBeUndefined()
|
||||
expect(db.getMessage(60)?.kind).toBe('mms')
|
||||
})
|
||||
|
||||
it('records why a send failed', () => {
|
||||
const t = db.insertPending({ did: '5550001111', contact: 'a', direction: 'out', body: 'x', ts: 1 })
|
||||
expect(db.getMessage(t)?.error).toBeUndefined()
|
||||
db.markFailed(t, "voip.ms didn't respond in time.")
|
||||
expect(db.getMessage(t)).toMatchObject({ status: 'failed', error: "voip.ms didn't respond in time." })
|
||||
})
|
||||
|
||||
it('migrates to v6: adds the send error column', () => {
|
||||
db.db.exec('ALTER TABLE messages DROP COLUMN error')
|
||||
db.db.pragma('user_version = 5')
|
||||
db.close()
|
||||
db = new MessageDb(path.join(dir, 'messages.db'))
|
||||
const t = db.insertPending({ did: '5550001111', contact: 'a', direction: 'out', body: 'x', ts: 1 })
|
||||
db.markFailed(t, 'nope')
|
||||
expect(db.getMessage(t)?.error).toBe('nope')
|
||||
})
|
||||
|
||||
describe('reconcileSent', () => {
|
||||
const MIN = 60_000
|
||||
const pending = (body: string, ts: number): number => db.insertPending({ did: '5550001111', contact: 'a', direction: 'out', body, ts })
|
||||
const poll = (...msgs: NewMessage[]): number[] => db.reconcileSent(db.upsertMessages(msgs))
|
||||
|
||||
it('replaces a failed copy that actually went out', () => {
|
||||
const t = pending('breakfast?', 10 * MIN)
|
||||
db.markFailed(t, 'timeout')
|
||||
expect(poll(msg(500, 'a', 'breakfast?', 11 * MIN, 'out'))).toEqual([t])
|
||||
expect(db.getMessage(t)).toBeUndefined()
|
||||
expect(db.getMessage(500)?.status).toBe('delivered')
|
||||
expect(db.getConversationMessages('5550001111', 'a')).toHaveLength(1)
|
||||
})
|
||||
|
||||
it('replaces a pending copy, and the late send reply is then a no-op', () => {
|
||||
const t = pending('hi', 10 * MIN)
|
||||
expect(poll(msg(501, 'a', 'hi', 10 * MIN, 'out'))).toEqual([t])
|
||||
db.confirmPending(t, 501)
|
||||
expect(db.getConversationMessages('5550001111', 'a').map((m) => m.id)).toEqual([501])
|
||||
})
|
||||
|
||||
it('ignores other texts, other chats, incoming messages, and far-off times', () => {
|
||||
const t = pending('hi', 100 * MIN)
|
||||
db.markFailed(t)
|
||||
expect(
|
||||
poll(
|
||||
msg(1, 'a', 'hello', 100 * MIN, 'out'),
|
||||
msg(2, 'b', 'hi', 100 * MIN, 'out'),
|
||||
msg(3, 'a', 'hi', 100 * MIN, 'in'),
|
||||
msg(4, 'a', 'hi', 80 * MIN, 'out'),
|
||||
msg(5, 'a', 'hi', 120 * MIN, 'out')
|
||||
)
|
||||
).toEqual([])
|
||||
expect(db.getMessage(t)?.status).toBe('failed')
|
||||
})
|
||||
|
||||
it('matches identical texts one to one, oldest first', () => {
|
||||
const t1 = pending('ok', 10 * MIN)
|
||||
const t2 = pending('ok', 10 * MIN + 1)
|
||||
expect(poll(msg(600, 'a', 'ok', 10 * MIN, 'out'))).toEqual([t1])
|
||||
expect(db.getMessage(t2)?.status).toBe('pending')
|
||||
expect(poll(msg(601, 'a', 'ok', 10 * MIN + 2000, 'out'))).toEqual([t2])
|
||||
expect(db.getConversationMessages('5550001111', 'a').map((m) => m.id)).toEqual([600, 601])
|
||||
})
|
||||
})
|
||||
|
||||
it('keeps the FTS index in sync when ids change', () => {
|
||||
const t = db.insertPending({ did: '5550001111', contact: 'a', direction: 'out', body: 'unique words', ts: 1 })
|
||||
db.confirmPending(t, 555)
|
||||
@@ -106,3 +274,61 @@ describe('toFtsQuery', () => {
|
||||
expect(toFtsQuery(' ')).toBe('')
|
||||
})
|
||||
})
|
||||
|
||||
describe('conversation names', () => {
|
||||
it('names a conversation locally and clears it', () => {
|
||||
db.upsertMessages([msg(1, '5550002222,5550003333', 'hi', 10)])
|
||||
db.setName('5550001111', '5550002222,5550003333', ' Hike crew ')
|
||||
expect(db.listConversations()[0].name).toBe('Hike crew')
|
||||
expect(db.getName('5550001111', '5550002222,5550003333')).toBe('Hike crew')
|
||||
db.setName('5550001111', '5550002222,5550003333', '')
|
||||
expect(db.listConversations()[0].name).toBeUndefined()
|
||||
})
|
||||
})
|
||||
|
||||
describe('name merging', () => {
|
||||
it('keeps the newest rename from either side', () => {
|
||||
db.setName('5550001111', 'a,b', 'Desk name', 100)
|
||||
db.setName('5550001111', 'c,d', 'Old', 100)
|
||||
const n = db.namesImport([
|
||||
{ did: '5550001111', contact: 'a,b', name: 'Older rabbit name', ts: 50 },
|
||||
{ did: '5550001111', contact: 'c,d', name: 'Rabbit name', ts: 200 },
|
||||
{ did: '5550001111', contact: 'e,f', name: null, ts: 300 }
|
||||
])
|
||||
expect(n).toBe(2)
|
||||
expect(db.getName('5550001111', 'a,b')).toBe('Desk name')
|
||||
expect(db.getName('5550001111', 'c,d')).toBe('Rabbit name')
|
||||
expect(db.namesExport()).toHaveLength(3)
|
||||
})
|
||||
})
|
||||
|
||||
describe('read state merging', () => {
|
||||
it('takes the later read point and the newer unread/archived change', () => {
|
||||
db.upsertMessages([msg(1, 'a', 'hi', 10), msg(2, 'b', 'yo', 20), msg(3, 'c', 'sup', 30)])
|
||||
db.markRead('5550001111', 'a') // read up to 10, here
|
||||
db.setArchived('5550001111', 'b', true, 1000)
|
||||
const n = db.readStateImport([
|
||||
{ did: '5550001111', contact: 'a', lastRead: 5, markedUnread: true, unreadTs: 1, archivedAt: null, archivedTs: null },
|
||||
{ did: '5550001111', contact: 'b', lastRead: 20, markedUnread: false, unreadTs: null, archivedAt: null, archivedTs: Date.now() + 1000 },
|
||||
{ did: '5550001111', contact: 'c', lastRead: 30, markedUnread: false, unreadTs: Date.now(), archivedAt: null, archivedTs: null }
|
||||
])
|
||||
expect(n).toBe(2)
|
||||
const conv = (c: string) => db.listConversations().find((x) => x.contact === c)!
|
||||
expect(conv('a').markedUnread).toBe(false) // our mark-read is newer than their mark-unread
|
||||
expect(conv('b').archived).toBe(false) // their unarchive is newer
|
||||
expect(conv('c').unread).toBe(0) // read on the other device
|
||||
expect(db.readStateExport()).toHaveLength(3)
|
||||
})
|
||||
})
|
||||
|
||||
describe('drafts', () => {
|
||||
it('keeps unsent text per contact until cleared, across reopening', () => {
|
||||
db.setDraft('5551230001', 'see you at ')
|
||||
db.setDraft('5551230002', 'ok')
|
||||
db.setDraft('5551230002', ' ')
|
||||
db.set('backfill_cursor', 'x') // other kv state isn't a draft
|
||||
db.close()
|
||||
db = new MessageDb(path.join(dir, 'messages.db'))
|
||||
expect(db.getDrafts()).toEqual({ '5551230001': 'see you at ' })
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user