Skip to content

Commit

Permalink
Split userinfo message into oo.authuser and oo.wsuser (See #41)
Browse files Browse the repository at this point in the history
  • Loading branch information
sffc committed Mar 29, 2021
1 parent 85461f2 commit fa7f9f5
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 25 deletions.
65 changes: 44 additions & 21 deletions client/app/js/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@ define(["jquery", "knockout", "canvg", "base64", "js/download", "ace/ext/static_
}
},
askForEnroll: function(program){
if(!OctMethods.editor.initialized){
if(!viewModel.currentUser()){
utils.alert(oo_translations["students.enroll.p1"]);
return;
}
Expand Down Expand Up @@ -844,7 +844,8 @@ define(["jquery", "knockout", "canvg", "base64", "js/download", "ace/ext/static_
socket.on("deleted", OctMethods.socketListeners.deleted);
// TODO: Stop this event from operating on everyone in a shared workspace
socket.on("binary", OctMethods.socketListeners.binary);
socket.on("userinfo", OctMethods.socketListeners.userinfo);
socket.on("oo.authuser", OctMethods.socketListeners.authuser);
socket.on("oo.wsuser", OctMethods.socketListeners.wsuser);
// The inconsistent naming convention here ("user" vs. "filelist") is for backwards compatibility. At some point I would like to rename this and other events all the way through the stack.
socket.on("user", OctMethods.socketListeners.filelist);
socket.on("fileadd", OctMethods.socketListeners.fileadd);
Expand Down Expand Up @@ -950,36 +951,56 @@ define(["jquery", "knockout", "canvg", "base64", "js/download", "ace/ext/static_
var blob = b64ToBlob(data.base64data, data.mime);
return download(blob, octfile.filename());
},
userinfo: function(data){
// One-time methods
if (!OctMethods.editor.initialized && data) {
OctMethods.editor.initialized = true;
authuser: function(data){
data = data && data.user;

// Trigger Knockout
data.name = data.name || data.displayName;
viewModel.currentUser(data);
if (!OctMethods.editor.seenAuthUser) {
OctMethods.editor.seenAuthUser = true;

// Legal runtime and other user settings
OctMethods.prompt.legalTime = data.legalTime;
OctMethods.prompt.countdownExtraTime = data.countdownExtraTime;
OctMethods.prompt.countdownRequestTime = data.countdownRequestTime;
viewModel.countdownExtraTimeSeconds(data.countdownExtraTime/1000);
// Ads setup
if (data && data.adsDisabled) {
$("#abox").hideSafe();
$("#main").css("top", 0);
$("#main").css("right", 0);
} else {
// TODO: Generalize this.
require(["fuse"]);
}

if (!data) {
return;
}

// Set up the UI
onboarding.showUserPromo(data);
onboarding.hideScriptPromo();
onboarding.hideBucketPromo();
if (data.adsDisabled) {
$(".adsbygoogle").css("display", "none");
$("#abox").hideSafe();
$("#main").css("top", 0);
$("#main").css("right", 0);
}

// Analytics
anal.signedin();
}
},
wsuser: function(data) {
data = data && data.user;

if (!OctMethods.editor.seenWsUser) {
OctMethods.editor.seenWsUser = true;

if (!data) {
return;
}

// Trigger Knockout
data.name = data.name || data.displayName;
viewModel.currentUser(data);

// Legal runtime and other user settings
OctMethods.prompt.legalTime = data.legalTime;
OctMethods.prompt.countdownExtraTime = data.countdownExtraTime;
OctMethods.prompt.countdownRequestTime = data.countdownRequestTime;
viewModel.countdownExtraTimeSeconds(data.countdownExtraTime/1000);
}
},
filelist: function(data){
// Load files
if (!data.success) {
Expand Down Expand Up @@ -1230,7 +1251,9 @@ define(["jquery", "knockout", "canvg", "base64", "js/download", "ace/ext/static_
defaultFilename: "my_script.m",
defaultContent: "disp(\"" + oo_translations["newfile.helloworld"] + "\");\n",
running: false,
initialized: false,
// AuthUser is the user who is currently signed in; WsUser is the user who owns the currently loaded workspace.
seenAuthUser: false,
seenWsUser: false,
bucketWarned: false,
save: function(octfile){
if (viewModel.purpose() === "bucket" && !OctMethods.editor.bucketWarned) {
Expand Down
2 changes: 1 addition & 1 deletion client/app/js/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,6 @@ setTimeout(function(){

// Load Social Bloatware (lowest priority)
setTimeout(function(){
require(["uservoice", "fuse"]);
require(["uservoice"]);
}, 500);

5 changes: 4 additions & 1 deletion front/src/socket_connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ export class SocketHandler implements IDestroyable {
init: ["user", "raw_init", ({user, raw_init}, next) => {
raw_init = raw_init || {};

// Send back auth user info
this.socket.emit("oo.authuser", { user });

// Process the user's requested action
let action = raw_init.action;
let info = raw_init.info;
Expand Down Expand Up @@ -204,7 +207,7 @@ export class SocketHandler implements IDestroyable {
case "project":
if (!bucket) return;
if (bucket.butype === "collab") {
// TODO: Should we start the collaborative session with the current user's tier or with the project owner's tier? For now, start it with the current user's tier.
// TODO(#41): Initialize the shared workspace with the project owner, not the auth user. Maybe pass null as the user here and then load the project owner inside SharedWorkspace.
this._log.info("Attaching to a collaborative project:", bucket.consoleText);
this.workspace = new SharedWorkspace(null, user, bucket, socket.id);
} else {
Expand Down
2 changes: 1 addition & 1 deletion front/src/workspace_normal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class NormalWorkspace
this._log = logger("workspace-nrm:uninitialized");

process.nextTick(()=>{
this.emit("data", "userinfo", user);
this.emit("data", "oo.wsuser", { user });
});
}

Expand Down
3 changes: 2 additions & 1 deletion front/src/workspace_shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,8 @@ export class SharedWorkspace
ready: ["user", ({user}, next) => {
this.user = user;
if (user) {
this.emit("data", "userinfo", user);
// TODO(#41): Make sure this is actually the workspace owner.
this.emit("data", "oo.wsuser", { user });
if (!this.wsId) {
this.setWsId(user.parametrized, true);
this._log.info("Connecting to student:", user.consoleText);
Expand Down

0 comments on commit fa7f9f5

Please sign in to comment.