| 1 |  |  | <?php
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | /**
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  * This Driver is based entirely on official documentation of the Mattermost Web
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * Services API and you can extend it by following the directives of the documentation.
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  *
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * For the full copyright and license information, please read the LICENSE.txt
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * file that was distributed with this source code. For the full list of
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * contributors, visit https://github.com/gnello/php-mattermost-driver/contributors
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  *
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * God bless this mess.
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  *
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  * @author Luca Agnello <[email protected]>
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  * @link https://api.mattermost.com/
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  */
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | 
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | namespace Gnello\Mattermost\Models;
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | 
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | use Psr\Http\Message\ResponseInterface;
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | 
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  | /**
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  * Class PostModel
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  *
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |  * @package Gnello\Mattermost\Models
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |  */
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  | class PostModel extends AbstractModel
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  | {
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |     /**
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |      * @var string
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |      */
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |     public static $endpoint = '/posts';
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  | 
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |     /**
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |      * @param array $requestOptions
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |      * @return ResponseInterface
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |      */
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |     public function createPost(array $requestOptions)
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |     {
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |         return $this->client->post(self::$endpoint, $requestOptions);
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |     }
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  | 
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |     /**
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |      * @param $postId
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |      * @return ResponseInterface
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |      */
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |     public function getPost($postId)
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |     {
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |         return $this->client->get(self::$endpoint . '/' . $postId);
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |     }
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  | 
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |     /**
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |      * @param $postId
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |      * @return ResponseInterface
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |      */
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |     public function deletePost($postId)
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |     {
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |         return $this->client->delete(self::$endpoint . '/' . $postId);
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |     }
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  | 
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |     /**
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |      * @param       $postId
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |      * @param array $requestOptions
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |      * @return ResponseInterface
 | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 63 |  |  |      */
 | 
            
                                                                        
                            
            
                                    
            
            
                | 64 |  |  |     public function updatePost($postId, array $requestOptions)
 | 
            
                                                                        
                            
            
                                    
            
            
                | 65 |  |  |     {
 | 
            
                                                                        
                            
            
                                    
            
            
                | 66 |  |  |         return $this->client->put(self::$endpoint . '/' . $postId, $requestOptions);
 | 
            
                                                                        
                            
            
                                    
            
            
                | 67 |  |  |     }
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  | 
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |     /**
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |      * @param       $postId
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |      * @param array $requestOptions
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |      * @return ResponseInterface
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |      */
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |     public function patchPost($postId, array $requestOptions)
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |     {
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |         return $this->client->put(self::$endpoint . '/' . $postId . '/patch', $requestOptions);
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |     }
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  | 
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |     /**
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |      * @param $postId
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |      * @return ResponseInterface
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |      */
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |     public function getThread($postId)
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |     {
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |         return $this->client->get(self::$endpoint . '/' . $postId . '/thread');
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |     }
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  | 
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |     /**
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |      * @param       $userId
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |      * @param array $requestOptions
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |      * @return ResponseInterface
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |      */
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |     public function getFlaggedPosts($userId, array $requestOptions)
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |     {
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |         return $this->client->get(UserModel::$endpoint . '/' . $userId . self::$endpoint . '/flagged', $requestOptions);
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |     }
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  | 
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |     /**
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |      * @param       $postId
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |      * @return ResponseInterface
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |      */
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |     public function getFileInfoForPost($postId)
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |     {
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |         return $this->client->get(self::$endpoint . '/' . $postId . '/files/info');
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |     }
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  | 
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |     /**
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |      * @param       $channelId
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |      * @param array $requestOptions
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |      * @return ResponseInterface
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |      */
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |     public function getPostsForChannel($channelId, array $requestOptions)
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |     {
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |         return $this->client->get(ChannelModel::$endpoint . '/' . $channelId . self::$endpoint, $requestOptions);
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |     }
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  | 
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |     /**
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |      * @param       $teamId
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |      * @param array $requestOptions
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |      * @return ResponseInterface
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |      */
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |     public function searchForTeamPosts($teamId, array $requestOptions)
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |     {
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |         return $this->client->post(TeamModel::$endpoint . '/' . $teamId . self::$endpoint . '/search', $requestOptions);
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |     }
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  | 
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |     /**
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  |      * @param       $postId
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  |      * @return ResponseInterface
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  |      */
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  |     public function pinPost($postId)
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  |     {
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  |         return $this->client->post(self::$endpoint . '/' . $postId . '/pin');
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  |     }
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  | 
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  |     /**
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  |      * @param       $postId
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  |      * @return ResponseInterface
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  |      */
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  |     public function unpinPost($postId)
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  |     {
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  |         return $this->client->post(self::$endpoint . '/' . $postId . '/unpin');
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  |     }
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  | 
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 |  |  |     /**
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  |      * @param       $postId
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 |  |  |      * @param       $actionId
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 |  |  |      * @return ResponseInterface
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 |  |  |      */
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 |  |  |     public function performPostAction($postId, $actionId)
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  |     {
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 |  |  |         return $this->client->post(self::$endpoint . '/' . $postId . '/actions/' . $actionId);
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 |  |  |     }
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 |  |  | 
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 |  |  |     /**
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 |  |  |      * @param $postId
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 157 |  |  |      * @return ResponseInterface
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 |  |  |      */
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 |  |  |     public function getReactions($postId)
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 160 |  |  |     {
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 161 |  |  |         return $this->client->get(self::$endpoint . '/' . $postId . '/reactions');
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 162 |  |  |     }
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 163 |  |  | 
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 164 |  |  |     /**
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 165 |  |  |      * @param array $requestOptions
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 166 |  |  |      * @return ResponseInterface
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 167 |  |  |      */
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 168 |  |  |     public function createEphemeralPost(array $requestOptions)
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 169 |  |  |     {
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 170 |  |  |         return $this->client->post(self::$endpoint . '/ephemeral', $requestOptions);
 | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 171 |  |  |     }
 | 
            
                                                        
            
                                    
            
            
                | 172 |  |  | } |