Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved handling of native quotes #12076

Merged
merged 6 commits into from Oct 30, 2022
Merged

Improved handling of native quotes #12076

merged 6 commits into from Oct 30, 2022

Conversation

annando
Copy link
Collaborator

@annando annando commented Oct 29, 2022

We are now only storing non native quotes in the body. All native quotes are done via the quote-uri-id field in the post. The whole code is cleaned up around this.

This PR has to be merged at the same time as the addon PR.

Comment on lines 751 to 752
$link = $post['plink'] ?: $post['uri'];
$body .= "\n♲ " . $link;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Energy is expensive, let's save the creation of an intermediary variable.

Suggested change
$link = $post['plink'] ?: $post['uri'];
$body .= "\n" . $link;
$body .= "\n" . ($post['plink'] ?: $post['uri']);

Comment on lines 3661 to 3699
if (!empty($shared['guid'])) {
$shared_item = Post::selectFirst(['uri-id'], ['guid' => $shared['guid'], 'uid' => [0, $uid]]);
if (!empty($shared_item['uri-id'])) {
Logger::debug('Found post by guid', ['guid' => $shared['guid'], 'uid' => $uid]);
}
}

if (empty($shared_item['uri-id']) && !empty($shared['message_id'])) {
$shared_item = Post::selectFirst(['uri-id'], ['uri' => $shared['message_id'], 'uid' => [0, $uid]]);
if (!empty($shared_item['uri-id'])) {
Logger::debug('Found post by message_id', ['message_id' => $shared['message_id'], 'uid' => $uid]);
}
}

if (empty($shared_item['uri-id']) && !empty($shared['link'])) {
$shared_item = Post::selectFirst(['uri-id'], ['plink' => $shared['link'], 'uid' => [0, $uid]]);
if (!empty($shared_item['uri-id'])) {
Logger::debug('Found post by link', ['link' => $shared['link'], 'uid' => $uid]);
}
}

if (empty($shared_item['uri-id'])) {
$url = $shared['message_id'] ?: $shared['link'];
$id = self::fetchByLink($url);
if (!$id) {
Logger::notice('Post could not be fetched.', ['url' => $url, 'uid' => $uid]);
return 0;
}

Logger::debug('Fetched shared post', ['id' => $id, 'url' => $url, 'uid' => $uid]);

$shared_item = Post::selectFirst(['uri-id'], ['id' => $id]);
if (!DBA::isResult($shared_item)) {
Logger::warning('Post does not exist.', ['id' => $id, 'url' => $url, 'uid' => $uid]);
return 0;
}
}

return $shared_item['uri-id'];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather we used early returns than the repetitive empty($shared_item['uri-id']) condition which means something different every time.

