1
0
Fork 0

Move Contact::ACCOUNT_TYPE_* constants to User::ACCOUNT_TYPE_*

- Keep Contact::TYPE_* constants for comparison with contact.contact-type
This commit is contained in:
Hypolite Petovan 2019-01-06 17:08:35 -05:00
parent ad9c67663d
commit 3d839bb176
12 changed files with 79 additions and 44 deletions

View file

@ -1995,10 +1995,11 @@ function admin_page_users(App $a)
User::PAGE_FLAGS_PRVGROUP => L10n::t('Private Forum')
];
$account_types = [
Contact::ACCOUNT_TYPE_PERSON => L10n::t('Personal Page'),
Contact::ACCOUNT_TYPE_ORGANISATION => L10n::t('Organisation Page'),
Contact::ACCOUNT_TYPE_NEWS => L10n::t('News Page'),
Contact::ACCOUNT_TYPE_COMMUNITY => L10n::t('Community Forum')
User::ACCOUNT_TYPE_PERSON => L10n::t('Personal Page'),
User::ACCOUNT_TYPE_ORGANISATION => L10n::t('Organisation Page'),
User::ACCOUNT_TYPE_NEWS => L10n::t('News Page'),
User::ACCOUNT_TYPE_COMMUNITY => L10n::t('Community Forum'),
User::ACCOUNT_TYPE_RELAY => L10n::t('Relay'),
];
$e['page_flags_raw'] = $e['page-flags'];

View file

