# 用户在线状态因不活动离开时未更新到服务器

**URL:** <https://meta.discourse.org/t/user-presence-is-not-updating-the-server-when-leaving-due-to-user-or-browser-inactivity/268103>\
**Category:** Bug\
**Created:** [2023 年6 月 12 日 23:14 UTC](https://meta.discourse.org/t/user-presence-is-not-updating-the-server-when-leaving-due-to-user-or-browser-inactivity/268103 "2023-06-12T23:14:19Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

作者： ![AhmedLoud](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ahmedloud/32/576547_2.png) [@AhmedLoud](https://meta.discourse.org/u/AhmedLoud)\
发布日期： [2023 年6 月 12 日 23:14 UTC](https://meta.discourse.org/t/user-presence-is-not-updating-the-server-when-leaving-due-to-user-or-browser-inactivity/268103/1 "2023-06-12T23:14:19Z")

</div>

当我们在同一个屏幕上只输入所有具有默认 `onlyWhenActive`（调用 `channel.enter()` 时默认为 true）的频道时 → 在进入空闲状态以更新这些频道时，会向服务器发出错误的调用

### 如何重现

- 首先禁用聊天插件（如果已启用）（这很重要，因为聊天插件会在所有屏幕上调用 `.enter({onlyWhenActive: false}`，并将 `onlyWhenActive` 选项设置为 false）

- 添加一个频道作为演示。我选择了 `topic-presence-display.js` 并添加了以下内容：

```js
  @on("init")
  _init() {
    this._presentChannel = this.presence.getChannel('/presence-idle-demo');
    this._presentChannel.enter();
  },

```

- 打开任何主题，并打开浏览器网络控制台 → 您应该会看到第一次调用 `/presence/update`

- 最小化浏览器窗口（打开网络选项卡）并等待稍多于 10 秒（这是浏览器的默认不活动时间）

- 再次打开浏览器并查看对 `/presence/update` 的最新调用

当前结果：

 ![image](https://global.discourse-cdn.com/meta/original/4X/1/1/1/1117428c429809664fc084667bd0c20379c47527.png)

而它应该是 `leave_channels[]: /presence-idle-demo`

我已提交一个拉取请求：

> <https://github.com/discourse/discourse/pull/22068>

---

_[View the full topic](https://meta.discourse.org/t/user-presence-is-not-updating-the-server-when-leaving-due-to-user-or-browser-inactivity/268103)._
