/** * Record this notice to the given group inboxes for delivery. * Overrides the regular parsing of !group markup. * * @param string $group_ids * @fixme might prefer URIs as identifiers, as for replies? * best with generalizations on user_group to support * remote groups better. */ function saveKnownGroups(array $group_ids) { $groups = array(); foreach (array_unique($group_ids) as $id) { $group = User_group::getKV('id', $id); if ($group instanceof User_group) { common_log(LOG_DEBUG, "Local delivery to group id {$id}, {$group->nickname}"); $result = $this->addToGroupInbox($group); if (!$result) { common_log_db_error($gi, 'INSERT', __FILE__); } if (common_config('group', 'addtag')) { // we automatically add a tag for every group name, too $tag = Notice_tag::pkeyGet(array('tag' => common_canonical_tag($group->nickname), 'notice_id' => $this->id)); if (is_null($tag)) { $this->saveTag($group->nickname); } } $groups[] = clone $group; } else { common_log(LOG_ERR, "Local delivery to group id {$id} skipped, doesn't exist"); } } return $groups; }
/** * Record this notice to the given group inboxes for delivery. * Overrides the regular parsing of !group markup. * * @param string $group_ids * @fixme might prefer URIs as identifiers, as for replies? * best with generalizations on user_group to support * remote groups better. */ function saveKnownGroups($group_ids) { if (!is_array($group_ids)) { // TRANS: Server exception thrown when no array is provided to the method saveKnownGroups(). throw new ServerException(_('Bad type provided to saveKnownGroups.')); } $groups = array(); foreach (array_unique($group_ids) as $id) { $group = User_group::staticGet('id', $id); if ($group) { common_log(LOG_ERR, "Local delivery to group id {$id}, {$group->nickname}"); $result = $this->addToGroupInbox($group); if (!$result) { common_log_db_error($gi, 'INSERT', __FILE__); } if (common_config('group', 'addtag')) { // we automatically add a tag for every group name, too $tag = Notice_tag::pkeyGet(array('tag' => common_canonical_tag($group->nickname), 'notice_id' => $this->id)); if (is_null($tag)) { $this->saveTag($group->nickname); } } $groups[] = clone $group; } else { common_log(LOG_ERR, "Local delivery to group id {$id} skipped, doesn't exist"); } } return $groups; }
/** * Parse !group delivery and record targets into group_inbox. * @return array of Group objects */ function saveGroups() { // Don't save groups for repeats if (!empty($this->repeat_of)) { return array(); } $groups = array(); /* extract all !group */ $count = preg_match_all('/(?:^|\\s)!([A-Za-z0-9]{1,64})/', strtolower($this->content), $match); if (!$count) { return $groups; } $profile = $this->getProfile(); /* Add them to the database */ foreach (array_unique($match[1]) as $nickname) { /* XXX: remote groups. */ $group = User_group::getForNickname($nickname, $profile); if (empty($group)) { continue; } // we automatically add a tag for every group name, too $tag = Notice_tag::pkeyGet(array('tag' => common_canonical_tag($nickname), 'notice_id' => $this->id)); if (is_null($tag)) { $this->saveTag($nickname); } if ($profile->isMember($group)) { $result = $this->addToGroupInbox($group); if (!$result) { common_log_db_error($gi, 'INSERT', __FILE__); } $groups[] = clone $group; } } return $groups; }
function saveGroups() { $enabled = common_config('inboxes', 'enabled'); if ($enabled !== true && $enabled !== 'transitional') { return; } /* extract all !group */ $count = preg_match_all('/(?:^|\\s)!([A-Za-z0-9]{1,64})/', strtolower($this->content), $match); if (!$count) { return true; } $profile = $this->getProfile(); /* Add them to the database */ foreach (array_unique($match[1]) as $nickname) { /* XXX: remote groups. */ $group = User_group::staticGet('nickname', $nickname); if (!$group) { continue; } // we automatically add a tag for every group name, too $tag = Notice_tag::pkeyGet(array('tag' => common_canonical_tag($nickname), 'notice_id' => $this->id)); if (is_null($tag)) { $this->saveTag($nickname); } if ($profile->isMember($group)) { $gi = new Group_inbox(); $gi->group_id = $group->id; $gi->notice_id = $this->id; $gi->created = common_sql_now(); $result = $gi->insert(); if (!$result) { common_log_db_error($gi, 'INSERT', __FILE__); } // FIXME: do this in an offline daemon $inbox = new Notice_inbox(); $UT = common_config('db', 'type') == 'pgsql' ? '"user"' : 'user'; $qry = 'INSERT INTO notice_inbox (user_id, notice_id, created, source) ' . "SELECT {$UT}.id, " . $this->id . ", '" . $this->created . "', 2 " . "FROM {$UT} JOIN group_member ON {$UT}.id = group_member.profile_id " . 'WHERE group_member.group_id = ' . $group->id . ' ' . 'AND NOT EXISTS (SELECT user_id, notice_id ' . 'FROM notice_inbox ' . "WHERE user_id = {$UT}.id " . 'AND notice_id = ' . $this->id . ' )'; if ($enabled === 'transitional') { $qry .= " AND {$UT}.inboxed = 1"; } $result = $inbox->query($qry); } } }