scratchattach
scratchattach copied to clipboard
Parsing alerts
Should there be a separate class for admin messages/classroom alerts? They come in a somewhat different format to an activity.Activity
Currently, scratchattach just returns a list of dictionaries straight from the api (at least for classroom alerts; I am not certain about user alerts since I cannot test it right now)
I will make a parser for classroom alerts
<script type="text/template" id="template-alert-list-item">
<div class="alert-item-content" data-alert-id="<%- id %>">
<span class="alert-icon small"></span>
<% switch(admin_action.type)
{ case 0: %>
<a href='/users/<%- admin_action.target_user.username %>'><%- admin_action.target_user.username %></a> was
banned.
<% break; case 1: %>
<a href='/users/<%- admin_action.target_user.username %>'><%- admin_action.target_user.username %></a> was
unbanned.
<% break; case 2: %>
<a href='/users/<%- admin_action.target_user.username %>'><%- admin_action.target_user.username %></a> was
excluded from homepage.
<% break; case 3: %>
<a href='/users/<%- admin_action.target_user.username %>'><%- admin_action.target_user.username %></a> was
excluded from homepage.
<% break; case 4: %>
<a href='/users/<%- admin_action.target_user.username %>'><%- admin_action.target_user.username %></a> was
notified by a Scratch Administrator. Notification Type: <%- admin_action.extra_data.notification_type ||
'Unknown' %>
<% break; case 5: %>
<a href='/users/<%- admin_action.target_user.username %>'><%- admin_action.target_user.username %></a> was
banned automatically.
<% break; case 6: %>
<a href='/projects/<%- admin_action.object_id %>'><%- admin_action.extra_data.project_title %></a> by <a
href='/users/<%- admin_action.target_user.username %>'><%- admin_action.target_user.username %></a> was
removed automatically.
<% break; case 7: %>
<% case 20: %>
<a href='/projects/<%- admin_action.object_id %>'><%- admin_action.extra_data.project_title %></a> by <a
href='/users/<%- admin_action.target_user.username %>'><%- admin_action.target_user.username %></a> was
censored.
<% break; case 8: %>
<a href='/projects/<%- admin_action.object_id %>'><%- admin_action.extra_data.project_title %></a> by <a
href='/users/<%- admin_action.target_user.username %>'><%- admin_action.target_user.username %></a> was
uncensored.
<% break; case 9: %>
<% case 10: %>
<a href='/projects/<%- admin_action.object_id %>'><%- admin_action.extra_data.project_title %></a> by <a
href='/users/<%- admin_action.target_user.username %>'><%- admin_action.target_user.username %></a> was
reviewed by a Scratch Administrator.
<% break; case 11: %>
<a href='/projects/<%- admin_action.object_id %>'><%- admin_action.extra_data.project_title %></a> by <a
href='/users/<%- admin_action.target_user.username %>'><%- admin_action.target_user.username %></a> was
deleted by a Scratch Administrator.
<% break; case 12: %>
<% case 17: %>
<a href='/users/<%- admin_action.target_user.username %>'><%- admin_action.target_user.username %></a> was
deleted by a Scratch Administrator.
<% break; case 13: %>
<% case 14: %>
<a href='/studios/<%- admin_action.object_id %>'><%- admin_action.extra_data.gallery_title %></a> was reviewed
by a Scratch Administrator.
<% break; case 15: %>
<a href='/studios/<%- admin_action.object_id %>'><%- admin_action.extra_data.gallery_title %></a> was deleted by
a Scratch Administrator.
<% break; case 16: %>
<a href='/users/<%- admin_action.target_user.username %>'><%- admin_action.target_user.username %></a> deleted
their own account.
<% break; case 18: %>
The email address of <a href='/users/<%- admin_action.target_user.username %>'><%-
admin_action.target_user.username %></a> was confirmed by a Scratch Administrator
<% break; case 19: %>
The email address of <a href='/users/<%- admin_action.target_user.username %>'><%-
admin_action.target_user.username %></a> was set as not confirmed by a Scratch Administrator
<% break; case 22: %>
<% if(typeof admin_action.extra_data.comment_content == 'undefined'){ %>
<a href='/users/<%- admin_action.target_user.username %>'><%- admin_action.target_user.username %></a> was
automatically muted by our comment filters.
<% } else { %>
<a href='/users/<%- admin_action.target_user.username %>'><%- admin_action.target_user.username %></a> was
automatically muted by our comment filters. The comment they tried to post was: <i><%-
admin_action.extra_data.comment_content.content %></i>
<% } %>
<% break; default: %>
<a href='/users/<%- admin_action.target_user.username %>'><%- admin_action.target_user.username %></a> had an
admin action performed. <em><%- admin_action.type %></em>
<% break;} %>
<span class="time"><span class="media-info-item date shortDateFormat last"><%- $.format.date(admin_action.datetime_created, "MM/dd/yyyy") %></span></span>
<% if(typeof classroom_names !== 'undefined'){ %>
<div class="alert-classroom-data">Classes: <em><%- classroom_names %></em></div>
<% } %>
<% if(this.allowHideAlerts) { %>
<span data-control="hide-alert" data-message-id="<%= admin_action.message %>" class="delete">x</span>
<% } %>
</div>
</script>
using this from the scratch html as reference for parsing alert type