Skip to content

Commit

Permalink
fix(chat): Allow flow-bots to update the last message info
Browse files Browse the repository at this point in the history
Signed-off-by: Joas Schilling <coding@schilljs.com>
  • Loading branch information
nickvergessen committed Mar 25, 2024
1 parent 46e27f7 commit 0cbb5aa
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
16 changes: 14 additions & 2 deletions lib/Chat/ChatManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,18 @@ public function addChangelogMessage(Room $chat, string $message): IComment {
* @param string $referenceId
* @return IComment
*/
public function sendMessage(Room $chat, ?Participant $participant, string $actorType, string $actorId, string $message, \DateTime $creationDateTime, ?IComment $replyTo, string $referenceId, bool $silent): IComment {
public function sendMessage(
Room $chat,
?Participant $participant,
string $actorType,
string $actorId,
string $message,
\DateTime $creationDateTime,
?IComment $replyTo,
string $referenceId,
bool $silent,
bool $forceLastMessageUpdate = false, // Remove when dropping commands
): IComment {
$comment = $this->commentsManager->create($actorType, $actorId, 'chat', (string) $chat->getId());
$comment->setMessage($message, self::MAX_CHAT_LENGTH);
$comment->setCreationDateTime($creationDateTime);
Expand Down Expand Up @@ -322,9 +333,10 @@ public function sendMessage(Room $chat, ?Participant $participant, string $actor
$this->participantService->updateLastReadMessage($participant, (int) $comment->getId());
}

// Update last_message
// Update last_message (not for commands)
if ($comment->getActorType() !== Attendee::ACTOR_BOTS
|| $comment->getActorId() === Attendee::ACTOR_ID_CHANGELOG
|| $forceLastMessageUpdate
|| str_starts_with($comment->getActorId(), Attendee::ACTOR_BOT_PREFIX)) {
$this->roomService->setLastMessage($chat, $comment);
$this->unreadCountCache->clear($chat->getId() . '-');
Expand Down
3 changes: 2 additions & 1 deletion lib/Flow/Operation.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ public function onEvent(string $eventName, Event $event, IRuleMatcher $ruleMatch
new \DateTime(),
null,
'',
false
false,
forceLastMessageUpdate: true,
);
} catch (UnexpectedValueException $e) {
continue;
Expand Down

0 comments on commit 0cbb5aa

Please sign in to comment.