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.
42 lines
1.3 KiB
TypeScript
42 lines
1.3 KiB
TypeScript
// 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'
|
|
}
|