v.7 by Sergey Chernov
2018-10-29 16:10

Subscriptions

When some user belongs to some group, there is a subscription for it. Subscription connects user to a group, set access rights, hold private user settings toward the group, like muting notification and so on.

Subscription record include information about group and current user rights and reading state for it. In full form it contains also <group record> with participating users records:

{
  "subscription": {
    {
      "id": 1958,
      "group_id": 252,
      "user_id": 1508,
      "role": "rw",
      "mute_until": null,
      "draft": null,
      "last_read_message_id": null,
      "created_at": "2018-10-16T18:03:27Z",
      "group": {
        "id": 252,
        "name": null,
        "is_deleted": false,
        "created_at": "2018-10-16 18:03:27 UTC",
        "updated_at": "2018-10-16 18:03:27 UTC",
        "last_message_id": null,
        "last_serial": null,
        "strid": "p2p:1508:1509",
        "type": "private_chat",
        "participants": [
          {
            "id": 1958,
            "group_id": 252,
            "user_id": 1508,
            "role": "rw",
            "mute_until": null,
            "draft": null,
            "last_read_message_id": null,
            "created_at": "2018-10-16T18:03:27Z",
            "user": {
              "id": 1508,
              "nick": "test_user_2"
            }
          },
          {
            "id": 1959,
            "group_id": 252,
            "user_id": 1509,
            "role": "rw",
            "mute_until": null,
            "draft": null,
            "last_read_message_id": null,
            "created_at": "2018-10-16T18:03:27Z",
            "user": {
              "id": 1509,
              "nick": "test_user_3"
            }
          }
        ]
      },
      "user": {
        "id": 1508,
        "nick": "test_user_2"
      }
    }
  ]
}

in short form. group object will not be included. It can be requireset separately.

To better understan subscriptions role in unichaat, see the diagram:

graph LR p2p(private chat) --> group room(room) --> group channel(channel)--> group group -.-> subscription1 group -.-> subscription2 group -.-> subscription3 subscription1 -.-> user1 subscription2 -.-> user2 user1 -.-> contact1 user1 -.-> contact2 user1 -.-> contact3 user2 -.-> contact4 user2 -.-> contact5 user2 -.-> contact6 contact4 -.-> user3 contact1 -.-> user3