# 时间线时间戳未更新

**URL:** https://meta.discourse.org/t/timeline-timestamp-not-updating/256447
**Category:** Bug
**Created:** [2023年二月27日 23:03 UTC](https://meta.discourse.org/t/timeline-timestamp-not-updating/256447 "2023-02-27T23:03:21Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![MarcP](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/marcp/32/160184_2.png) [@MarcP](https://meta.discourse.org/u/MarcP)
#### Post date: [2023年二月27日 23:03 UTC](https://meta.discourse.org/t/timeline-timestamp-not-updating/256447/1 "2023-02-27T23:03:22Z")

</div>

注意到：

 ![image](https://global.discourse-cdn.com/meta/original/4X/d/e/b/debfa1f2318edc6e97c81d7476c4fb089561a6f4.png)

刷新后已更新。但如果与帖子时间戳匹配，那会更合乎逻辑，帖子时间戳无需刷新即可更新。

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [2023年二月28日 01:27 UTC](https://meta.discourse.org/t/timeline-timestamp-not-updating/256447/2 "2023-02-28T01:27:49Z")

</div>

这个很有意思，可能和我们的glimmer操作有关，@isaac

---

<div class="post-metadata">

### Author: ![isaac](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/isaac/32/235758_2.png) [@isaac](https://meta.discourse.org/u/isaac)
#### Post date: [2023年三月8日 17:39 UTC](https://meta.discourse.org/t/timeline-timestamp-not-updating/256447/4 "2023-03-08T17:39:20Z")

</div>

深入研究旧实现，我想知道这是否以前也存在问题……

```plaintext
      const bottomAge = relativeAge(
        new Date(topic.last_posted_at || topic.created_at),
        {
          addAgo: true,
          defaultFormat: timelineDate,
        }
      );
      const scroller = [
        h(
          "div.timeline-date-wrapper",
          this.attach("link", {
            className: "now-date",
            rawLabel: bottomAge,
            action: "jumpBottom",
          })
        ),
      ];

```

这在 widget 的 `html()` 函数中被调用，看起来我们没有任何钩子可以在时间流逝时更新它。

显然，期望的功能是在创建帖子时使用最新日期更新 `bottomAge`，然后随着时间的推移自动更新它。我们现在可以做的是添加一个函数到

> <https://github.com/discourse/discourse/blob/d78fed7dc63565b2864381bf7877ba6673dc642c/app/assets/javascripts/discourse/app/components/topic-timeline/container.js#L169-L170>

并在滚动时更新 `bottomAge`，但实际上感觉有点奇怪。这个想法的另一个问题是，很难将最新帖子的日期更新时间与主题时间轴上的 `bottomAge` 日期更新时间相匹配。帖子的相对 `created_at` 会滞后大约 10 秒……在滚动时造成不匹配。

理想情况下，我们可以跟踪帖子的相对 `created_at` 日期并将其插入时间轴，但我不知道这是否可能。

@david，你有什么想法吗？

---

<div class="post-metadata">

### Author: ![david](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/david/32/157490_2.png) [@david](https://meta.discourse.org/u/david)
#### Post date: [2023年三月9日 09:43 UTC](https://meta.discourse.org/t/timeline-timestamp-not-updating/256447/5 "2023-03-09T09:43:57Z")

</div>

> [@isaacjanzen](#):
>
> 期望的功能是在创建帖子时更新 `bottomAge` 为最新的日期，然后随着时间的推移自动继续更新它

是的，那将是理想的 👍

如果我们使用正确的 HTML 结构，随着时间的推移自动更新可以由我们的相对日期帮助程序 [自动处理](https://github.com/discourse/discourse/blob/7b1eb080baefbb36e71b7256acf9655700bb53c6/app/assets/javascripts/discourse/app/initializers/relative-ages.js#L8-L10)。

为了处理 `topic.last_posted_at` 值的更改，我们应该能够依赖 Glimmer 的响应性，而不是在滚动时执行操作。例如：

```js
get bottomAge(){
  return this.args.topic.get("last_posted_at") || this.args.topic.get("created_at");
}

```

然后在 hbs 中，我们可以使用 [我们的相对日期帮助程序](https://github.com/discourse/discourse/blob/7b1eb080baefbb36e71b7256acf9655700bb53c6/app/assets/javascripts/discourse/app/helpers/application.js#L13-L15) 来渲染它，以便自动更新的正确结构

```plaintext
{{age-with-tooltip this.bottomAge}}

```

可能需要对帮助程序进行一些改进，以便它能够支持 ‘addAgo’ 和 ‘defaultFormat’ 参数？

---

<div class="post-metadata">

### Author: ![isaac](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/isaac/32/235758_2.png) [@isaac](https://meta.discourse.org/u/isaac)
#### Post date: [2023年三月14日 15:48 UTC](https://meta.discourse.org/t/timeline-timestamp-not-updating/256447/6 "2023-03-14T15:48:44Z")

</div>

这将通过以下方式修复：

> <https://github.com/discourse/discourse/pull/20665#pullrequestreview-1339566167>
>
> \# Context
> https://meta.discourse.org/t/timeline-timestamp-not-updating/256447/1…
> 
> During the upgrade of the topic-timeline to glimmer the "latest post" timestamp was not updating on the timeline in relation to the relative age of the post. It was only updating on a hard refresh.
> 
> \# Fix
> Use the \`age-with-tooltip\` helper to update the created\_at date automatically as time passes.
> 
> \# Additional
> Add the ability to pass params to \`age-with-tooltip\` so that we can include options like \`addAgo\` and \`defaultFormat\`

---

<div class="post-metadata">

### Author: ![isaac](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/isaac/32/235758_2.png) [@isaac](https://meta.discourse.org/u/isaac)
#### Post date: [2023年三月14日 16:08 UTC](https://meta.discourse.org/t/timeline-timestamp-not-updating/256447/7 "2023-03-14T16:08:37Z")

</div>


