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\SharingFrame; |
35
|
|
|
|
36
|
|
|
|
37
|
|
|
class BroadcastService { |
38
|
|
|
|
39
|
|
|
/** @var string */ |
40
|
|
|
private $userId; |
41
|
|
|
|
42
|
|
|
/** @var ConfigService */ |
43
|
|
|
private $configService; |
44
|
|
|
|
45
|
|
|
/** @var CirclesRequest */ |
46
|
|
|
private $circlesRequest; |
47
|
|
|
|
48
|
|
|
/** @var MiscService */ |
49
|
|
|
private $miscService; |
50
|
|
|
|
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* SharesService constructor. |
54
|
|
|
* |
55
|
|
|
* @param string $userId |
56
|
|
|
* @param ConfigService $configService |
57
|
|
|
* @param CirclesRequest $circlesRequest |
58
|
|
|
* @param MiscService $miscService |
59
|
|
|
*/ |
60
|
|
|
public function __construct( |
61
|
|
|
string $userId, |
62
|
|
|
ConfigService $configService, |
63
|
|
|
CirclesRequest $circlesRequest, |
64
|
|
|
MiscService $miscService |
65
|
|
|
) { |
66
|
|
|
$this->userId = $userId; |
67
|
|
|
$this->configService = $configService; |
68
|
|
|
$this->circlesRequest = $circlesRequest; |
69
|
|
|
$this->miscService = $miscService; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
|
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* broadcast the SharingFrame item using a IBroadcaster. |
76
|
|
|
* The broadcast is usually set by the app that created the SharingFrame item. |
77
|
|
|
* |
78
|
|
|
* @param string $broadcast |
79
|
|
|
* @param SharingFrame $frame |
80
|
|
|
* |
81
|
|
|
* @throws BroadcasterIsNotCompatible |
82
|
|
|
*/ |
83
|
|
|
public function broadcastFrame(string $broadcast, SharingFrame $frame) { |
84
|
|
|
|
85
|
|
|
if ($broadcast === null) { |
86
|
|
|
return; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
$broadcaster = \OC::$server->query($broadcast); |
90
|
|
|
if (!($broadcaster instanceof IBroadcaster)) { |
91
|
|
|
throw new BroadcasterIsNotCompatible(); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
$broadcaster->init(); |
95
|
|
|
$users = $this->circlesRequest->getMembers($frame->getCircleId(), Member::LEVEL_MEMBER); |
96
|
|
|
foreach ($users AS $user) { |
97
|
|
|
$broadcaster->broadcast($user->getUserId(), $frame); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
|
103
|
|
|
|
104
|
|
|
} |