|
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\Share; |
|
34
|
|
|
|
|
35
|
|
|
|
|
36
|
|
|
class SharesService { |
|
37
|
|
|
|
|
38
|
|
|
/** @var string */ |
|
39
|
|
|
private $userId; |
|
40
|
|
|
|
|
41
|
|
|
/** @var CirclesRequest */ |
|
42
|
|
|
private $circlesRequest; |
|
43
|
|
|
|
|
44
|
|
|
/** @var FederatedService */ |
|
45
|
|
|
private $federatedService; |
|
46
|
|
|
/** @var MiscService */ |
|
47
|
|
|
private $miscService; |
|
48
|
|
|
|
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* SharesService constructor. |
|
52
|
|
|
* |
|
53
|
|
|
* @param string $userId |
|
54
|
|
|
* @param CirclesRequest $circlesRequest |
|
55
|
|
|
* @param FederatedService $federatedService |
|
56
|
|
|
* @param MiscService $miscService |
|
57
|
|
|
*/ |
|
58
|
|
|
public function __construct( |
|
59
|
|
|
string $userId, |
|
60
|
|
|
CirclesRequest $circlesRequest, |
|
61
|
|
|
FederatedService $federatedService, |
|
62
|
|
|
MiscService $miscService |
|
63
|
|
|
) { |
|
64
|
|
|
$this->userId = $userId; |
|
65
|
|
|
$this->circlesRequest = $circlesRequest; |
|
66
|
|
|
$this->federatedService = $federatedService; |
|
67
|
|
|
$this->miscService = $miscService; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* shareItem() |
|
73
|
|
|
* |
|
74
|
|
|
* Share a Share item locally, and spread it live if a broadcaster is set. |
|
75
|
|
|
* Function will also initiate the federated broadcast to linked circles. |
|
76
|
|
|
* |
|
77
|
|
|
* @param Share $share |
|
78
|
|
|
* @param string|null $broadcast |
|
79
|
|
|
* |
|
80
|
|
|
* @return bool |
|
81
|
|
|
* @throws BroadcasterIsNotCompatible |
|
82
|
|
|
*/ |
|
83
|
|
|
public function shareItem(Share $share, string $broadcast = null) { |
|
84
|
|
|
|
|
85
|
|
|
$share->setAuthor($this->userId); |
|
86
|
|
|
// TODO: VERIFIER QUE L'UTILISATEUR EST BIEN MEMBRE |
|
87
|
|
|
// creer l'item localement, tenter de broadcaster is possible. |
|
88
|
|
|
// et lancer une requete en local pour initialiser un partage federated en async |
|
89
|
|
|
// en precisant qu'il a deja ete broadcaste en local |
|
90
|
|
|
// federatedController->shareFederatedItem() |
|
91
|
|
|
// $circle = $this-> |
|
|
|
|
|
|
92
|
|
|
// $circle = $this->dbCircles->getDetailsFromCircle($circleId, $this->userId); |
|
|
|
|
|
|
93
|
|
|
|
|
94
|
|
|
$this->circlesRequest->createShare($share); |
|
95
|
|
|
|
|
96
|
|
|
if ($broadcast !== null) { |
|
97
|
|
|
$broadcaster = \OC::$server->query($broadcast); |
|
98
|
|
|
if (!($broadcaster instanceof IBroadcaster)) { |
|
99
|
|
|
throw new BroadcasterIsNotCompatible(); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
$broadcaster->init(); |
|
103
|
|
|
|
|
104
|
|
|
$users = $this->circlesRequest->getAudience($share->getCircleId()); |
|
105
|
|
|
foreach ($users AS $user) { |
|
106
|
|
|
$share->setCircleName($user['circle_name']); |
|
107
|
|
|
$broadcaster->broadcast($user['uid'], $share); |
|
108
|
|
|
} |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
$this->shareItemToFederatedLinks($share, $broadcast); |
|
112
|
|
|
|
|
113
|
|
|
return true; |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
|
|
117
|
|
|
|
|
118
|
|
|
|
|
119
|
|
|
public function shareItemToFederatedLinks(Share $share, string $broadcast = null) { |
|
|
|
|
|
|
120
|
|
|
|
|
121
|
|
|
//$circles = $this->circlesRequest->getFederatedLinks($share->getCircle()); |
|
122
|
|
|
// TODO, envoyer une requete http sur le broadcaster local en precisant qu'il a deja ete broadcaste en local |
|
|
|
|
|
|
123
|
|
|
//broadcastItem() |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
|
|
127
|
|
|
|
|
128
|
|
|
// public function reshare($circleId, $source, $type, $shareid) { |
|
|
|
|
|
|
129
|
|
|
// $this->miscService->log( |
|
130
|
|
|
// "__reshare" . $circleId . ' ' . $source . ' ' . $type . ' ' . json_encode($item) |
|
131
|
|
|
// ); |
|
132
|
|
|
// |
|
133
|
|
|
// $share = new Share($source, $type); |
|
134
|
|
|
// $share->setCircleId($circleId); |
|
135
|
|
|
// $share->setItem($item); |
|
136
|
|
|
// |
|
137
|
|
|
// $share->setAuthor($this->userId); |
|
138
|
|
|
// |
|
139
|
|
|
// $this->circlesRequest->createShare($share); |
|
140
|
|
|
// |
|
141
|
|
|
// return true; |
|
142
|
|
|
// } |
|
143
|
|
|
|
|
144
|
|
|
} |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.