Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
What's new
4
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Switch to GitLab Next
Sign in / Register
Toggle navigation
Menu
Open sidebar
Minds
Minds Backend - Engine
Commits
94b95611
Commit
94b95611
authored
Sep 17, 2019
by
Mark Harding
Browse files
(feat): various changes to support with frontend work
parent
691dc667
Pipeline
#82710072
failed with stages
in 7 minutes and 27 seconds
Changes
10
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Controllers/api/v2/subscriptions/incoming.php
View file @
94b95611
...
...
@@ -51,7 +51,7 @@ class incoming implements Interfaces\Api
$urn
=
"urn:subscription-request:"
.
implode
(
'-'
,
[
Session
::
getLoggedInUserGuid
(),
$subscriberGuid
]);
$request
=
$manager
->
get
(
$urn
);
if
(
!
$request
||
$request
->
getPublisherGuid
()
!=
Session
::
getLoggedInUserGuid
())
{
return
Factory
::
response
([
'status'
=>
'error'
,
...
...
Controllers/api/v2/subscriptions/incoming/all.php
View file @
94b95611
...
...
@@ -17,7 +17,7 @@ class all implements Interfaces\Api
// Return a list of subscription requests
$manager
=
Di
::
_
()
->
get
(
'Subscriptions\Requests\Manager'
);
$requests
=
$manager
->
getIncoming
Reque
st
s
(
Session
::
getLoggedInUserGuid
(),
[]);
$requests
=
$manager
->
getIncoming
Li
st
(
Session
::
getLoggedInUserGuid
(),
[]);
return
Factory
::
response
([
'requests'
=>
Factory
::
exportable
(
$requests
),
...
...
Controllers/api/v2/subscriptions/outgoing.php
View file @
94b95611
...
...
@@ -5,6 +5,7 @@ namespace Minds\Controllers\api\v2\subscriptions;
use
Minds\Api\Factory
;
use
Minds\Core\Di\Di
;
use
Minds\Core\Session
;
use
Minds\Core\Subscriptions\Requests\SubscriptionRequest
;
use
Minds\Entities\Factory
as
EntitiesFactory
;
use
Minds\Interfaces
;
...
...
@@ -49,7 +50,7 @@ class outgoing implements Interfaces\Api
$request
=
new
SubscriptionRequest
();
$request
->
setPublisherGuid
(
$pages
[
0
])
->
setSubscriberGuid
(
Session
::
getLoggedInGuid
());
->
setSubscriberGuid
(
Session
::
getLoggedIn
User
Guid
());
try
{
$manager
->
add
(
$request
);
...
...
Core/Provisioner/Provisioners/cassandra-provision.cql
View file @
94b95611
...
...
@@ -1452,6 +1452,6 @@ CREATE TABLE minds.subscription_requests (
publisher_guid bigint,
subscriber_guid bigint,
timestamp timestamp,
accept
ed boolean,
declin
ed boolean,
PRIMARY KEY (publisher_guid, subscriber_guid)
);
\ No newline at end of file
);
Core/Subscriptions/Manager.php
View file @
94b95611
...
...
@@ -94,14 +94,19 @@ class Manager
/**
* Subscribe to a publisher
* @param User $publisher
* @param bool $force
* @return Subscription
*/
public
function
subscribe
(
$publisher
)
public
function
subscribe
(
$publisher
,
$force
=
false
)
{
$subscription
=
new
Subscription
();
$subscription
->
setSubscriberGuid
(
$this
->
subscriber
->
getGuid
())
->
setPublisherGuid
(
$publisher
->
getGuid
());
if
(
$publisher
->
getMode
()
===
2
&&
!
$force
)
{
throw
new
\
Exception
(
"Can not subscribe to closed channel, send a request instead"
);
}
if
(
$this
->
getSubscriptionsCount
()
>=
static
::
MAX_SUBSCRIPTIONS
)
{
$this
->
sendNotificationDelegate
->
onMaxSubscriptions
(
$subscription
);
throw
new
TooManySubscriptionsException
();
...
...
Core/Subscriptions/Requests/Delegates/SubscriptionsDelegate.php
View file @
94b95611
<?php
namespace
Minds\Core\Subscriptions\Requests\Delegates
;
use
Minds\Core\Di\Di
;
use
Minds\Core\EntitiesBuilder
;
use
Minds\Core\Subscriptions\Manager
as
SubscriptionsManager
;
use
Minds\Core\Subscriptions\Requests\SubscriptionRequest
;
class
SubscriptionsDelegate
{
/** @var SubscriptionsManager */
private
$subscriptionsManager
;
/** @var EntitiesBuilder */
private
$entitiesBuilder
;
public
function
__construct
(
$subscriptionsManager
=
null
,
$entitiesBuilder
=
null
)
{
$this
->
subscriptionsManager
=
$subscriptionsManager
??
Di
::
_
()
->
get
(
'Subscriptions\Manager'
);
$this
->
entitiesBuilder
=
$entitiesBuilder
??
Di
::
_
()
->
get
(
'EntitiesBuilder'
);
}
/**
* Called when subscription request is accepted
* @param SubscriptionRequest $subscriptionRequest
...
...
@@ -12,6 +27,10 @@ class SubscriptionsDelegate
*/
public
function
onAccept
(
SubscriptionRequest
$subscriptionRequest
):
void
{
// TODO
$subscriber
=
$this
->
entitiesBuilder
->
single
(
$subscriptionRequest
->
getSubscriberGuid
());
$publisher
=
$this
->
entitiesBuilder
->
single
(
$subscriptionRequest
->
getPublisherGuid
());
$this
->
subscriptionsManager
->
setSubscriber
(
$subscriber
);
$this
->
subscriptionsManager
->
subscribe
(
$publisher
,
true
);
}
}
Core/Subscriptions/Requests/Manager.php
View file @
94b95611
...
...
@@ -40,8 +40,19 @@ class Manager
*/
public
function
getIncomingList
(
$user_guid
,
array
$opts
=
[])
{
$opts
=
array_merge
([
'hydrate'
=>
true
,
],
$opts
);
$opts
[
'publisher_guid'
]
=
$user_guid
;
$response
=
$this
->
repository
->
getList
(
$opts
);
if
(
$opts
[
'hydrate'
])
{
foreach
(
$response
as
$i
=>
$request
)
{
$request
->
setSubscriber
(
$this
->
entitiesBuilder
->
single
(
$request
->
getSubscriberGuid
()));
}
}
return
$response
;
}
...
...
@@ -98,8 +109,7 @@ class Manager
throw
new
SubscriptionRequestAlreadyCompletedException
();
}
$subscriptionRequest
->
setAccepted
(
true
);
$this
->
repository
->
update
(
$subscriptionRequest
);
$this
->
repository
->
delete
(
$subscriptionRequest
);
$this
->
notificationsDelegate
->
onAccept
(
$subscriptionRequest
);
$this
->
subscriptionsDelegate
->
onAccept
(
$subscriptionRequest
);
...
...
@@ -124,7 +134,7 @@ class Manager
throw
new
SubscriptionRequestAlreadyCompletedException
();
}
$subscriptionRequest
->
set
Accepted
(
fals
e
);
$subscriptionRequest
->
set
Declined
(
tru
e
);
$this
->
repository
->
update
(
$subscriptionRequest
);
$this
->
notificationsDelegate
->
onDecline
(
$subscriptionRequest
);
...
...
Core/Subscriptions/Requests/Repository.php
View file @
94b95611
...
...
@@ -11,7 +11,6 @@ use Minds\Common\Repository\Response;
use
Minds\Common\Urn
;
use
Cassandra\Timestamp
;
use
Cassandra\Bigint
;
use
Cassandra\Boolean
;
class
Repository
{
...
...
@@ -32,6 +31,7 @@ class Repository
{
$opts
=
array_merge
([
'publisher_guid'
=>
null
,
'show_declined'
=>
false
,
'limit'
=>
5000
,
'token'
=>
''
,
],
$opts
);
...
...
@@ -45,7 +45,7 @@ class Repository
"SELECT * FROM subscription_requests
WHERE publisher_guid = ?"
,
[
$opts
[
'publisher_guid'
],
new
Bigint
(
$opts
[
'publisher_guid'
]
)
,
]
);
$result
=
$this
->
db
->
request
(
$prepared
);
...
...
@@ -56,10 +56,11 @@ class Repository
$subscriptionRequest
->
setPublisherGuid
((
string
)
$row
[
'publisher_guid'
])
->
setSubscriberGuid
((
string
)
$row
[
'subscriber_guid'
])
->
setTimestampMs
((
int
)
$row
[
'timestamp'
]
->
time
());
->
setTimestampMs
((
int
)
$row
[
'timestamp'
]
->
time
())
->
setDeclined
((
bool
)
$row
[
'declined'
]);
if
(
$
row
[
'accept
ed'
])
{
$subscriptionRequest
->
setAccepted
((
bool
)
$row
[
'accepted'
])
;
if
(
$
subscriptionRequest
->
isDeclined
()
&&
!
$opts
[
'show_declin
ed'
])
{
continue
;
}
$response
[]
=
$subscriptionRequest
;
...
...
@@ -84,8 +85,8 @@ class Repository
WHERE publisher_guid = ?
AND subscriber_guid = ?"
,
[
$publisherGuid
,
$subscriberGuid
,
new
Bigint
(
$publisherGuid
)
,
new
Bigint
(
$subscriberGuid
)
,
]
);
$result
=
$this
->
db
->
request
(
$prepared
);
...
...
@@ -96,15 +97,16 @@ class Repository
$row
=
$result
[
0
];
if
(
!
$row
)
{
return
null
;
}
$subscriptionRequest
=
new
SubscriptionRequest
();
$subscriptionRequest
->
setPublisherGuid
((
string
)
$row
[
'publisher_guid'
])
->
setSubscriberGuid
((
string
)
$row
[
'subscriber_guid'
])
->
setTimestampMs
((
int
)
$row
[
'timestamp'
]
->
time
());
if
(
$row
[
'accepted'
])
{
$subscriptionRequest
->
setAccepted
((
bool
)
$row
[
'accepted'
]);
}
->
setTimestampMs
((
int
)
$row
[
'timestamp'
]
->
time
())
->
setDeclined
((
bool
)
$row
[
'declined'
]);
return
$subscriptionRequest
;
}
...
...
@@ -142,11 +144,11 @@ class Repository
public
function
update
(
SubscriptionRequest
$subscriptionRequest
,
array
$field
=
[]):
bool
{
$statement
=
"UPDATE subscription_requests
SET
accept
ed = ?
SET
declin
ed = ?
WHERE publisher_guid = ?
AND subscriber_guid = ?"
;
$values
=
[
new
Boolean
(
$subscriptionRequest
->
getAccept
ed
()
)
,
$subscriptionRequest
->
isDeclin
ed
(),
new
Bigint
(
$subscriptionRequest
->
getPublisherGuid
()),
new
Bigint
(
$subscriptionRequest
->
getSubscriberGuid
()),
];
...
...
Core/Subscriptions/Requests/SubscriptionRequest.php
View file @
94b95611
...
...
@@ -4,15 +4,20 @@
*/
namespace
Minds\Core\Subscriptions\Requests
;
use
Minds\Entities\User
;
use
Minds\Traits\MagicAttributes
;
/**
* @method SubscriptionRequest setPublisherGuid(string $publisherGuid)
* @method string getPublisherGuid()
* @method SubscriptionRequest setPublisher(User $user)
* @method User getPublisher()
* @method SubscriptionRequest setSubscriberGuid(string $subscriberGuid)
* @method string getSubscriberGuid()
* @method SubscriptionRequest setAccepted(bool $accepted)
* @method string getAccepted()
* @method SubscriptionRequest setSubscriber(User $subscriber)
* @method User getSubscriber()
* @method SubscriptionRequest setDeclined(bool $declined)
* @method bool getDeclined()
* @method SubscriptionRequest setTimestampMs(int $timestampMs)
* @method int getTimestampMs()
*/
...
...
@@ -23,11 +28,17 @@ class SubscriptionRequest
/** @var string */
private
$publisherGuid
;
/** @var User */
private
$publisher
;
/** @var string */
private
$subscriberGuid
;
/** @var User */
private
$subscriber
;
/** @var bool */
private
$
accepted
;
private
$
declined
=
false
;
/** @var int */
private
$timestampMs
;
...
...
@@ -48,8 +59,10 @@ class SubscriptionRequest
{
return
[
'publisher_guid'
=>
(
string
)
$this
->
publisherGuid
,
'publisher'
=>
$this
->
publisher
?
$this
->
publisher
->
export
()
:
null
,
'subscriber_guid'
=>
(
string
)
$this
->
subscriberGuid
,
'accepted'
=>
(
bool
)
$this
->
accepted
,
'subscriber'
=>
$this
->
subscriber
?
$this
->
subscriber
->
export
()
:
null
,
'declined'
=>
(
bool
)
$this
->
declined
,
'timestamp_ms'
=>
$this
->
timestampMs
,
'timestamp_sec'
=>
round
(
$this
->
timestampMs
/
1000
),
];
...
...
Spec/Core/Subscriptions/Requests/RepositorySpec.php
View file @
94b95611
...
...
@@ -39,7 +39,7 @@ class RepositorySpec extends ObjectBehavior
'publisher_guid'
=>
'123'
,
'subscriber_guid'
=>
'456'
,
'timestamp'
=>
new
Timestamp
(
time
()),
'
accept
ed'
=>
null
,
'
declin
ed'
=>
null
,
]
],
'next-page-token'
));
...
...
@@ -61,18 +61,19 @@ class RepositorySpec extends ObjectBehavior
'publisher_guid'
=>
new
Bigint
(
123
),
'subscriber_guid'
=>
new
Bigint
(
456
),
'timestamp'
=>
new
Timestamp
(
time
()),
'
accept
ed'
=>
null
,
'
declin
ed'
=>
null
,
],
[
'publisher_guid'
=>
new
Bigint
(
'1789'
),
'subscriber_guid'
=>
new
Bigint
(
'1123'
),
'timestamp'
=>
new
Timestamp
(
time
()),
'
accept
ed'
=>
new
Boolean
(
true
)
,
'
declin
ed'
=>
true
,
]
],
'next-page-token'
));
$response
=
$this
->
getList
([
'publisher_guid'
=>
'123'
,
'show_declined'
=>
true
,
]);
$response
[
0
]
->
getPublisherGuid
()
->
shouldBe
(
'123'
);
...
...
@@ -82,7 +83,7 @@ class RepositorySpec extends ObjectBehavior
->
shouldBe
(
'1789'
);
$response
[
1
]
->
getSubscriberGuid
()
->
shouldBe
(
'1123'
);
$response
[
1
]
->
is
Accept
ed
()
$response
[
1
]
->
is
Declin
ed
()
->
shouldBe
(
true
);
}
...
...
@@ -110,7 +111,7 @@ class RepositorySpec extends ObjectBehavior
$subscriptionRequest
=
new
SubscriptionRequest
();
$subscriptionRequest
->
setPublisherGuid
(
'123'
)
->
setSubscriberGuid
(
'456'
)
->
set
Accept
ed
(
true
);
->
set
Declin
ed
(
true
);
$this
->
db
->
request
(
Argument
::
that
(
function
(
$prepared
)
{
$values
=
$prepared
->
build
()[
'values'
];
...
...
Write
Preview
Supports
Markdown
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