Skip to content

Commit 2c9dc44

Browse files
committed
Add ThreadModel
1 parent 01cb11d commit 2c9dc44

File tree

3 files changed

+124
-0
lines changed

3 files changed

+124
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ $result = $driver->getPreferenceModel('user_id')->getUserPreference();
208208
- [Status](https://api.mattermost.com/#tag/status)
209209
- [System](https://api.mattermost.com/#tag/system)
210210
- [Teams](https://api.mattermost.com/#tag/teams)
211+
- [Threads](https://api.mattermost.com/#tag/threads)
211212
- [Users](https://api.mattermost.com/#tag/users)
212213
- [Webhooks](https://api.mattermost.com/#tag/webhooks)
213214

src/Driver.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
use Gnello\Mattermost\Models\SchemeModel;
3636
use Gnello\Mattermost\Models\SystemModel;
3737
use Gnello\Mattermost\Models\TeamModel;
38+
use Gnello\Mattermost\Models\ThreadModel;
3839
use Gnello\Mattermost\Models\UserModel;
3940
use Gnello\Mattermost\Models\WebhookModel;
4041
use GuzzleHttp\Psr7\Response;
@@ -354,4 +355,12 @@ public function getIntegrationActionsModel()
354355
{
355356
return $this->getModel(IntegrationActionsModel::class);
356357
}
358+
359+
/**
360+
* @return ThreadModel
361+
*/
362+
public function getThreadModel()
363+
{
364+
return $this->getModel(ThreadModel::class);
365+
}
357366
}

src/Models/ThreadModel.php

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
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 ThreadsModel
22+
*
23+
* @package Gnello\Mattermost
24+
*/
25+
class ThreadModel extends AbstractModel
26+
{
27+
/**
28+
* @var string
29+
*/
30+
public static $endpoint = '/threads';
31+
32+
/**
33+
* @param $userId
34+
* @param $teamId
35+
* @param array $requestOptions
36+
* @return ResponseInterface
37+
*/
38+
public function getThreadsThatUserIsFollowing($userId, $teamId, array $requestOptions)
39+
{
40+
return $this->client->get(UserModel::$endpoint . '/' . $userId . '/' . TeamModel::$endpoint . '/' . $teamId
41+
. '/' . self::$endpoint , $requestOptions);
42+
}
43+
44+
/**
45+
* @param $userId
46+
* @param $teamId
47+
* @return ResponseInterface
48+
*/
49+
public function getUnreadMentionCounts($userId, $teamId)
50+
{
51+
return $this->client->get(UserModel::$endpoint . '/' . $userId . '/' . TeamModel::$endpoint . '/' . $teamId
52+
. '/' . self::$endpoint . '/mention_counts');
53+
}
54+
55+
/**
56+
* @param $userId
57+
* @param $teamId
58+
* @return ResponseInterface
59+
*/
60+
public function markThreadsAsRead($userId, $teamId)
61+
{
62+
return $this->client->put(UserModel::$endpoint . '/' . $userId . '/' . TeamModel::$endpoint . '/' . $teamId
63+
. '/' . self::$endpoint . '/read');
64+
}
65+
66+
/**
67+
* @param $userId
68+
* @param $teamId
69+
* @param $threadId
70+
* @param $timestamp
71+
* @return ResponseInterface
72+
*/
73+
public function markThreadToTimestamp($userId, $teamId, $threadId, $timestamp)
74+
{
75+
return $this->client->put(UserModel::$endpoint . '/' . $userId . '/' . TeamModel::$endpoint . '/' . $teamId
76+
. '/' . self::$endpoint . '/' . $threadId . '/read/' . $timestamp);
77+
}
78+
79+
/**
80+
* @param $userId
81+
* @param $teamId
82+
* @param $threadId
83+
* @return ResponseInterface
84+
*/
85+
public function startFollowingThread($userId, $teamId, $threadId)
86+
{
87+
return $this->client->put(UserModel::$endpoint . '/' . $userId . '/' . TeamModel::$endpoint . '/' . $teamId
88+
. '/' . self::$endpoint . '/' . $threadId . '/following');
89+
}
90+
91+
/**
92+
* @param $userId
93+
* @param $teamId
94+
* @param $threadId
95+
* @return ResponseInterface
96+
*/
97+
public function stopFollowingThread($userId, $teamId, $threadId)
98+
{
99+
return $this->client->delete(UserModel::$endpoint . '/' . $userId . '/' . TeamModel::$endpoint . '/'
100+
. $teamId . '/' . self::$endpoint . '/' . $threadId . '/following');
101+
}
102+
103+
/**
104+
* @param $userId
105+
* @param $teamId
106+
* @param $threadId
107+
* @return ResponseInterface
108+
*/
109+
public function getThreadFollowedByUser($userId, $teamId, $threadId)
110+
{
111+
return $this->client->get(UserModel::$endpoint . '/' . $userId . '/' . TeamModel::$endpoint . '/' . $teamId
112+
. '/' . self::$endpoint . '/' . $threadId);
113+
}
114+
}

0 commit comments

Comments
 (0)