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:
+32
-2
@@ -1,5 +1,5 @@
|
||||
// The typed bridge exposed to the renderer as window.api.
|
||||
import type { ContactInfo, Conversation, Credentials, Did, Message, SearchHit, Settings, SyncStatus } from './types'
|
||||
import type { AddressBook, ChatExport, ContactInfo, NewContact, Conversation, Credentials, Did, Message, OutgoingAttachment, SearchHit, Settings, SyncStatus, Theme } from './types'
|
||||
|
||||
export interface AppState {
|
||||
configured: boolean
|
||||
@@ -8,6 +8,13 @@ export interface AppState {
|
||||
dataDir: string
|
||||
dids: Did[]
|
||||
keyringBackend: string
|
||||
gvoiceNumber?: string // set when Google Voice is connected
|
||||
}
|
||||
|
||||
export interface RabbitStatus {
|
||||
adb: boolean // adb is installed
|
||||
bundledVersion?: string // the Android app this build carries
|
||||
device?: { serial: string; model: string; installedVersion?: string }
|
||||
}
|
||||
|
||||
export interface Api {
|
||||
@@ -15,16 +22,37 @@ export interface Api {
|
||||
testCredentials(creds: Credentials): Promise<Did[]>
|
||||
saveSetup(creds: Credentials, settings: Settings): Promise<void>
|
||||
updateSettings(settings: Settings): Promise<void>
|
||||
setTheme(theme: Theme): Promise<void>
|
||||
signOut(): Promise<void>
|
||||
connectGoogleVoice(): Promise<void>
|
||||
connectGoogleVoiceCookies(text: string): Promise<void>
|
||||
disconnectGoogleVoice(): Promise<void>
|
||||
|
||||
rabbitStatus(): Promise<RabbitStatus>
|
||||
rabbitInstall(mode?: 'full' | 'update'): Promise<void> // update: app only, keeps its data
|
||||
rabbitSync(): Promise<void>
|
||||
onRabbitProgress(cb: (step: string) => void): () => void
|
||||
|
||||
listContacts(): Promise<ContactInfo[]>
|
||||
listAddressBooks(): Promise<{ books: AddressBook[]; default?: string }>
|
||||
addContact(c: NewContact): Promise<string> // resolves with the book's name
|
||||
listConversations(): Promise<Conversation[]>
|
||||
getMessages(did: string, contact: string): Promise<Message[]>
|
||||
markRead(did: string, contact: string): Promise<void>
|
||||
markUnread(did: string, contact: string): Promise<void>
|
||||
setArchived(did: string, contact: string, archived: boolean): Promise<void>
|
||||
setName(did: string, contact: string, name: string | null): Promise<void>
|
||||
// Unsent composer text, by contact; kept until sent or cleared.
|
||||
getDrafts(): Promise<Record<string, string>>
|
||||
setDraft(contact: string, text: string): Promise<void>
|
||||
search(query: string, scope?: { did: string; contact: string }): Promise<SearchHit[]>
|
||||
send(did: string, contact: string, text: string): Promise<void>
|
||||
send(did: string, contact: string, text: string, attachments?: OutgoingAttachment[]): Promise<void>
|
||||
deleteFailed(id: number): Promise<void>
|
||||
retryFailed(id: number): Promise<void>
|
||||
saveMedia(id: number, index: number): Promise<void>
|
||||
exportChat(did: string, contact: string, opts: ChatExport): Promise<boolean> // false: no file chosen
|
||||
readMedia(id: number, index: number): Promise<{ mime: string; data: Uint8Array<ArrayBuffer> }>
|
||||
copyImage(png: Uint8Array): Promise<void> // onto the system clipboard
|
||||
|
||||
syncStatus(): Promise<SyncStatus>
|
||||
pollNow(): Promise<void>
|
||||
@@ -36,4 +64,6 @@ export interface Api {
|
||||
onConversationsChanged(cb: () => void): () => void
|
||||
onSyncStatus(cb: (s: SyncStatus) => void): () => void
|
||||
onContactsChanged(cb: () => void): () => void
|
||||
onStateChanged(cb: () => void): () => void
|
||||
onOpenConversation(cb: (key: { did: string; contact: string }) => void): () => void
|
||||
}
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
// Attachment type helpers shared by main (file names) and renderer (display).
|
||||
import type { MediaRef } from './types'
|
||||
|
||||
const EXT_BY_MIME: Record<string, string> = {
|
||||
'image/jpeg': 'jpg',
|
||||
'image/png': 'png',
|
||||
'image/gif': 'gif',
|
||||
'image/webp': 'webp',
|
||||
'image/bmp': 'bmp',
|
||||
'video/mp4': 'mp4',
|
||||
'video/3gpp': '3gp',
|
||||
'video/quicktime': 'mov',
|
||||
'audio/mpeg': 'mp3',
|
||||
'audio/mp4': 'm4a',
|
||||
'audio/amr': 'amr',
|
||||
'audio/ogg': 'ogg',
|
||||
'text/vcard': 'vcf',
|
||||
'text/x-vcard': 'vcf',
|
||||
'text/plain': 'txt'
|
||||
}
|
||||
const MIME_BY_EXT: Record<string, string> = {
|
||||
...Object.fromEntries(Object.entries(EXT_BY_MIME).map(([m, e]) => [e, m])),
|
||||
jpeg: 'image/jpeg'
|
||||
}
|
||||
|
||||
export function guessMime(nameOrUrl: string): string | undefined {
|
||||
const ext = /\.([a-z0-9]+)(?:[?#].*)?$/i.exec(nameOrUrl)?.[1]?.toLowerCase()
|
||||
return ext ? MIME_BY_EXT[ext] : undefined
|
||||
}
|
||||
|
||||
export function extFor(mime: string | undefined): string {
|
||||
return (mime && EXT_BY_MIME[mime.split(';')[0].trim()]) || 'bin'
|
||||
}
|
||||
|
||||
export type MediaKind = 'image' | 'video' | 'audio' | 'file'
|
||||
|
||||
export function mediaKind(ref: MediaRef): MediaKind {
|
||||
const mime = ref.mime ?? guessMime(ref.file ?? ref.url ?? '') ?? ''
|
||||
const top = mime.split('/')[0]
|
||||
return top === 'image' || top === 'video' || top === 'audio' ? top : 'file'
|
||||
}
|
||||
+21
-19
@@ -14,23 +14,25 @@ export function formatNumber(n: string): string {
|
||||
return n
|
||||
}
|
||||
|
||||
// Split text into voip.ms-sized parts (160 chars max per sendSMS call),
|
||||
// preferring to break on whitespace.
|
||||
export function splitMessage(text: string, max = 160): string[] {
|
||||
const parts: string[] = []
|
||||
let rest = text.trim()
|
||||
while ([...rest].length > max) {
|
||||
const chars = [...rest]
|
||||
let cut = max
|
||||
for (let i = max; i > max * 0.6; i--) {
|
||||
if (/\s/.test(chars[i])) {
|
||||
cut = i
|
||||
break
|
||||
}
|
||||
}
|
||||
parts.push(chars.slice(0, cut).join('').trimEnd())
|
||||
rest = chars.slice(cut).join('').trimStart()
|
||||
}
|
||||
if (rest) parts.push(rest)
|
||||
return parts
|
||||
// Group chats (Google Voice only) are keyed by their members' numbers, sorted
|
||||
// and comma-joined, in the place a 1:1 chat keeps its one number.
|
||||
export function groupKey(numbers: string[]): string {
|
||||
return [...new Set(numbers.map(normalizeNumber).filter(Boolean))].sort().join(',')
|
||||
}
|
||||
|
||||
export function isGroup(contact: string): boolean {
|
||||
return contact.includes(',')
|
||||
}
|
||||
|
||||
export function groupMembers(contact: string): string[] {
|
||||
return contact.split(',')
|
||||
}
|
||||
|
||||
// voip.ms's sendSMS takes at most 160 characters. Longer texts go out as one
|
||||
// text-only MMS, which the recipient sees as a single message (split SMS arrive
|
||||
// as separate fragments, often out of order).
|
||||
export const SMS_TEXT_LIMIT = 160
|
||||
|
||||
export function charCount(text: string): number {
|
||||
return [...text].length
|
||||
}
|
||||
|
||||
@@ -0,0 +1,139 @@
|
||||
// iMessage "tapbacks" sent to non-iPhones arrive as plain texts:
|
||||
// Loved “see you at 9” Laughed at “lol” Reacted 🎉 to “we won”
|
||||
// Removed a heart from “see you at 9” Liked an image
|
||||
// We fold them into emoji reactions on the message they quote (found by
|
||||
// searching back through the conversation), the way Signal shows reactions.
|
||||
// A reaction whose message can't be found stays an ordinary message.
|
||||
|
||||
const VERBS: Record<string, string> = {
|
||||
loved: '❤️',
|
||||
liked: '👍',
|
||||
disliked: '👎',
|
||||
'laughed at': '😂',
|
||||
emphasized: '‼️',
|
||||
questioned: '❓'
|
||||
}
|
||||
|
||||
const REMOVED: Record<string, string> = {
|
||||
'a heart': '❤️',
|
||||
'a like': '👍',
|
||||
'a dislike': '👎',
|
||||
'a laugh': '😂',
|
||||
'an exclamation': '‼️',
|
||||
'an exclamation mark': '‼️',
|
||||
'a question mark': '❓'
|
||||
}
|
||||
|
||||
// Quotes come curly from iPhones, sometimes straight.
|
||||
const Q_OPEN = '[“"”]'
|
||||
const Q_CLOSE = '[”"“]'
|
||||
const MEDIA = /^(?:an? )?(?:image|photo|picture|movie|video|attachment|audio message|gif|sticker)$/i
|
||||
|
||||
export interface ParsedReaction {
|
||||
emoji: string
|
||||
removed: boolean
|
||||
// The quoted text, or `media` for "Loved an image" and the like.
|
||||
target: { text: string } | { media: true }
|
||||
}
|
||||
|
||||
const REACTED = new RegExp(`^Reacted (.+?) to (?:${Q_OPEN}([\\s\\S]*)${Q_CLOSE}|(.+))$`)
|
||||
const VERB = new RegExp(`^(Loved|Liked|Disliked|Laughed at|Emphasized|Questioned) (?:${Q_OPEN}([\\s\\S]*)${Q_CLOSE}|(.+))$`)
|
||||
const REMOVE = new RegExp(`^Removed (an? .+?) from (?:${Q_OPEN}([\\s\\S]*)${Q_CLOSE}|(.+))$`)
|
||||
|
||||
function target(quoted: string | undefined, bare: string | undefined): ParsedReaction['target'] | null {
|
||||
if (quoted !== undefined) return { text: quoted }
|
||||
if (bare && MEDIA.test(bare.trim())) return { media: true }
|
||||
return null
|
||||
}
|
||||
|
||||
export function parseReaction(body: string): ParsedReaction | null {
|
||||
const s = body.trim()
|
||||
let m = VERB.exec(s)
|
||||
if (m) {
|
||||
const t = target(m[2], m[3])
|
||||
return t && { emoji: VERBS[m[1].toLowerCase()], removed: false, target: t }
|
||||
}
|
||||
m = REACTED.exec(s)
|
||||
if (m && [...m[1]].length <= 4) {
|
||||
const t = target(m[2], m[3])
|
||||
return t && { emoji: m[1], removed: false, target: t }
|
||||
}
|
||||
m = REMOVE.exec(s)
|
||||
if (m) {
|
||||
const kind = m[1].toLowerCase()
|
||||
// "Removed a 😂 from …" (newer iOS) names the emoji itself.
|
||||
const emoji = REMOVED[kind] ?? (/^an? (.{1,4})$/u.exec(m[1])?.[1] ?? '')
|
||||
const t = target(m[2], m[3])
|
||||
return emoji && t ? { emoji, removed: true, target: t } : null
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
export interface Reaction {
|
||||
emoji: string
|
||||
from: string // the reactor's number, or 'me'
|
||||
ts: number
|
||||
}
|
||||
|
||||
interface Foldable {
|
||||
id: number
|
||||
body: string
|
||||
ts: number
|
||||
direction: 'in' | 'out'
|
||||
contact: string
|
||||
sender?: string
|
||||
media?: unknown[]
|
||||
}
|
||||
|
||||
// Phones swap straight and curly apostrophes, so compare without the difference.
|
||||
const norm = (s: string): string => s.replace(/[‘’]/g, "'").replace(/\s+/g, ' ').trim()
|
||||
|
||||
function matches(body: string, quoted: string): boolean {
|
||||
const b = norm(body)
|
||||
const q = norm(quoted)
|
||||
if (!q) return false
|
||||
if (b === q) return true
|
||||
// Long messages get quoted cut short with an ellipsis.
|
||||
const cut = q.replace(/(…|\.\.\.)$/, '').trimEnd()
|
||||
return cut !== q && cut.length >= 8 && b.startsWith(cut)
|
||||
}
|
||||
|
||||
// The conversation's messages (oldest first) without the reaction texts we
|
||||
// could place, plus each placed reaction keyed by the message it's on. Each
|
||||
// person keeps one reaction per message, like iMessage: a newer one replaces
|
||||
// theirs, a "Removed …" takes it away.
|
||||
export function foldReactions<T extends Foldable>(msgs: T[]): { shown: T[]; reactions: Map<number, Reaction[]> } {
|
||||
const hidden = new Set<number>()
|
||||
const byTarget = new Map<number, Map<string, Reaction>>()
|
||||
msgs.forEach((m, i) => {
|
||||
const r = parseReaction(m.body)
|
||||
if (!r) return
|
||||
let found: T | undefined
|
||||
for (let j = i - 1; j >= 0 && !found; j--) {
|
||||
const c = msgs[j]
|
||||
if (hidden.has(c.id) || parseReaction(c.body)) continue
|
||||
if ('media' in r.target ? !!c.media?.length : matches(c.body, r.target.text)) found = c
|
||||
}
|
||||
if (!found) return
|
||||
hidden.add(m.id)
|
||||
const from = m.direction === 'out' ? 'me' : (m.sender ?? m.contact)
|
||||
const mine = byTarget.get(found.id) ?? new Map<string, Reaction>()
|
||||
if (r.removed) {
|
||||
if (mine.get(from)?.emoji === r.emoji) mine.delete(from)
|
||||
} else {
|
||||
mine.set(from, { emoji: r.emoji, from, ts: m.ts })
|
||||
}
|
||||
byTarget.set(found.id, mine)
|
||||
})
|
||||
const reactions = new Map<number, Reaction[]>()
|
||||
for (const [id, mine] of byTarget) if (mine.size) reactions.set(id, [...mine.values()].sort((a, b) => a.ts - b.ts))
|
||||
return { shown: hidden.size ? msgs.filter((m) => !hidden.has(m.id)) : msgs, reactions }
|
||||
}
|
||||
|
||||
// A reaction text as a short preview line: "❤️ to “see you at 9”".
|
||||
export function reactionPreview(body: string): string | null {
|
||||
const r = parseReaction(body)
|
||||
if (!r) return null
|
||||
const what = 'media' in r.target ? 'a photo' : `“${norm(r.target.text)}”`
|
||||
return r.removed ? `Removed ${r.emoji} from ${what}` : `${r.emoji} to ${what}`
|
||||
}
|
||||
+70
-1
@@ -2,6 +2,37 @@
|
||||
|
||||
export type Direction = 'in' | 'out'
|
||||
export type MessageStatus = 'delivered' | 'pending' | 'failed'
|
||||
export type MessageKind = 'sms' | 'mms'
|
||||
export type Theme = 'system' | 'light' | 'dark'
|
||||
|
||||
// One MMS attachment. `url` is where voip.ms serves it; `file` is our cached
|
||||
// copy (a name inside <dataDir>/media), filled in once downloaded or sent.
|
||||
export interface MediaRef {
|
||||
url?: string
|
||||
file?: string
|
||||
mime?: string
|
||||
width?: number
|
||||
height?: number
|
||||
}
|
||||
|
||||
// "Export chat": which days, which format, and the names shown in the chat.
|
||||
export interface ChatExport {
|
||||
from?: string // YYYY-MM-DD, inclusive; neither = all time
|
||||
to?: string
|
||||
format: 'pdf' | 'txt'
|
||||
attachments: boolean // PDF only: show photos (otherwise "[Photo]")
|
||||
title: string // the chat's name as shown
|
||||
names: Record<string, string> // group senders' names, by number
|
||||
}
|
||||
|
||||
// An attachment on its way out (already compressed by the renderer).
|
||||
export interface OutgoingAttachment {
|
||||
name: string
|
||||
mime: string
|
||||
data: Uint8Array
|
||||
width?: number
|
||||
height?: number
|
||||
}
|
||||
|
||||
export interface Message {
|
||||
id: number
|
||||
@@ -10,8 +41,11 @@ export interface Message {
|
||||
direction: Direction
|
||||
body: string
|
||||
ts: number // epoch ms, UTC
|
||||
kind: 'sms' | 'mms'
|
||||
kind: MessageKind
|
||||
status: MessageStatus
|
||||
media?: MediaRef[]
|
||||
error?: string // why a send failed
|
||||
sender?: string // who sent an incoming group message (normalized number)
|
||||
}
|
||||
|
||||
export interface Conversation {
|
||||
@@ -20,7 +54,13 @@ export interface Conversation {
|
||||
lastBody: string
|
||||
lastTs: number
|
||||
lastDirection: Direction
|
||||
lastKind: MessageKind
|
||||
lastMedia?: MediaRef // first attachment of the last message, if any
|
||||
lastSender?: string // sender of the last message, in group chats
|
||||
name?: string // a name you gave the conversation (local only)
|
||||
unread: number
|
||||
markedUnread: boolean // manually marked unread (shown as a dot)
|
||||
archived: boolean
|
||||
}
|
||||
|
||||
export interface ContactInfo {
|
||||
@@ -31,6 +71,20 @@ export interface ContactInfo {
|
||||
book: string
|
||||
}
|
||||
|
||||
export interface AddressBook {
|
||||
uid: string
|
||||
name: string
|
||||
account: string // e.g. the Nextcloud account it belongs to
|
||||
}
|
||||
|
||||
export interface NewContact {
|
||||
first: string
|
||||
last: string
|
||||
org: string
|
||||
number: string // E.164
|
||||
book?: string // address book uid; default: GNOME Contacts' own default
|
||||
}
|
||||
|
||||
export interface SearchHit {
|
||||
id: number
|
||||
did: string
|
||||
@@ -40,10 +94,13 @@ export interface SearchHit {
|
||||
snippet: string // contains / markers around matched text
|
||||
}
|
||||
|
||||
export type Provider = 'voipms' | 'gvoice'
|
||||
|
||||
export interface Did {
|
||||
did: string
|
||||
description: string
|
||||
smsEnabled: boolean
|
||||
provider?: Provider // absent = voip.ms
|
||||
}
|
||||
|
||||
export interface SyncStatus {
|
||||
@@ -53,6 +110,15 @@ export interface SyncStatus {
|
||||
lastPoll?: number
|
||||
error?: string
|
||||
total: number
|
||||
gvoice?: GvStatus
|
||||
}
|
||||
|
||||
// Google Voice syncs on its own, so it reports separately.
|
||||
export interface GvStatus {
|
||||
phase: 'idle' | 'backfill' | 'polling' | 'error' | 'signedOut'
|
||||
backfillDone: boolean
|
||||
lastPoll?: number
|
||||
error?: string
|
||||
}
|
||||
|
||||
export interface Settings {
|
||||
@@ -60,6 +126,9 @@ export interface Settings {
|
||||
dids: string[] // DIDs to sync; empty = all SMS-enabled
|
||||
defaultDid?: string
|
||||
backfillFloor: string // YYYY-MM-DD, stop backfill here
|
||||
theme: Theme
|
||||
notifications: boolean // new messages go to the notification list
|
||||
contactBook?: string // where "Add to contacts" puts them; default: GNOME Contacts' default
|
||||
}
|
||||
|
||||
export interface Credentials {
|
||||
|
||||
Reference in New Issue
Block a user