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\IBroadcaster; |
33
|
|
|
use OCA\Circles\Model\Member; |
34
|
|
|
use OCA\Circles\Model\Frame; |
35
|
|
|
|
36
|
|
|
|
37
|
|
|
class SharesService { |
38
|
|
|
|
39
|
|
|
/** @var string */ |
40
|
|
|
private $userId; |
41
|
|
|
|
42
|
|
|
/** @var CirclesRequest */ |
43
|
|
|
private $circlesRequest; |
44
|
|
|
|
45
|
|
|
/** @var FederatedService */ |
46
|
|
|
private $federatedService; |
47
|
|
|
/** @var MiscService */ |
48
|
|
|
private $miscService; |
49
|
|
|
|
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* SharesService constructor. |
53
|
|
|
* |
54
|
|
|
* @param string $userId |
55
|
|
|
* @param CirclesRequest $circlesRequest |
56
|
|
|
* @param FederatedService $federatedService |
57
|
|
|
* @param MiscService $miscService |
58
|
|
|
*/ |
59
|
|
|
public function __construct( |
60
|
|
|
string $userId, |
61
|
|
|
CirclesRequest $circlesRequest, |
62
|
|
|
FederatedService $federatedService, |
63
|
|
|
MiscService $miscService |
64
|
|
|
) { |
65
|
|
|
$this->userId = $userId; |
66
|
|
|
$this->circlesRequest = $circlesRequest; |
67
|
|
|
$this->federatedService = $federatedService; |
68
|
|
|
$this->miscService = $miscService; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* createFrame() |
74
|
|
|
* |
75
|
|
|
* Save the Frame containing the Payload. |
76
|
|
|
* The Payload will be shared locally, and spread it live if a Broadcaster is set. |
77
|
|
|
* Function will also initiate the federated broadcast to linked circles. |
78
|
|
|
* |
79
|
|
|
* @param Frame $frame |
80
|
|
|
* @param string|null $broadcast |
81
|
|
|
* |
82
|
|
|
* @return bool |
83
|
|
|
* @throws BroadcasterIsNotCompatible |
84
|
|
|
*/ |
85
|
|
|
public function createFrame(Frame $frame, string $broadcast = null) { |
86
|
|
|
|
87
|
|
|
$frame->setAuthor($this->userId); |
88
|
|
|
|
89
|
|
|
// TODO: VERIFIER QUE L'UTILISATEUR EST BIEN MEMBRE |
90
|
|
|
$circle = $this->circlesRequest->getDetails($frame->getCircleId(), $this->userId); |
91
|
|
|
$frame->setCircleName($circle->getName()); |
92
|
|
|
|
93
|
|
|
$this->circlesRequest->createShare($frame); |
94
|
|
|
$this->broadcastItem($broadcast, $frame); |
95
|
|
|
|
96
|
|
|
$this->federatedService->initiateRemoteShare($frame->getUniqueId()); |
97
|
|
|
|
98
|
|
|
return true; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* broadcast the Share item using a IBroadcaster, usually set by the app that created the Share |
104
|
|
|
* item. |
105
|
|
|
* |
106
|
|
|
* @param string $broadcast |
107
|
|
|
* @param Frame $frame |
108
|
|
|
* |
109
|
|
|
* @throws BroadcasterIsNotCompatible |
110
|
|
|
*/ |
111
|
|
|
private function broadcastItem(string $broadcast, Frame $frame) { |
112
|
|
|
|
113
|
|
|
if ($broadcast === null) { |
114
|
|
|
return; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
$broadcaster = \OC::$server->query($broadcast); |
118
|
|
|
if (!($broadcaster instanceof IBroadcaster)) { |
119
|
|
|
throw new BroadcasterIsNotCompatible(); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
$broadcaster->init(); |
123
|
|
|
$users = $this->circlesRequest->getMembers($frame->getCircleId(), Member::LEVEL_MEMBER); |
124
|
|
|
foreach ($users AS $user) { |
125
|
|
|
$broadcaster->broadcast($user->getUserId(), $frame); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
|
131
|
|
|
public function shareItemToFederatedLinks(Frame $share, string $broadcast = null) { |
|
|
|
|
132
|
|
|
|
133
|
|
|
//$circles = $this->circlesRequest->getFederatedLinks($share->getCircle()); |
134
|
|
|
// TODO, envoyer une requete http sur le broadcaster local en precisant qu'il a deja ete broadcaste en local |
|
|
|
|
135
|
|
|
//broadcastItem() |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
|
139
|
|
|
|
140
|
|
|
// public function reshare($circleId, $source, $type, $shareid) { |
|
|
|
|
141
|
|
|
// $this->miscService->log( |
142
|
|
|
// "__reshare" . $circleId . ' ' . $source . ' ' . $type . ' ' . json_encode($item) |
143
|
|
|
// ); |
144
|
|
|
// |
145
|
|
|
// $share = new Share($source, $type); |
146
|
|
|
// $share->setCircleId($circleId); |
147
|
|
|
// $share->setItem($item); |
148
|
|
|
// |
149
|
|
|
// $share->setAuthor($this->userId); |
150
|
|
|
// |
151
|
|
|
// $this->circlesRequest->createShare($share); |
152
|
|
|
// |
153
|
|
|
// return true; |
154
|
|
|
// } |
155
|
|
|
|
156
|
|
|
} |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.