如何将第一条消息设置为接收者的未读?

发布于 2025-02-02 17:47:17 字数 1130 浏览 5 评论 0原文

我与两个参与者进行了对话:

var createdConversation = await ConversationResource.CreateAsync(uniqueName: uniqueName);

var sender = await ParticipantResource.CreateAsync(pathConversationSid: createdConversation.Sid, identity: "sender");
var receiver = await ParticipantResource.CreateAsync(pathConversationSid: createdConversation.Sid, identity: "receiver");

我想在此新创建的对话中发送一条初始消息:

var message = await MessageResource.CreateAsync(
    pathConversationSid: createdConversation.Sid,
    author: sender.Identity,
    body: intitialMessage);

之后,我希望此新消息为读取 sender 接收者似乎是不可能的。
我可以将senderlastreadMessageIndex设置为创建message.index,但这不会为reveriver < /代码>。只要接收器 is null unreadMessagesCount也将是null null < /code>,看起来接收器在此对话中没有新消息。

关于我如何与初始消息创建新对话的任何建议,这将显示为一位用户的未读?

I have a conversation with two participants:

var createdConversation = await ConversationResource.CreateAsync(uniqueName: uniqueName);

var sender = await ParticipantResource.CreateAsync(pathConversationSid: createdConversation.Sid, identity: "sender");
var receiver = await ParticipantResource.CreateAsync(pathConversationSid: createdConversation.Sid, identity: "receiver");

And I want to send a initial message in this newly created conversation:

var message = await MessageResource.CreateAsync(
    pathConversationSid: createdConversation.Sid,
    author: sender.Identity,
    body: intitialMessage);

After that, I want this new message to be read for the sender and unread for receiver which seems not possible.
I can set the lastReadMessageIndex of the sender to the created message.Index but this won't create read horizon for the receiver. And as long as the lastReadMessageIndex of the receiver is null, the unreadMessagesCount will be also null, and it will look like the receiver has no new messages in this conversation.

Any suggestions on how I can create a new conversation with initial message, which will be displayed as unread for one of the users?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

老旧海报 2025-02-09 17:47:17

目前不可能这样做。这是作为特征差距在内部在内部提出的。

同时,您可能需要解决问题。我想到的一件事是将任何具有nulllastreadMessageIndex的对话标记为UI中未读的任何对话。

Currently it is not possible to do this. This has been raised internally at Twilio as a feature gap.

In the meantime you may need to workaround it. One thing I thought of would be to mark any conversations that have a lastReadMessageIndex of null as unread in your UI.

贱贱哒 2025-02-09 17:47:17

由于没有“简单的方法”来实现这一目标,因此我正在加载对话及其消息来计算unreadMessagesCount

var conversation = await UserConversationResource.FetchAsync(
    pathUserSid: userSid, 
    pathConversationSid: conversationSid);

var conversationHasNoReadHorizon = conversation.UnreadMessagesCount == null;
if (conversationHasNoReadHorizon)
{
    var messages = await MessageResource.ReadAsync(pathConversationSid: conversationSid);

    return messages.Count(message => message.Author != callerId);
}
else
{
    return conversation.UnreadMessagesCount ?? 0;
}

As there is no "easy way" to achieve this, I am loading the conversation and its messages to calculate the unreadMessagesCount.

var conversation = await UserConversationResource.FetchAsync(
    pathUserSid: userSid, 
    pathConversationSid: conversationSid);

var conversationHasNoReadHorizon = conversation.UnreadMessagesCount == null;
if (conversationHasNoReadHorizon)
{
    var messages = await MessageResource.ReadAsync(pathConversationSid: conversationSid);

    return messages.Count(message => message.Author != callerId);
}
else
{
    return conversation.UnreadMessagesCount ?? 0;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文