This commit is contained in:
Mike Macgirvin 2022-09-22 15:27:30 +10:00
parent 346380267e
commit 9d0335614b
2 changed files with 46 additions and 61 deletions

View file

@ -13,7 +13,7 @@ class OAuth2Storage extends Pdo
* @param string $password
* @return bool
*/
public function checkUserCredentials($username, $password)
public function checkUserCredentials($username, $password): bool
{
$user = $this->getUser($username);
if ($user) {
@ -27,7 +27,7 @@ class OAuth2Storage extends Pdo
* @param string $username
* @return array|bool
*/
public function getUserDetails($username)
public function getUserDetails($username): array|bool
{
return $this->getUser($username);
}
@ -39,7 +39,7 @@ class OAuth2Storage extends Pdo
* @param string $password
* @return bool
*/
protected function checkPassword($user, $password)
protected function checkPassword($user, $password): bool
{
$x = account_verify_password($user, $password);
@ -50,7 +50,7 @@ class OAuth2Storage extends Pdo
* @param string $username
* @return array|bool
*/
public function getUser($username)
public function getUser($username): bool|array
{
$x = Channel::from_id($username);
@ -78,7 +78,7 @@ class OAuth2Storage extends Pdo
] );
}
public function scopeExists($scope)
public function scopeExists($scope): bool
{
// Report that the scope is valid even if it's not.
// We will only return a very small subset no matter what.
@ -97,7 +97,7 @@ class OAuth2Storage extends Pdo
return null;
}
public function getUserClaims($user_id, $claims)
public function getUserClaims($user_id, $claims): array
{
// Populate the CLAIMS requested (if any).
// @TODO: create a more reasonable/comprehensive list.
@ -138,12 +138,12 @@ class OAuth2Storage extends Pdo
* @param string $lastName
* @return bool
*/
public function setUser($username, $password, $firstName = null, $lastName = null)
public function setUser($username, $password, $firstName = null, $lastName = null): bool
{
return true;
}
public function setClientDetails($client_id, $client_secret = null, $redirect_uri = null, $grant_types = null, $scope = null, $user_id = null, $client_name = null)
public function setClientDetails($client_id, $client_secret = null, $redirect_uri = null, $grant_types = null, $scope = null, $user_id = null, $client_name = null): bool
{
// if it exists, update it.
if ($this->getClientDetails($client_id)) {
@ -155,10 +155,7 @@ class OAuth2Storage extends Pdo
return $stmt->execute(compact('client_id', 'client_secret', 'redirect_uri', 'grant_types', 'scope', 'user_id', 'client_name'));
}
public function checkRestrictedGrantType($client_id, $grant_type)
public function checkRestrictedGrantType($client_id, $grant_type): bool
{
$details = $this->getClientDetails($client_id);
if ($details['grant_types']) {

View file

@ -4,7 +4,6 @@
* @brief Items related functions.
*/
use Code\Lib as Zlib;
use Code\Lib\Libzot;
use Code\Lib\Libsync;
use Code\Lib\AccessList;
@ -2308,30 +2307,27 @@ function item_update_parent_commented($item) {
function send_status_notifications($item)
{
// only send notifications for comments
// logger('notifications: ' . print_r($item, true));
if ($item['mid'] == $item['parent_mid'] && intval($item['item_blocked']) !== ITEM_MODERATED) {
return;
}
$original_author = false;
if ($item['mid'] == $item['parent_mid']) {
// This is a moderated top-level post. Find the original author.
if (str_contains($item['body'],'[/share]')) {
preg_match("/portable_id='(.*?)'/ism", $item['body'], $matches);
logger('matches: ' . print_r($matches, true));
if ($matches) {
$s = q("select * from xchan where xchan_hash = '%s'",
dbesc(urldecode($matches[1]))
);
if ($s) {
$original_author = array_shift($s);
if ($item['mid'] === $item['parent_mid']) {
if (intval($item['item_blocked']) === ITEM_MODERATED) {
if (str_contains($item['body'],'[/share]')) {
preg_match("/portable_id='(.*?)'/ism", $item['body'], $matches);
logger('matches: ' . print_r($matches, true));
if ($matches) {
$s = q("select * from xchan where xchan_hash = '%s'",
dbesc(urldecode($matches[1]))
);
if ($s) {
$original_author = array_shift($s);
}
}
}
}
else {
return;
}
}
$notify = false;
@ -2350,21 +2346,21 @@ function send_status_notifications($item)
$thr_parent_id = $r[0]['id'];
}
$r = q("select channel_hash from channel where channel_id = %d limit 1",
intval($item['uid'])
);
if (!$r)
$r = Channel::from_id($item['uid']);
if (!$r) {
return;
}
// my own post - no notification needed
if ($item['author_xchan'] === $r[0]['channel_hash'] && intval($item['item_blocked']) !== ITEM_MODERATED) {
if ($item['author_xchan'] === $r['channel_hash'] && intval($item['item_blocked']) !== ITEM_MODERATED) {
return;
}
// I'm the owner - notify me
if($item['owner_xchan'] === $r[0]['channel_hash'])
if ($item['owner_xchan'] === $r['channel_hash']) {
$notify = true;
}
// Was I involved in this conversation?
@ -2372,28 +2368,29 @@ function send_status_notifications($item)
dbesc($item['parent_mid']),
intval($item['uid'])
);
if($x) {
foreach($x as $xx) {
if($xx['author_xchan'] === $r[0]['channel_hash']) {
if ($x) {
foreach ($x as $xx) {
if ($xx['author_xchan'] === $r[0]['channel_hash']) {
$notify = true;
// check for an unfollow thread activity - we should probably decode the obj and check the id
// but it will be extremely rare for this to be wrong.
if(($xx['verb'] === ACTIVITY_IGNORE)
&& ($xx['obj_type'] === ACTIVITY_OBJ_NOTE || $xx['obj_type'] === ACTIVITY_OBJ_PHOTO)
&& ($xx['parent'] != $xx['id']))
if (($xx['verb'] === ACTIVITY_IGNORE)
&& ($xx['obj_type'] === ACTIVITY_OBJ_NOTE || $xx['obj_type'] === ACTIVITY_OBJ_PHOTO)
&& ($xx['parent'] != $xx['id'])) {
$unfollowed = true;
}
}
if($xx['id'] == $xx['parent']) {
if ($xx['id'] == $xx['parent']) {
$parent = $xx['parent'];
}
}
}
if($unfollowed)
if ($unfollowed) {
return;
}
if (intval($item['item_private']) === 2) {
$notify_type = NOTIFY_MAIL;
@ -2407,7 +2404,8 @@ function send_status_notifications($item)
else {
$notify_type = NOTIFY_COMMENT;
}
$link = z_root() . (($notify_type === NOTIFY_MODERATE) ? '/moderate' : '/display' ). '/?mid=' . gen_link_id($item['mid']);
$link = z_root() . (($notify_type === NOTIFY_MODERATE) ? '/moderate' : '/display' )
. '/?mid=' . gen_link_id($item['mid']);
$y = q("select id from notify where link = '%s' and uid = %d limit 1",
dbesc($link),
intval($item['uid'])
@ -2423,7 +2421,7 @@ function send_status_notifications($item)
Enotify::submit([
'type' => $notify_type,
'from_xchan' => $original_author ? $original_author['xchan_hash'] : $item['author_xchan'],
'to_xchan' => $r[0]['channel_hash'],
'to_xchan' => $r['channel_hash'],
'item' => $item,
'link' => $link,
'verb' => $item['verb'],
@ -3146,7 +3144,7 @@ function start_delivery_chain($channel, $item, $item_id, bool|array $parent, $gr
}
// Send Announce activities for group comments so they will show up in microblog streams
// Send Announce activities for group comments, so they will show up in microblog streams
if ($group && $parent) {
logger('comment arrived in group', LOGGER_DEBUG);
@ -3168,7 +3166,7 @@ function start_delivery_chain($channel, $item, $item_id, bool|array $parent, $gr
if ($edit) {
if (intval($item['item_deleted'])) {
drop_item($item['id'],DROPITEM_PHASE1);
Run::Summon([ 'Notifier','drop',$item['id'] ]);
Run::Summon(['Notifier', 'drop', $item['id'] ]);
return;
}
return;
@ -3202,24 +3200,17 @@ function start_delivery_chain($channel, $item, $item_id, bool|array $parent, $gr
}
$arr['author_xchan'] = $channel['channel_hash'];
$arr['item_wall'] = 1;
$arr['item_private'] = (($channel['channel_allow_cid'] || $channel['channel_allow_gid'] || $channel['channel_deny_cid'] || $channel['channel_deny_gid']) ? 1 : 0);
$arr['item_origin'] = 1;
$arr['item_thread_top'] = 0;
$arr['allow_cid'] = $channel['channel_allow_cid'];
$arr['allow_gid'] = $channel['channel_allow_gid'];
$arr['deny_cid'] = $channel['channel_deny_cid'];
$arr['deny_gid'] = $channel['channel_deny_gid'];
$arr['comment_policy'] = map_scope(PermissionLimits::Get($channel['channel_id'],'post_comments'));
$arr['replyto'] = z_root() . '/channel/' . $channel['channel_address'];
$post = item_store($arr);
$post_id = $post['item_id'];
@ -3235,13 +3226,10 @@ function start_delivery_chain($channel, $item, $item_id, bool|array $parent, $gr
return;
}
// Change this copy of the post to a forum head message and deliver to all the tgroup members
// also reset all the privacy bits to the forum default permissions
$private = (($channel['channel_allow_cid'] || $channel['channel_allow_gid'] || $channel['channel_deny_cid'] || $channel['channel_deny_gid']) ? 1 : 0);
$item_origin = ($item['item_deleted']) ? 0 : 1;
$item_wall = 1;
$item_uplink = 0;
@ -3260,7 +3248,7 @@ function start_delivery_chain($channel, $item, $item_id, bool|array $parent, $gr
else {
$item_uplink = 1;
if (! $edit) {
$r = q("update item set source_xchan = owner_xchan where id = %d",
q("update item set source_xchan = owner_xchan where id = %d",
intval($item_id)
);
}