summaryrefslogtreecommitdiff
path: root/classes
diff options
context:
space:
mode:
Diffstat (limited to 'classes')
-rw-r--r--classes/Fave.php25
-rw-r--r--classes/Group_member.php50
-rw-r--r--classes/Notice.php91
-rw-r--r--classes/Subscription.php26
-rw-r--r--classes/User.php24
5 files changed, 202 insertions, 14 deletions
diff --git a/classes/Fave.php b/classes/Fave.php
index ed4f56aee..f21f1b529 100644
--- a/classes/Fave.php
+++ b/classes/Fave.php
@@ -129,4 +129,29 @@ class Fave extends Memcached_DataObject
return $ids;
}
+
+ function asActivity()
+ {
+ $notice = Notice::staticGet('id', $this->notice_id);
+ $profile = Profile::staticGet('id', $this->user_id);
+
+ $act = new Activity();
+
+ $act->verb = ActivityVerb::FAVORITE;
+ $act->id = TagURI::mint('favor:%d:%d:%s',
+ $profile->id,
+ $notice->id,
+ common_date_iso8601($this->modified));
+
+ $act->time = strtotime($this->modified);
+ $act->title = _("Favor");
+ $act->content = sprintf(_("%s marked notice %s as a favorite."),
+ $profile->getBestName(),
+ $notice->uri);
+
+ $act->actor = ActivityObject::fromProfile($profile);
+ $act->objects[] = ActivityObject::fromNotice($notice);
+
+ return $act;
+ }
}
diff --git a/classes/Group_member.php b/classes/Group_member.php
index 2239461be..939a9cde7 100644
--- a/classes/Group_member.php
+++ b/classes/Group_member.php
@@ -65,4 +65,54 @@ class Group_member extends Memcached_DataObject
return true;
}
+
+ function getMember()
+ {
+ $member = Profile::staticGet('id', $this->profile_id);
+
+ if (empty($member)) {
+ throw new Exception("Profile ID {$this->profile_id} invalid.");
+ }
+
+ return $member;
+ }
+
+ function getGroup()
+ {
+ $group = User_group::staticGet('id', $this->group_id);
+
+ if (empty($group)) {
+ throw new Exception("Group ID {$this->group_id} invalid.");
+ }
+
+ return $group;
+ }
+
+ function asActivity()
+ {
+ $member = $this->getMember();
+ $group = $this->getGroup();
+
+ $act = new Activity();
+
+ $act->id = TagURI::mint('join:%d:%d:%s',
+ $member->id,
+ $group->id,
+ common_date_iso8601($this->created));
+
+ $act->actor = ActivityObject::fromProfile($member);
+ $act->verb = ActivityVerb::JOIN;
+ $act->objects[] = ActivityObject::fromGroup($group);
+
+ $act->time = strtotime($this->created);
+ $act->title = _("Join");
+
+ // TRANS: Success message for subscribe to group attempt through OStatus.
+ // TRANS: %1$s is the member name, %2$s is the subscribed group's name.
+ $act->content = sprintf(_('%1$s has joined group %2$s.'),
+ $member->getBestName(),
+ $group->getBestName());
+
+ return $act;
+ }
}
diff --git a/classes/Notice.php b/classes/Notice.php
index f1b012465..4f23e3500 100644
--- a/classes/Notice.php
+++ b/classes/Notice.php
@@ -753,8 +753,15 @@ class Notice extends Memcached_DataObject
}
/**
- * @param $groups array of Group *objects*
- * @param $recipients array of profile *ids*
+ * Pull up a full list of local recipients who will be getting
+ * this notice in their inbox. Results will be cached, so don't
+ * change the input data wily-nilly!
+ *
+ * @param array $groups optional list of Group objects;
+ * if left empty, will be loaded from group_inbox records
+ * @param array $recipient optional list of reply profile ids
+ * if left empty, will be loaded from reply records
+ * @return array associating recipient user IDs with an inbox source constant
*/
function whoGets($groups=null, $recipients=null)
{
@@ -787,27 +794,27 @@ class Notice extends Memcached_DataObject
$ni[$id] = NOTICE_INBOX_SOURCE_SUB;
}
- $profile = $this->getProfile();
-
foreach ($groups as $group) {
$users = $group->getUserMembers();
foreach ($users as $id) {
if (!array_key_exists($id, $ni)) {
- $user = User::staticGet('id', $id);
- if (!$user->hasBlocked($profile)) {
- $ni[$id] = NOTICE_INBOX_SOURCE_GROUP;
- }
+ $ni[$id] = NOTICE_INBOX_SOURCE_GROUP;
}
}
}
foreach ($recipients as $recipient) {
-
if (!array_key_exists($recipient, $ni)) {
- $recipientUser = User::staticGet('id', $recipient);
- if (!empty($recipientUser)) {
- $ni[$recipient] = NOTICE_INBOX_SOURCE_REPLY;
- }
+ $ni[$recipient] = NOTICE_INBOX_SOURCE_REPLY;
+ }
+ }
+
+ // Exclude any deleted, non-local, or blocking recipients.
+ $profile = $this->getProfile();
+ foreach ($ni as $id => $source) {
+ $user = User::staticGet('id', $id);
+ if (empty($user) || $user->hasBlocked($profile)) {
+ unset($ni[$id]);
}
}
@@ -1212,6 +1219,64 @@ class Notice extends Memcached_DataObject
return $groups;
}
+ function asActivity()
+ {
+ $profile = $this->getProfile();
+
+ $act = new Activity();
+
+ $act->actor = ActivityObject::fromProfile($profile);
+ $act->verb = ActivityVerb::POST;
+ $act->objects[] = ActivityObject::fromNotice($this);
+
+ $act->time = strtotime($this->created);
+ $act->link = $this->bestUrl();
+
+ $act->content = common_xml_safe_str($this->rendered);
+ $act->id = $this->uri;
+ $act->title = common_xml_safe_str($this->content);
+
+ $ctx = new ActivityContext();
+
+ if (!empty($this->reply_to)) {
+ $reply = Notice::staticGet('id', $this->reply_to);
+ if (!empty($reply)) {
+ $ctx->replyToID = $reply->uri;
+ $ctx->replyToUrl = $reply->bestUrl();
+ }
+ }
+
+ $ctx->location = $this->getLocation();
+
+ $conv = null;
+
+ if (!empty($this->conversation)) {
+ $conv = Conversation::staticGet('id', $this->conversation);
+ if (!empty($conv)) {
+ $ctx->conversation = $conv->uri;
+ }
+ }
+
+ $reply_ids = $this->getReplies();
+
+ foreach ($reply_ids as $id) {
+ $profile = Profile::staticGet('id', $id);
+ if (!empty($profile)) {
+ $ctx->attention[] = $profile->getUri();
+ }
+ }
+
+ $groups = $this->getGroups();
+
+ foreach ($groups as $group) {
+ $ctx->attention[] = $group->uri;
+ }
+
+ $act->context = $ctx;
+
+ return $act;
+ }
+
// This has gotten way too long. Needs to be sliced up into functional bits
// or ideally exported to a utility class.
diff --git a/classes/Subscription.php b/classes/Subscription.php
index 0225ed4df..1287499fa 100644
--- a/classes/Subscription.php
+++ b/classes/Subscription.php
@@ -235,4 +235,30 @@ class Subscription extends Memcached_DataObject
'subscribed' => $other->id));
return (empty($sub)) ? false : true;
}
+
+ function asActivity()
+ {
+ $subscriber = Profile::staticGet('id', $this->subscriber);
+ $subscribed = Profile::staticGet('id', $this->subscribed);
+
+ $act = new Activity();
+
+ $act->verb = ActivityVerb::FOLLOW;
+
+ $act->id = TagURI::mint('follow:%d:%d:%s',
+ $subscriber->id,
+ $subscribed->id,
+ common_date_iso8601($this->created));
+
+ $act->time = strtotime($this->created);
+ $act->title = _("Follow");
+ $act->content = sprintf(_("%s is now following %s."),
+ $subscriber->getBestName(),
+ $subscribed->getBestName());
+
+ $act->actor = ActivityObject::fromProfile($subscriber);
+ $act->objects[] = ActivityObject::fromProfile($subscribed);
+
+ return $act;
+ }
}
diff --git a/classes/User.php b/classes/User.php
index 8033229c4..b85192b29 100644
--- a/classes/User.php
+++ b/classes/User.php
@@ -255,6 +255,19 @@ class User extends Memcached_DataObject
$user->inboxed = 1;
+ // Set default-on options here, otherwise they'll be disabled
+ // initially for sites using caching, since the initial encache
+ // doesn't know about the defaults in the database.
+ $user->emailnotifysub = 1;
+ $user->emailnotifyfav = 1;
+ $user->emailnotifynudge = 1;
+ $user->emailnotifymsg = 1;
+ $user->emailnotifyattn = 1;
+ $user->emailmicroid = 1;
+ $user->emailpost = 1;
+ $user->jabbermicroid = 1;
+ $user->viewdesigns = 1;
+
$user->created = common_sql_now();
if (Event::handle('StartUserRegister', array(&$user, &$profile))) {
@@ -269,7 +282,13 @@ class User extends Memcached_DataObject
}
$user->id = $id;
- $user->uri = common_user_uri($user);
+
+ if (!empty($uri)) {
+ $user->uri = $uri;
+ } else {
+ $user->uri = common_user_uri($user);
+ }
+
if (!empty($password)) { // may not have a password for OpenID users
$user->password = common_munge_password($password, $id);
}
@@ -552,6 +571,9 @@ class User extends Memcached_DataObject
if (Subscription::exists($other, $self)) {
Subscription::cancel($other, $self);
}
+ if (Subscription::exists($self, $other)) {
+ Subscription::cancel($self, $other);
+ }
$block->query('COMMIT');