@ -14,6 +14,7 @@ use Friendica\Core\Renderer;
use Friendica\Database\DBA;
use Friendica\Model\Contact;
use Friendica\Model\Item;
use Friendica\Model\User;
function community_init(App $a)
{
@ -44,16 +45,16 @@ function community_content(App $a, $update = 0)
if ($a->argc > 2) {
switch ($a->argv[2]) {
case 'person':
$accounttype = Contact::ACCOUNT_TYPE_PERSON;
$accounttype = User::ACCOUNT_TYPE_PERSON;
break;
case 'organisation':
$accounttype = Contact::ACCOUNT_TYPE_ORGANISATION;
$accounttype = User::ACCOUNT_TYPE_ORGANISATION;
break;
case 'news':
$accounttype = Contact::ACCOUNT_TYPE_NEWS;
$accounttype = User::ACCOUNT_TYPE_NEWS;
break;
case 'community':
$accounttype = Contact::ACCOUNT_TYPE_COMMUNITY;
$accounttype = User::ACCOUNT_TYPE_COMMUNITY;
break;
}
}

View file

@ -9,6 +9,7 @@ use Friendica\Core\System;
use Friendica\Database\DBA;
use Friendica\Model\Contact;
use Friendica\Model\Profile;
use Friendica\Model\User;
function noscrape_init(App $a)
{
@ -32,7 +33,7 @@ function noscrape_init(App $a)
'guid' => $a->profile['guid'],
'key' => $a->profile['pubkey'],
'homepage' => System::baseUrl()."/profile/{$which}",
'comm' => ($a->profile['account-type'] == Contact::ACCOUNT_TYPE_COMMUNITY),
'comm' => ($a->profile['account-type'] == User::ACCOUNT_TYPE_COMMUNITY),
'account-type' => $a->profile['account-type'],
];

View file

@ -74,27 +74,30 @@ class Contact extends BaseObject
/**
* @name account types
*
* ACCOUNT_TYPE_PERSON - the account belongs to a person
* TYPE_UNKNOWN - the account has been imported from gcontact where this is the default type value
*
* TYPE_PERSON - the account belongs to a person
* Associated page types: PAGE_NORMAL, PAGE_SOAPBOX, PAGE_FREELOVE
*
* ACCOUNT_TYPE_ORGANISATION - the account belongs to an organisation
* TYPE_ORGANISATION - the account belongs to an organisation
* Associated page type: PAGE_SOAPBOX
*
* ACCOUNT_TYPE_NEWS - the account is a news reflector
* TYPE_NEWS - the account is a news reflector
* Associated page type: PAGE_SOAPBOX
*
* ACCOUNT_TYPE_COMMUNITY - the account is community forum
* TYPE_COMMUNITY - the account is community forum
* Associated page types: PAGE_COMMUNITY, PAGE_PRVGROUP
*
* ACCOUNT_TYPE_RELAY - the account is a relay
* TYPE_RELAY - the account is a relay
* This will only be assigned to contacts, not to user accounts
* @{
*/
const ACCOUNT_TYPE_PERSON = 0;
const ACCOUNT_TYPE_ORGANISATION = 1;
const ACCOUNT_TYPE_NEWS = 2;
const ACCOUNT_TYPE_COMMUNITY = 3;
const ACCOUNT_TYPE_RELAY = 4;
const TYPE_UNKNOWN = -1;
const TYPE_PERSON = User::ACCOUNT_TYPE_PERSON;
const TYPE_ORGANISATION = User::ACCOUNT_TYPE_ORGANISATION;
const TYPE_NEWS = User::ACCOUNT_TYPE_NEWS;
const TYPE_COMMUNITY = User::ACCOUNT_TYPE_COMMUNITY;
const TYPE_RELAY = User::ACCOUNT_TYPE_RELAY;
/**
* @}
*/
@ -740,7 +743,7 @@ class Contact extends BaseObject
DBA::update('contact', $fields, ['nurl' => Strings::normaliseLink($contact['url'])]);
if (!empty($contact['batch'])) {
$condition = ['batch' => $contact['batch'], 'contact-type' => self::ACCOUNT_TYPE_RELAY];
$condition = ['batch' => $contact['batch'], 'contact-type' => self::TYPE_RELAY];
DBA::update('contact', $fields, $condition);
}
}
@ -1436,7 +1439,7 @@ class Contact extends BaseObject
$sql = "`item`.`uid` = ?";
}
$contact_field = ($contact["contact-type"] == self::ACCOUNT_TYPE_COMMUNITY ? 'owner-id' : 'author-id');
$contact_field = ($contact["contact-type"] == self::TYPE_COMMUNITY ? 'owner-id' : 'author-id');
if ($thread_mode) {
$condition = ["`$contact_field` = ? AND `gravity` = ? AND " . $sql,
@ -1492,9 +1495,9 @@ class Contact extends BaseObject
|| (isset($contact['prv']) && intval($contact['prv']))
|| (isset($contact['community']) && intval($contact['community']))
) {
$type = self::ACCOUNT_TYPE_COMMUNITY;
$type = self::TYPE_COMMUNITY;
} else {
$type = self::ACCOUNT_TYPE_PERSON;
$type = self::TYPE_PERSON;
}
// The "contact-type" (contact table) and "account-type" (user table) are more general then the chaos from above.
@ -1507,15 +1510,15 @@ class Contact extends BaseObject
}
switch ($type) {
case self::ACCOUNT_TYPE_ORGANISATION:
case self::TYPE_ORGANISATION:
$account_type = L10n::t("Organisation");
break;
case self::ACCOUNT_TYPE_NEWS:
case self::TYPE_NEWS:
$account_type = L10n::t('News');
break;
case self::ACCOUNT_TYPE_COMMUNITY:
case self::TYPE_COMMUNITY:
$account_type = L10n::t("Forum");
break;

View file

@ -48,6 +48,35 @@ class User
/**
* @}
*/
/**
* Account types
*
* ACCOUNT_TYPE_PERSON - the account belongs to a person
* Associated page types: PAGE_FLAGS_NORMAL, PAGE_FLAGS_SOAPBOX, PAGE_FLAGS_FREELOVE
*
* ACCOUNT_TYPE_ORGANISATION - the account belongs to an organisation
* Associated page type: PAGE_FLAGS_SOAPBOX
*
* ACCOUNT_TYPE_NEWS - the account is a news reflector
* Associated page type: PAGE_FLAGS_SOAPBOX
*
* ACCOUNT_TYPE_COMMUNITY - the account is community forum
* Associated page types: PAGE_COMMUNITY, PAGE_FLAGS_PRVGROUP
*
* ACCOUNT_TYPE_RELAY - the account is a relay
* This will only be assigned to contacts, not to user accounts
* @{
*/
const ACCOUNT_TYPE_PERSON = 0;
const ACCOUNT_TYPE_ORGANISATION = 1;
const ACCOUNT_TYPE_NEWS = 2;
const ACCOUNT_TYPE_COMMUNITY = 3;
const ACCOUNT_TYPE_RELAY = 4;
/**
* @}
*/
/**
* Returns true if a user record exists with the provided id
*

View file

@ -417,7 +417,7 @@ class Probe
// This doesn't cover the case when a community isn't a community anymore
if (!empty($data['community']) && $data['community']) {
$fields['community'] = $data['community'];
$fields['contact-type'] = Contact::ACCOUNT_TYPE_COMMUNITY;
$fields['contact-type'] = Contact::TYPE_COMMUNITY;
}
$fieldnames = [];

View file

@ -503,13 +503,13 @@ class Receiver
// Check if the potential receiver is following the actor
// Exception: The receiver is targetted via "to" or this is a comment
if ((($element != 'as:to') && empty($replyto)) || ($contact['contact-type'] == Contact::ACCOUNT_TYPE_COMMUNITY)) {
if ((($element != 'as:to') && empty($replyto)) || ($contact['contact-type'] == Contact::TYPE_COMMUNITY)) {
$networks = [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS];
$condition = ['nurl' => Strings::normaliseLink($actor), 'rel' => [Contact::SHARING, Contact::FRIEND],
'network' => $networks, 'archive' => false, 'pending' => false, 'uid' => $contact['uid']];
// Forum posts are only accepted from forum contacts
if ($contact['contact-type'] == Contact::ACCOUNT_TYPE_COMMUNITY) {
if ($contact['contact-type'] == Contact::TYPE_COMMUNITY) {
$condition['rel'] = [Contact::SHARING, Contact::FRIEND, Contact::FOLLOWER];
}
@ -576,7 +576,7 @@ class Receiver
// When the possible receiver isn't a community, then it is no valid receiver
$owner = User::getOwnerDataById($contact['uid']);
if (empty($owner) || ($owner['contact-type'] != Contact::ACCOUNT_TYPE_COMMUNITY)) {
if (empty($owner) || ($owner['contact-type'] != Contact::TYPE_COMMUNITY)) {
return false;
}

View file

@ -2878,7 +2878,7 @@ class DFRN
DBA::update('contact', ['contact-type' => $accounttype], ['uid' => 0, 'nurl' => $importer['nurl']]);
}
// A forum contact can either have set "forum" or "prv" - but not both
if ($accounttype == Contact::ACCOUNT_TYPE_COMMUNITY) {
if ($accounttype == User::ACCOUNT_TYPE_COMMUNITY) {
// It's a forum, so either set the public or private forum flag
$condition = ['(`forum` != ? OR `prv` != ?) AND `id` = ?', $forum, !$forum, $importer['id']];
DBA::update('contact', ['forum' => $forum, 'prv' => !$forum], $condition);

View file

@ -147,7 +147,7 @@ class Diaspora
// Fetch the relay contact
$condition = ['uid' => 0, 'nurl' => Strings::normaliseLink($server_url),
'contact-type' => Contact::ACCOUNT_TYPE_RELAY];
'contact-type' => Contact::TYPE_RELAY];
$contact = DBA::selectFirst('contact', $fields, $condition);
if (DBA::isResult($contact)) {
@ -187,7 +187,7 @@ class Diaspora
$fields = array_merge($fields, $network_fields);
$condition = ['uid' => 0, 'nurl' => Strings::normaliseLink($server_url),
'contact-type' => Contact::ACCOUNT_TYPE_RELAY];
'contact-type' => Contact::TYPE_RELAY];
if (DBA::exists('contact', $condition)) {
unset($fields['created']);
@ -3165,7 +3165,7 @@ class Diaspora
Logger::log("transmit: ".$logid."-".$guid." to ".$dest_url." returns: ".$return_code);
if (!$return_code || (($return_code == 503) && (stristr($postResult->getHeader(), "retry-after")))) {
if (!$no_queue && !empty($contact['contact-type']) && ($contact['contact-type'] != Contact::ACCOUNT_TYPE_RELAY)) {
if (!$no_queue && !empty($contact['contact-type']) && ($contact['contact-type'] != Contact::TYPE_RELAY)) {
Logger::log("queue message");
// queue message for redelivery
Queue::add($contact["id"], Protocol::DIASPORA, $envelope, $public_batch, $guid);

View file

@ -1349,7 +1349,7 @@ class OStatus
$attributes = ["href" => System::baseUrl() . $selfUri, "rel" => "self", "type" => "application/atom+xml"];
XML::addElement($doc, $root, "link", "", $attributes);
if ($owner['account-type'] == Contact::ACCOUNT_TYPE_COMMUNITY) {
if ($owner['account-type'] == Contact::TYPE_COMMUNITY) {
$condition = ['uid' => $owner['uid'], 'self' => false, 'pending' => false,
'archive' => false, 'hidden' => false, 'blocked' => false];
$members = DBA::count('contact', $condition);
@ -1461,7 +1461,7 @@ class OStatus
$profile = DBA::selectFirst('profile', ['homepage', 'publish'], ['uid' => $owner['uid'], 'is-default' => true]);
$author = $doc->createElement("author");
XML::addElement($doc, $author, "id", $owner["url"]);
if ($owner['account-type'] == Contact::ACCOUNT_TYPE_COMMUNITY) {
if ($owner['account-type'] == User::ACCOUNT_TYPE_COMMUNITY) {
XML::addElement($doc, $author, "activity:object-type", ACTIVITY_OBJ_GROUP);
} else {
XML::addElement($doc, $author, "activity:object-type", ACTIVITY_OBJ_PERSON);
@ -1945,7 +1945,7 @@ class OStatus
$title = sprintf("New note by %s", $owner["nick"]);
}
if ($owner['account-type'] == Contact::ACCOUNT_TYPE_COMMUNITY) {
if ($owner['account-type'] == User::ACCOUNT_TYPE_COMMUNITY) {
$contact = self::contactEntry($item['author-link'], $owner);
$author = self::addAuthor($doc, $contact, false);
$entry->appendChild($author);
@ -2108,8 +2108,8 @@ class OStatus
foreach ($mentioned as $mention) {
$condition = ['uid' => $owner['uid'], 'nurl' => Strings::normaliseLink($mention)];
$contact = DBA::selectFirst('contact', ['forum', 'prv', 'self', 'contact-type'], $condition);
if ($contact["forum"] || $contact["prv"] || ($owner['contact-type'] == Contact::ACCOUNT_TYPE_COMMUNITY) ||
($contact['self'] && ($owner['account-type'] == Contact::ACCOUNT_TYPE_COMMUNITY))) {
if ($contact["forum"] || $contact["prv"] || ($owner['contact-type'] == Contact::TYPE_COMMUNITY) ||
($contact['self'] && ($owner['account-type'] == User::ACCOUNT_TYPE_COMMUNITY))) {
XML::addElement($doc, $entry, "link", "",
[
"rel" => "mentioned",
@ -2126,7 +2126,7 @@ class OStatus
}
}
if ($owner['account-type'] == Contact::ACCOUNT_TYPE_COMMUNITY) {
if ($owner['account-type'] == User::ACCOUNT_TYPE_COMMUNITY) {
XML::addElement($doc, $entry, "link", "", [
"rel" => "mentioned",
"ostatus:object-type" => "http://activitystrea.ms/schema/1.0/group",
@ -2236,7 +2236,7 @@ class OStatus
$condition[] = ACTIVITY_OBJ_COMMENT;
}
if ($owner['account-type'] != Contact::ACCOUNT_TYPE_COMMUNITY) {
if ($owner['account-type'] != User::ACCOUNT_TYPE_COMMUNITY) {
$condition[0] .= " AND `contact-id` = ? AND `author-id` = ?";
$condition[] = $owner["id"];
$condition[] = $authorid;

View file

@ -301,7 +301,7 @@ class Delivery extends BaseObject
// Se we transmit with the new method and via Diaspora as a fallback
if (!empty($items) && (($items[0]['uid'] == 0) || ($contact['uid'] == 0))) {
// Transmit in public if it's a relay post
$public_dfrn = ($contact['contact-type'] == Contact::ACCOUNT_TYPE_RELAY);
$public_dfrn = ($contact['contact-type'] == Contact::TYPE_RELAY);
$deliver_status = DFRN::transmit($owner, $contact, $atom, $public_dfrn);
@ -359,7 +359,7 @@ class Delivery extends BaseObject
private static function deliverDiaspora($cmd, $contact, $owner, $items, $target_item, $public_message, $top_level, $followup)
{
// We don't treat Forum posts as "wall-to-wall" to be able to post them via Diaspora
$walltowall = $top_level && ($owner['id'] != $items[0]['contact-id']) & ($owner['account-type'] != Contact::ACCOUNT_TYPE_COMMUNITY);
$walltowall = $top_level && ($owner['id'] != $items[0]['contact-id']) & ($owner['account-type'] != User::ACCOUNT_TYPE_COMMUNITY);
if ($public_message) {
$loc = 'public batch ' . $contact['batch'];

View file

@ -138,7 +138,7 @@ class Queue
$deliver_status = Diaspora::transmit($owner, $contact, $data, $public, true, 'Queue:' . $q_item['id'], true);
if ((($deliver_status >= 200) && ($deliver_status <= 299)) ||
($contact['contact-type'] == Contact::ACCOUNT_TYPE_RELAY)) {
($contact['contact-type'] == Contact::TYPE_RELAY)) {
QueueModel::removeItem($q_item['id']);
} else {
QueueModel::updateTime($q_item['id']);