diff --git a/android/app/src/main/java/me/teafry/voipmessages/Store.java b/android/app/src/main/java/me/teafry/voipmessages/Store.java index 7dd6cf3..cc986db 100644 --- a/android/app/src/main/java/me/teafry/voipmessages/Store.java +++ b/android/app/src/main/java/me/teafry/voipmessages/Store.java @@ -90,6 +90,12 @@ final class Store { if (!hasColumn("read_state", "name_ts")) db.execSQL("ALTER TABLE read_state ADD COLUMN name_ts INTEGER"); if (!hasColumn("read_state", "unread_ts")) db.execSQL("ALTER TABLE read_state ADD COLUMN unread_ts INTEGER"); if (!hasColumn("read_state", "archived_ts")) db.execSQL("ALTER TABLE read_state ADD COLUMN archived_ts INTEGER"); + // voip.ms gives a received picture with no words the text "MMS Received"; + // nobody wrote it, so it goes (once, for what came in before). + if (get("mms_received_stripped") == null) { + db.execSQL("UPDATE messages SET body = '' WHERE media_json IS NOT NULL AND lower(trim(body)) = 'mms received'"); + set("mms_received_stripped", "1"); + } if (get("unread_floor") == null) set("unread_floor", String.valueOf(System.currentTimeMillis())); } diff --git a/android/app/src/main/java/me/teafry/voipmessages/VoipMs.java b/android/app/src/main/java/me/teafry/voipmessages/VoipMs.java index 3fadfa6..a30ca0c 100644 --- a/android/app/src/main/java/me/teafry/voipmessages/VoipMs.java +++ b/android/app/src/main/java/me/teafry/voipmessages/VoipMs.java @@ -126,6 +126,8 @@ final class VoipMs { JSONArray refs = new JSONArray(); for (String u : urls) refs.put(new JSONObject().put("url", u)); m.mediaJson = refs.toString(); + // voip.ms's own stand-in text for a picture with no words, not the sender's. + if (m.body.trim().equalsIgnoreCase("MMS Received")) m.body = ""; } else if (Phone.charCount(m.body) > Phone.SMS_TEXT_LIMIT) { m.kind = "mms"; } diff --git a/android/build.py b/android/build.py index 3979ccf..78c8f6c 100644 --- a/android/build.py +++ b/android/build.py @@ -26,8 +26,8 @@ import sys import zipfile from pathlib import Path -VERSION_NAME = "0.7.2" -VERSION_CODE = 10 +VERSION_NAME = "0.7.3" +VERSION_CODE = 11 PACKAGE = "me.teafry.voipmessages" DEV_PACKAGE = PACKAGE + ".dev" diff --git a/package.json b/package.json index 4c7b266..c641309 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "voipms-desktop", "productName": "bubble", - "version": "0.7.2", + "version": "0.8.0", "description": "Signal-style desktop SMS client for voip.ms", "author": "trav ", "private": true, diff --git a/resources/android/VoipMessages.apk b/resources/android/VoipMessages.apk index 73e7585..252d6be 100644 Binary files a/resources/android/VoipMessages.apk and b/resources/android/VoipMessages.apk differ diff --git a/resources/android/VoipMessages.json b/resources/android/VoipMessages.json index bf9a387..7b67970 100644 --- a/resources/android/VoipMessages.json +++ b/resources/android/VoipMessages.json @@ -1 +1 @@ -{"version_name": "0.7.2", "version_code": 10, "package": "me.teafry.voipmessages"} +{"version_name": "0.7.3", "version_code": 11, "package": "me.teafry.voipmessages"} diff --git a/src/main/db.ts b/src/main/db.ts index bb2393b..4e7ad83 100644 --- a/src/main/db.ts +++ b/src/main/db.ts @@ -6,7 +6,7 @@ import type { Conversation, Direction, MediaRef, Message, MessageKind, MessageSt import { SNIPPET_END, SNIPPET_START } from '@shared/types' import { fixVoipDst } from './voipms' -const SCHEMA_VERSION = 10 +const SCHEMA_VERSION = 11 export interface ReadState { did: string @@ -166,6 +166,10 @@ export class MessageDb { // v10: when read/unread and archived last changed, so they merge with the Rabbit too. if (!rsCols.some((c) => c.name === 'unread_ts')) this.db.exec(`ALTER TABLE read_state ADD COLUMN unread_ts INTEGER`) if (!rsCols.some((c) => c.name === 'archived_ts')) this.db.exec(`ALTER TABLE read_state ADD COLUMN archived_ts INTEGER`) + // v11: voip.ms gives a received picture with no words the text "MMS + // Received"; nobody wrote it, so it goes. + if (version >= 1 && version < 11) + this.db.exec(`UPDATE messages SET body = '' WHERE media_json IS NOT NULL AND lower(trim(body)) = 'mms received'`) this.db.pragma(`user_version = ${SCHEMA_VERSION}`) } diff --git a/src/main/sync.ts b/src/main/sync.ts index d165289..0d5a148 100644 --- a/src/main/sync.ts +++ b/src/main/sync.ts @@ -18,6 +18,8 @@ function parseYmd(s: string): number { return Date.parse(s + 'T00:00:00Z') } +export const isMmsPlaceholder = (body: string): boolean => body.trim().toLowerCase() === 'mms received' + export function toNewMessage(r: RawSms): NewMessage { const m: NewMessage = { id: Number(r.id), @@ -34,6 +36,8 @@ export function toNewMessage(r: RawSms): NewMessage { if (urls.length) { m.kind = 'mms' m.media = urls.map((url) => ({ url })) + // voip.ms's own stand-in text for a picture with no words, not the sender's. + if (isMmsPlaceholder(m.body)) m.body = '' } else if (charCount(m.body) > SMS_TEXT_LIMIT) { m.kind = 'mms' } diff --git a/src/renderer/src/components/ChatView.tsx b/src/renderer/src/components/ChatView.tsx index 698fbaa..c9ffab8 100644 --- a/src/renderer/src/components/ChatView.tsx +++ b/src/renderer/src/components/ChatView.tsx @@ -7,7 +7,7 @@ import { chatsWith, convName, dayLabel, sameDay, senderName, senderShortName } f import { Avatar } from './Avatar' import { Composer, type ComposerHandle } from './Composer' import { CloseIcon, DownIcon, SearchIcon, UpIcon } from './Icons' -import { Lightbox } from './Lightbox' +import { conversationMedia, Lightbox } from './Lightbox' import { MessageBubble } from './MessageBubble' import { DEFAULT_QUICK_REACTIONS, reactionText, sameEmoji, type Reaction } from '@shared/reactions' import { foldConversation, type Version } from '@shared/edits' @@ -95,6 +95,7 @@ export function ChatView({ conv, contact, contactMap, conversations, onOpen, nam const [hits, setHits] = useState([]) const [hitIdx, setHitIdx] = useState(0) const [lightbox, setLightbox] = useState<{ id: number; index: number }>() + const media = useMemo(() => conversationMedia(messages ?? []), [messages]) const [dragging, setDragging] = useState(false) const virtuoso = useRef(null) const searchInput = useRef(null) @@ -281,22 +282,36 @@ export function ChatView({ conv, contact, contactMap, conversations, onOpen, nam setHeaderMenu({ x: e.clientX, y: e.clientY }) }} > - + {/* A clickable picture (#clickable): finger, tooltip, Tab, Enter/Space. */}
{ + if (e.key !== 'Enter' && e.key !== ' ') return + e.preventDefault() + onInfo() + }} > + +
+ {/* The number lives in Get info, not here. */} +
{name}
-
- {group ? `${members.length} people` : contact ? formatNumber(conv.contact) : ''} - {smsDids.length > 1 && ( - - {contact || group ? ' · ' : ''} - - - )} -
+ {(group || smsDids.length > 1) && ( +
+ {group && `${members.length} people`} + {smsDids.length > 1 && ( + + {group ? ' · ' : ''} + + + )} +
+ )}
- +
{convName(conv.contact, contactMap, name)}
-
- {members.length} people · -
+ {group ? ( +
+ {members.length} people · +
+ ) : ( + <> + {/* Without a contact the name already is the number. */} + {person && ( +
+ {formatNumber(conv.contact)} + {person.label ? · {person.label} : null} +
+ )} +
+ +
+ {!person && ( + + )} + + )}
-
-

