Skip to content

Commit 956e02b

Browse files
authored
Further simplications for literals (#35)
A follow up on #34
1 parent fbaee03 commit 956e02b

File tree

2 files changed

+13
-23
lines changed

2 files changed

+13
-23
lines changed

stream_chat/channel.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def create(self, user_id):
7171
:param user_id: the ID of the user creating this channel
7272
:return:
7373
"""
74-
self.custom_data["created_by"] = {'id': user_id}
74+
self.custom_data["created_by"] = {"id": user_id}
7575
return self.query(watch=False, state=False, presence=False)
7676

7777
def query(self, **options):
@@ -81,8 +81,7 @@ def query(self, **options):
8181
:param options: the query options, check docs on https://getstream.io/chat/docs/
8282
:return: Returns a query response
8383
"""
84-
payload = {"state": True, "data": self.custom_data}
85-
payload.update(options)
84+
payload = {"state": True, "data": self.custom_data, **options}
8685

8786
url = "channels/{}".format(self.channel_type)
8887
if self.id is not None:
@@ -261,6 +260,4 @@ def show(self, user_id):
261260

262261

263262
def add_user_id(payload, user_id):
264-
payload = payload.copy()
265-
payload.update({'user': {'id': user_id}})
266-
return payload
263+
return {**payload, "user": {"id": user_id}}

stream_chat/client.py

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def __init__(self, api_key, api_secret, timeout=6.0, **options):
4040
self.session = requests.Session()
4141

4242
def get_default_params(self):
43-
return {'api_key': self.api_key}
43+
return {"api_key": self.api_key}
4444

4545
def _parse_response(self, response):
4646
try:
@@ -127,33 +127,27 @@ def export_user(self, user_id, **options):
127127
return self.get("users/{}/export".format(user_id), options)
128128

129129
def ban_user(self, target_id, **options):
130-
data = {'target_user_id': target_id}
131-
data.update(options)
130+
data = {"target_user_id": target_id, **options}
132131
return self.post("moderation/ban", data=data)
133132

134133
def unban_user(self, target_id, **options):
135-
params = {'target_user_id': target_id}
136-
params.update(options)
134+
params = {"target_user_id": target_id, **options}
137135
return self.delete("moderation/ban", params)
138136

139137
def flag_message(self, target_id, **options):
140-
data = {'target_message_id': target_id}
141-
data.update(options)
138+
data = {"target_message_id": target_id, **options}
142139
return self.post("moderation/flag", data=data)
143140

144141
def unflag_message(self, target_id, **options):
145-
data = {'target_message_id': target_id}
146-
data.update(options)
142+
data = {"target_message_id": target_id, **options}
147143
return self.post("moderation/unflag", data=data)
148144

149145
def flag_user(self, target_id, **options):
150-
data = {'target_user_id': target_id}
151-
data.update(options)
146+
data = {"target_user_id": target_id, **options}
152147
return self.post("moderation/flag", data=data)
153148

154149
def unflag_user(self, target_id, **options):
155-
data = {'target_user_id': target_id}
156-
data.update(options)
150+
data = {"target_user_id": target_id, **options}
157151
return self.post("moderation/unflag", data=data)
158152

159153
def mute_user(self, target_id, user_id, **options):
@@ -165,7 +159,7 @@ def mute_user(self, target_id, user_id, **options):
165159
:param options: additional mute options
166160
:return:
167161
"""
168-
data = dict(target_id=target_id, user_id=user_id, **options)
162+
data = {"target_id": target_id, "user_id": user_id, **options}
169163
return self.post("moderation/mute", data=data)
170164

171165
def unmute_user(self, target_id, user_id):
@@ -177,7 +171,7 @@ def unmute_user(self, target_id, user_id):
177171
:return:
178172
"""
179173

180-
data = {'target_id': target_id, 'user_id': user_id}
174+
data = {"target_id": target_id, "user_id": user_id}
181175
return self.post("moderation/unmute", data=data)
182176

183177
def mark_all_read(self, user_id):
@@ -292,8 +286,7 @@ def verify_webhook(self, request_body, x_signature):
292286
return signature == x_signature
293287

294288
def search(self, filter_conditions, query, **options):
295-
params = options.copy()
296-
params.update({"filter_conditions": filter_conditions, "query": query})
289+
params = {**options, "filter_conditions": filter_conditions, "query": query}
297290
return self.get("search", params={"payload": json.dumps(params)})
298291

299292
def send_file(self, uri, url, name, user, content_type=None):

0 commit comments

Comments
 (0)