The + opens a screen with a number field (its placeholder "Number", a
parameter of the compose field now) and Start; the number becomes a
conversation key through Number's ConversationKey, as an sms: link's
does (E.164 through the country code, a short code as digits), anything
else is refused in place. A long press on a conversation row offers to
delete the conversation, on a message to copy its text to the clipboard
or delete it; only those two have one: App tells the recogniser before
each press whether what it lands on has a long press (GestureDetector's
longPress), and without one a press held as long — on a button, a field,
a sheet's row — stays a tap at its release, so a slow finger presses the
button all the same. A sheet draws on the overlay layer over a scrim and
pushes its regions last, so they win the hit test, and the wheel scrolls
nothing under it; Escape, the back arrow and a tap outside dismiss it.
Deleting a conversation also closes its notification and drops its
draft; the + keeps the draft of the conversation it leaves, as Back
does, and so does a view that closes because its last message was
deleted. The deletes go through Sync (Erase, EraseConversation: the
commit before, which keeps a deleted text deleted). The number field's
box is drawn by its screen, as the send bar's is by the bar: the shared
field drawing paints no background of its own. Opening a conversation,
from a notification or a link, leaves the new-conversation screen and
any sheet, and the + leaves any sheet. A key whose press changed the
screen acts once: held, its repeats are not the new screen's — Enter,
which started the conversation, would type line breaks into its field,
and Escape would go on back, from a sheet through the conversation and
its draft. A sheet that asks to delete a conversation goes when a text
arrives for it: a yes would delete that text unread. A press on the
conversation's row opens no such sheet either while the row it aimed at
had not shown the text — the regions are a frame's: the press that is
down when the text arrives, and one that comes down before the next
frame is drawn, have no long press; a release before the long-press time
is still the row's tap, while the row stays under the finger.
--new and --bench-sheet put either on screen for the bench
(--bench-sheet conversation or message, each on the screen a long press
opens it over: another value is refused, and one that finds nothing to
press says so in the log), and are window flags as --screenshot is.
Tested: the screens and the sheets by the bench (--new, --bench-sheet)
and the phone step's screenshots; the deletes' logic with the commit
before, in tests/Store and tests/Sync; the press without a long press in
tests/Gesture (the timer gives no long press and a move within the slop
nothing; the release is the tap, however late; a slide off the control
is a drag); a deleted conversation's draft dropped, in tests/Edit. The
press on a row a text arrived for has no bench: none holds a finger on a
row.
imsd keeps a received text until an app deletes it, and a delete can be
refused (polkit, for a session that is not the active one) or time out:
the List after the next start would carry the text again and the app
would import it again (within a run Sync's own record of what it
imported keeps it out). And a deleted row is a tombstone whose bytes
stay in the file until it is rewritten.
The store gains a second table, erased.cdb: the imsd ids of received
texts the user deleted while imsd may still hold their copies, its
format held by the build as the first table's is. Erase and
EraseConversation remember the id before the row goes (a crash between
the two leaves a remembered id, never a text that comes back; a
remembering the store refuses refuses the delete), ImsdIds folds the
remembered ids in, so Sync's `known` keeps a List from importing them,
and ForgetErased drops the ids a List no longer carries — of those
remembered before that List was sent: an id remembered while it was in
flight waits for the next (FetchList's `before` snapshot). Sync's Erase
and EraseConversation go to the store; Fail and the Send continuation
check that the row still exists, so a text deleted while its Send is in
flight takes no late word, and a late answer for a deleted message finds
no row and is logged. main compacts both files at start when either
holds deleted rows or bytes an update or a delete orphaned (a state
reason replaced by another can leave some, so a start after a send may
rewrite both with nothing deleted), and opens the store again on what is
there if the rewrite failed: a deleted text's bytes leave the files at
the next start (a resident instance keeps them until then — nothing
holds a row id across the rewrite but the app itself).
Tested: tests/Store — the remembered ids across a reopen and as known, a
deleted sent text's id not remembered, the ids imsd no longer lists
forgotten, the bytes of deleted texts and forgotten ids gone after the
Compact and a reopen while the kept ones stay, a forgotten id alone
enough for a Compact, the second file private and rewritten with the
first; tests/Sync — a message deleted while it is sending (its late
answers write nothing and are logged), a received text imported,
remembered when deleted and forgotten when no longer listed, a text
signalled while a List is in flight kept by the List sent before the
delete — which forgets the id remembered before it went out — and
forgotten by the next, and a state for another client's text leaving
every message alone.
The resident model: a close tears the window down — a fling stops, the
device finishes its frame, the listeners let go, the frame driver and
the canvas go — and keeps the process, the store, the screens and the
bus subscription. Show builds the window again, with a conversation left
open coming back (its caret blinking again; an Open or a Show that lands
between a close and its deferred teardown keeps the window); the Wayland
display source is kept across a hide. A text that arrives for the kept
conversation while the window is hidden — from the close on, not from
its deferred teardown — stays unread and keeps its notification, like
any other conversation's; showing the window again marks it read and
closes the notification. Without a session bus, where nothing could show
the window again, a close ends the process as before. A second launch
reaches the running instance over the bus name and a notification's tap
through its ActionInvoked signal, as before.
--hide-after and --hide-every drive the cycle from the bench as closes
(without a session bus such a close ends the process, as any close does
there), and are window flags as --screenshot is.
--prefill types into the opened conversation's field (App::Prefill, the
bench's typing, comes with it), --send-draft taps Send 1.5 s after start
and --screenshot-after chooses the moment of the capture, so a machine
can exercise the compose path and look at the result; --prefill and
--send-draft are window flags as --screenshot is — refused beside --send
and --quit, and beside a running instance (--screenshot-after acts
through --screenshot, refused there, its seconds checked as
--quit-after's are) — and a --prefill text that is not UTF-8 is refused
as --send's is. utilities/fake-imsd.py owns net.catcrafts.IMS1 on the
session bus with the answers chosen on its command line: a registered
daemon (its GetStatus answers name the subscriber's number, --ppi; the
Messaging one and every text the SIM's operator, --operator) that
accepts sends and reports them sent (the stamp in imsd's ISO 8601 form,
at the host's offset) and delivered, a store to list and delete, texts
injected at start or delivered as unicast Received while the app runs,
the refusals (AccessDenied, NotSupported, failed sends) and a Subscribe
answered late (--subscribe-delay: the app before imsd's status is in).
It runs on the host (python3-gi), the app in the sandbox, both on the
same session bus.
A text message needs several lines and UTF-8, and the library's
InputField is one line edited by byte, so the field is the app's own.
Its state and editing are the core's (ImsdMessages:Edit, tested without
a window): a plain struct, insertion at the cursor, Backspace and Delete
by code point, Home and End within the line, a newline. Ui:Compose turns
the keys into those edits and draws the field one to five lines tall —
as many as half the area under the header and the banner holds, and one
at the least — with the canvas's word wrapper (a longer text shows the
lines that end at the caret's, or the first ones while the caret is
among them), a placeholder when empty, the caret at the cursor, and a
tap placing the cursor at the nearest byte by the widths the glyphs are
drawn at, in the text as it is when the tap lands (an edit since the
last frame only asked for one; a field no frame has laid out yet takes a
tap as one at its text's end; a tap at or past the last line's end asks
for the text's end, where a space the wrapper hung off the line may be).
The bar under a conversation holds the field and Send, enabled only with
text, a sendable status and an address to send to; Send hands the text
to Sync with that address and clears the field (a store that refuses the
text keeps the draft) (Model's SendAddress: as a link gave it, else the
latest message's — the network's form of a received text, the dialled
form of ours — never the key, whose completed country code is a guess
that groups; a conversation with neither has Send off, and so has one
whose address is not international — a national number, a short code;
typed, linked or the message's — and was typed or written under another
SIM's plan than the one known now, which the plan each row and the view
carry tells (the view's is that of the SIM the address was typed under,
which Number's AfterStatus keeps; Number's AnotherPlan, its second
caller)); Sync's StateChanged moves the bubble's caption. Keys reach the
field while a conversation is open (Escape goes back, Ctrl+Enter sends),
a held key repeats through a timer since frames are on demand, and the
caret blinks on one. A text typed and not sent is its conversation's,
not the view's: leaving the conversation (Back, another one opened by a
notification or a link) keeps it by the conversation's key for the run,
and opening the conversation again takes it up (Edit's Drafts: an empty
field keeps nothing and drops nothing; the draft of a typed or linked
address follows imsd's status as the open conversation's key does —
Number's AfterStatus over the address and the plan kept with it — so one
left before the status brought the country code is found under the key
the address makes afterwards; and a second text kept under one key — two
keys that became one — goes after the first on a line of its own).
Tested: tests/Model, the address a text goes to (the typed or linked
one, the latest message's, none for an emptied conversation, none under
another SIM's plan than it was typed or written under — a national
number with or without a trunk prefix under another country's SIM, a
short code under another operator's too, though dialled under the same
operator, the own number read when it was typed or not; a national
number typed before the own number was read, none under another operator
— an international one under any — and a typed address judged by its own
plan, whatever the latest row's); tests/Edit (code points of one to four
bytes, the moves within a line, the edits that change nothing, the first
line shown as the caret moves down a long text; the drafts: kept and
taken up by key with the cursor, taken once, an empty field keeping and
dropping nothing, one per conversation, a second text under one key on a
line of its own; a typed address's following the status — moved when the
code comes, not while texts are stored under its key, not under another
SIM's status, a list conversation's left alone and the store not asked,
the learned plan kept, two keys that became one keeping both texts).
The executable shows the window at start unless --daemon (which
--headless and --send imply), on Activate and Open from a second launch
or a notification (of the URIs an Open carries, its first sms: link),
and on an sms: link, which opens the conversation of its first recipient
at once (Number's SmsUriRecipient: the scheme in any case, the fields
after '?' dropped, percent-escapes decoded; then ConversationKey with
the country code known at that moment — --country's, else the one imsd's
status gave once it is in, else what the number itself carries — which
takes NormalizeNumber's result as a phone number — E.164, or digits: a
short code, a national number no country code completed — and nothing
else), or just the window when it names no phone number; the
conversation remembers the address as dialled and the plan of the SIM it
was typed under, and that SIM's statuses move its key (Number's
AfterStatus, one step, applied in App::Status: another SIM's status —
another operator's, or without operators another own number's code,
Number's SameSim — changes nothing, so a SIM change leaves the key and
the plan the address was typed under; the same SIM's fills in what the
plan lacks, and the key follows from its digits to the centre's stand-in
and from any key to the own number's code once the plan has it, never
from one stand-in's key to another's and not while the code is lost, the
conversation it moves to shown at its latest message — and only while
nothing is stored under the key: a text stored before the code arrived
keeps the conversation on the key its rows carry). The shell forwards
Sync's events to the window and the notifier closes a conversation's
notification when it is opened (one closed while its Notify is on its
way goes when the answer comes). --screenshot renders one frame outside
the compositor's pacing 2.5 s after start — 600 ms later where it has to
make the window first — and saves it as a PNG before quitting, or ends
with exit 1 when no frame was captured — with a line when no window
could render it or another instance is running (a flag that acts on the
window finds none there: the run forwards nothing), and without one when
the run ended before the capture (the display gone, a close that quits);
a PNG the library cannot write is not noticed at this commit, and a
capture that throws ends the process — the verification path for a
machine without eyes, which must not depend on a desktop that repaints —
and --quit-after ends a bench on its own clock (a number of seconds its
timer can take: anything else is refused); a --send errand ended by
anything but its final state — that clock — exits 2, as it does on a
signal, its end latched before the loop stops; --screenshot beside
--send or --quit is refused, neither having a window. The window is torn
down in order before the bus client stops, and when the compositor's
connection breaks the process ends, so the next launch starts afresh. A
window the library cannot make (no display, no Vulkan driver) is logged
by Ui's Show and the start ends with exit 1, as a start without its
database does; a resident instance logs it and runs on without one, and
a later Activate or Open logs the same at once, the device's set-up
running only once.
Tested: tests/Number, the sms: links (a query, an escape, a list, the
scheme in capitals, no number), the keys of typed addresses, SameSim
(the same operator, another operator of one country, a status without
its operator, nothing known, own numbers' codes without operators) and
AfterStatus through the statuses a typed address meets: the stand-in
completing its digits while the plan learns the operator; another
stand-in, a lost code and another operator's status — its own number's
code the stand-in's or not — changing nothing; rows keeping the key
while the plan learns the code; the own number's code moving the
stand-in's key, at once or once nothing is stored; a key the own
number's code made, and its plan, staying under another SIM and under
its own SIM's stand-in; an own code that makes the stand-in's key; a
short code; --country before the operator; no operators; no address; an
international address, under another SIM and under its own; and the
address as dialled making the key the address as typed made.
The window library. Loop makes the Wayland display a GSource
(libwayland's prepare_read protocol) so D-Bus and the window are served
from one thread without the library's StartSync, which runs a loop of
its own that serves no GMainContext and would starve the bus; the app
owns its frame callback too — a redraw is a frame request and a bare
commit, the compositor's done runs one Window::Update, and nothing
re-arms unless something is dirty or animating — or the day changes: the
captions name the day and an idle window draws no frame by itself, so a
timer on the wall clock, which wakes at the next local midnight and
whenever that clock is set, asks for one when the local date is another
one (DayWatch); when the compositor's connection breaks the source stops
and says so (App's onDisplayLost), since the process cannot connect its
display again. Canvas initialises the device once per process and holds
the window, the font with a word wrapper and a text width over its
unrounded advances, as DrawText draws them, and four compositing layers
(background, the clipped scrolling content, the chrome, an overlay):
within one fused dispatch all quads composite before all text, so the
layers are separate dispatches in that order. The layers' buffer slots
hand their numbers back to the descriptor heap when they go, so the heap
is declared before them and outlives them. Screens draw the conversation
list (avatars, previews, time captions, unread badges, the
new-conversation button, with room under the last row to scroll clear of
it) and one conversation (day separators, wrapped bubbles, clock and
state captions — only what is in view, the layer's glyph budget being
finite) and record the regions a tap can hit. App wires them to the
store and Sync: mouse events become gestures (the detector's slop and
fling threshold set from the window's scale, the positions being buffer
pixels), a tap is resolved against the last frame's regions (which name
the conversation or message they drew, not a position a reload may
shift), scrolling is by wheel, drag or fling (a press stops a fling; a
screen change stops a fling and cancels the press under it, so the
scroll left behind keeps no velocity for a return to revive and a
release after a link's or a notification's Open is no tap on the new
screen), the window is created on the first Show (when the library
cannot and says so — no display, a compositor without wl_shm,
wl_compositor or xdg_wm_base, no Vulkan driver — Show logs why, Open
opens nothing, and the app runs on without one; a later Show fails at
once, the device's set-up running only once) and torn down in order on
Shutdown. ScreenshotThenQuit renders one frame outside the compositor's
pacing and saves it; a window it creates first waits 600 ms for the
compositor's configure, which sizes it (to the screen, on a phone). A
capture with no window to render it — none could be made, or it went
before the frame — is logged and sets App's exitCode to 1.
project.cpp gains Crafter.Graphics (--local takes the branch worktree with
the Wayland input work until it is merged), the imsd-messages-ui library,
and libevdev from the prefix of packaging/build-libevdev.sh on the
library's include path and the executable's library path (a sysroot
build looks for it in the sysroot instead).
What a finger or a mouse did, decided from raw Down/Move/Up/Cancel
phases over the app's own point type: a short press within the slop is a
tap at the press position, a press held past the long-press time (the
host's timer) a long press, movement past the slop a drag with its
deltas, a fast release a fling with a velocity (the last 100 ms of
movement before it: a finger held still before letting go flings
nothing). With it the scroll physics of a list (clamped offset, a
decaying fling that stops at the edges) and the topmost hit region under
a point.
Tested: tests/Gesture.
The executable now runs the app without its window: it owns the session
name or forwards to the instance that does (an sms: link, --quit; --quit
beside --send is refused, the errand being no instance, and so is a link
that is not UTF-8, which D-Bus does not carry; a name request that fails
or is refused ends the run with the error's words, exit 1, nobody being
shown to run), opens the database (the executable's own Crafter.DB
dependency enters here, with its first use), connects the GDBus client
to Sync and the notifier, and runs the GLib main loop. --daemon is the
resident mode, --headless adds a log line per event for the ssh smoke
test on the phone, --session talks to imsd --session, --data-dir and
--country override the database directory and the default country code
(a country code as the ITU's length rule reads one: a key is made of the
code as it is and read by that rule, so anything else is refused). A
--daemon with no sms: link that finds the name owned ends at once
instead of forwarding an Activate: the running instance already imports
and notifies, and a forwarded Activate asks it for its window;
--headless then exits 1, having run nothing (a link and --quit are
forwarded from a --daemon as from any launch). A Subscribe, a GetStatus
or a List that failed against a present imsd is tried again every 30 s,
and so is a text Sync holds for a store that refused it; that text is
notified all the same (OnUnstored), the notification being where it
shows, and is announced as any import once its row is in.
--send sends one text to the number as dialled (stored under its
normalised key; a NUMBER or TEXT that is not UTF-8 is refused before
anything is stored, exit 2: imsd takes D-Bus strings, and GLib would put
its own text in the place of other bytes and have that sent; an empty
NUMBER is refused there too) and exits on imsd's word for the submission
— sent (0) or failed (1), which reaches it as the message's change (a
status report's word follows sent, imsd's order) — or on its own failure
(1), a store that refuses the text among them; imsd has 60 s to be ready
and to take the text, then 2 (no final state) — once it has taken it the
clock decides nothing, since imsd bounds its submission itself and ends
it with a word, and a clock of the app's would report no final state for
a text imsd goes on to send — as a SIGINT or SIGTERM after the start-up,
before a final state, is 2 (a resident instance ending on either says so
in its log: a session bus closing under it sends SIGTERM too). It is a
client of its own: it takes no instance name, since a launch that finds
the name taken forwards and exits, and it leaves imsd's stored and
signalled texts to the instance that owns the user's store; beside that
instance it needs a --data-dir of its own, the store taking one writer.
It sends once GetStatus has answered, with Sync's Send gaining a force
flag that skips the local readiness check: imsd answers a Send to its
caller, subscribed or not, so a refused or unregistered errand ends with
imsd's own reason. Its rule is Sync's SendErrand, a class over the
listener's events with no GLib in it: one Send once the status is in and
none after an end, latched before the call (Sync announces a status from
inside Send — the store's word on its write — and the loop can dispatch
one after the clock's or a signal's end); one end — the message's final
state, the store's refusal, or none on the clock (which decides until
imsd has taken the text), a signal or the loop's end; the first of them
stands. The shell drives it with its loop, its 60 s source and its log.
Tested: tests/Sync, the errand among its cases (a forced send against an
unregistered status; imsd's words reaching the listener as the message's
changes, as they come), and its rule: one Send across a status announced
from inside Send (the store's recovery, end to end on a store refused
under the file-size limit), 0 on sent, 1 on failed and on the store's
refusal, 2 on the clock before imsd's id and on a signal, the clock
deciding nothing once imsd took the text, a final state given first
standing over the clock and the loop's end after it.
The GLib side of the app. Variant reads imsd's Received dictionary by
key and type as its SmsVariant writes it (`to`, the number the text
arrived for, a tel: URI read like the status's `ppi`; `operator`, the
SIM it arrived under), the GetStatus one with the subscriber's own
number and the SIM's operator in it (`ppi`, a tel: URI as the frozen
interface gives it; `operator`), and maps a GError to the core's error
kinds off GDBus's own mapping. Client is the Sync logic's transport:
asynchronous calls with their continuations as user data — every reply
guarded where it is delivered (OnCallDone), as are the signal handlers
and the name watch's callbacks: a throw is a fault the events hear, not
the end of the process — the calls behind imsd's polkit gate allow
interaction: Subscribe, List and Delete wait two minutes; Send has no
bound of the client's, since imsd sends the text once its prompt lets
the call through, however late, and a Send given up on would be failed
by Sync and be sent all the same; GetStatus ten seconds — (one call: the
Messaging status carries the own number, imsd reading both from one
snapshot; AGENTS.md §1 names both interfaces), the Messaging and
RegistrationChanged signals, and a watch on net.catcrafts.IMS1 whose
appeared callback is where Sync subscribes. Notifier shows one desktop
notification per conversation and replaces it as more texts arrive: one
Notify at a time per conversation, since the id to replace comes with
the answer; its default action asks the app for that conversation; the
body is escaped when the server renders markup (GetCapabilities, asked
once; Plasma and GNOME do), so a text's '<' or '&' shows as typed.
Instance owns net.catcrafts.ImsdMessages and serves
org.freedesktop.Application there, the Desktop Entry Specification's
interface of a running application: Activate, Open and ActivateAction,
each with its platform data — sent empty and not read: nothing in the
app can use an activation token yet — and one action, quit, any other
refused (the object registered before the name is asked for, so a launch
that forwards the moment the name is granted finds it; Own tells a name
another instance holds from a request that failed or was refused, and
keeps the error's words); it forwards a call to the owner. project.cpp
computes the gio flags once for the bus library, the executable and the
Decode test.
Tested: tests/Decode (every key of imsd's Received dictionary, one with
ten of them, GetStatus, the own number, the SIM's operator, the error
kinds, the markup escape, the parameters of the instance's three calls).
imsd keeps a received text it could store until the app deletes it and
sends its signals unicast to subscribers, so the logic is: Subscribe
whenever net.catcrafts.IMS1 appears (imsd's restart empties its list),
then GetStatus, whose answer ends the connecting state, and List, both
at once — a listed or signalled text keys itself by the number it
arrived for (imsd's `to`, the subscriber's own number at receipt) or,
lacking one, by the service centre that delivered it (Model's
MessageFromReceived), so no import waits for a status; import what the
store lacks, keyed by imsd's id (its run's token makes it unique across
imsd's runs, §8.4), and delete imsd's copy — again for a copy still
listed, so a delete that timed out gets another chance. A short message
type 0 (Model's IsType0) is not imported: imsd acknowledged it, and its
copy is deleted like any other. A copy polkit refused to delete is
counted on the banner and tried again at the next List imsd admits (one
polkit action gates List and Delete, so an admitted List means an
admitted Delete) and once imsd has restarted. A Received signal imports
and lists again, because a signal is queued for nobody. The listener is
called through a guard (GuardedListener): a throw out of a handler — a
logging failure, a bad_alloc — is caught and told once, so no handler
can stop Sync's own sequence, whatever the order of a word and the step
after it. A store that refuses a write (its disk full) is on the banner.
A listed text stays imsd's — nothing is deleted — and a signalled one is
held in memory and told through OnUnstored: imsd signals a text its own
store refused too, the signal then its only delivery, so no List may
ever carry it; the held text is tried again whenever a List comes back
with imsd's texts and at each Refresh, which is wanted while one is
held, until its row is in or a List carries it; one imsd did not store
is lost with a process that ends before then. Of the refusal itself the
store tells Sync of a refusal once and once of the next write that got
room (one that grew a file), every write but a Compact passing that one
gate, and the flag stays the store's — read again after the start's
sweep and after imsd's vanish; a send still goes, its own write a try —
refused, it answers kNotStored and the caller keeps the text; through,
it goes to imsd, and imsd's id lands in place (the store keeps it
inline) — a recovery lists at once and the Refresh lists meanwhile, so
the held imports are tried once there is room. A listener's call can
come from inside Sync's own (the store's word on a write, inside Send),
which the listener interface says. A Send stores the message pending
under its conversation key and asks imsd for the address as dialled (the
key groups; a country code completed for it is never dialled), the row
carrying the plan it is dialled under — the country code of the SIM's
own number, never the service centre's stand-in, and its operator, which
imsd's status gives — which a retry under another SIM's plan fails on,
since the address would reach another subscriber or another service
there (Number's AnotherPlan, here with its first caller: the same
operator is the same plan, a side's code known or not; under another
operator a national number means the same while both SIMs' own numbers
have one country code, and a short code is the operator's own; without
both operators the codes decide alone), and the StateChanged for its id
(unique across imsd's runs by the run's token, so it names one message)
moves it on — each word as it comes, imsd giving them in order (the
submission's first, a report's after sent; its AGENTS.md section 8.4) —
and a retry drops the failed attempt's imsd id (a row's id names its
current attempt); a Send's error fails the row and Retry sends the text
again, so the transport's contract (ImsdTransport's comment) is that a
Send is answered by imsd, or because imsd has left the bus, and never by
a clock of the transport's own, since imsd sends what it was asked once
its polkit prompt lets the call through, however late; imsd vanishing
fails what was in flight, and a message still pending from an earlier
run is failed at start, because its answer may have come while the app
was not running. A refused Subscribe or List is the degraded mode: the
banner says so and sending is off — until Refresh is admitted again,
since imsd asks polkit on every gated call and a refusal that held while
the session was inactive lifts when it is active (a List answered ends
it, a refused Subscribe is made again; every refusal is announced, and
RefreshWanted() asks for the Refresh). A Subscribe that fails otherwise,
a GetStatus or a List (one that timed out: the texts imsd holds would
wait for the next signal) is tried again by Refresh too, which
RefreshWanted() asks for — one Subscribe at a time, so a rule that
prompts is not asked again while that Subscribe waits on its prompt; a
registration change reads the status again, since imsd fills in the
subscriber's own number and the service centre's when it registers; the
own number's country code completes a typed national number (a received
one carries its own), the centre's stands in when the network gave no
tel: URI (an MVNO's centre can be abroad); without either a national
number stays as typed, since the store's correspondents do not say where
the subscriber is. The transport is an interface with callbacks, so the
tests' fake can stand in for the bus.
Tested: tests/Sync on a fake transport that records every call and
answers when told, the retries, the second GetStatus, the as-dialled
destination, a retry under another SIM (refused for a national number
under another country's and for a short code under another operator of
the same country; let through under the same operator, its own number
read or not, and for a national number under another operator of its
country), the plan's code the own number's or the constructor's override
and never the centre's, a short message type 0 left out of the store
with imsd's copy deleted, a text signalled before the status's answer
imported at once by the number it arrived for, a listener's throw at a
status — the constructor's among them, over a store that refuses — a log
line and a registration change caught and told, stopping no step, a
Refresh over an unanswered Subscribe sending none, a List that timed out
listed again, the words applied as they come, a retry under a new id,
and a refusal lifted among them; the store's refusal under the file-size
limit (the flag, the Refresh wanted and the log; a send answered
kNotStored with imsd asked nothing; an import refused leaving imsd's
copy with the banner up across imsd's restart; a short text sent through
the refusal, imsd's id landing in place and its `sent` with it, a failed
attempt's id dropped at the retry; then, room again, the send's own
write clearing the flag and the held text imported and deleted at the
List the recovery sends); a signalled text the store refuses that no
List carries (told as unstored once, unread though its conversation is
open, held across a List's answer and a Refresh, stored at the Refresh
after there is room, its delete answered NotFound), one a List does
carry (the copy held here dropped, the text imported by the next List),
and one still held when another write gives the store room (a Refresh
wanted for it alone until the recovery's List is answered); a listed
text the store refuses is not held.
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.
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.
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.
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.
An address becomes one conversation key. A number in international form
becomes E.164, and one in national form gets the given country code in
front — nine digits or more with a leading 0, or eight or more without
one, as a plan without a trunk prefix writes its numbers, the latter
only while the result is no longer than a number can be; the country
code of an E.164 number is found by the ITU length rule; short codes and
alphanumeric senders are their own keys. The display form puts a space
after the country code.
The key groups; a text goes to the address as dialled (DialledNumber:
the separators gone, a parenthesised trunk zero after a country code
dropped — not after Italy's code or San Marino's, where no zero is a
trunk prefix (a landline's is part of its number, a mobile has none):
such an address names two numbers and is none — nothing added), since
imsd sends a national number or a short code with the type unknown and
the network reads it by its own dialling plan — a country code completed
for the key would be dialled for real. A national number's leading 0 is
taken for the trunk prefix and goes when the country code is added — not
under Italy's code or San Marino's, where it is the number's and stays.
The key's known limits are of grouping: a number written with its
country code and no '+' is completed as a national one, one of a plan
whose trunk prefix is not a lone 0 (Hungary's 06, Russia's 8) is
completed wrongly, and a national number shorter than those lengths
(Iceland's seven digits) stays its digits.
Tested: tests/Number, thirty-two normalisation cases (the parenthesised
trunk zero of an international number, one after San Marino's code left
as no number, a national number's zero kept under Italy's code and San
Marino's, the numbers without a trunk prefix and both rules' shortest
numbers among them), twelve dialled forms (two with a zero in
parentheses after Italy's code, left as typed, among them), the country
codes of one-, two- and three-digit countries, the display forms.
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.