v0.8.8: bubble for Android 0.7.5 — the composer is always the small size; smoother scrolling past photos
Android: the composer used to shrink only with the keyboard up; now it is always that size (small text, tight padding, 60 dp buttons), and the keyboard only takes a line off the text box and the subtitle. Checked on the Rabbit with the dev app, at rest and typing. Desktop: the chat and Get info show a smaller copy of each still picture (720 px long edge, made once into <dataDir>/thumbs) instead of decoding a phone's 4000 px photo every time a row scrolls in. Full size, Save and Copy still use the original; GIFs and pictures already that small are served as they are. Pictures decode off the main thread.
This commit is contained in:
+8
-4
@@ -239,13 +239,17 @@ async function servePhoto(req: Request): Promise<Response> {
|
||||
}
|
||||
}
|
||||
|
||||
// ---- MMS attachments: mms-media://m/<messageId>/<index> ----
|
||||
// ---- MMS attachments: mms-media://m/<messageId>/<index>[?thumb] ----
|
||||
// ?thumb: a smaller copy of a still picture, for the chat and Get info.
|
||||
async function serveMedia(req: Request): Promise<Response> {
|
||||
const [id, index] = new URL(req.url).pathname.slice(1).split('/').map(Number)
|
||||
const url = new URL(req.url)
|
||||
const [id, index] = url.pathname.slice(1).split('/').map(Number)
|
||||
const ref = await media.resolve(id, index)
|
||||
if (!ref?.file) return new Response(null, { status: 404 })
|
||||
const headers = { 'content-type': ref.mime ?? guessMime(ref.file) ?? 'application/octet-stream' }
|
||||
return new Response(fs.readFileSync(media.filePath(ref.file)), { headers })
|
||||
const thumb = url.searchParams.has('thumb') ? await media.thumb(ref).catch(() => undefined) : undefined
|
||||
const file = thumb ?? media.filePath(ref.file)
|
||||
const mime = thumb ? (thumb.endsWith('.png') ? 'image/png' : 'image/jpeg') : (ref.mime ?? guessMime(ref.file) ?? 'application/octet-stream')
|
||||
return new Response(await fs.promises.readFile(file), { headers: { 'content-type': mime } })
|
||||
}
|
||||
|
||||
async function saveMediaAs(id: number, index: number): Promise<void> {
|
||||
|
||||
@@ -9,6 +9,9 @@ import { extFor, guessMime } from '@shared/mime'
|
||||
import type { MediaRef } from '@shared/types'
|
||||
import type { MessageDb, NewMessage } from './db'
|
||||
|
||||
// Long edge of a thumbnail: twice the chat's largest picture box, for HiDPI.
|
||||
const THUMB_EDGE = 720
|
||||
|
||||
export class MediaStore {
|
||||
private inflight = new Map<string, Promise<MediaRef | undefined>>()
|
||||
|
||||
@@ -23,6 +26,30 @@ export class MediaStore {
|
||||
return path.join(this.dir, path.basename(file))
|
||||
}
|
||||
|
||||
// A smaller copy of a still picture for the chat and Get info, made once
|
||||
// and kept in <dataDir>/thumbs (outside media/, so it never goes to the
|
||||
// Rabbit or into backups as if it were an attachment). The chat shows
|
||||
// pictures at most 300x360, so a phone's 4000 px photo was being decoded
|
||||
// whole, again and again as rows scrolled in and out. Undefined = use the
|
||||
// original: already small, animated (GIF), or a format nativeImage can't read.
|
||||
async thumb(ref: MediaRef): Promise<string | undefined> {
|
||||
if (!ref.file) return undefined
|
||||
const mime = ref.mime ?? guessMime(ref.file) ?? ''
|
||||
if (!mime.startsWith('image/') || mime === 'image/gif') return undefined
|
||||
const png = mime === 'image/png' || mime === 'image/webp' // may be see-through
|
||||
const out = path.join(this.dir, '..', 'thumbs', `${path.basename(ref.file)}.${THUMB_EDGE}.${png ? 'png' : 'jpg'}`)
|
||||
if (fs.existsSync(out)) return out
|
||||
const img = nativeImage.createFromPath(this.filePath(ref.file))
|
||||
if (img.isEmpty()) return undefined
|
||||
const { width, height } = img.getSize()
|
||||
if (Math.max(width, height) <= THUMB_EDGE) return undefined
|
||||
const scale = THUMB_EDGE / Math.max(width, height)
|
||||
const small = img.resize({ width: Math.round(width * scale), height: Math.round(height * scale), quality: 'good' })
|
||||
await fs.promises.mkdir(path.dirname(out), { recursive: true })
|
||||
await fs.promises.writeFile(out, png ? small.toPNG() : small.toJPEG(85))
|
||||
return out
|
||||
}
|
||||
|
||||
save(data: Uint8Array, mime: string): string {
|
||||
const file = `${crypto.createHash('sha1').update(data).digest('hex')}.${extFor(mime)}`
|
||||
fs.mkdirSync(this.dir, { recursive: true })
|
||||
|
||||
@@ -8,7 +8,7 @@ import { CloseIcon } from './Icons'
|
||||
import { Via } from './Via'
|
||||
import { useAddContact } from './AddContact'
|
||||
import { conversationMedia, Lightbox, type MediaItem } from './Lightbox'
|
||||
import { mediaSrc } from './MessageBubble'
|
||||
import { mediaSrc, thumbSrc } from './MessageBubble'
|
||||
|
||||
interface Props {
|
||||
conv: ConvKey
|
||||
@@ -67,7 +67,7 @@ function MediaGrid({ conv }: { conv: ConvKey }) {
|
||||
</span>
|
||||
</>
|
||||
) : (
|
||||
<img src={mediaSrc(it.id, it.index)} alt="" loading="lazy" draggable={false} onError={() => setBroken((b) => new Set(b).add(key(it)))} />
|
||||
<img src={thumbSrc(it.id, it.index)} alt="" loading="lazy" decoding="async" draggable={false} onError={() => setBroken((b) => new Set(b).add(key(it)))} />
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
|
||||
@@ -30,6 +30,8 @@ function renderText(text: string, highlight: string): ReactNode[] {
|
||||
}
|
||||
|
||||
export const mediaSrc = (id: number, index: number): string => `mms-media://m/${id}/${index}`
|
||||
// The smaller copy the chat and Get info show (the original if it's small already).
|
||||
export const thumbSrc = (id: number, index: number): string => `${mediaSrc(id, index)}?thumb`
|
||||
|
||||
// Display box for an image: fit within 300×360, keeping the aspect ratio when
|
||||
// we know it (so the list doesn't jump when the image arrives).
|
||||
@@ -41,8 +43,8 @@ function imageBox(ref: MediaRef): { width: number; height: number } | undefined
|
||||
|
||||
function Attachment({ id, index, media, onOpen, onMenu, onLoad }: { id: number; index: number; media: MediaRef; onOpen: () => void; onMenu: (e: React.MouseEvent) => void; onLoad: () => void }) {
|
||||
const [broken, setBroken] = useState(false)
|
||||
const src = mediaSrc(id, index)
|
||||
const kind = mediaKind(media)
|
||||
const src = kind === 'image' ? thumbSrc(id, index) : mediaSrc(id, index)
|
||||
// Still on the Rabbit (relayed history): asked for, it arrives after the Rabbit's next check.
|
||||
if (broken && media.url?.startsWith('mmspart:') && !media.file) return <div className="media-missing">On the Rabbit — it'll appear after its next check</div>
|
||||
if (broken) return <div className="media-missing">Media unavailable</div>
|
||||
@@ -53,6 +55,7 @@ function Attachment({ id, index, media, onOpen, onMenu, onLoad }: { id: number;
|
||||
src={src}
|
||||
alt=""
|
||||
draggable={false}
|
||||
decoding="async"
|
||||
style={imageBox(media) ?? { minHeight: 120, minWidth: 120 }}
|
||||
onClick={onOpen}
|
||||
onContextMenu={onMenu}
|
||||
|
||||
Reference in New Issue
Block a user