|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace GetStream\Doctrine; |
|
4
|
|
|
|
|
5
|
|
|
use GetStream\Stream\Client; |
|
6
|
|
|
use GetStream\Stream\Feed; |
|
7
|
|
|
|
|
8
|
|
|
class FeedManager implements FeedManagerInterface |
|
9
|
|
|
{ |
|
10
|
|
|
/** |
|
11
|
|
|
* @var Client |
|
12
|
|
|
*/ |
|
13
|
|
|
private $client; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* @var string |
|
17
|
|
|
*/ |
|
18
|
|
|
private $userFeed = 'user'; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @var string |
|
22
|
|
|
*/ |
|
23
|
|
|
private $notificationFeed = 'notification'; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @var string[] |
|
27
|
|
|
*/ |
|
28
|
|
|
private $newsFeeds = []; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @param Client $client |
|
32
|
|
|
*/ |
|
33
|
8 |
|
public function __construct(Client $client) |
|
34
|
|
|
{ |
|
35
|
8 |
|
$this->client = $client; |
|
36
|
8 |
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @param string $userFeed |
|
40
|
|
|
* |
|
41
|
|
|
* @return $this |
|
42
|
|
|
*/ |
|
43
|
1 |
|
public function setUserFeed($userFeed) |
|
44
|
|
|
{ |
|
45
|
1 |
|
$this->userFeed = $userFeed; |
|
46
|
|
|
|
|
47
|
1 |
|
return $this; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @param string $notificationFeed |
|
52
|
|
|
* |
|
53
|
|
|
* @return $this |
|
54
|
|
|
*/ |
|
55
|
1 |
|
public function setNotificationFeed($notificationFeed) |
|
56
|
|
|
{ |
|
57
|
1 |
|
$this->notificationFeed = $notificationFeed; |
|
58
|
|
|
|
|
59
|
1 |
|
return $this; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* @param array $newsFeeds |
|
64
|
|
|
* |
|
65
|
|
|
* @return $this |
|
66
|
|
|
*/ |
|
67
|
3 |
|
public function setNewsFeeds(array $newsFeeds) |
|
68
|
|
|
{ |
|
69
|
3 |
|
$this->newsFeeds = $newsFeeds; |
|
70
|
|
|
|
|
71
|
3 |
|
return $this; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* @return Client |
|
76
|
|
|
*/ |
|
77
|
1 |
|
public function getClient() |
|
78
|
|
|
{ |
|
79
|
1 |
|
return $this->client; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* @param string $feed |
|
84
|
|
|
* @param string $id |
|
85
|
|
|
* |
|
86
|
|
|
* @return Feed |
|
87
|
|
|
*/ |
|
88
|
6 |
|
public function getFeed($feed, $id) |
|
89
|
|
|
{ |
|
90
|
6 |
|
return $this->client->feed($feed, $id); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* @param string $userId |
|
95
|
|
|
* |
|
96
|
|
|
* @return Feed |
|
97
|
|
|
*/ |
|
98
|
3 |
|
public function getUserFeed($userId) |
|
99
|
|
|
{ |
|
100
|
3 |
|
return $this->getFeed($this->userFeed, $userId); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* @param string $userId |
|
105
|
|
|
* |
|
106
|
|
|
* @return Feed |
|
107
|
|
|
*/ |
|
108
|
1 |
|
public function getNotificationFeed($userId) |
|
109
|
|
|
{ |
|
110
|
1 |
|
return $this->getFeed($this->notificationFeed, $userId); |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* @param string $userId |
|
115
|
|
|
* |
|
116
|
|
|
* @return Feed[] |
|
117
|
|
|
*/ |
|
118
|
|
|
public function getNewsFeeds($userId) |
|
119
|
|
|
{ |
|
120
|
3 |
|
return array_map(function ($feed) use ($userId) { |
|
121
|
3 |
|
return $this->getFeed($feed, $userId); |
|
122
|
3 |
|
}, array_combine($this->newsFeeds, $this->newsFeeds)); |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
/** |
|
126
|
|
|
* @param string $userId |
|
127
|
|
|
* @param string $targetUserId |
|
128
|
|
|
*/ |
|
129
|
1 |
|
public function followUser($userId, $targetUserId) |
|
130
|
|
|
{ |
|
131
|
1 |
|
$newsFeeds = $this->getNewsFeeds($userId); |
|
132
|
1 |
|
$targetFeed = $this->getUserFeed($targetUserId); |
|
133
|
|
|
|
|
134
|
1 |
|
foreach ($newsFeeds as $feed) { |
|
135
|
1 |
|
$feed->follow($targetFeed->getSlug(), $targetFeed->getUserId()); |
|
136
|
|
|
} |
|
137
|
1 |
|
} |
|
138
|
|
|
|
|
139
|
|
|
/** |
|
140
|
|
|
* @param string $userId |
|
141
|
|
|
* @param string $targetUserId |
|
142
|
|
|
*/ |
|
143
|
1 |
|
public function unfollowUser($userId, $targetUserId) |
|
144
|
|
|
{ |
|
145
|
1 |
|
$newsFeeds = $this->getNewsFeeds($userId); |
|
146
|
1 |
|
$targetFeed = $this->getUserFeed($targetUserId); |
|
147
|
|
|
|
|
148
|
1 |
|
foreach ($newsFeeds as $feed) { |
|
149
|
1 |
|
$feed->unfollow($targetFeed->getSlug(), $targetFeed->getUserId()); |
|
150
|
|
|
} |
|
151
|
1 |
|
} |
|
152
|
|
|
} |
|
153
|
|
|
|