Skip to content
Next
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Switch to GitLab Next
Sign in / Register
Toggle navigation
Minds Backend - Engine
Project
Project
Details
Activity
Releases
Cycle Analytics
Insights
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Locked Files
Issues
219
Issues
219
List
Boards
Labels
Service Desk
Milestones
Merge Requests
30
Merge Requests
30
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
List
Container Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Minds
Minds Backend - Engine
Commits
d73a5a51
Commit
d73a5a51
authored
13 minutes ago
by
Juan Manuel Solaro
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(feat) filter activities by time_created to get scheduled
parent
adc64ef1
epic/post-scheduler
1 merge request
!294
WIP: epic/post-scheduler
Pipeline
#77400177
passed with stages
in 9 minutes and 34 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
195 additions
and
13 deletions
+195
-13
scheduled.php
Controllers/api/v2/channel/scheduled.php
+183
-0
Repository.php
Core/Feeds/Top/Repository.php
+12
-13
No files found.
Controllers/api/v2/channel/scheduled.php
0 → 100644
View file @
d73a5a51
<?php
namespace
Minds\Controllers\api\v2\channel
;
use
Minds\Api\Exportable
;
use
Minds\Api\Factory
;
use
Minds\Core
;
use
Minds\Core\Di\Di
;
use
Minds\Entities\Factory
as
EntitiesFactory
;
use
Minds\Entities\User
;
use
Minds\Interfaces
;
class
scheduled
implements
Interfaces\Api
{
/**
* Equivalent to HTTP GET method
* @param array $pages
* @return mixed|null
* @throws \Exception
*/
public
function
get
(
$pages
)
{
/** @var User $currentUser */
$currentUser
=
Core\Session
::
getLoggedinUser
();
//
$container_guid
=
$pages
[
0
]
??
null
;
if
(
!
$container_guid
)
{
return
Factory
::
response
([
'status'
=>
'error'
,
'message'
=>
'Invalid container'
,
]);
}
$container
=
EntitiesFactory
::
build
(
$container_guid
);
if
(
!
$container
||
!
Core\Security\ACL
::
_
()
->
read
(
$container
,
$currentUser
))
{
return
Factory
::
response
([
'status'
=>
'error'
,
'message'
=>
'Forbidden'
,
]);
}
$type
=
''
;
switch
(
$pages
[
1
])
{
case
'activities'
:
$type
=
'activity'
;
break
;
case
'images'
:
$type
=
'object:image'
;
break
;
case
'videos'
:
$type
=
'object:video'
;
break
;
case
'blogs'
:
$type
=
'object:blog'
;
break
;
}
//
$hardLimit
=
5000
;
$offset
=
0
;
if
(
isset
(
$_GET
[
'offset'
]))
{
$offset
=
intval
(
$_GET
[
'offset'
]);
}
$limit
=
12
;
if
(
isset
(
$_GET
[
'limit'
]))
{
$limit
=
abs
(
intval
(
$_GET
[
'limit'
]));
}
if
((
$offset
+
$limit
)
>
$hardLimit
)
{
$limit
=
$hardLimit
-
$offset
;
}
if
(
$limit
<=
0
)
{
return
Factory
::
response
([
'status'
=>
'success'
,
'entities'
=>
[],
'load-next'
=>
$hardLimit
,
'overflow'
=>
true
,
]);
}
//
$sync
=
(
bool
)
(
$_GET
[
'sync'
]
??
false
);
$fromTimestamp
=
$_GET
[
'from_timestamp'
]
??
0
;
$asActivities
=
(
bool
)
(
$_GET
[
'as_activities'
]
??
true
);
$forcePublic
=
(
bool
)
(
$_GET
[
'force_public'
]
??
false
);
$query
=
null
;
if
(
isset
(
$_GET
[
'query'
]))
{
$query
=
$_GET
[
'query'
];
}
$custom_type
=
isset
(
$_GET
[
'custom_type'
])
&&
$_GET
[
'custom_type'
]
?
[
$_GET
[
'custom_type'
]]
:
null
;
/** @var Core\Feeds\Top\Manager $manager */
$manager
=
Di
::
_
()
->
get
(
'Feeds\Top\Manager'
);
/** @var Core\Feeds\Top\Entities $entities */
$entities
=
new
Core\Feeds\Top\Entities
();
$entities
->
setActor
(
$currentUser
);
$isOwner
=
false
;
if
(
$currentUser
)
{
$entities
->
setActor
(
$currentUser
);
$isOwner
=
$currentUser
->
guid
==
$container_guid
;
}
$opts
=
[
'cache_key'
=>
$currentUser
?
$currentUser
->
guid
:
null
,
'container_guid'
=>
$container_guid
,
'access_id'
=>
$isOwner
&&
!
$forcePublic
?
[
0
,
1
,
2
,
$container_guid
]
:
[
2
,
$container_guid
],
'custom_type'
=>
$custom_type
,
'limit'
=>
$limit
,
'type'
=>
$type
,
'algorithm'
=>
'latest'
,
'period'
=>
'1y'
,
'sync'
=>
$sync
,
'from_timestamp'
=>
$fromTimestamp
,
'query'
=>
$query
,
'single_owner_threshold'
=>
0
,
'pinned_guids'
=>
$type
===
'activity'
?
array_reverse
(
$container
->
getPinnedPosts
())
:
null
,
'time_created_upper'
=>
false
,
];
if
(
isset
(
$_GET
[
'nsfw'
]))
{
$nsfw
=
$_GET
[
'nsfw'
]
??
''
;
$opts
[
'nsfw'
]
=
explode
(
','
,
$nsfw
);
}
try
{
$result
=
$manager
->
getList
(
$opts
);
if
(
!
$sync
)
{
// Remove all unlisted content, if ES document is not in sync, it'll
// also remove pending activities
$result
=
$result
->
filter
([
$entities
,
'filter'
]);
if
(
$asActivities
)
{
// Cast to ephemeral Activity entities, if another type
$result
=
$result
->
map
([
$entities
,
'cast'
]);
}
}
return
Factory
::
response
([
'status'
=>
'success'
,
'entities'
=>
Exportable
::
_
(
$result
),
'load-next'
=>
$result
->
getPagingToken
(),
]);
}
catch
(
\Exception
$e
)
{
error_log
(
$e
);
return
Factory
::
response
([
'status'
=>
'error'
,
'message'
=>
$e
->
getMessage
()]);
}
}
public
function
post
(
$pages
)
{
return
Factory
::
response
([]);
}
public
function
put
(
$pages
)
{
return
Factory
::
response
([]);
}
public
function
delete
(
$pages
)
{
return
Factory
::
response
([]);
}
}
This diff is collapsed.
Click to expand it.
Core/Feeds/Top/Repository.php
View file @
d73a5a51
...
...
@@ -33,7 +33,7 @@ class Repository
* @return \Generator|ScoredGuid[]
* @throws \Exception
*/
public
function
getList
(
array
$opts
=
[]
,
bool
$filter_by_time_created
=
true
)
public
function
getList
(
array
$opts
=
[])
{
$opts
=
array_merge
([
'offset'
=>
0
,
...
...
@@ -54,7 +54,7 @@ class Repository
'exclude_moderated'
=>
false
,
'moderation_reservations'
=>
null
,
'pinned_guids'
=>
null
,
'time_created_upper'
=>
$filter_by_time_created
?
time
()
:
null
,
'time_created_upper'
=>
time
()
,
],
$opts
);
if
(
!
$opts
[
'type'
])
{
...
...
@@ -257,19 +257,18 @@ class Repository
}
// Filter by time created to cut out scheduled feeds
if
(
$opts
[
'time_created_upper'
])
{
if
(
!
isset
(
$body
[
'query'
][
'function_score'
][
'query'
][
'bool'
][
'must'
]))
{
$body
[
'query'
][
'function_score'
][
'query'
][
'bool'
][
'must'
]
=
[];
}
$time_created_upper
=
$opts
[
'time_created_upper'
]
?
'lte'
:
'gt'
;
if
(
!
isset
(
$body
[
'query'
][
'function_score'
][
'query'
][
'bool'
][
'must'
]))
{
$body
[
'query'
][
'function_score'
][
'query'
][
'bool'
][
'must'
]
=
[];
}
$body
[
'query'
][
'function_score'
][
'query'
][
'bool'
][
'must'
][]
=
[
'range'
=>
[
'time_created'
=>
[
'lte'
=>
(
int
)
$opts
[
'time_created_upper'
],
],
$body
[
'query'
][
'function_score'
][
'query'
][
'bool'
][
'must'
][]
=
[
'range'
=>
[
'time_created'
=>
[
$time_created_upper
=>
(
int
)
(
$opts
[
'time_created_upper'
]
?:
time
()),
],
]
;
}
]
,
];
//
if
(
$opts
[
'query'
])
{
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment