md-platform

ShowViewsToggle.md
View raw Back to list

Show / Hide View Count — Frontend Integration

This feature lets a video opt out of having its view count displayed. The backend exposes a per-video setting, settings.showViews, and accepts it on the create/update flows. The view count value is still returned — the flag only tells the client whether to render it.

Summary for the frontend

Read settings.showViews (boolean) on the video object
Write showViews (boolean) in the create/update request body
Default true (views shown) — backward compatible for existing videos
When false Hide the views UI; the count is still present in the payload

1. Reading the flag (display side)

Every video-returning response now includes a settings object:

{
  "id": "abc123",
  "name": "My video",
  "views": 1234,
  "metrics": {
    "views": 1234,
    "likes": 10,
    "comments": 3
    // ...
  },
  "settings": {
    "showViews": true
  }
}

Render the view count only when showViews is true:

const showViews = video.settings?.showViews ?? true;

if (showViews) {
  renderViews(video.metrics.views);
}

Always fall back to true (?? true) when settings or showViews is missing. Older cached payloads or other edge cases may omit it, and the intended default is "views visible".

Endpoints that return settings.showViews

The plain listing grids (AdminListVideoDto, AdminListLiveVideoDto) do not include view counts, so they do not carry settings. If you need the flag there, ask the backend to add it.


2. Writing the flag (create / edit side)

showViews is a top-level boolean in the request body (note: it is nested under settings in responses, but flat in requests).

Create a video — POST /studio/v1/videos

{
  "title": "My video",
  "description": { /* ... */ },
  "type": 0,
  "isShort": false,
  "isPremium": false,
  "showViews": true
}

Update a video — PUT /studio/v1/videos/{id}

{
  "name": "My video",
  "visibility": 1,
  "isPremium": false,
  "showViews": false   // hide the view count
}

Admin update — PUT /admin/v1/videos/{id}

Same showViews field, alongside the other admin fields (displayScore, etc.).

Send showViews on every update. The update handlers set the value from the request each time, so omitting it lets the JSON binder fall back to the command default (true). To preserve a previously-disabled state, always include the current value — initialize your form control from settings.showViews when loading the edit screen.


3. Suggested UI

A simple toggle on the video create/edit form, e.g.:

Show view count [ ✓ ] When off, viewers won't see how many times this video has been watched.


Notes / FAQ