|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Circles - Bring cloud-users closer together. |
|
4
|
|
|
* |
|
5
|
|
|
* This file is licensed under the Affero General Public License version 3 or |
|
6
|
|
|
* later. See the COPYING file. |
|
7
|
|
|
* |
|
8
|
|
|
* @author Maxence Lange <[email protected]> |
|
9
|
|
|
* @copyright 2017 |
|
10
|
|
|
* @license GNU AGPL version 3 or any later version |
|
11
|
|
|
* |
|
12
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
13
|
|
|
* it under the terms of the GNU Affero General Public License as |
|
14
|
|
|
* published by the Free Software Foundation, either version 3 of the |
|
15
|
|
|
* License, or (at your option) any later version. |
|
16
|
|
|
* |
|
17
|
|
|
* This program is distributed in the hope that it will be useful, |
|
18
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
19
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
20
|
|
|
* GNU Affero General Public License for more details. |
|
21
|
|
|
* |
|
22
|
|
|
* You should have received a copy of the GNU Affero General Public License |
|
23
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
24
|
|
|
* |
|
25
|
|
|
*/ |
|
26
|
|
|
|
|
27
|
|
|
namespace OCA\Circles\Service; |
|
28
|
|
|
|
|
29
|
|
|
|
|
30
|
|
|
use OCA\Circles\Db\CirclesRequest; |
|
31
|
|
|
use OCA\Circles\Exceptions\BroadcasterIsNotCompatible; |
|
32
|
|
|
use OCA\Circles\Exceptions\MemberDoesNotExistException; |
|
33
|
|
|
use OCA\Circles\IBroadcaster; |
|
34
|
|
|
use OCA\Circles\Model\Member; |
|
35
|
|
|
use OCA\Circles\Model\SharingFrame; |
|
36
|
|
|
|
|
37
|
|
|
|
|
38
|
|
|
class SharesService { |
|
39
|
|
|
|
|
40
|
|
|
/** @var string */ |
|
41
|
|
|
private $userId; |
|
42
|
|
|
|
|
43
|
|
|
/** @var ConfigService */ |
|
44
|
|
|
private $configService; |
|
45
|
|
|
|
|
46
|
|
|
/** @var CirclesRequest */ |
|
47
|
|
|
private $circlesRequest; |
|
48
|
|
|
|
|
49
|
|
|
/** @var BroadcastService */ |
|
50
|
|
|
private $broadcastService; |
|
51
|
|
|
|
|
52
|
|
|
/** @var FederatedService */ |
|
53
|
|
|
private $federatedService; |
|
54
|
|
|
|
|
55
|
|
|
/** @var MiscService */ |
|
56
|
|
|
private $miscService; |
|
57
|
|
|
|
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* SharesService constructor. |
|
61
|
|
|
* |
|
62
|
|
|
* @param string $userId |
|
63
|
|
|
* @param ConfigService $configService |
|
64
|
|
|
* @param CirclesRequest $circlesRequest |
|
65
|
|
|
* @param BroadcastService $broadcastService |
|
66
|
|
|
* @param FederatedService $federatedService |
|
67
|
|
|
* @param MiscService $miscService |
|
68
|
|
|
*/ |
|
69
|
|
|
public function __construct( |
|
70
|
|
|
string $userId, |
|
71
|
|
|
ConfigService $configService, |
|
72
|
|
|
CirclesRequest $circlesRequest, |
|
73
|
|
|
BroadcastService $broadcastService, |
|
74
|
|
|
FederatedService $federatedService, |
|
75
|
|
|
MiscService $miscService |
|
76
|
|
|
) { |
|
77
|
|
|
$this->userId = $userId; |
|
78
|
|
|
$this->configService = $configService; |
|
79
|
|
|
$this->circlesRequest = $circlesRequest; |
|
80
|
|
|
$this->broadcastService = $broadcastService; |
|
81
|
|
|
$this->federatedService = $federatedService; |
|
82
|
|
|
$this->miscService = $miscService; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* createFrame() |
|
88
|
|
|
* |
|
89
|
|
|
* Save the Frame containing the Payload. |
|
90
|
|
|
* The Payload will be shared locally, and spread it live if a Broadcaster is set. |
|
91
|
|
|
* Function will also initiate the federated broadcast to linked circles. |
|
92
|
|
|
* |
|
93
|
|
|
* @param SharingFrame $frame |
|
94
|
|
|
* @param string|null $broadcast |
|
95
|
|
|
* |
|
96
|
|
|
* @throws MemberDoesNotExistException |
|
97
|
|
|
*/ |
|
98
|
|
|
public function createFrame(SharingFrame $frame, string $broadcast = null) { |
|
99
|
|
|
|
|
100
|
|
|
$circle = $this->circlesRequest->getDetails($frame->getCircleId(), $this->userId); |
|
101
|
|
|
if ($circle->getUser() |
|
102
|
|
|
->getLevel() < Member::LEVEL_MEMBER |
|
103
|
|
|
) { |
|
104
|
|
|
throw new MemberDoesNotExistException(); |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
$frame->setAuthor($this->userId); |
|
108
|
|
|
$frame->setHeader('author', $this->userId); |
|
109
|
|
|
$frame->setHeader('circleName', $circle->getName()); |
|
110
|
|
|
$frame->setHeader('broadcast', $broadcast); |
|
111
|
|
|
$frame->generateUniqueId(); |
|
112
|
|
|
$frame->setCircleName($circle->getName()); |
|
113
|
|
|
|
|
114
|
|
|
$this->circlesRequest->saveFrame($frame); |
|
115
|
|
|
|
|
116
|
|
|
$this->broadcastService->broadcastFrame($frame->getHeader('broadcast'), $frame); |
|
117
|
|
|
|
|
118
|
|
|
if ($this->configService->isFederatedAllowed()) { |
|
119
|
|
|
$this->federatedService->initiateRemoteShare($circle->getId(), $frame->getUniqueId()); |
|
120
|
|
|
} |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
|
|
124
|
|
|
/** |
|
125
|
|
|
* @param int $circleId |
|
126
|
|
|
* @param $uniqueId |
|
127
|
|
|
* |
|
128
|
|
|
* @return null|SharingFrame |
|
129
|
|
|
*/ |
|
130
|
|
|
public function getFrameFromUniqueId(int $circleId, $uniqueId) { |
|
131
|
|
|
if ($uniqueId === null || $uniqueId === '') { |
|
132
|
|
|
return null; |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
return $this->circlesRequest->getFrame($circleId, $uniqueId); |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
|
|
139
|
|
|
} |