Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 102 additions & 5 deletions docs/dev/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,112 @@ API errors are returned as JSON with a top-level `code` field and HTTP status `2

### comment.giveForObj

Returns comment tree by photo number.
Returns the comment tree for a photo or news item. Top-level comments are returned in `comments`; replies are nested in the parent comment's `comments` array.

Parameter | Mandatory | Type | Description |
--- | --- | --- | --- |
cid | ✓ | int | unique photo number |
Parameter | Mandatory | Type | Default | Description |
--- | --- | --- | --- | --- |
cid | ✓ | int | | unique object number |
type | | string | `photo` | object type: `photo` or `news` |
showDel | | bool | `false` | include deleted comments when the authenticated user has permission to view them |
Comment thread
thankfulfor marked this conversation as resolved.
Resolved

Only the exact value `news` selects a news item. If `type` is omitted or has any other value, the method handles `cid` as a photo number. `showDel` has no effect on anonymous requests.

**Query example:**

`https://api.pastvu.com/api2?method=comment.giveForObj&params={"cid":23314}`
`https://api.pastvu.com/api2?method=comment.giveForObj&params={"cid":539434}`

**Response example (shortened):**

```json
{
"result": {
"comments": [
{
"cid": 1324546,
"user": "user1",
"stamp": 1488382828246,
"txt": "Вероятно, снимок сделан с территории Кремля...",
"s": 5,
"type": 1,
"level": 0,
"comments": [
{
"cid": 1324559,
"user": "user2",
"stamp": 1488384195442,
"txt": "Спасибо, поправлено.",
"parent": 1324546,
"level": 1,
"s": 5,
"type": 1,
"latest": true
}
]
}
],
"countTotal": 2,
"users": {
"user1": {
"disp": "User One",
"login": "user1",
"ranks": ["mec_gold", "adviser"],
"online": false
},
"user2": {
"avatar": "/_a/h/user2.png",
"disp": "User Two",
"login": "user2",
"ranks": [],
"online": false
}
},
"latestCid": 1324559,
"cid": 539434
},
"rid": "request-id"
}
```

**Key response fields:**

Field | Type | Description |
--- | --- | --- |
`result.cid` | int | requested object number |
`result.comments` | array | top-level comments; replies are nested recursively in `comments` |
`result.comments[].cid` | int | unique comment number |
`result.comments[].user` | string | comment author's login; corresponding profile data is in `result.users` |
`result.comments[].stamp` | int | comment creation time as a Unix timestamp in milliseconds |
`result.comments[].txt` | string | comment text as HTML; omitted for a deleted-comment placeholder |
`result.comments[].parent` | int | parent comment number; included for replies |
`result.comments[].level` | int | nesting level, starting with `0` for a top-level comment |
`result.comments[].comments` | array | direct replies to the comment; omitted for a deleted-comment placeholder |
`result.comments[].del` | bool | `true` for a deleted-comment placeholder returned with `showDel` |
`result.comments[].latest` | bool | whether this is the newest comment in the tree |
`result.countTotal` | int | total number of non-deleted comments, including nested replies |
`result.users` | object | comment authors keyed by login |
`result.latestCid` | int | number of the newest comment |
`rid` | string | request identifier used for diagnostics |

Authenticated responses also include `countNew`, `countDel`, and `canReply`. `canModerate` is `true` for a moderator of the object and is otherwise omitted. Individual comments can include permission and unread-status fields.

An authenticated request records the current time as the user's last comment view, resets the new-comment counter, and can clear a scheduled comment notification for the object.

With `showDel: true`, an eligible deleted comment is returned as a placeholder with `del: true`. Its `txt` and nested `comments` fields are omitted.

When no comments match, the empty response depends on authentication:

- an anonymous response omits `users` and includes `latestCid: 0`;
- an authenticated response includes `users: {}` and omits `latestCid`.

**Errors:**

Code | When returned |
--- | --- |
`BAD_PARAMS` | `cid` is missing, is `0`, or cannot be converted to a number |
`NO_SUCH_PHOTO` | a photo does not exist or is not available to the current user |
`COMMENT_NO_OBJECT` | a news item does not exist or is not available to the current user |

API errors are returned as JSON with a top-level `code` field and HTTP status `200 OK`. Check `code` rather than relying on the HTTP status alone.

### photo.giveNearestPhotos

Expand Down
107 changes: 102 additions & 5 deletions i18n/ru/docusaurus-plugin-content-docs/current/dev/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,112 @@ cid | ✓ | int | уникальный номер снимка |

### comment.giveForObj

Возвращает дерево комментариев по номеру фотографии.
Возвращает дерево комментариев к фотографии или новости. Комментарии верхнего уровня находятся в массиве `comments`, а ответы — в массиве `comments` родительского комментария.

