Completed
Push — master ( 4edf58...b5cbd9 )
by Maxence
19s queued 10s
created

BroadcastService::feedBroadcaster()   A

Complexity

Conditions 4
Paths 6

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 18
rs 9.6666
c 0
b 0
f 0
cc 4
nc 6
nop 3
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 daita\MySmallPhpTools\Model\SimpleDataStore;
31
use Exception;
32
use OCA\Circles\Db\CirclesRequest;
33
use OCA\Circles\Db\MembersRequest;
34
use OCA\Circles\Model\GlobalScale\GSEvent;
35
use OCA\Circles\Model\SharingFrame;
36
37
38
class BroadcastService {
39
40
41
	/** @var string */
42
	private $userId;
43
44
	/** @var GSUpstreamService */
45
	private $gsUpstreamService;
46
47
	/** @var ConfigService */
48
	private $configService;
49
50
	/** @var CirclesRequest */
51
	private $circlesRequest;
52
53
	/** @var MembersRequest */
54
	private $membersRequest;
55
56
	/** @var MiscService */
57
	private $miscService;
58
59
60
	/**
61
	 * BroadcastService constructor.
62
	 *
63
	 * @param string $userId
64
	 * @param ConfigService $configService
65
	 * @param CirclesRequest $circlesRequest
66
	 * @param MembersRequest $membersRequest
67
	 * @param GSUpstreamService $gsUpstreamService
68
	 * @param MiscService $miscService
69
	 */
70
	public function __construct(
71
		$userId,
72
		ConfigService $configService,
73
		CirclesRequest $circlesRequest,
74
		MembersRequest $membersRequest,
75
		GSUpstreamService $gsUpstreamService,
76
		MiscService $miscService
77
	) {
78
		$this->userId = $userId;
79
		$this->configService = $configService;
80
		$this->circlesRequest = $circlesRequest;
81
		$this->membersRequest = $membersRequest;
82
		$this->gsUpstreamService = $gsUpstreamService;
83
		$this->miscService = $miscService;
84
	}
85
86
87
	/**
88
	 * broadcast the SharingFrame item using a IBroadcaster.
89
	 * The broadcast is usually set by the app that created the SharingFrame item.
90
	 *
91
	 * If the circle is not a Personal Circle, we first call createShareToCircle()
92
	 * Then for each members of the circle, we call createShareToUser()
93
	 * If the circle is a Personal Circle, we don't send data about the SharingFrame but null.
94
	 *
95
	 * @param SharingFrame $frame
96
	 *
97
	 * @throws Exception
98
	 */
99
	public function broadcastFrame(SharingFrame $frame) {
100
		if ($frame->getHeader('broadcast') === null) {
101
			return;
102
		}
103
104
		$event = new GSEvent(GSEvent::FILE_SHARE, true);
105
		$event->setAsync(true);
106
		$event->setSeverity(GSEvent::SEVERITY_HIGH);
107
		$event->setCircle($frame->getCircle());
108
		$event->setData(new SimpleDataStore(['frame' => json_decode(json_encode($frame), true)]));
109
110
		$this->gsUpstreamService->newEvent($event);
111
	}
112
113
}
114
115