v.4 by Alexander Myodov
2019-01-23 21:01

Private chats


These are special kind of unichat groups reserved for private conversations. The private chats cannot be administered (moderated) and do not support inviting participants. Only a single private chat could exist between a given pair of users.

Create/get private chat

get_private_subscription(user_id: <long>) -> {subscription: <subscription_record>}

Returns subscription to the private group for current and specified user, creating it if need. See also unichat subscriptions. The returned structure may look like:

{
  "subscription": {
    "id": 6062,
    "group_id": 1028,
    "user_id": 3768,
    "role": "rw",
    "mute_until": null,
    "draft": null,
    "last_read_message_id": null,
    "created_at": "2018-10-23T13:57:10Z",
    "group": {
      "id": 1028,
      "name": null,
      "is_deleted": false,
      "created_at": "2018-10-23 13:57:10 UTC",
      "updated_at": "2018-10-23 13:57:10 UTC",
      "type": "private_chat",
      "icon": null,
      "participants": [
        {
          "id": 6062,
          "group_id": 1028,
          "user_id": 3768,
          "role": "rw",
          "mute_until": null,
          "draft": null,
          "last_read_message_id": null,
          "created_at": "2018-10-23T13:57:10Z",
          "user": {
            "id": 3768,
            "nick": "test_user_1",
            "avatar": null
          }
        },
        {
          "id": 6063,
          "group_id": 1028,
          "user_id": 3769,
          "role": "rw",
          "mute_until": null,
          "draft": null,
          "last_read_message_id": null,
          "created_at": "2018-10-23T13:57:10Z",
          "user": {
            "id": 3769,
            "nick": "test_user_2",
            "avatar": null
          }
        }
      ]
    },
    "user": {
      "id": 3768,
      "nick": "test_user_1",
      "avatar": null
    }
  }
}

Notice subscription.group.type above.

There are always only 2 participants and chat type is private_chat. Use it as a usual unichat group to write, list and change messages.

Important. UI can not delete private chat group or unsubscribe from it. Instead, a party can block the other one, or mute the notifications, to achieve the same effect. We advise just not to show the private chats for blocked users.