we now have got an uri-id field for the contact table

This commit is contained in:
Michael 2021-07-08 18:59:58 +00:00
parent 178bc543e3
commit 901c3f4855
5 changed files with 102 additions and 87 deletions

View file

@ -126,6 +126,7 @@ CREATE TABLE IF NOT EXISTS `contact` (
`dfrn-id` varchar(255) NOT NULL DEFAULT '' COMMENT '', `dfrn-id` varchar(255) NOT NULL DEFAULT '' COMMENT '',
`url` varchar(255) NOT NULL DEFAULT '' COMMENT '', `url` varchar(255) NOT NULL DEFAULT '' COMMENT '',
`nurl` varchar(255) NOT NULL DEFAULT '' COMMENT '', `nurl` varchar(255) NOT NULL DEFAULT '' COMMENT '',
`uri-id` int unsigned COMMENT 'Id of the item-uri table entry that contains the contact url',
`addr` varchar(255) NOT NULL DEFAULT '' COMMENT '', `addr` varchar(255) NOT NULL DEFAULT '' COMMENT '',
`alias` varchar(255) NOT NULL DEFAULT '' COMMENT '', `alias` varchar(255) NOT NULL DEFAULT '' COMMENT '',
`pubkey` text COMMENT 'RSA public key 4096 bit', `pubkey` text COMMENT 'RSA public key 4096 bit',
@ -202,7 +203,9 @@ CREATE TABLE IF NOT EXISTS `contact` (
INDEX `uid_self_contact-type` (`uid`,`self`,`contact-type`), INDEX `uid_self_contact-type` (`uid`,`self`,`contact-type`),
INDEX `self_network_uid` (`self`,`network`,`uid`), INDEX `self_network_uid` (`self`,`network`,`uid`),
INDEX `gsid` (`gsid`), INDEX `gsid` (`gsid`),
INDEX `uri-id` (`uri-id`),
FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE, FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE,
FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
FOREIGN KEY (`gsid`) REFERENCES `gserver` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT FOREIGN KEY (`gsid`) REFERENCES `gserver` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT
) DEFAULT COLLATE utf8mb4_general_ci COMMENT='contact table'; ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='contact table';

View file

@ -6,89 +6,90 @@ contact table
Fields Fields
------ ------
| Field | Description | Type | Null | Key | Default | Extra | | Field | Description | Type | Null | Key | Default | Extra |
| ------------------------- | --------------------------------------------------------- | ------------------ | ---- | --- | ------------------- | -------------- | | ------------------------- | ------------------------------------------------------------ | ------------------ | ---- | --- | ------------------- | -------------- |
| id | sequential ID | int unsigned | NO | PRI | NULL | auto_increment | | id | sequential ID | int unsigned | NO | PRI | NULL | auto_increment |
| uid | Owner User id | mediumint unsigned | NO | | 0 | | | uid | Owner User id | mediumint unsigned | NO | | 0 | |
| created | | datetime | NO | | 0001-01-01 00:00:00 | | | created | | datetime | NO | | 0001-01-01 00:00:00 | |
| updated | Date of last contact update | datetime | YES | | 0001-01-01 00:00:00 | | | updated | Date of last contact update | datetime | YES | | 0001-01-01 00:00:00 | |
| self | 1 if the contact is the user him/her self | boolean | NO | | 0 | | | self | 1 if the contact is the user him/her self | boolean | NO | | 0 | |
| remote_self | | boolean | NO | | 0 | | | remote_self | | boolean | NO | | 0 | |
| rel | The kind of the relation between the user and the contact | tinyint unsigned | NO | | 0 | | | rel | The kind of the relation between the user and the contact | tinyint unsigned | NO | | 0 | |
| duplex | | boolean | NO | | 0 | | | duplex | | boolean | NO | | 0 | |
| network | Network of the contact | char(4) | NO | | | | | network | Network of the contact | char(4) | NO | | | |
| protocol | Protocol of the contact | char(4) | NO | | | | | protocol | Protocol of the contact | char(4) | NO | | | |
| name | Name that this contact is known by | varchar(255) | NO | | | | | name | Name that this contact is known by | varchar(255) | NO | | | |
| nick | Nick- and user name of the contact | varchar(255) | NO | | | | | nick | Nick- and user name of the contact | varchar(255) | NO | | | |
| location | | varchar(255) | YES | | | | | location | | varchar(255) | YES | | | |
| about | | text | YES | | NULL | | | about | | text | YES | | NULL | |
| keywords | public keywords (interests) of the contact | text | YES | | NULL | | | keywords | public keywords (interests) of the contact | text | YES | | NULL | |
| gender | Deprecated | varchar(32) | NO | | | | | gender | Deprecated | varchar(32) | NO | | | |
| xmpp | | varchar(255) | NO | | | | | xmpp | | varchar(255) | NO | | | |
| attag | | varchar(255) | NO | | | | | attag | | varchar(255) | NO | | | |
| avatar | | varchar(255) | NO | | | | | avatar | | varchar(255) | NO | | | |
| photo | Link to the profile photo of the contact | varchar(255) | YES | | | | | photo | Link to the profile photo of the contact | varchar(255) | YES | | | |
| thumb | Link to the profile photo (thumb size) | varchar(255) | YES | | | | | thumb | Link to the profile photo (thumb size) | varchar(255) | YES | | | |
| micro | Link to the profile photo (micro size) | varchar(255) | YES | | | | | micro | Link to the profile photo (micro size) | varchar(255) | YES | | | |
| header | Header picture | varchar(255) | YES | | NULL | | | header | Header picture | varchar(255) | YES | | NULL | |
| site-pubkey | | text | YES | | NULL | | | site-pubkey | | text | YES | | NULL | |
| issued-id | | varchar(255) | NO | | | | | issued-id | | varchar(255) | NO | | | |
| dfrn-id | | varchar(255) | NO | | | | | dfrn-id | | varchar(255) | NO | | | |
| url | | varchar(255) | NO | | | | | url | | varchar(255) | NO | | | |
| nurl | | varchar(255) | NO | | | | | nurl | | varchar(255) | NO | | | |
| addr | | varchar(255) | NO | | | | | uri-id | Id of the item-uri table entry that contains the contact url | int unsigned | YES | | NULL | |
| alias | | varchar(255) | NO | | | | | addr | | varchar(255) | NO | | | |
| pubkey | RSA public key 4096 bit | text | YES | | NULL | | | alias | | varchar(255) | NO | | | |
| prvkey | RSA private key 4096 bit | text | YES | | NULL | | | pubkey | RSA public key 4096 bit | text | YES | | NULL | |
| batch | | varchar(255) | NO | | | | | prvkey | RSA private key 4096 bit | text | YES | | NULL | |
| request | | varchar(255) | YES | | NULL | | | batch | | varchar(255) | NO | | | |
| notify | | varchar(255) | YES | | NULL | | | request | | varchar(255) | YES | | NULL | |
| poll | | varchar(255) | YES | | NULL | | | notify | | varchar(255) | YES | | NULL | |
| confirm | | varchar(255) | YES | | NULL | | | poll | | varchar(255) | YES | | NULL | |
| subscribe | | varchar(255) | YES | | NULL | | | confirm | | varchar(255) | YES | | NULL | |
| poco | | varchar(255) | YES | | NULL | | | subscribe | | varchar(255) | YES | | NULL | |
| aes_allow | | boolean | NO | | 0 | | | poco | | varchar(255) | YES | | NULL | |
| ret-aes | | boolean | NO | | 0 | | | aes_allow | | boolean | NO | | 0 | |
| usehub | | boolean | NO | | 0 | | | ret-aes | | boolean | NO | | 0 | |
| subhub | | boolean | NO | | 0 | | | usehub | | boolean | NO | | 0 | |
| hub-verify | | varchar(255) | NO | | | | | subhub | | boolean | NO | | 0 | |
| last-update | Date of the last try to update the contact info | datetime | NO | | 0001-01-01 00:00:00 | | | hub-verify | | varchar(255) | NO | | | |
| success_update | Date of the last successful contact update | datetime | NO | | 0001-01-01 00:00:00 | | | last-update | Date of the last try to update the contact info | datetime | NO | | 0001-01-01 00:00:00 | |
| failure_update | Date of the last failed update | datetime | NO | | 0001-01-01 00:00:00 | | | success_update | Date of the last successful contact update | datetime | NO | | 0001-01-01 00:00:00 | |
| failed | Connection failed | boolean | YES | | NULL | | | failure_update | Date of the last failed update | datetime | NO | | 0001-01-01 00:00:00 | |
| name-date | | datetime | NO | | 0001-01-01 00:00:00 | | | failed | Connection failed | boolean | YES | | NULL | |
| uri-date | | datetime | NO | | 0001-01-01 00:00:00 | | | name-date | | datetime | NO | | 0001-01-01 00:00:00 | |
| avatar-date | | datetime | NO | | 0001-01-01 00:00:00 | | | uri-date | | datetime | NO | | 0001-01-01 00:00:00 | |
| term-date | | datetime | NO | | 0001-01-01 00:00:00 | | | avatar-date | | datetime | NO | | 0001-01-01 00:00:00 | |
| last-item | date of the last post | datetime | NO | | 0001-01-01 00:00:00 | | | term-date | | datetime | NO | | 0001-01-01 00:00:00 | |
| last-discovery | date of the last follower discovery | datetime | NO | | 0001-01-01 00:00:00 | | | last-item | date of the last post | datetime | NO | | 0001-01-01 00:00:00 | |
| priority | | tinyint unsigned | NO | | 0 | | | last-discovery | date of the last follower discovery | datetime | NO | | 0001-01-01 00:00:00 | |
| blocked | Node-wide block status | boolean | NO | | 1 | | | priority | | tinyint unsigned | NO | | 0 | |
| block_reason | Node-wide block reason | text | YES | | NULL | | | blocked | Node-wide block status | boolean | NO | | 1 | |
| readonly | posts of the contact are readonly | boolean | NO | | 0 | | | block_reason | Node-wide block reason | text | YES | | NULL | |
| writable | | boolean | NO | | 0 | | | readonly | posts of the contact are readonly | boolean | NO | | 0 | |
| forum | contact is a forum | boolean | NO | | 0 | | | writable | | boolean | NO | | 0 | |
| prv | contact is a private group | boolean | NO | | 0 | | | forum | contact is a forum | boolean | NO | | 0 | |
| contact-type | | tinyint | NO | | 0 | | | prv | contact is a private group | boolean | NO | | 0 | |
| manually-approve | | boolean | YES | | NULL | | | contact-type | | tinyint | NO | | 0 | |
| hidden | | boolean | NO | | 0 | | | manually-approve | | boolean | YES | | NULL | |
| archive | | boolean | NO | | 0 | | | hidden | | boolean | NO | | 0 | |
| pending | | boolean | NO | | 1 | | | archive | | boolean | NO | | 0 | |
| deleted | Contact has been deleted | boolean | NO | | 0 | | | pending | | boolean | NO | | 1 | |
| rating | | tinyint | NO | | 0 | | | deleted | Contact has been deleted | boolean | NO | | 0 | |
| unsearchable | Contact prefers to not be searchable | boolean | NO | | 0 | | | rating | | tinyint | NO | | 0 | |
| sensitive | Contact posts sensitive content | boolean | NO | | 0 | | | unsearchable | Contact prefers to not be searchable | boolean | NO | | 0 | |
| baseurl | baseurl of the contact | varchar(255) | YES | | | | | sensitive | Contact posts sensitive content | boolean | NO | | 0 | |
| gsid | Global Server ID | int unsigned | YES | | NULL | | | baseurl | baseurl of the contact | varchar(255) | YES | | | |
| reason | | text | YES | | NULL | | | gsid | Global Server ID | int unsigned | YES | | NULL | |
| closeness | | tinyint unsigned | NO | | 99 | | | reason | | text | YES | | NULL | |
| info | | mediumtext | YES | | NULL | | | closeness | | tinyint unsigned | NO | | 99 | |
| profile-id | Deprecated | int unsigned | YES | | NULL | | | info | | mediumtext | YES | | NULL | |
| bdyear | | varchar(4) | NO | | | | | profile-id | Deprecated | int unsigned | YES | | NULL | |
| bd | | date | NO | | 0001-01-01 | | | bdyear | | varchar(4) | NO | | | |
| notify_new_posts | | boolean | NO | | 0 | | | bd | | date | NO | | 0001-01-01 | |
| fetch_further_information | | tinyint unsigned | NO | | 0 | | | notify_new_posts | | boolean | NO | | 0 | |
| ffi_keyword_denylist | | text | YES | | NULL | | | fetch_further_information | | tinyint unsigned | NO | | 0 | |
| ffi_keyword_denylist | | text | YES | | NULL | |
Indexes Indexes
------------ ------------
@ -118,6 +119,7 @@ Indexes
| uid_self_contact-type | uid, self, contact-type | | uid_self_contact-type | uid, self, contact-type |
| self_network_uid | self, network, uid | | self_network_uid | self, network, uid |
| gsid | gsid | | gsid | gsid |
| uri-id | uri-id |
Foreign Keys Foreign Keys
------------ ------------
@ -125,6 +127,7 @@ Foreign Keys
| Field | Target Table | Target Field | | Field | Target Table | Target Field |
|-------|--------------|--------------| |-------|--------------|--------------|
| uid | [user](help/database/db_user) | uid | | uid | [user](help/database/db_user) | uid |
| uri-id | [item-uri](help/database/db_item-uri) | id |
| gsid | [gserver](help/database/db_gserver) | id | | gsid | [gserver](help/database/db_gserver) | id |
Return to [database documentation](help/database) Return to [database documentation](help/database)

View file

@ -185,6 +185,12 @@ class Contact
$fields['gsid'] = GServer::getID($fields['baseurl'], true); $fields['gsid'] = GServer::getID($fields['baseurl'], true);
} }
if (!empty($fields['url']) && !empty($fields['guid'])) {
$fields['uri-id'] = ItemURI::insert(['uri' => $fields['url'], 'guid' => $fields['guid']]);
} elseif (!empty($fields['url'])) {
$fields['uri-id'] = ItemURI::getIdByURI($fields['url']);
}
if (empty($fields['created'])) { if (empty($fields['created'])) {
$fields['created'] = DateTimeFormat::utcNow(); $fields['created'] = DateTimeFormat::utcNow();
} }
@ -2144,9 +2150,10 @@ class Contact
return true; return true;
} }
$ret['nurl'] = Strings::normaliseLink($ret['url']); $ret['nurl'] = Strings::normaliseLink($ret['url']);
$ret['uri-id'] = ItemURI::getIdByURI($ret['url']);
$ret['updated'] = $updated; $ret['updated'] = $updated;
$ret['failed'] = false; $ret['failed'] = false;
// Only fill the pubkey if it had been empty before. We have to prevent identity theft. // Only fill the pubkey if it had been empty before. We have to prevent identity theft.
if (empty($pubkey) && !empty($new_pubkey)) { if (empty($pubkey) && !empty($new_pubkey)) {

View file

@ -111,7 +111,7 @@ class Account extends BaseDataTransferObject
$created = $userContactCreated < $publicContactCreated && ($userContactCreated != DBA::NULL_DATETIME) ? $userContactCreated : $publicContactCreated; $created = $userContactCreated < $publicContactCreated && ($userContactCreated != DBA::NULL_DATETIME) ? $userContactCreated : $publicContactCreated;
$this->created_at = DateTimeFormat::utc($created, DateTimeFormat::JSON); $this->created_at = DateTimeFormat::utc($created, DateTimeFormat::JSON);
$this->note = BBCode::convert($publicContact['about'], false); $this->note = BBCode::convertForItem($publicContact['uri-id'] ?? 0, $publicContact['about'], BBCode::API);
$this->url = $publicContact['url']; $this->url = $publicContact['url'];
$this->avatar = Contact::getAvatarUrlForId($userContact['id'] ?? 0 ?: $publicContact['id'], Proxy::SIZE_SMALL, $userContact['updated'] ?? '' ?: $publicContact['updated']); $this->avatar = Contact::getAvatarUrlForId($userContact['id'] ?? 0 ?: $publicContact['id'], Proxy::SIZE_SMALL, $userContact['updated'] ?? '' ?: $publicContact['updated']);
$this->avatar_static = $this->avatar; $this->avatar_static = $this->avatar;

View file

@ -183,6 +183,7 @@ return [
"dfrn-id" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""], "dfrn-id" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
"url" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""], "url" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
"nurl" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""], "nurl" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
"uri-id" => ["type" => "int unsigned", "foreign" => ["item-uri" => "id"], "comment" => "Id of the item-uri table entry that contains the contact url"],
"addr" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""], "addr" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
"alias" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""], "alias" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
"pubkey" => ["type" => "text", "comment" => "RSA public key 4096 bit"], "pubkey" => ["type" => "text", "comment" => "RSA public key 4096 bit"],
@ -260,7 +261,8 @@ return [
"uid_contact-type" => ["uid", "contact-type"], "uid_contact-type" => ["uid", "contact-type"],
"uid_self_contact-type" => ["uid", "self", "contact-type"], "uid_self_contact-type" => ["uid", "self", "contact-type"],
"self_network_uid" => ["self", "network", "uid"], "self_network_uid" => ["self", "network", "uid"],
"gsid" => ["gsid"] "gsid" => ["gsid"],
"uri-id" => ["uri-id"],
] ]
], ],
"item-uri" => [ "item-uri" => [