123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177 |
- <?php
- if (!defined('STATUSNET')) {
-
-
- exit(1);
- }
- class ActivityMover extends QueueHandler
- {
- function transport()
- {
- return 'actmove';
- }
- function handle($data) : bool
- {
- list ($act, $sink, $userURI, $remoteURI) = $data;
- $user = User::getKV('uri', $userURI);
- try {
- $remote = Profile::fromUri($remoteURI);
- } catch (UnknownUriException $e) {
-
-
-
- return true;
- }
- try {
- $this->moveActivity($act, $sink, $user, $remote);
- } catch (ClientException $cex) {
- $this->log(LOG_WARNING,
- $cex->getMessage());
-
- return true;
- } catch (ServerException $sex) {
- $this->log(LOG_WARNING,
- $sex->getMessage());
-
- return false;
- } catch (Exception $ex) {
- $this->log(LOG_WARNING,
- $ex->getMessage());
-
- return true;
- }
- }
- function moveActivity($act, $sink, $user, $remote)
- {
- if (empty($user)) {
-
- throw new Exception(sprintf(_('No such user "%s".'),$act->actor->id));
- }
- switch ($act->verb) {
- case ActivityVerb::POST:
- $this->log(LOG_INFO,
- "Moving notice {$act->objects[0]->id} by ".
- "{$act->actor->id} to {$remote->nickname}.");
-
- $sink->postActivity($act);
- $notice = Notice::getKV('uri', $act->objects[0]->id);
- if (!empty($notice)) {
- $notice->deleteAs($user->getProfile(), false);
- }
- break;
- case ActivityVerb::JOIN:
- $this->log(LOG_INFO,
- "Moving group join of {$act->objects[0]->id} by ".
- "{$act->actor->id} to {$remote->nickname}.");
- $sink->postActivity($act);
- $group = User_group::getKV('uri', $act->objects[0]->id);
- if (!empty($group)) {
- $user->leaveGroup($group);
- }
- break;
- case ActivityVerb::FOLLOW:
- if ($act->actor->id === $user->getUri()) {
- $this->log(LOG_INFO,
- "Moving subscription to {$act->objects[0]->id} by ".
- "{$act->actor->id} to {$remote->nickname}.");
- $sink->postActivity($act);
- try {
- $other = Profile::fromUri($act->objects[0]->id);
- Subscription::cancel($user->getProfile(), $other);
- } catch (UnknownUriException $e) {
-
- }
- } else {
- $otherUser = User::getKV('uri', $act->actor->id);
- if (!empty($otherUser)) {
- $this->log(LOG_INFO,
- "Changing sub to {$act->objects[0]->id}".
- "by {$act->actor->id} to {$remote->nickname}.");
- $otherProfile = $otherUser->getProfile();
- Subscription::ensureStart($otherProfile, $remote);
- Subscription::cancel($otherProfile, $user->getProfile());
- } else {
- $this->log(LOG_NOTICE,
- "Not changing sub to {$act->objects[0]->id}".
- "by remote {$act->actor->id} ".
- "to {$remote->nickname}.");
- }
- }
- break;
- }
- }
-
- protected function log($level, $message)
- {
- common_log($level, "ActivityMover: " . $message);
- }
- }
|