Commit graph imsd-messages/project.cpp
Author SHA1 Message Date
9707c9fa26
Store: the message database on Crafter.DB
One table without an ordered column: Crafter.DB enforces the order on
every write, and a List() import after a restart can carry an older
stamp than the last row, so a conversation is sorted on read. A row
carries the plan it was written under, the SIM's country code and its
operator, a column each. Messages are looked up by imsd id (unique
across imsd's runs by its run token: an id names one message, and an
empty one — a text imsd has not answered yet — none); read marks and
deletes go per message and per conversation; every write but a Compact
is caught at this one boundary — a store that refuses one (Crafter.DB's
IOError: the disk full, the file system read-only) answers nullopt from
Add, false or a count of 0 (a row appended before its Flush failed is
tombstoned; an in-place write whose Flush failed stays in the row as the
process reads it; SetState's state and imsd's id land in place even when
a reason cannot — the id is inline in the row, 64 bytes as imsd bounds
it, one past that refused rather than thrown), and tells its
onWriteState listener once of the refusal and once of the next write
that got room, which is one that grew a file: Crafter.DB allocates its
extents, so a write that fit the ones it had (an in-place one, a short
row) is no recovery. So a refused write ends no caller's process and the
app's banner can say so. A lock file beside the table, held for the
store's life, makes a second store on the same directory throw
LockedError (the table's own lock sits on an inode a Compact replaces);
it is built on Crafter.DB's File and Os — the directory made 0700 at
every component, the file 0600 and never a symlink, a lock that fails
for any reason but another holder an IOError, not a LockedError. Every
change a call answers as made — a row id, true, a count — is committed
before the call returns, so a row Add returned is on disk. The file's
format is held by the build: static_asserts on the row's size and layout
fingerprint (Crafter.DB's Layout) and on the stored values of Direction
and MessageState, so a column changed without a version bump fails the
build and not a user's open, and an enumerator moved fails it where an
open would misread the stored states without a word.

Tested: tests/Store in a temp directory: the round trip, the sort of a
later-appended older message, the updates, the lookup by imsd id and an
erased row's, an id past imsd's bound refused, the lock from a second
open, persistence across a reopen, Compact, a row kept by a child
process that ends without a flush, the private file modes, and a write
refused under the file-size limit (told once with its reason, the rows
before it standing, an in-place write going through and telling nothing,
a state landing without its refused reason and imsd's id beside it, the
next Add after the limit's lifting telling of the recovery once), and a
Flush failing after its Append (the descriptor pointed at /dev/null for
the one write) tombstoning the row Add refused.
2026-11-18 01:12:27 +01:00
724cd409ba
Model: messages, conversations and the banner
The GLib-free shape of what the app shows: imsd's state words (each
applies as it comes: imsd gives a message's words in order, the
submission's first and a status report's after sent, its AGENTS.md
section 8.4); a received text (the dictionary of imsd's AGENTS.md
section 8.4) becoming a message keyed by the sender's address completed
with the code of the number it arrived for (imsd's `to`, the
subscriber's own number at receipt — the record's: a text imsd kept
across a SIM change would otherwise take the new SIM's code) or, lacking
one, of the service centre that delivered it, the own number's code —
none where the centre's stood in, which names no SIM's country — and the
operator of the SIM it arrived under (imsd's `operator`) its plan
(Number's SimPlan), and whose sort time is the service centre's stamp,
else its arrival; the short message type 0, which a phone acknowledges
and discards (IsType0, TS 23.040 9.2.3.9); the grouping into
conversations newest first, unread counting incoming unread only; and
the one-line banner from what the app knows about imsd: absent,
connecting (GetStatus has not answered since imsd appeared), off,
subscribe refused, unregistered, the store refusing a write (its disk
full: texts wait; a send still goes), subscribe failed otherwise — what
blocks sending before what only costs live updates — messages it may not
delete.

Tested: tests/Model.
2026-11-17 22:24:23 +01:00
335b27b72d
Wrap: word wrap and ellipsis over a measure function
Crafter.Graphics shapes one line at a time and drops newlines, so the app
breaks text itself: a greedy wrap with breaks after spaces and hyphens
(a space that itself overflows ends the line after the words that fit,
and opens no line of its own when it ends the text or a newline
follows; one at a line's start is no break at all, nor is a run of
them: a break is recorded only once the line holds a word, and a run of
spaces wider than the line splits like a word, with the same rule at the
text's end and before a newline), hard breaks at
newlines, over-long words split between code points, and
the run of spaces where a line wraps left out of both lines. Results are
cached per (text, width, size). The measure is a function, so the caller
supplies the advances; the tests use a constant ten-pixel advance.

Tested: tests/Wrap on a ten-pixel monospace measure, a leading run of
spaces among the cases.
2026-11-17 06:14:18 +01:00
2a833b0bad
Time: ISO 8601 stamps, civil dates and the captions
imsd renders the service centre's time stamp of a text as ISO 8601 with
the centre's offset and adds the arrival epoch; the captions need the
user's local day and clock. The parser is hand-rolled, with the
calendar's own check of the date (a 30th of February is no date); the
civil dates, the weekdays and the month names are std::chrono's calendar
and its formatting; every caption takes the local offset of the instant
as an argument, so nothing here depends on a time zone database and the
tests inject the offsets.

Tested: tests/Time, the KPN bench stamp in five spellings, rejected
garbage and days the month does not have, the day and list captions
around midnight and across a year.
2026-11-17 06:14:18 +01:00
3d635a6f9d
project: the repository skeleton
The SMS app for imsd's net.catcrafts.IMS1.Messaging interface starts
here: the licence (GPL-3.0-only), FUNDING.yml, README and AGENTS, a
project.cpp with the three build products (imsd-messages-core: std and
Crafter.DB; imsd-messages-bus: GLib; the imsd-messages executable),
their module units as stubs, the version constant, the bundled Noto Sans
font with its OFL text, and the first test. This commit is the base every
later range is reviewed against.

Tested: crafter-build builds the three products and --version answers,
crafter-build test passes the one test, lint and format --check are clean
on every text rule and on the AST rules for the eleven files without a
global module fragment; the four files that include gio/gio.h are not
parsed by the lint driver's libclang (no C++ standard library on its
include path: 'type_traits' file not found), which is a Crafter.Build
matter.
2026-10-17 23:14:00 +02:00