Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ android {
applicationId "com.egebulut.opencommunicate"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 38
versionName "0.9.4"
versionCode 39
versionName "0.9.5"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
aaptOptions {
// Files and dirs to omit from the packaged assets dir, modified to accommodate modern web apps.
Expand Down
3 changes: 2 additions & 1 deletion app/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@opencommunicate/app",
"private": true,
"version": "0.9.4",
"version": "0.9.5",
"type": "module",
"scripts": {
"dev": "vite",
Expand All @@ -27,6 +27,7 @@
"@capacitor/share": "^8.0.2",
"@capgo/capacitor-speech-recognition": "^8.4.4",
"@huggingface/transformers": "^4.3.1",
"marked": "^18.1.2",
"onnxruntime-web": "1.31.0-dev.20260914-8d85527a0",
"react": "^19.3.0",
"react-dom": "^19.3.0"
Expand Down
19 changes: 10 additions & 9 deletions app/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { answerPasswordQuestions, backUp, keysFor, rememberPassword } from "./ke
import { NoDictation, NoVoice, record, transcribe, warmUp, type Recording, dictate, dictationLang, installVoice, readAloud, setDictationLang, stopReading, whisperReady, type Dictation } from "./voice.ts";
import { clearStored, describe, fetchFile, isLocal, kindOf, mediaModes, mimeOf, objectUrl, remember, setMediaMode, shrinkPhoto, storedSize, type MediaKind, type MediaMode, type VoiceFile } from "./media.ts";
import { LANGS, LOCALE, S, lang, setLang, type Lang } from "./i18n.tsx";
import { MessageText } from "./markdown.tsx";
import { accountProblem, canSignIn, checkAccount, claim, clearChats, clearSignIn, credKey, currentToken, dropCred, renewCred, loadChats, noteHead, pruneCreds, putCred, readStored, takeAuth, saveChats, sourceFor, tokenFor, withChat, withoutChat, type Chats, type Cred, desktopApp, finishSignIn, githubLogin, hosted, join, listRepos, native, readSignIn, repoExists, saveSession, saveSignIn, setPassword, startSignIn, type DeviceCode, type Session } from "./session.ts";

const POLL_MS = 4000;
Expand Down Expand Up @@ -823,7 +824,7 @@ function Chat({ session, onSession, onSignOut, chats, activity, onOpen, onAdd }:
if (await watcher.tickDrafts().catch(() => false)) takeDrafts(watcher.drafts, draftsAsked);
for (const m of fresh) {
if (m.from === session.device.id || isEditNotice(m) || !wantsNotice(meRef.current, m)) continue;
if (document.hidden || activeRef.current !== m.channel) notify(`${m.fromNick}#${m.from}`, m.locked ? "🔒" : m.text || S.fileNotice);
if (document.hidden || activeRef.current !== m.channel) notify(`${m.fromNick}#${m.from}`, m.locked ? "🔒" : snippet({ text: m.text }, 200) || S.fileNotice);
}
if (await watcher.tickPresence().catch(() => false)) setPresence(watcher.presence);
if (Date.now() - beat > 5 * 60_000) { beat = Date.now(); bus.heartbeat(session.device).catch(() => {}); }
Expand Down Expand Up @@ -1360,7 +1361,6 @@ function highlight(m: Message, q: string): ReactNode {
return <>{from > 0 && "…"}{text.slice(from, i)}<mark>{text.slice(i, i + q.length)}</mark>{text.slice(i + q.length, i + q.length + 80)}</>;
}

const linkify = (text: string) => text.split(/(https?:\/\/\S+)/g).map((part, i) => (/^https?:\/\//.test(part) ? <a key={i} href={part} onClick={(e) => { e.preventDefault(); openLink(part); }}>{part}</a> : part));
const num = (x: number) => x.toLocaleString(LOCALE, { maximumFractionDigits: 1 });
const size = (n: number) => (n < 1024 ? `${n} B` : n < 1e6 ? `${num(n / 1024)} KB` : `${num(n / 1e6)} MB`);
const time = (iso: string) => new Date(iso).toLocaleTimeString(LOCALE, { hour: "2-digit", minute: "2-digit" });
Expand Down Expand Up @@ -1392,19 +1392,20 @@ function systemText(m: Message, devices: Device[]): string {
* little movement fires onHold with the point to anchor a menu. A normal tap still works (links, buttons). */
function Swipeable({ className, children, onSwipe, onHold }: { className: string; children: ReactNode; onSwipe: () => void; onHold: (x: number, y: number) => void }) {
const ref = useRef<HTMLDivElement>(null);
const start = useRef<{ x: number; y: number } | null>(null);
const start = useRef<{ x: number; y: number; fixed: boolean } | null>(null);
const dx = useRef(0);
const hold = useRef<ReturnType<typeof setTimeout> | null>(null);
const clearHold = () => { if (hold.current) { clearTimeout(hold.current); hold.current = null; } };
const begin = (x: number, y: number) => {
start.current = { x, y }; dx.current = 0;
// on a table or code that scrolls sideways, a sideways drag scrolls it: the bubble stays put
const begin = (x: number, y: number, target: EventTarget) => {
start.current = { x, y, fixed: !!(target as Element).closest?.(".scroll-x") }; dx.current = 0;
clearHold();
hold.current = setTimeout(() => { if (start.current && Math.abs(dx.current) < 8) { onHold(x, y); start.current = null; if (ref.current) ref.current.style.transform = ""; } }, 500);
};
const move = (x: number, y: number) => {
if (!start.current) return;
const ddx = x - start.current.x, ddy = y - start.current.y;
if (Math.abs(ddy) > Math.abs(ddx)) { start.current = null; clearHold(); if (ref.current) ref.current.style.transform = ""; return; } // vertical: let the list scroll
if (Math.abs(ddy) > Math.abs(ddx) || start.current.fixed) { start.current = null; clearHold(); if (ref.current) ref.current.style.transform = ""; return; } // vertical: let the list scroll
dx.current = Math.max(-80, Math.min(0, ddx));
if (Math.abs(ddx) > 6) clearHold();
if (ref.current) ref.current.style.transform = `translateX(${dx.current}px)`;
Expand All @@ -1418,10 +1419,10 @@ function Swipeable({ className, children, onSwipe, onHold }: { className: string
return (
<div ref={ref} className={`${className} swipeable`}
onContextMenu={(e) => { e.preventDefault(); onHold(e.clientX, e.clientY); }}
onTouchStart={(e) => begin(e.touches[0].clientX, e.touches[0].clientY)}
onTouchStart={(e) => begin(e.touches[0].clientX, e.touches[0].clientY, e.target)}
onTouchMove={(e) => move(e.touches[0].clientX, e.touches[0].clientY)}
onTouchEnd={end}
onPointerDown={(e) => { if (e.pointerType === "mouse") begin(e.clientX, e.clientY); }}
onPointerDown={(e) => { if (e.pointerType === "mouse") begin(e.clientX, e.clientY, e.target); }}
onPointerMove={(e) => { if (e.pointerType === "mouse") move(e.clientX, e.clientY); }}
onPointerUp={(e) => { if (e.pointerType === "mouse") end(); }}
onPointerLeave={(e) => { if (e.pointerType === "mouse" && start.current) end(); }}>
Expand Down Expand Up @@ -1546,7 +1547,7 @@ function MessageList({ list, me, bus, devices, authors, loading, ticks, quoted,
{quotedIds(m).map((id) => { const q = quoted(id); return <button key={id} className="quote" onClick={() => onJump(id)}>{q ? <><span className="quote-who">{q.from === me.id ? S.you : q.fromNick}</span><span className="quote-text">{q.deleted ? S.deletedMsg : snippet(q, 90)}</span></> : <span className="quote-text muted">{S.quotedMessage}</span>}</button>; })}
{m.deleted && <div className="text deleted">🚫 {S.deletedMsg}</div>}
{m.locked && <div className="text deleted">🔒 {S.lockedMsg}</div>}
{m.text && !m.locked && <div className="text">{linkify(m.text)}</div>}
{m.text && !m.locked && <div className="text"><MessageText text={m.text} /></div>}
{m.edits && openEdits.has(m.id) && <div className="edits" aria-label={S.earlier}>{m.edits.map((e, i) => <div key={i}><span className="muted">{when(e.at)}</span> {e.text}</div>)}</div>}
{m.files?.map((f, i) => <Attachment key={`${i}-${f.name}`} file={f} bus={bus} />)}
{m.ask && still && (() => {
Expand Down
93 changes: 93 additions & 0 deletions app/src/markdown.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import { Fragment, useMemo, type ReactNode } from "react";
import { Lexer, type Token, type Tokens } from "marked";
import { openLink } from "./platform.ts";

/** A message's text: links open outside the app, and a fenced block (```lang … ```) shows as what it holds:
* ```md as Markdown (tables too), any other as code. Nothing in a message ever becomes HTML: Markdown is parsed
* to tokens and drawn here, and HTML written in it shows as text. */
export function MessageText({ text }: { text: string }) {
const parts = useMemo(() => fences(text), [text]);
return <>{parts.map((p, i) => typeof p === "string" ? <Fragment key={i}>{linkify(p)}</Fragment>
: MARKDOWN.has(p.lang) ? <Markdown key={i} src={p.body} /> : <Code key={i} text={p.body} />)}</>;
}

const MARKDOWN = new Set(["md", "markdown"]);
type Fence = { lang: string; body: string };

/** Text and the fenced blocks in it, in order; a block left open stays text. */
export function fences(text: string): (string | Fence)[] {
const out: (string | Fence)[] = [];
const re = /^(`{3,})[ \t]*([\w+#.-]*)[^\n]*\n([\s\S]*?)\n?^\1[ \t]*$\n?/gm; // closed by as many backticks: ```` can hold ```
let at = 0;
for (let m; (m = re.exec(text)); at = re.lastIndex) {
const before = text.slice(at, m.index).replace(/\n$/, "");
if (before) out.push(before);
out.push({ lang: m[2].toLowerCase(), body: m[3] });
}
if (at < text.length) out.push(text.slice(at));
return out;
}

function linkify(text: string): ReactNode[] {
return text.split(/(https?:\/\/\S+)/g).map((part, i) => (/^https?:\/\//.test(part) ? <Link key={i} href={part}>{part}</Link> : part));
}

function Link({ href, children }: { href: string; children: ReactNode }) {
return <a href={href} onClick={(e) => { e.preventDefault(); openLink(href); }}>{children}</a>;
}

/** Wide tables and long lines scroll sideways inside the bubble instead of widening it. */
function Code({ text }: { text: string }) {
return <div className="scroll-x"><pre className="code"><code>{text}</code></pre></div>;
}

function Markdown({ src }: { src: string }) {
const tokens = useMemo(() => new Lexer({ gfm: true }).lex(src), [src]);
return <div className="md">{blocks(tokens)}</div>;
}

const blocks = (tokens: Token[]): ReactNode[] => tokens.map(block);

function block(t: Token, k: number): ReactNode {
switch (t.type) {
case "space": return null;
case "heading": { const H = `h${Math.min(t.depth + 2, 6)}` as "h3"; return <H key={k}>{inline(t.tokens)}</H>; } // # is still small in a bubble
case "paragraph": return <p key={k}>{inline(t.tokens)}</p>;
case "text": return <Fragment key={k}>{t.tokens ? inline(t.tokens) : t.text}</Fragment>; // a tight list's item
case "blockquote": return <blockquote key={k}>{blocks(t.tokens ?? [])}</blockquote>;
case "code": return <Code key={k} text={t.text} />;
case "hr": return <hr key={k} />;
case "list": {
const L = t.ordered ? "ol" : "ul";
return <L key={k} start={t.ordered && t.start !== 1 ? Number(t.start) : undefined} className={t.items.some((i: Tokens.ListItem) => i.task) ? "tasks" : undefined}>
{t.items.map((item: Tokens.ListItem, j: number) => <li key={j}>{blocks(item.tokens)}</li>)}
</L>;
}
case "checkbox": return <input key={k} type="checkbox" checked={t.checked} disabled />;
case "table": {
const cell = (c: Tokens.TableCell, j: number, Tag: "th" | "td") => <Tag key={j} style={{ textAlign: c.align ?? undefined }}>{inline(c.tokens)}</Tag>;
return <div key={k} className="scroll-x"><table>
<thead><tr>{t.header.map((c: Tokens.TableCell, j: number) => cell(c, j, "th"))}</tr></thead>
<tbody>{t.rows.map((r: Tokens.TableCell[], j: number) => <tr key={j}>{r.map((c, n) => cell(c, n, "td"))}</tr>)}</tbody>
</table></div>;
}
default: return <p key={k}>{t.raw}</p>; // HTML and anything else: as written
}
}

function inline(tokens: Token[] = []): ReactNode[] {
return tokens.map((t, k) => {
switch (t.type) {
case "strong": return <strong key={k}>{inline(t.tokens)}</strong>;
case "em": return <em key={k}>{inline(t.tokens)}</em>;
case "del": return <del key={k}>{inline(t.tokens)}</del>;
case "codespan": return <code key={k}>{t.text}</code>;
case "br": return <br key={k} />;
case "text": return <Fragment key={k}>{t.tokens ? inline(t.tokens) : t.text}</Fragment>;
case "escape": return <Fragment key={k}>{t.text}</Fragment>;
// a web link opens outside the app; an image is a link too (loading it would tell its server who read the message)
case "link": case "image": return /^https?:\/\//i.test(t.href) ? <Link key={k} href={t.href}>{t.type === "link" ? inline(t.tokens) : t.text || t.href}</Link> : <Fragment key={k}>{t.raw}</Fragment>;
default: return <Fragment key={k}>{t.raw}</Fragment>;
}
});
}
19 changes: 19 additions & 0 deletions app/src/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,25 @@ nav .muted.small { padding: 2px 10px; margin: 0; }
.kind-tag { margin-left: 6px; font-size: 11px; font-weight: 600; color: var(--muted); border: 1px solid var(--line); border-radius: 6px; padding: 0 5px; }
.text { white-space: pre-wrap; overflow-wrap: anywhere; }
.text a { color: var(--accent); }
/* fenced blocks in a message: ```md as Markdown, any other as code; wide ones scroll sideways */
.scroll-x { overflow-x: auto; max-width: 100%; margin: 6px 0; }
.text code, .md code { font: .9em/1.45 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; background: color-mix(in srgb, currentColor 8%, transparent); border-radius: 4px; padding: 0 4px; }
.text pre.code { margin: 0; padding: 8px 10px; border-radius: 8px; background: color-mix(in srgb, currentColor 6%, transparent); white-space: pre; overflow-wrap: normal; }
.text pre.code code { background: none; padding: 0; }
.md { white-space: normal; }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p, .md ul, .md ol, .md blockquote { margin: 6px 0; }
.md ul, .md ol { padding-left: 20px; }
.md ul.tasks { list-style: none; padding-left: 2px; }
.md input[type="checkbox"] { width: auto; padding: 0; margin: 0 6px 0 0; vertical-align: -1px; accent-color: var(--accent); }
.md h3, .md h4, .md h5, .md h6 { margin: 10px 0 4px; line-height: 1.3; }
.md h3 { font-size: 1.2em; } .md h4 { font-size: 1.1em; } .md h5, .md h6 { font-size: 1em; }
.md blockquote { padding-left: 10px; border-left: 3px solid var(--line); color: var(--muted); }
.md hr { border: 0; border-top: 1px solid var(--line); margin: 10px 0; }
.md table { border-collapse: collapse; font-size: .95em; width: max-content; max-width: 64em; } /* a row on one line where it can be: past the bubble, it scrolls */
.md th, .md td { border: 1px solid var(--line); padding: 4px 8px; overflow-wrap: normal; vertical-align: top; }
.md th { background: color-mix(in srgb, currentColor 6%, transparent); white-space: nowrap; text-align: start; }
.meta { font-size: 11px; color: var(--muted); text-align: right; margin-top: 2px; }
.msg.pending { opacity: .7; }
.msg.failed { border-color: var(--danger); }
Expand Down
2 changes: 1 addition & 1 deletion cli/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@opencommunicate/cli",
"private": true,
"version": "0.9.4",
"version": "0.9.5",
"type": "module",
"bin": {
"opencom": "dist/opencom.mjs"
Expand Down
2 changes: 1 addition & 1 deletion core/package.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{ "name": "@opencommunicate/core", "private": true, "version": "0.9.4", "type": "module", "main": "src/index.ts" }
{ "name": "@opencommunicate/core", "private": true, "version": "0.9.5", "type": "module", "main": "src/index.ts" }
2 changes: 1 addition & 1 deletion core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1108,7 +1108,7 @@ export function newestByChannel(list: Pick<Message, "id" | "channel">[]): Record
export function snippet(m: Pick<Message, "text" | "files" | "locked"> | undefined, max = 80): string {
if (!m) return "";
if (m.locked) return "🔒";
const t = (m.text ?? "").replace(/\s+/g, " ").trim();
const t = (m.text ?? "").replace(/^`{3,}.*$/gm, "").replace(/\s+/g, " ").trim(); // a fenced block's ```lang lines say nothing
if (t) return t.length > max ? t.slice(0, max - 1) + "…" : t;
return m.files?.length ? `📎 ${m.files[0].name}` : "";
}
Expand Down
4 changes: 2 additions & 2 deletions core/src/notify.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* Phone notifications through ntfy (https://ntfy.sh, free, no account). A device that turns them on stores
its own secret topic URL in devices/<id>.json (the bus repo is private); whoever sends a message posts a
short notice to the recipients' topics. The ntfy app on the phone shows it at once. */
import { dmPeer, handle, isDm, wantsNotice, type Device, type Group, type Message } from "./index.ts";
import { dmPeer, handle, isDm, snippet, wantsNotice, type Device, type Group, type Message } from "./index.ts";

export function recipients(m: Message, devices: Device[], groups: Group[]): Device[] {
const others = devices.filter((d) => d.id !== m.from);
Expand All @@ -15,7 +15,7 @@ export async function notifyRecipients(m: Message, from: Device, devices: Device
const where = m.channel === "all" ? "#all" : isDm(m.channel) ? "" : `#${groups.find((g) => g.channel === m.channel)?.name ?? m.channel}`;
const title = `${handle(from)}${where ? ` → ${where}` : ""}`;
// a sealed message's words go no further than the chat: ntfy.sh only hears that there is one
const body = m.enc ? "🔒" : (m.text || (m.files?.length ? `📎 ${m.files.map((x) => x.name).join(", ")}` : "")).slice(0, 200);
const body = m.enc ? "🔒" : snippet({ text: m.text }, 200) || (m.files?.length ? `📎 ${m.files.map((x) => x.name).join(", ")}` : "").slice(0, 200);
// a recipient who muted the channel, or wants only mentions there, is skipped
const targets = recipients(m, devices, groups).filter((d) => /^https:\/\/ntfy\.sh\/[\w-]{12,64}$/.test(d.notify ?? "") && wantsNotice(d, m));
// Title and click go in the query string: HTTP headers must be Latin-1, and titles hold "→", emoji and Turkish.
Expand Down
7 changes: 6 additions & 1 deletion core/test/search.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// older() pages through what is not loaded yet, newest first.
import { test } from "node:test";
import assert from "node:assert/strict";
import { Bus, msgPath, newerVersion, searchMessages } from "../src/index.ts";
import { Bus, msgPath, newerVersion, searchMessages, snippet } from "../src/index.ts";

test("newerVersion compares part by part as numbers", () => {
assert.equal(newerVersion("0.7.10", "0.7.9"), true);
Expand Down Expand Up @@ -46,3 +46,8 @@ test("older() pages through what is not loaded, newest first", async () => {
assert.deepEqual(next.messages.map((m) => m.text), ["m2", "m1"]);
assert.equal(next.left, 0, "the DM is not one of the channels asked for");
});

test("a snippet (a chat's last message, a notification) leaves out a fenced block's backtick lines", () => {
assert.equal(snippet({ text: "Plan:\n```md\n| a | b |\n|-|-|\n```\nok" }), "Plan: | a | b | |-|-| ok");
assert.equal(snippet({ text: "```\n```" }), "");
});
2 changes: 1 addition & 1 deletion desktop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@opencommunicate/desktop",
"productName": "OpenCommunicate",
"private": true,
"version": "0.9.4",
"version": "0.9.5",
"description": "OpenCommunicate for macOS and Windows",
"author": "Ege BULUT",
"main": "main.cjs",
Expand Down
4 changes: 4 additions & 0 deletions docs/AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ opencom send "Backend" "@frontend-claude the API field is now user_id" # group
opencom send all "Deploy finished." --file deploy.log
```

In the apps, a fenced block marked `md` shows as Markdown (headings, lists, checklists, links, tables; a table too
wide for the screen scrolls sideways), and any other fenced block as code. Use one for a table or a structured
report: `opencom send ege#7779 $'Results:\n```md\n| suite | result |\n|-|-|\n| unit | 79/79 |\n```'`. HTML stays text.

## Status

`opencom status "deploying 0.8.5 to the site"` tells people what this session is doing: the apps show it next
Expand Down
Loading
Loading