Name

- setDraft(e.target.value)} - onKeyDown={(e) => e.key === 'Enter' && dirty && save()} - /> -

Only you see this name; it stays on this computer. Leave it empty to show the members' names.

-
+ {group && ( +
+

Name

+ setDraft(e.target.value)} + onKeyDown={(e) => e.key === 'Enter' && dirty && save()} + /> +

Only you see this name; it stays on this computer. Leave it empty to show the members' names.

+
+ )} -
-

Members

- {members.map((n) => { - const c = contactMap.get(n) - return ( -
- -
-
{displayName(n, c)}
- {c && ( -
- {formatNumber(n)} - {c.label ? ` · ${c.label}` : ''} -
+ {group && ( +
+

Members

+ {members.map((n) => { + const c = contactMap.get(n) + return ( +
+ +
+
{displayName(n, c)}
+ {c && ( +
+ {formatNumber(n)} + {c.label ? ` · ${c.label}` : ''} +
+ )} +
+ {!c && ( + )}
- {!c && ( - - )} -
- ) - })} -
+ ) + })} + + )} + +
- - + {group ? ( + <> + + + + ) : ( + + )}
diff --git a/src/renderer/src/components/ConversationList.tsx b/src/renderer/src/components/ConversationList.tsx index 796f748..6b42db2 100644 --- a/src/renderer/src/components/ConversationList.tsx +++ b/src/renderer/src/components/ConversationList.tsx @@ -37,7 +37,7 @@ export function ConversationList({ conversations, contactMap, selected, multiDid if (!conversations.length) return
{emptyText}
const menuItems = (c: Conversation) => [ - ...(isGroup(c.contact) ? [{ label: 'Get info…', onSelect: () => onInfo(c) }] : []), + { label: 'Get info…', onSelect: () => onInfo(c) }, ...(!isGroup(c.contact) && !contactMap.get(c.contact) ? [{ label: 'Add to contacts…', onSelect: () => addContact(c.contact) }] : []), c.archived ? { label: 'Unarchive', onSelect: () => void window.api.setArchived(c.did, c.contact, false) } diff --git a/src/renderer/src/components/Icons.tsx b/src/renderer/src/components/Icons.tsx index 1bde1c1..6f23822 100644 --- a/src/renderer/src/components/Icons.tsx +++ b/src/renderer/src/components/Icons.tsx @@ -29,6 +29,16 @@ export const BackIcon = () => ( ) +export const LeftIcon = ({ size = 28 }: { size?: number }) => ( + + + +) +export const RightIcon = ({ size = 28 }: { size?: number }) => ( + + + +) export const UpIcon = () => ( diff --git a/src/renderer/src/components/Lightbox.tsx b/src/renderer/src/components/Lightbox.tsx index 66f3a7b..79012bc 100644 --- a/src/renderer/src/components/Lightbox.tsx +++ b/src/renderer/src/components/Lightbox.tsx @@ -1,6 +1,8 @@ import { useEffect, useState } from 'react' +import { mediaKind } from '@shared/mime' +import type { Message } from '@shared/types' import { ContextMenu, type MenuItem } from './ContextMenu' -import { CloseIcon, DownloadIcon } from './Icons' +import { CloseIcon, DownloadIcon, LeftIcon, RightIcon } from './Icons' import { mediaSrc } from './MessageBubble' // Copy an attachment to the clipboard as a PNG (so GIF/WebP/HEIC work too). @@ -23,20 +25,58 @@ export const imageMenuItems = (id: number, index: number): MenuItem[] => [ { label: 'Save image…', onSelect: () => void window.api.saveMedia(id, index).catch(() => undefined) } ] -export function Lightbox({ id, index, onClose }: { id: number; index: number; onClose: () => void }) { +// One picture or video in a conversation. +export interface MediaItem { + id: number // the message + index: number // which of its attachments + ts: number + video: boolean +} + +// Every picture and video in a conversation, oldest first. +export function conversationMedia(messages: Message[]): MediaItem[] { + const out: MediaItem[] = [] + for (const m of messages) { + m.media?.forEach((ref, index) => { + const kind = mediaKind(ref) + if (kind === 'image' || kind === 'video') out.push({ id: m.id, index, ts: m.ts, video: kind === 'video' }) + }) + } + return out +} + +// Full size, over everything. ← and → step through `items` (oldest first). +export function Lightbox({ items, start, onClose }: { items: MediaItem[]; start: number; onClose: () => void }) { + const [at, setAt] = useState(start) const [menu, setMenu] = useState<{ x: number; y: number }>() + const item = items[at] + const step = (dir: 1 | -1): void => setAt((i) => Math.min(items.length - 1, Math.max(0, i + dir))) useEffect(() => { const onKey = (e: KeyboardEvent): void => { - if (e.key === 'Escape' && !menu) onClose() + if (menu) return + // Ours alone: not the dialog underneath, a video's seek or the composer's caret. + if (e.key === 'Escape') onClose() + else if (e.key === 'ArrowLeft' || e.key === 'ArrowRight') step(e.key === 'ArrowLeft' ? -1 : 1) + else return + e.preventDefault() + e.stopPropagation() } - window.addEventListener('keydown', onKey) - return () => window.removeEventListener('keydown', onKey) - }, [onClose, menu]) + window.addEventListener('keydown', onKey, true) + return () => window.removeEventListener('keydown', onKey, true) + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [onClose, menu, items.length]) + if (!item) return null + const { id, index } = item return (
e.target === e.currentTarget && onClose()}>
+ {items.length > 1 && ( + + {at + 1} of {items.length} · {new Date(item.ts).toLocaleDateString(undefined, { dateStyle: 'medium' })} + + )} @@ -44,15 +84,30 @@ export function Lightbox({ id, index, onClose }: { id: number; index: number; on
- { - e.preventDefault() - setMenu({ x: e.clientX, y: e.clientY }) - }} - /> + {items.length > 1 && ( + <> + + + + )} + {item.video ? ( +
) diff --git a/src/renderer/src/styles.css b/src/renderer/src/styles.css index 2781857..6f64b28 100644 --- a/src/renderer/src/styles.css +++ b/src/renderer/src/styles.css @@ -3768,4 +3768,105 @@ label.check { padding: 0; } +/* ---------- chat header: the picture opens Get info (#clickable) ---------- */ +.chat-avatar { + border-radius: 50%; + cursor: pointer; +} +.chat-avatar:focus-visible { + outline: none; + box-shadow: 0 0 0 2px var(--highlight); +} + +/* ---------- Get info: the number, and the chat's photos ---------- */ +.conv-info-number { + font-size: 15px; + user-select: text; +} +.conv-info-top .member-add { + margin: 6px 0 0; +} +.media-grid { + display: grid; + grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); + gap: 4px; + max-height: 284px; + overflow-y: auto; +} +/* Clickable pictures: finger + tooltip + Tab ring, never shaded. */ +.media-thumb { + position: relative; + aspect-ratio: 1; + border-radius: 8px; + overflow: hidden; + cursor: pointer; + background: var(--stripe); +} +.media-thumb:focus-visible { + outline: none; + box-shadow: inset 0 0 0 2px var(--highlight); +} +.media-thumb img, +.media-thumb video { + width: 100%; + height: 100%; + object-fit: cover; + display: block; + pointer-events: none; +} +.media-thumb-play { + position: absolute; + inset: 0; + display: flex; + align-items: center; + justify-content: center; + color: #fff; + font-size: 22px; + text-shadow: 0 1px 4px rgba(0, 0, 0, 0.7); +} +.media-thumb-missing { + display: flex; + height: 100%; + align-items: center; + justify-content: center; + font-size: 11px; + color: var(--muted, #808080); +} + +/* ---------- lightbox: step through the chat's photos ---------- */ +.lightbox video { + max-width: 100%; + max-height: 100%; + border-radius: 4px; +} +.lightbox-bar { + align-items: center; +} +.lightbox-count { + color: #ddd; + font-size: 13px; + margin-right: 8px; +} +/* Embossed buttons over the dark: the ordinary glyph color, not light gray on white. */ +.lightbox .icon-btn, +.lightbox .icon-btn:hover { + color: var(--glyph); +} +.lightbox-step { + position: absolute; + top: 50%; + transform: translateY(-50%); + width: 44px; + height: 64px; + z-index: 1; +} +.lightbox-step.prev { + left: 8px; +} +.lightbox-step.next { + right: 8px; +} +.lightbox-step:disabled { + visibility: hidden; +} } diff --git a/test/sync.test.ts b/test/sync.test.ts index 16d6ee6..754e99c 100644 --- a/test/sync.test.ts +++ b/test/sync.test.ts @@ -48,6 +48,14 @@ describe('toNewMessage (MMS)', () => { expect(toNewMessage({ ...mms, col_media1: url, media: [url] })).toMatchObject({ kind: 'mms', media: [{ url }] }) expect(toNewMessage({ ...mms, col_media1: url })).toMatchObject({ kind: 'mms', media: [{ url }] }) }) + it('drops voip.ms\'s "MMS Received" stand-in text from pictures', () => { + const url = 'https://voip.ms/media/abc/media.jpeg' + expect(toNewMessage({ ...mms, message: 'MMS Received', col_media1: url }).body).toBe('') + expect(toNewMessage({ ...mms, message: ' mms received\n', col_media1: url }).body).toBe('') + expect(toNewMessage({ ...mms, message: 'MMS Received, thanks', col_media1: url }).body).toBe('MMS Received, thanks') + // Typed by a person, with no picture: kept. + expect(toNewMessage({ ...mms, message: 'MMS received', col_media1: '' }).body).toBe('MMS received') + }) it('treats rows without media as plain texts', () => { const m = toNewMessage({ ...mms, message: 'long text', col_media1: '', media: [] }) expect(m.kind).toBeUndefined()