Skip to content

Commit 5500ea4

Browse files
feat: added pin, archive and partial member update functions
1 parent fa23514 commit 5500ea4

File tree

3 files changed

+144
-0
lines changed

3 files changed

+144
-0
lines changed

stream_chat/async_chat/channel.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,3 +209,54 @@ async def unmute(self, user_id: str) -> StreamResponse:
209209
"channel_cid": self.cid,
210210
}
211211
return await self.client.post("moderation/unmute/channel", data=params)
212+
213+
async def pin(self, user_id: str) -> StreamResponse:
214+
if not user_id:
215+
raise StreamChannelException("user_id must not be empty")
216+
217+
payload = {
218+
"set": {
219+
"pinned": True
220+
}
221+
}
222+
return self.client.patch(f"{self.url}/member/{user_id}", data=payload)
223+
224+
async def unpin(self, user_id: str) -> StreamResponse:
225+
if not user_id:
226+
raise StreamChannelException("user_id must not be empty")
227+
228+
payload = {
229+
"set": {
230+
"pinned": False
231+
}
232+
}
233+
return self.client.patch(f"{self.url}/member/{user_id}", data=payload)
234+
235+
async def archive(self, user_id: str) -> StreamResponse:
236+
if not user_id:
237+
raise StreamChannelException("user_id must not be empty")
238+
239+
payload = {
240+
"set": {
241+
"archived": True
242+
}
243+
}
244+
return self.client.patch(f"{self.url}/member/{user_id}", data=payload)
245+
246+
async def unarchive(self, user_id: str) -> StreamResponse:
247+
if not user_id:
248+
raise StreamChannelException("user_id must not be empty")
249+
250+
payload = {
251+
"set": {
252+
"archived": False
253+
}
254+
}
255+
return self.client.patch(f"{self.url}/member/{user_id}", data=payload)
256+
257+
async def update_member_partial(self, user_id: str, to_set: Dict = None, to_unset: Iterable[str] = None) -> Union[StreamResponse, Awaitable[StreamResponse]]:
258+
if not user_id:
259+
raise StreamChannelException("user_id must not be empty")
260+
261+
payload = {"set": to_set or {}, "unset": to_unset or []}
262+
return self.client.patch(f"{self.url}/member/{user_id}", data=payload)

stream_chat/base/channel.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,48 @@ def unmute(self, user_id: str) -> Union[StreamResponse, Awaitable[StreamResponse
440440
"""
441441
pass
442442

443+
@abc.abstractmethod
444+
def pin(self, user_id: str) -> Union[StreamResponse, Awaitable[StreamResponse]]:
445+
"""
446+
Pins a channel
447+
Allows a user to pin the channel (only for theirselves)
448+
"""
449+
pass
450+
451+
@abc.abstractmethod
452+
def unpin(self, user_id: str) -> Union[StreamResponse, Awaitable[StreamResponse]]:
453+
"""
454+
Unpins a channel
455+
Allows a user to unpin the channel (only for theirselves)
456+
"""
457+
pass
458+
459+
@abc.abstractmethod
460+
def archive(self, user_id: str) -> Union[StreamResponse, Awaitable[StreamResponse]]:
461+
"""
462+
Pins a channel
463+
Allows a user to archive the channel (only for theirselves)
464+
"""
465+
pass
466+
467+
@abc.abstractmethod
468+
def unarchive(self, user_id: str) -> Union[StreamResponse, Awaitable[StreamResponse]]:
469+
"""
470+
Unpins a channel
471+
Allows a user to unpin the channel (only for theirselves)
472+
"""
473+
pass
474+
475+
@abc.abstractmethod
476+
def update_member_partial(self, user_id: str, to_set: Dict = None, to_unset: Iterable[str] = None) -> Union[StreamResponse, Awaitable[StreamResponse]]:
477+
"""
478+
Update channel member partially
479+
480+
:param to_set: a dictionary of key/value pairs to set or to override
481+
:param to_unset: a list of keys to clear
482+
"""
483+
pass
484+
443485

444486
def add_user_id(payload: Dict, user_id: str) -> Dict:
445487
return {**payload, "user": {"id": user_id}}

stream_chat/channel.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,3 +210,54 @@ def unmute(self, user_id: str) -> StreamResponse:
210210
"channel_cid": self.cid,
211211
}
212212
return self.client.post("moderation/unmute/channel", data=params)
213+
214+
def pin(self, user_id: str) -> StreamResponse:
215+
if not user_id:
216+
raise StreamChannelException("user_id must not be empty")
217+
218+
payload = {
219+
"set": {
220+
"pinned": True
221+
}
222+
}
223+
return self.client.patch(f"{self.url}/member/{user_id}", data=payload)
224+
225+
def unpin(self, user_id: str) -> StreamResponse:
226+
if not user_id:
227+
raise StreamChannelException("user_id must not be empty")
228+
229+
payload = {
230+
"set": {
231+
"pinned": False
232+
}
233+
}
234+
return self.client.patch(f"{self.url}/member/{user_id}", data=payload)
235+
236+
def archive(self, user_id: str) -> StreamResponse:
237+
if not user_id:
238+
raise StreamChannelException("user_id must not be empty")
239+
240+
payload = {
241+
"set": {
242+
"archived": True
243+
}
244+
}
245+
return self.client.patch(f"{self.url}/member/{user_id}", data=payload)
246+
247+
def unarchive(self, user_id: str) -> StreamResponse:
248+
if not user_id:
249+
raise StreamChannelException("user_id must not be empty")
250+
251+
payload = {
252+
"set": {
253+
"archived": False
254+
}
255+
}
256+
return self.client.patch(f"{self.url}/member/{user_id}", data=payload)
257+
258+
def update_member_partial(self, user_id: str, to_set: Dict = None, to_unset: Iterable[str] = None) -> Union[StreamResponse, Awaitable[StreamResponse]]:
259+
if not user_id:
260+
raise StreamChannelException("user_id must not be empty")
261+
262+
payload = {"set": to_set or {}, "unset": to_unset or []}
263+
return self.client.patch(f"{self.url}/member/{user_id}", data=payload)

0 commit comments

Comments
 (0)