@@ 64-82 (lines=19) @@ | ||
61 | * @throws \RuntimeException |
|
62 | * @throws \Throwable |
|
63 | */ |
|
64 | public function allBeforeId(string $roomId, string $beforeId = null, string $query = null) |
|
65 | { |
|
66 | $limit = 100; |
|
67 | $route = $this->routeForMessagesIterator($roomId, $limit, $query); |
|
68 | ||
69 | do { |
|
70 | if ($beforeId !== null) { |
|
71 | $route->with('beforeId', $beforeId); |
|
72 | } |
|
73 | ||
74 | $response = array_reverse($this->fetch($route)); |
|
75 | ||
76 | foreach ($response as $message) { |
|
77 | yield $message; |
|
78 | } |
|
79 | ||
80 | $beforeId = count($response) > 0 ? end($response)['id'] : null; |
|
81 | } while (count($response) >= $limit); |
|
82 | } |
|
83 | ||
84 | /** |
|
85 | * @param string $roomId |
|
@@ 116-134 (lines=19) @@ | ||
113 | * @throws \RuntimeException |
|
114 | * @throws \Throwable |
|
115 | */ |
|
116 | public function allAfterId(string $roomId, string $afterId = null, string $query = null) |
|
117 | { |
|
118 | $limit = 100; |
|
119 | $route = $this->routeForMessagesIterator($roomId, $limit, $query); |
|
120 | ||
121 | do { |
|
122 | if ($afterId !== null) { |
|
123 | $route->with('afterId', $afterId); |
|
124 | } |
|
125 | ||
126 | $response = (array)$this->fetch($route); |
|
127 | ||
128 | foreach ($response as $message) { |
|
129 | yield $message; |
|
130 | } |
|
131 | ||
132 | $afterId = count($response) > 0 ? end($response)['id'] : null; |
|
133 | } while (count($response) >= $limit); |
|
134 | } |
|
135 | ||
136 | /** |
|
137 | * There is also a way to retrieve a single message using its id. |