首页 > 解决方案 > 如何更改要阅读的消息状态

问题描述

在显示所有聊天消息时,我尝试更改消息的状态(已读或未读)。

实体

class Message
{
    /**
     * @ORM\Column(type="text",nullable=true)
     * @var string|null
     */
    public ?string $text;
    /**
     * @ORM\Column(type="guid",nullable=true)
     * @var string|null
     */
    public ?string $imageId;

    /**
     * @ORM\Column(type="datetime_immutable")
     * @var DateTimeImmutable
     */
    public DateTimeImmutable $createdAt;

    /**
     * @ORM\Column(type="boolean")
     * @var bool
     */
    public bool $received;
}

控制器 AllMessage

        $message = $this->supportMessageRepository->findAllByUserId($customerId);
        $items = array_map([$this->supportMessageMapper, 'map'], $message);

思路: 实现思路:当窗口打开或用户开始输入时,获取前面的标志为true | false 并且如果标志为 true,则更改消息的状态

问题: 但我不明白如何在收到列表时更改消息的状态(新的、尚未阅读的)。

问题: 如果用户每次调用一个方法来获取消息列表,调用时间是节省的,如果比上一次长,就在entity中创建一个函数来改变状态。问题是,这会起作用吗,还是我能以这种方式仅更改一条消息的状态?

标签: phpdoctrine-ormchat

解决方案


推荐阅读