-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add activity logging for favorites in dav #48612
base: master
Are you sure you want to change the base?
Conversation
cde368c
to
e747f11
Compare
3a2b521
to
fbd6419
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it not be cleaner and make more sense to emit just the event and handle the activity in an event listener?
Then only one place for the activity is required and one would not mix different apps (files app activity in dav app).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't get why this is need. Isn't TagService
already doing that?
server/apps/files/lib/Service/TagService.php
Lines 101 to 131 in ff9ea47
protected function addActivity($addToFavorite, $fileId, $path) { | |
$user = $this->userSession->getUser(); | |
if (!$user instanceof IUser) { | |
return; | |
} | |
if ($addToFavorite) { | |
$event = new NodeAddedToFavorite($user, $fileId, $path); | |
} else { | |
$event = new NodeRemovedFromFavorite($user, $fileId, $path); | |
} | |
$this->dispatcher->dispatchTyped($event); | |
$event = $this->activityManager->generateEvent(); | |
try { | |
$event->setApp('files') | |
->setObject('files', $fileId, $path) | |
->setType('favorite') | |
->setAuthor($user->getUID()) | |
->setAffectedUser($user->getUID()) | |
->setTimestamp(time()) | |
->setSubject( | |
$addToFavorite ? FavoriteProvider::SUBJECT_ADDED : FavoriteProvider::SUBJECT_REMOVED, | |
['id' => $fileId, 'path' => $path] | |
); | |
$this->activityManager->publish($event); | |
} catch (\InvalidArgumentException $e) { | |
} catch (\BadMethodCallException $e) { | |
} | |
} | |
} |
EDIT: reading the issue
if ((int)$favState === 1 || $favState === 'true') { | ||
$this->addActivity(true, $node->getId(), $path); | ||
$this->getTagger()->tagAs($node->getId(), self::TAG_FAVORITE); | ||
} else { | ||
$this->addActivity(false, $node->getId(), $path); | ||
$this->getTagger()->unTag($node->getId(), self::TAG_FAVORITE); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe use those methods instead:
Lines 481 to 497 in ff9ea47
public function addToFavorites($objid) { | |
if (!$this->userHasTag(ITags::TAG_FAVORITE, $this->user)) { | |
$this->add(ITags::TAG_FAVORITE); | |
} | |
return $this->tagAs($objid, ITags::TAG_FAVORITE); | |
} | |
/** | |
* Remove an object from favorites | |
* | |
* @param int $objid The id of the object | |
* @return boolean | |
*/ | |
public function removeFromFavorites($objid) { | |
return $this->unTag($objid, ITags::TAG_FAVORITE); | |
} | |
And then emit the event in those methods?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addActivity
fromTagService
can be copied toTags
.- Then
TagService
can be deleted. - And then
server/apps/files/lib/Controller/ApiController.php
Lines 126 to 127 in ff9ea47
$this->tagService->updateFileTags($path, $tags); } catch (\OCP\Files\NotFoundException $e) {
935e3b1
to
e61f394
Compare
739acab
to
6f98dd1
Compare
lib/public/ITags.php
Outdated
* @return boolean | ||
* @since 6.0.0 | ||
*/ | ||
public function addToFavorites($objid); | ||
public function addToFavorites($objid, $path); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a good idea to break a public API by adding an argument
6f98dd1
to
205809a
Compare
205809a
to
f6dd0c2
Compare
lib/private/Tags.php
Outdated
/** | ||
* @param bool $addToFavorite | ||
* @param int $fileId | ||
* @param string $path | ||
*/ | ||
protected function addActivity($addToFavorite, $fileId, $path) { | ||
$user = $this->userSession->getUser(); | ||
if (!$user instanceof IUser) { | ||
return; | ||
} | ||
|
||
if ($addToFavorite) { | ||
$event = new NodeAddedToFavorite($user, $fileId, $path); | ||
} else { | ||
$event = new NodeRemovedFromFavorite($user, $fileId, $path); | ||
} | ||
$this->eventDispatcher->dispatchTyped($event); | ||
|
||
$event = $this->activityManager->generateEvent(); | ||
try { | ||
$event->setApp('files') | ||
->setObject('files', $fileId, $path) | ||
->setType('favorite') | ||
->setAuthor($user->getUID()) | ||
->setAffectedUser($user->getUID()) | ||
->setTimestamp(time()) | ||
->setSubject( | ||
$addToFavorite ? FavoriteProvider::SUBJECT_ADDED : FavoriteProvider::SUBJECT_REMOVED, | ||
['id' => $fileId, 'path' => $path] | ||
); | ||
$this->activityManager->publish($event); | ||
} catch (\InvalidArgumentException $e) { | ||
} catch (\BadMethodCallException $e) { | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For me it feels wrong to do this here in the library instead of the files app.
I think it would be cleaner to just emit NodeAddedToFavorite
in addToFavorites
and the NodeRemovedFromFavorite
in removeFromFavorites
.
Then in the files app there could be an event listener to create the activity, so no need to wire activity management directly into the tagger.
f6dd0c2
to
6c82e9e
Compare
Signed-off-by: grnd-alt <[email protected]>
6c82e9e
to
6eca638
Compare
Summary
Dav api did not log favorite added/removed events.
Checklist