`MessageFwdHeader` 类型中 `saved_from_peer` 和 `saved_from_msg_id` 的含义。

huangapple go评论59阅读模式
英文:

Meaning of `saved_from_peer` and `saved_from_msg_id` inside `MessageFwdHeader` type

问题

电报中的消息可以从用户/聊天/频道转发到其他用户/聊天/频道。消息类型具有 fwd_from 字段,类型为 messageFwdHeader - 此对象内部的 from_id 字段描述消息的来源(用户或频道)。如果我们谈论的是发布此消息的频道,我们将在 channel_post 字段中得到消息ID。

所有这些都很有道理。有人发布了一条消息,它被转发或再次转发了很多次,但我们仍然有原始作者的ID以及消息的ID。

但也有 saved_from_peersaved_from_msg_id 字段。引用自文档

saved_from_peer [...] 仅适用于转发到当前用户(inputPeerSelf)的消息,包含最初发送消息的用户/频道的完整信息

saved_from_msg_id [...] 仅适用于转发到当前用户(inputPeerSelf)的消息,消息从原始用户/频道转发的ID

但是... from_idchannel_post 字段中,我们似乎已经获得了这两个数据,不是吗?

我们可以比较 from_idsaved_from_peer 的定义:最初发送消息的用户的ID 对比 [...] 最初发送消息的用户/频道的完整信息

这两个字段的类型相同,定义没有显著差异。

这些字段实际上是什么意思呢?

英文:

The message in telegram can be forwarded from users/chats/channels to other users/chats/channels. The message type has a fwd_from field with type messageFwdHeader - the from_id field inside of this object describes where the message comes from (user or channel). If we're talking about a channel who posted this message, we would have channel_post field populated with the message ID.

All seems to make sense. Someone posted a message, it got forwarded or re-forwarded any number of times, but we still have the ID of the original author as well as message's ID.

But there are also saved_from_peer and saved_from_msg_id fields. Citing from the docs:

saved_from_peer	[...] Only for messages forwarded to the current user (inputPeerSelf), full info about the user/channel that originally sent the message
saved_from_msg_id [...] Only for messages forwarded to the current user (inputPeerSelf), ID of the message that was forwarded from the original user/channel

But... we already seem to get both of these pieces of data inside from_id and channel_post fields, don't we?

We can compare the definitions of from_id vs saved_from_peer: The ID of the user that originally sent the message vs [...] full info about the user/channel that originally sent the message.

The types of the fields are the same, the definitions have no significant difference.

What do these fields actually mean?

答案1

得分: 1

根据文档,saved_from*字段在转发消息到您自己的“已保存消息”中使用。

如果您不处理已保存的消息,可以忽略它,这个字段存在是为了在加入的群组中返回上下文,因为channel_post只适用于转发到已保存消息之外的频道。

它会在saved_from peer中提供消息ID和保存的peer信息。

from_id字段用作发送消息的用户的圆形头像,有时它可能等于saved_from peer(当消息在广播中发送时,没有可见的发送者,所以会是频道本身)。

英文:

As the docs state saved_from* fields are utilized on forwarded messages to yourself, the "Saved Messages".

Not much more into it, ignore it if you're not dealing with saved messages, this exists incase you wanted to go back to the context in joined groups too, since channel_post is only for channels if forwarded outside of saved message.

it gives you the message id in the saved_from peer and naturally the saved from peer.

the from_id is utilized as the circular avatar of user who sent the message, which can be equal to saved_from peer sometimes (when message was sent in broadcast, no sender is visible so will be the channel itself)

答案2

得分: 0

@MustA已经掌握了大部分内容,我注意到了一些特殊情况。

假设我们有一个频道A,它有一个链接到它的讨论组B。每次我们将新消息添加到A并查看B发生了什么时,情况就会变得有些特殊。

我们将消息M1发布到A,它会自动转发到B,从而在B内创建M1的副本。这个副本的fwd_from字段会被设置为:

{
  "from_id": "频道A的ID",
  "channel_post": "在A内的M1的ID",
  "saved_from_msg_id": None,
  "saved_from_peer": None
}

这很简单。

但是,现在让我们将频道C加入进来。我们将消息M2C转发到A,它会自动转发到B。此时,fwd_from看起来会是这样的:

{
  "from_id": "频道C的ID",
  "channel_post": "在C内的M2的ID",
  "saved_from_msg_id": "在A内的M2的ID",
  "saved_from_peer": "频道A的ID"
}

你看出发生了什么了吗? from_idchannel_post总是指向原始作者,而saved_from_peersaved_from_msg_id则指向此消息的最后来源,即在我们的情况下是频道A由于A不是帖子的原始作者,我们不会在from_id字段内收到它

对于将用户U的消息M3转发到频道的情况也是一样:

{
  "from_id": "用户U的ID",
  "channel_post": None,
  "saved_from_msg_id": "在A内的M3的ID",
  "saved_from_peer": "频道A的ID"
}

因此,实际上,这个字段比官方文档所说的功能更强大。

英文:

@MustA got the main part of it, I noticed some pecurialities.

Imagine we've got channel A, which has discussion group B linked to it. Every time we're gonna be adding a new message to A and seeing what's happened to B.

We post message M1 to A, it automatically gets forwarded to B, thus creating a copy of M1 inside B. This copy would have fwd_from set to:

{
  "from_id": "channel A id",
  "channel_post": "id of M1 inside A",
  "saved_from_msg_id": None,
  "saved_from_peer": None
}

It's easy.

But let's add channel C to the mix. We'd forward message M2 from C into A, and it gets auto-forwarded to B. The fwd_from would then look like:

{
  "from_id": "channel C id",
  "channel_post": "id of M2 inside C",
  "saved_from_msg_id": "id of M2 inside A",
  "saved_from_peer": "channel A id"
}

Do you see what happened? from_id and channel_post always point to the original author, whilst saved_from_peer and saved_from_msg_id point to the last source of this message, in our case channel A. And since A isn't the original author of the post, we don't receive it inside the from_id field.

The same goes for forwarding user U's message M3 to the channel:

{
  "from_id": "user U id",
  "channel_post": None,
  "saved_from_msg_id": "id of M3 inside A",
  "saved_from_peer": "channel A id"
}

So in the end the field actually has more capabilities than the official docs say.

huangapple
  • 本文由 发表于 2023年4月10日 21:46:45
  • 转载请务必保留本文链接:https://go.coder-hub.com/75977677.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定