CLEMA protocol

Presence (Status)

A user's presence is what the server sees and what they say about themselves: whether they can be reached (online), whether somebody is looking at a client of theirs (active) and since when nobody has been (last_active_at), whether they hide (invisible), and a custom status of their own โ€” an emoji with a caption. How much of it a viewer is told is the user's presence setting and the viewer's: see Who Sees When.

Get Contact Statuses

Request (everybody followed): the presence of everybody whose presence the user follows: their contacts and the people they have a direct conversation with.

{"id": "40", "type": "presence.get"}

Request (specific user):

{
  "id": "40",
  "type": "presence.get",
  "data": {
    "user_id": 67890
  }
}

Success:

{
  "id": "40",
  "type": "presence.get",
  "ok": true,
  "data": {
    "statuses": [
      {"user_id": 67890, "online": true, "active": true, "custom": {"emoji": "๐Ÿ•", "text": "Lunch", "until": "2024-01-15T15:00:00Z"}, "time": "2024-01-15T14:00:00Z"},
      {"user_id": 67891, "online": true, "active": false, "last_active_at": "2024-01-15T12:30:00Z", "custom": {"emoji": "โ›”"}, "time": "2024-01-15T09:00:00Z"},
      {"user_id": 67892, "online": false, "active": false, "last_active_at": "2024-01-15T10:00:00Z", "custom": {"emoji": "๐Ÿ–๏ธ", "text": "On vacation"}, "time": "2024-01-15T10:00:00Z"},
      {"user_id": 67893, "online": false, "active": false, "last_seen": "week"}
    ]
  }
}
Field Type Description
user_id number The user's ID
online boolean Whether the user can be reached and seen
active boolean Whether somebody is looking at a client of the user
last_active_at string While nobody is, when somebody last was (RFC 3339); absent when that was never known
last_seen string For a viewer who is told no more, roughly when the user was last here, in place of all of the above: recently (within three days), week (within seven), month (within thirty) or long_ago, counted from the start of that day in UTC; absent when that was never known
custom object The user's custom status; absent when there is none
time string When the user last went online or offline (RFC 3339)
invisible boolean Whether the user hides; only ever told to their own devices
invisible_until string While the user hides, when that ends by itself (RFC 3339); only ever told to their own devices

Custom field: an emoji with an optional caption that the user shows next to their name, such as ๐Ÿ• "Lunch" or ๐Ÿ–๏ธ "On vacation" โ€” the one way they say something about themselves. It is shown whether the user is online or not. Clients offer three presets among their suggestions: ๐Ÿ˜Š for free for chat, โ›” for busy, ๐Ÿ”• for do not disturb. They are custom statuses like any other, set with no caption, and a client reads one without a caption as the preset's name in its reader's words โ€” "Busy", ยซะ—ะฐะฝัั‚ยป โ€” as it reads an ICQ client's occupied, which arrives so. There is no away: that nobody is at the screen is what active says. until, when present, is the moment it clears itself; once it has passed, it is no longer shown, and within a minute the server clears it and tells the user's devices and contacts.

Field Type Description
emoji string One emoji
text string Caption; absent when there is none
until string When the status clears itself (RFC 3339); absent to keep it until changed

Invisible: keeps the user online for themselves and offline for everybody else: followers receive presence.offline when the user turns invisible, see them offline with the moment they did, and receive presence.online when they come back. Messages, pushes and everything else work as usual, except what would give the user away: a delivery they report is not recorded, and how far they read a direct conversation reaches the other side only when they are visible again, after presence.online โ€” which tells it the messages read were delivered as well. A new account is visible.

A user is online while they can be reached: at least one of their connections is open, active or not, or at least one of their sessions is registered for pushes โ€” unless they are invisible. time is when that last changed. Being online is what a direct transfer needs; it is not what clients show.

A user is active while somebody is looking at a client of theirs: one of their connections is active and they are not invisible. This is what clients show as "online"; a page left in a background tab, or a phone a push keeps online, is online without being active, which is what a messenger shows as "last seen": last_active_at. Becoming active reaches contacts at once; nobody looking any more only after a grace of about half a minute without anybody looking again, so that a switch between apps tells them nothing, and then as presence.updated with the moment it began. A user who goes offline or invisible stops being active with it, and while invisible their last_active_at stays where it was when they became so. A connection through a transport adapter is active unless its protocol says its person is idle or away, as OSCAR's idle notification, away and not available do.

Asking about oneself is how a device learns what the account says: the answer carries invisible and, while it hides, invisible_until, and online says whether the account can be reached at all.

Who Sees When

The user's presence setting says whom they show when they were here: a viewer it lets through, whom the viewer's own setting lets through the other way, is told everything above. Each sees the other as the other sees them, so that hiding one's own is hiding from others'. Anybody else is told only:

They hear of a new custom status, and of last_seen moving on: the server tells them with presence.updated as a span ends โ€” at the midnight, UTC, three, seven or thirty days after the day the user was last here, so that it tells no more than that day โ€” and when the user comes back from longer ago than recently. Across a block, either way, nothing is told: a specific lookup returns user_not_found, and an all-contacts lookup omits the user.

Set Presence

{"id":"41","type":"presence.set","data":{"custom":{"emoji":"โ›”"}}}
{"id":"42","type":"presence.set","data":{"custom":{"emoji":"๐Ÿ•","text":"Lunch","until":"2024-01-15T15:00:00Z"}}}
{"id":"43","type":"presence.set","data":{"invisible":true,"invisible_for":28800}}
{"id":"44","type":"presence.set","data":{"custom":null}}
Field Type Required Description
invisible boolean No Whether to hide
invisible_for number With invisible: true For how many seconds to hide, from 1 to 604800 (a week)
custom object No A new custom status, or null to clear it