Параметр | Обязательный | Тип | Описание |
--- | --- | --- | --- |
cid | ✓ | int | уникальный номер снимка |
Параметр | Обязательный | Тип | По умолчанию | Описание |
--- | --- | --- | --- | --- |
cid | ✓ | int | | уникальный номер объекта |
type | | string | `photo` | тип объекта: `photo` или `news` |
showDel | | bool | `false` | включать удалённые комментарии, если у авторизованного пользователя есть право их просматривать |

Только точное значение `news` выбирает новость. Если `type` не указан или содержит другое значение, метод обрабатывает `cid` как номер фотографии. Параметр `showDel` не влияет на анонимные запросы.

**Пример запроса:**

`https://api.pastvu.com/api2?method=comment.giveForObj&params={"cid":23314}`
`https://api.pastvu.com/api2?method=comment.giveForObj&params={"cid":539434}`

**Сокращённый пример ответа:**

```json
{
"result": {
"comments": [
{
"cid": 1324546,
"user": "user1",
"stamp": 1488382828246,
"txt": "Вероятно, снимок сделан с территории Кремля...",
"s": 5,
"type": 1,
"level": 0,
"comments": [
{
"cid": 1324559,
"user": "user2",
"stamp": 1488384195442,
"txt": "Спасибо, поправлено.",
"parent": 1324546,
"level": 1,
"s": 5,
"type": 1,
"latest": true
}
]
}
],
"countTotal": 2,
"users": {
"user1": {
"disp": "User One",
"login": "user1",
"ranks": ["mec_gold", "adviser"],
"online": false
},
"user2": {
"avatar": "/_a/h/user2.png",
"disp": "User Two",
"login": "user2",
"ranks": [],
"online": false
}
},
"latestCid": 1324559,
"cid": 539434
},
"rid": "request-id"
}
```

**Основные поля ответа:**

Поле | Тип | Описание |
--- | --- | --- |
`result.cid` | int | номер запрошенного объекта |
`result.comments` | array | комментарии верхнего уровня; ответы рекурсивно вложены в массивы `comments` |
`result.comments[].cid` | int | уникальный номер комментария |
`result.comments[].user` | string | логин автора комментария; данные профиля находятся в `result.users` |
`result.comments[].stamp` | int | время создания комментария в виде Unix timestamp в миллисекундах |
`result.comments[].txt` | string | текст комментария в формате HTML; отсутствует у заглушки удалённого комментария |
`result.comments[].parent` | int | номер родительского комментария; возвращается для ответов |
`result.comments[].level` | int | уровень вложенности; для комментария верхнего уровня равен `0` |
`result.comments[].comments` | array | непосредственные ответы на комментарий; отсутствуют у заглушки удалённого комментария |
`result.comments[].del` | bool | значение `true` у заглушки удалённого комментария, возвращённой с `showDel` |
`result.comments[].latest` | bool | признак самого нового комментария в дереве |
`result.countTotal` | int | общее количество комментариев без удалённых, включая вложенные ответы |
`result.users` | object | авторы комментариев с логинами в качестве ключей |
`result.latestCid` | int | номер самого нового комментария |
`rid` | string | идентификатор запроса для диагностики |

Для авторизованных запросов в ответ также входят поля `countNew`, `countDel` и `canReply`. Поле `canModerate` равно `true` для модератора объекта, а в остальных случаях отсутствует. У отдельных комментариев могут появляться поля с правами пользователя и признаком непрочитанного комментария.

Авторизованный запрос записывает текущее время как время последнего просмотра комментариев, сбрасывает счётчик новых комментариев и может удалить запланированное уведомление о комментариях к объекту.

При `showDel: true` доступный удалённый комментарий возвращается как заглушка с `del: true`. Поля `txt` и вложенный массив `comments` у неё отсутствуют.

Если подходящих комментариев нет, состав пустого ответа зависит от авторизации:

- в анонимном ответе нет поля `users`, а `latestCid` равен `0`;
- в авторизованном ответе есть `users: {}`, но нет поля `latestCid`.

**Ошибки:**

Код | Когда возвращается |
--- | --- |
`BAD_PARAMS` | `cid` не указан, равен `0` или не преобразуется в число |
`NO_SUCH_PHOTO` | фотография не существует или недоступна текущему пользователю |
`COMMENT_NO_OBJECT` | новость не существует или недоступна текущему пользователю |

Ошибки API возвращаются в JSON с полем `code` на верхнем уровне и HTTP-статусом `200 OK`. Проверяйте `code` в ответе, а не только HTTP-статус.

### photo.giveNearestPhotos

Expand Down
Loading