Skip to content

Commit

Permalink
Merge pull request #14344 from nextcloud/bugfix/noid/allow-to-edit-bo…
Browse files Browse the repository at this point in the history
…t-messages-in-one-to-one

fix(chat): Allow to edit messages of bots in one-to-one conversations
  • Loading branch information
nickvergessen authored Feb 11, 2025
2 parents 13776f6 + a3e3f28 commit f9958b2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
6 changes: 5 additions & 1 deletion lib/Controller/ChatController.php
Original file line number Diff line number Diff line change
Expand Up @@ -989,7 +989,11 @@ public function editMessage(int $messageId, string $message): DataResponse {

// Special case for if the message is a bridged message, then the message is the bridge bot's message.
$isOwnMessage = $isOwnMessage || ($comment->getActorType() === Attendee::ACTOR_BRIDGED && $attendee->getActorId() === MatterbridgeManager::BRIDGE_BOT_USERID);
if (!$isOwnMessage
$isBotInOneToOne = $comment->getActorType() === Attendee::ACTOR_BOTS
&& str_starts_with($comment->getActorId(), Attendee::ACTOR_BOT_PREFIX)
&& ($this->room->getType() === Room::TYPE_ONE_TO_ONE
|| $this->room->getType() === Room::TYPE_ONE_TO_ONE_FORMER);
if (!($isOwnMessage || $isBotInOneToOne)
&& (!$this->participant->hasModeratorPermissions(false)
|| $this->room->getType() === Room::TYPE_ONE_TO_ONE
|| $this->room->getType() === Room::TYPE_ONE_TO_ONE_FORMER)) {
Expand Down
7 changes: 6 additions & 1 deletion src/composables/useMessageInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export function useMessageInfo(message = ref({})) {
isEditable: computed(() => false),
isDeleteable: computed(() => false),
isCurrentUserOwnMessage: computed(() => false),
isBotInOneToOne: computed(() => false),
isObjectShare: computed(() => false),
isConversationModifiable: computed(() => false),
isConversationReadOnly: computed(() => false),
Expand All @@ -57,10 +58,14 @@ export function useMessageInfo(message = ref({})) {
message.value.actorId === currentActorId
&& message.value.actorType === currentActorType
)
const isBotInOneToOne = computed(() =>
message.value.actorId.startsWith(ATTENDEE.BOT_PREFIX)
&& message.value.actorType === ATTENDEE.ACTOR_TYPE.BOTS
)

const isEditable = computed(() => {
if (!hasTalkFeature(message.value.token, 'edit-messages') || !isConversationModifiable.value || isObjectShare.value || message.value.systemMessage
|| ((!store.getters.isModerator || isOneToOneConversation.value) && !isCurrentUserOwnMessage.value)) {
|| ((!store.getters.isModerator || isOneToOneConversation.value) && !(isCurrentUserOwnMessage.value || isBotInOneToOne.value))) {
return false
}

Expand Down
1 change: 1 addition & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ export const ATTENDEE = {
REMOTES: 'remotes',
},

BOT_PREFIX: 'bot-',
BRIDGE_BOT_ID: 'bridge-bot',

CHANGELOG_BOT_ID: 'changelog',
Expand Down

0 comments on commit f9958b2

Please sign in to comment.