Skip to content

Commit 576d33b

Browse files
committed
fix: classroom activity - some cases lead to same outcome
1 parent 37e44cd commit 576d33b

File tree

1 file changed

+9
-43
lines changed

1 file changed

+9
-43
lines changed

scratchattach/site/activity.py

Lines changed: 9 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,9 @@ def _update_from_json(self, data: dict):
8080
else:
8181
recipient_username = None
8282

83-
default_case = False
84-
"""Whether this is 'blank'; it will default to 'user performed an action'"""
83+
default_case = True
84+
# Even if `activity_type` is an invalid value; it will default to 'user performed an action'
85+
8586
if activity_type == 0:
8687
# follow
8788
followed_username = data["followed_username"]
@@ -150,13 +151,7 @@ def _update_from_json(self, data: dict):
150151
self.project_id = project_id
151152
self.recipient_username = recipient_username
152153

153-
elif activity_type == 8:
154-
default_case = True
155-
156-
elif activity_type == 9:
157-
default_case = True
158-
159-
elif activity_type == 10:
154+
elif activity_type in (8, 9, 10):
160155
# Share/Reshare project
161156
project_id = data["project"]
162157
is_reshare = data["is_reshare"]
@@ -187,9 +182,6 @@ def _update_from_json(self, data: dict):
187182
self.project_id = parent_id
188183
self.recipient_username = recipient_username
189184

190-
elif activity_type == 12:
191-
default_case = True
192-
193185
elif activity_type == 13:
194186
# Create ('add') studio
195187
studio_id = data["gallery"]
@@ -216,16 +208,7 @@ def _update_from_json(self, data: dict):
216208
self.username = username
217209
self.gallery_id = studio_id
218210

219-
elif activity_type == 16:
220-
default_case = True
221-
222-
elif activity_type == 17:
223-
default_case = True
224-
225-
elif activity_type == 18:
226-
default_case = True
227-
228-
elif activity_type == 19:
211+
elif activity_type in (16, 17, 18, 19):
229212
# Remove project from studio
230213

231214
project_id = data["project"]
@@ -240,13 +223,7 @@ def _update_from_json(self, data: dict):
240223
self.username = username
241224
self.project_id = project_id
242225

243-
elif activity_type == 20:
244-
default_case = True
245-
246-
elif activity_type == 21:
247-
default_case = True
248-
249-
elif activity_type == 22:
226+
elif activity_type in (20, 21, 22):
250227
# Was promoted to manager for studio
251228
studio_id = data["gallery"]
252229

@@ -260,13 +237,7 @@ def _update_from_json(self, data: dict):
260237
self.recipient_username = recipient_username
261238
self.gallery_id = studio_id
262239

263-
elif activity_type == 23:
264-
default_case = True
265-
266-
elif activity_type == 24:
267-
default_case = True
268-
269-
elif activity_type == 25:
240+
elif activity_type in (23, 24, 25):
270241
# Update profile
271242
raw = f"{username} made a profile update"
272243

@@ -276,10 +247,7 @@ def _update_from_json(self, data: dict):
276247

277248
self.username = username
278249

279-
elif activity_type == 26:
280-
default_case = True
281-
282-
elif activity_type == 27:
250+
elif activity_type in (26, 27):
283251
# Comment (quite complicated)
284252
comment_type: int = data["comment_type"]
285253
fragment = data["comment_fragment"]
@@ -314,12 +282,10 @@ def _update_from_json(self, data: dict):
314282
self.comment_obj_title = comment_obj_title
315283
self.comment_id = comment_id
316284

317-
else:
318-
default_case = True
319285

320286
if default_case:
321287
# This is coded in the scratch HTML, haven't found an example of it though
322-
raw = f"{username} performed an action"
288+
raw = f"{username} performed an action."
323289

324290
self.raw = raw
325291
self.datetime_created = _time

0 commit comments

Comments
 (0)