Todo migration

pull/1/head
yflory 5 years ago
parent fb10d65a4f
commit de684edfe2

@ -12,7 +12,7 @@ define(function() {
* You should never remove the drive from this list. * You should never remove the drive from this list.
*/ */
config.availablePadTypes = ['drive', 'teams', 'pad', 'sheet', 'code', 'slide', 'poll', 'kanban', 'whiteboard', config.availablePadTypes = ['drive', 'teams', 'pad', 'sheet', 'code', 'slide', 'poll', 'kanban', 'whiteboard',
/*'oodoc', 'ooslide',*/ 'file', 'todo', 'contacts']; /*'oodoc', 'ooslide',*/ 'file', /*'todo',*/ 'contacts'];
/* The registered only types are apps restricted to registered users. /* The registered only types are apps restricted to registered users.
* You should never remove apps from this list unless you know what you're doing. The apps * You should never remove apps from this list unless you know what you're doing. The apps
* listed here by default can't work without a user account. * listed here by default can't work without a user account.

@ -4,10 +4,12 @@ define([
'/common/common-hash.js', '/common/common-hash.js',
'/common/common-util.js', '/common/common-util.js',
'/common/common-messaging.js', '/common/common-messaging.js',
'/common/cryptget.js',
'/common/outer/mailbox.js', '/common/outer/mailbox.js',
'/customize/messages.js',
'/bower_components/nthen/index.js', '/bower_components/nthen/index.js',
'/bower_components/chainpad-crypto/crypto.js', '/bower_components/chainpad-crypto/crypto.js',
], function (AppConfig, Feedback, Hash, Util, Messaging, Mailbox, nThen, Crypto) { ], function (AppConfig, Feedback, Hash, Util, Messaging, Crypt, Mailbox, Messages, nThen, Crypto) {
// Start migration check // Start migration check
// Versions: // Versions:
// 1: migrate pad attributes // 1: migrate pad attributes
@ -320,6 +322,140 @@ define([
Feedback.send('Migrate-9', true); Feedback.send('Migrate-9', true);
userObject.version = version = 9; userObject.version = version = 9;
} }
}).nThen(function (waitFor) {
// Migration 10: deprecate todo
var fixTodo = function () {
var h = store.proxy.todo;
if (!h) { return; }
var next = waitFor(function () {
Feedback.send('Migrate-10', true);
userObject.version = version = 10; // XXX
});
var old;
var opts = {
network: store.network,
initialState: '{}',
metadata: {
owners: store.proxy.edPublic ? [store.proxy.edPublic] : []
}
};
nThen(function (w) {
Crypt.get(h, w(function (err, val) {
if (err || !val) {
w.abort();
next();
return;
}
try {
old = JSON.parse(val);
} catch (e) {} // We will abort in the next step in case of error
}), opts);
}).nThen(function (w) {
if (!old || typeof(old) !== "object") {
w.abort();
next();
return;
}
var k = {
content: {
data: {
"1": {
id: "1",
color: 'color6',
item: [],
title: Messages.kanban_todo
},
"2": {
id: "2",
color: 'color3',
item: [],
title: Messages.kanban_working
},
"3": {
id: "3",
color: 'color5',
item: [],
title: Messages.kanban_done
},
},
items: {},
list: [1, 2, 3]
},
metadata: {
title: Messages.type.todo,
defaultTitle: Messages.type.todo,
type: "kanban"
}
};
var i = 4;
var items = false;
(old.order || []).forEach(function (key) {
var data = old.data[key];
if (!data || !data.task) { return; }
items = true;
var column = data.state ? '3' : '1';
k.content.data[column].item.push(i);
k.content.items[i] = {
id: i,
title: data.task
};
i++;
});
if (!items) {
w.abort();
next();
return;
}
var newH = Hash.createRandomHash('kanban');
var secret = Hash.getSecrets('kanban', newH);
var oldSecret = Hash.getSecrets('todo', h);
Crypt.put(newH, JSON.stringify(k), w(function (err) {
if (err) {
w.abort();
next();
return;
}
if (store.rpc) {
store.rpc.pin([secret.channel], function () {
// Try to pin and ignore errors...
// Todo won't be available anyway so keep your unpinned kanban
});
store.rpc.unpin([oldSecret.channel], function () {
// Try to unpin and ignore errors...
});
}
var href = Hash.hashToHref(newH, 'kanban');
store.manager.addPad(['root'], {
title: Messages.type.todo,
owners: opts.metadata.owners,
channel: secret.channel,
href: href,
roHref: Hash.hashToHref(Hash.getViewHashFromKeys(secret), 'kanban'),
atime: +new Date(),
ctime: +new Date()
}, w(function (e) {
if (e) { return void console.error(e); }
delete store.proxy.todo;
var myData = Messaging.createData(userObject);
var ctx = { store: store };
Mailbox.sendTo(ctx, 'MOVE_TODO', {
user: myData,
href: href,
}, {
channel: myData.notifications,
curvePublic: myData.curvePublic
}, function (obj) {
if (obj && obj.error) { return void console.error(obj); }
});
}));
}), opts);
}).nThen(function () {
next();
});
};
if (version < 10) {
fixTodo();
}
/*}).nThen(function (waitFor) { /*}).nThen(function (waitFor) {
// Test progress bar in the loading screen // Test progress bar in the loading screen
var i = 0; var i = 0;

@ -365,6 +365,29 @@ define([
} }
}; };
Messages.todo_move = "Your todo list has been moved to the pad <b>{0}</b>, as the Todo app is now deprecated.";
handlers['MOVE_TODO'] = function(common, data) {
var content = data.content;
var msg = content.msg;
// Display the notification
var title = Util.fixHTML(Messages.type.todo);
var href = msg.content.href;
content.getFormatText = function() {
return Messages._getKey('todo_move', [title]);
};
if (href) {
content.handler = function() {
common.openURL(href);
defaultDismiss(common, data)();
};
}
if (!content.archived) {
content.dismissHandler = defaultDismiss(common, data);
}
};
// NOTE: don't forget to fixHTML everything returned by "getFormatText" // NOTE: don't forget to fixHTML everything returned by "getFormatText"

@ -508,6 +508,12 @@ define([
cb(true); cb(true);
}; };
// Make sure "todo migration" notifications are from yourself
handlers['MOVE_TODO'] = function (ctx, box, data, cb) {
var curve = ctx.store.proxy.curvePublic;
if (data.msg.author !== curve) { return void cb(true); }
cb();
};
// Hide duplicates when receiving a SHARE_PAD notification: // Hide duplicates when receiving a SHARE_PAD notification:
// Keep only one notification per channel: the stronger and more recent one // Keep only one notification per channel: the stronger and more recent one

@ -7,6 +7,7 @@ define([
'/common/sframe-common-outer.js' '/common/sframe-common-outer.js'
], function (nThen, ApiConfig, DomReady, RequireConfig, SFCommonO) { ], function (nThen, ApiConfig, DomReady, RequireConfig, SFCommonO) {
var requireConfig = RequireConfig(); var requireConfig = RequireConfig();
window.location.href = '/drive/';
// Loaded in load #2 // Loaded in load #2
nThen(function (waitFor) { nThen(function (waitFor) {

Loading…
Cancel
Save