[COMPONENTS][Conversation] Added missing foreign keys to ConversationMute Entity

Fixed 'is_muted' variable check logic that impeded the Conversation from being muted
This commit is contained in:
Eliseu Amaro 2022-01-07 21:14:13 +00:00
parent fc57b3290e
commit d17f276419
Signed by: eliseuamaro
GPG Key ID: 96DA09D4B97BC2D5
3 changed files with 11 additions and 7 deletions

View File

@ -101,12 +101,12 @@ class Conversation extends FeedController
$user = Common::ensureLoggedIn();
$is_muted = ConversationMute::isMuted($conversation_id, $user);
$form = Form::create([
['mute_conversation', SubmitType::class, ['label' => $is_muted ? _m('Mute conversation') : _m('Unmute conversation')]],
['mute_conversation', SubmitType::class, ['label' => $is_muted ? _m('Unmute conversation') : _m('Mute conversation')]],
]);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
if ($is_muted) {
if (!$is_muted) {
DB::persist(ConversationMute::create(['conversation_id' => $conversation_id, 'actor_id' => $user->getId()]));
} else {
DB::removeBy('conversation_mute', ['conversation_id' => $conversation_id, 'actor_id' => $user->getId()]);

View File

@ -227,7 +227,7 @@ class Conversation extends Component
}
$actions[] = [
'title' => ConversationMute::isMuted($note, $user) ? _m('Mute conversation') : _m('Unmute conversation'),
'title' => ConversationMute::isMuted($note, $user) ? _m('Unmute conversation') : _m('Mute conversation'),
'classes' => '',
'url' => Router::url('conversation_mute', ['conversation_id' => $note->getConversationId()]),
];

View File

@ -118,11 +118,15 @@ class ConversationMute extends Entity
return [
'name' => 'conversation_mute',
'fields' => [
'conversation_id' => ['type' => 'int', 'foreign key' => true, 'target' => 'Conversation.id', 'multiplicity' => 'one to one', 'not null' => true, 'description' => 'The conversation being blocked'],
'actor_id' => ['type' => 'int', 'foreign key' => true, 'target' => 'Actor.id', 'multiplicity' => 'one to one', 'not null' => true, 'description' => 'Who blocked the conversation'],
'created' => ['type' => 'datetime', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was created'],
'conversation_id' => ['type' => 'int', 'foreign key' => true, 'target' => 'Conversation.id', 'multiplicity' => 'one to one', 'not null' => true, 'description' => 'The conversation being blocked'],
'actor_id' => ['type' => 'int', 'foreign key' => true, 'target' => 'Actor.id', 'multiplicity' => 'one to one', 'not null' => true, 'description' => 'Who blocked the conversation'],
'created' => ['type' => 'datetime', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was created'],
],
'primary key' => ['conversation_id', 'actor_id'],
'foreign keys' => [
'conversation_id_to_id_fkey' => ['conversation', ['conversation_id' => 'id']],
'actor_id_to_id_fkey' => ['actor', ['actor_id' => 'id']],
],
'primary key' => ['conversation_id', 'actor_id'],
];
}
}