Suggested change
if (!empty($shared['guid'])) {
$shared_item = Post::selectFirst(['uri-id'], ['guid' => $shared['guid'], 'uid' => [0, $uid]]);
if (!empty($shared_item['uri-id'])) {
Logger::debug('Found post by guid', ['guid' => $shared['guid'], 'uid' => $uid]);
}
}
if (empty($shared_item['uri-id']) && !empty($shared['message_id'])) {
$shared_item = Post::selectFirst(['uri-id'], ['uri' => $shared['message_id'], 'uid' => [0, $uid]]);
if (!empty($shared_item['uri-id'])) {
Logger::debug('Found post by message_id', ['message_id' => $shared['message_id'], 'uid' => $uid]);
}
}
if (empty($shared_item['uri-id']) && !empty($shared['link'])) {
$shared_item = Post::selectFirst(['uri-id'], ['plink' => $shared['link'], 'uid' => [0, $uid]]);
if (!empty($shared_item['uri-id'])) {
Logger::debug('Found post by link', ['link' => $shared['link'], 'uid' => $uid]);
}
}
if (empty($shared_item['uri-id'])) {
$url = $shared['message_id'] ?: $shared['link'];
$id = self::fetchByLink($url);
if (!$id) {
Logger::notice('Post could not be fetched.', ['url' => $url, 'uid' => $uid]);
return 0;
}
Logger::debug('Fetched shared post', ['id' => $id, 'url' => $url, 'uid' => $uid]);
$shared_item = Post::selectFirst(['uri-id'], ['id' => $id]);
if (!DBA::isResult($shared_item)) {
Logger::warning('Post does not exist.', ['id' => $id, 'url' => $url, 'uid' => $uid]);
return 0;
}
}
return $shared_item['uri-id'];
if (!empty($shared['guid'])) {
$shared_item = Post::selectFirst(['uri-id'], ['guid' => $shared['guid'], 'uid' => [0, $uid]]);
if (!empty($shared_item['uri-id'])) {
Logger::debug('Found post by guid', ['guid' => $shared['guid'], 'uid' => $uid]);
return $shared_item['uri-id'];
}
}
if (!empty($shared['message_id'])) {
$shared_item = Post::selectFirst(['uri-id'], ['uri' => $shared['message_id'], 'uid' => [0, $uid]]);
if (!empty($shared_item['uri-id'])) {
Logger::debug('Found post by message_id', ['message_id' => $shared['message_id'], 'uid' => $uid]);
return $shared_item['uri-id'];
}
}
if (!empty($shared['link'])) {
$shared_item = Post::selectFirst(['uri-id'], ['plink' => $shared['link'], 'uid' => [0, $uid]]);
if (!empty($shared_item['uri-id'])) {
Logger::debug('Found post by link', ['link' => $shared['link'], 'uid' => $uid]);
return $shared_item['uri-id'];
}
}
$url = $shared['message_id'] ?: $shared['link'];
$id = self::fetchByLink($url);
if (!$id) {
Logger::notice('Post could not be fetched.', ['url' => $url, 'uid' => $uid]);
return 0;
}
Logger::debug('Fetched shared post', ['id' => $id, 'url' => $url, 'uid' => $uid]);
$shared_item = Post::selectFirst(['uri-id'], ['id' => $id]);
if (!DBA::isResult($shared_item)) {
Logger::warning('Post does not exist.', ['id' => $id, 'url' => $url, 'uid' => $uid]);
return 0;
}
return $shared_item['uri-id'];

@annando
Copy link
Collaborator Author

annando commented Oct 29, 2022

@MrPetovan changes are applied.

Comment on lines 3693 to 3700
if (!DBA::isResult($shared_item)) {
Logger::warning('Post does not exist.', ['id' => $id, 'url' => $url, 'uid' => $uid]);
return 0;
} else {
Logger::debug('Fetched shared post', ['id' => $id, 'url' => $url, 'uid' => $uid]);
}

return $shared_item['uri-id'];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Almost there, no need for an else statement here and we can avoid a negative condition.

Suggested change
if (!DBA::isResult($shared_item)) {
Logger::warning('Post does not exist.', ['id' => $id, 'url' => $url, 'uid' => $uid]);
return 0;
} else {
Logger::debug('Fetched shared post', ['id' => $id, 'url' => $url, 'uid' => $uid]);
}
return $shared_item['uri-id'];
if (DBA::isResult($shared_item)) {
Logger::debug('Fetched shared post', ['id' => $id, 'url' => $url, 'uid' => $uid]);
return $shared_item['uri-id'];
}
Logger::warning('Post does not exist.', ['id' => $id, 'url' => $url, 'uid' => $uid]);
return 0;

@MrPetovan
Copy link
Collaborator

Does this fix #12073 ?

@MrPetovan MrPetovan added this to the 2022.12 milestone Oct 29, 2022
@annando
Copy link
Collaborator Author

annando commented Oct 29, 2022

Yeah

@MrPetovan MrPetovan linked an issue Oct 30, 2022 that may be closed by this pull request
@MrPetovan
Copy link
Collaborator

Did you see my second Change Request?

@MrPetovan MrPetovan merged commit 6a205b2 into friendica:develop Oct 30, 2022
@annando annando deleted the quote branch October 30, 2022 14:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[twitter] Image attachments in shared tweets are shown twice
2 participants