A request carries invisible or custom or both; a field left out stays as it is.

Hiding always ends: nobody is left hidden and forgotten. invisible: true needs invisible_for, and invisible: false, which shows the user again, takes none; hiding asked for again while hiding sets a new end. The end is invisible_for seconds from when the server takes the request, to the second โ€” a span rather than a moment, so that how far the client's clock is off does not decide whether a week is too long โ€” and the user's own devices are told it as invisible_until. Once it has passed, within a minute the server shows the user again as though they had asked: their devices receive presence.self, their followers presence.online. An ICQ client has no say in how long it hides: an account hidden from one hides for a week. Once hiding has ended, by its time or elsewhere, an ICQ client still saying invisible is not taken as hiding again, nor is one signing on so: that would hide the account anew every week; hiding again from ICQ is picking another state, then Invisible.

Both apply to the whole account rather than to one device, so a client that sets them changes what every other one shows. They are kept until changed or until they end, whatever connections come and go. The response is the caller's own status as asking about oneself gives it, and setting what is already set changes nothing and tells nobody. The account's other devices receive the new status as presence.self.

Presence Events (Push)

Server notifies the user's followers when the user comes online, goes offline, or changes what they say about themselves: whoever lists the user among their contacts, and whoever has a direct conversation with them โ€” written in, or holding a draft of theirs. A shared group follows nobody. Somebody starting a direct conversation with another is told the other's presence at once, as is the other. Every event carries the same object presence.get lists, as the receiver may see it (Who Sees When). Anybody else โ€” somebody whose card is open โ€” asks with presence.get for that user.

User Online:

{
  "type": "presence.online",
  "data": {
    "user_id": 67890,
    "online": true,
    "active": true,
    "time": "2024-01-15T14:00:00Z"
  }
}

User Offline:

{
  "type": "presence.offline",
  "data": {
    "user_id": 67890,
    "online": false,
    "active": false,
    "last_active_at": "2024-01-15T14:30:00Z",
    "custom": {"emoji": "๐Ÿ–๏ธ", "text": "On vacation"},
    "time": "2024-01-15T14:30:00Z"
  }
}

Presence Changed:

{
  "type": "presence.updated",
  "data": {
    "user_id": 67890,
    "online": true,
    "active": false,
    "last_active_at": "2024-01-15T14:09:30Z",
    "custom": {"emoji": "๐Ÿ•", "text": "Lunch"},
    "time": "2024-01-15T14:10:00Z"
  }
}

presence.updated reports somebody online becoming active or no longer, a new custom status of anybody, online or not โ€” set, cleared, or run out โ€” and, to those who see the user roughly, everything they hear of. A user turning invisible or visible again reaches contacts as presence.offline or presence.online.

These events are about contacts: they reach whoever lists the user, the user included if they listed themselves, with what each may see. What the account says about itself reaches its own devices separately:

Own Status Changed:

{
  "type": "presence.self",
  "data": {
    "user_id": 12345,
    "online": true,
    "active": true,
    "invisible": true,
    "invisible_until": "2024-01-15T22:10:00Z",
    "custom": {"emoji": "๐Ÿ•", "text": "Lunch"},
    "time": "2024-01-15T14:10:00Z"
  }
}

presence.self carries the account's own status as asking about oneself gives it. It reaches the account's other devices when one of them sets it, and all of them when the custom status runs out or hiding ends.

When how much a receiver sees of a user changes โ€” a presence setting, a block lifted, a contact added or removed under "my contacts" โ€” they are told what they see now: presence.online or presence.offline with all of it, presence.updated with the rough of it, or, across a block, a presence.offline carrying nothing but user_id, with online and active false.

Contact Requests

Somebody who writes to a user who does not have them as a contact โ€” a direct message, a forward or a direct transfer โ€” asks to be taken in. The user is told at once, before the message itself, by an event of their account stream:

{
  "type": "contact.requested",
  "seq": "45",
  "data": {
    "contact": {
      "user_id": 67890,
      "nick": "Alice",
      "avatar_hash": "a1b2c3d4",
      "requested_at": "2024-01-15T14:00:00Z"
    }
  }
}

The entry is the one contact events carry: nick is the name the person goes by (Add Contact), a snapshot, and requested_at when they asked.

A request is not a contact. No privacy setting that trusts contacts trusts it, and contact.list returns it apart from the contacts, in requests, newest first. The user takes the person in with contact.add, which makes them a contact and answers the request, or turns them away with contact.delete, which counts as taking them out of the list: nothing asks about them again, and no address book brings them back. A client answering a request it shows passes "request": true, so that an answer given after the request was settled elsewhere changes nothing. Either reaches the user's other clients as contact.added or contact.deleted. An address book that finds the person takes them in too, which answers the request: the uploading session learns it from matches[].added, and every session of the user from contact.added. Replying to a request does not answer it.

Nobody is asked about who is a contact already, somebody turned away or taken out of the list, or somebody a block separates from the user. Somebody who answers a direct chat the user started โ€” whose first message is the user's โ€” is not asked about either: the user chose to write to them, so they are taken in as a contact, and the user's clients are told with contact.added before the message:

{
  "type": "contact.added",
  "seq": "46",
  "data": {
    "contact": {"user_id": 67890, "nick": "Alice", "avatar_hash": "a1b2c3d4"},
    "presence": {"user_id": 67890, "online": true, "active": true, "time": "2024-01-15T14:00:00Z"}
  }
}

A request's typing reaches the user as a contact's does. A block ends the requests between the two either way.

A bot is written to as a service is used: it asks nobody to be taken in, nobody asks it, and writing to one takes it into no contact list. Its typing reaches whoever it talks with all the same: it is in no direct chat but one they began.