なんかもうめっちゃ変えた

This commit is contained in:
syuilo 2017-01-21 21:08:40 +09:00
parent cd6b681748
commit 5da436a285
10 changed files with 31 additions and 49 deletions

View file

@ -5,6 +5,8 @@
*/
import Appdata from '../../../models/appdata';
import User from '../../../models/user';
import serialize from '../../../serializers/user';
import event from '../../../event';
/**
* Set app data
@ -24,30 +26,34 @@ module.exports = (params, user, app, isSecure) =>
}
if (isSecure) {
const set = {
const _user = await User.findOneAndUpdate(user._id, {
$set: {
data: Object.assign(user.data || {}, JSON.parse(data))
}
};
await User.update({ _id: user._id }, set);
});
res(204);
// Publish i updated event
event(user._id, 'i_updated', await serialize(_user, user, {
detail: true,
includeSecrets: true
}));
} else {
const appdata = await Appdata.findOne({
app_id: app._id,
user_id: user._id
});
const set = {
$set: {
data: Object.assign((appdata || {}).data || {}, JSON.parse(data))
}
};
await Appdata.update({
app_id: app._id,
user_id: user._id
}, Object.assign({
app_id: app._id,
user_id: user._id
}, set), {
}, {
$set: {
data: Object.assign((appdata || {}).data || {}, JSON.parse(data))
}
}), {
upsert: true
});
res(204);

View file

@ -67,6 +67,11 @@ module.exports = callback => {
if (me != null) {
riot.observable(me);
me.update = data => {
if (data) Object.assign(me, data);
me.trigger('updated');
};
if (me.data.cache) {
localStorage.setItem('me', JSON.stringify(me));

View file

@ -9,10 +9,3 @@ module.exports = (me) ->
if @SIGNIN
@on \mount ~> me.on \updated @update
@on \unmount ~> me.off \updated @update
update-i: (data) ->
if data?
Object.assign me, data
me.trigger \updated
me: me

View file

@ -30,9 +30,7 @@ module.exports = (me) ~>
get-state = ~> state
event.on \i_updated (data) ~>
Object.assign me, data
me.trigger \updated
event.on \i_updated me.update
{
state-ev

View file

@ -55,11 +55,10 @@
e.stop-propagation!
@I.data.no_donation = true
@I.update!
@api \i/appdata/set do
data: JSON.stringify do
no_donation: @I.data.no_donation
.then ~>
@update-i!
@unmount!

View file

@ -81,21 +81,15 @@
@set-avatar = ~>
@refs.ctx.close!
@update-avatar @I, (i) ~>
@update-i i
, @file
@update-avatar @I, null, @file
@set-banner = ~>
@refs.ctx.close!
@update-banner @I, (i) ~>
@update-i i
, @file
@update-banner @I, null, @file
@set-wallpaper = ~>
@refs.ctx.close!
@update-wallpaper @I, (i) ~>
@update-i i
, @file
@update-wallpaper @I, null, @file
@add-app = ~>
@NotImplementedException!

View file

@ -46,11 +46,9 @@
@mixin \update-banner
@set-avatar = ~>
@update-avatar @I, (i) ~>
@update-i i
@update-avatar @I
@set-banner = ~>
@update-banner @I, (i) ~>
@update-i i
@update-banner @I
</script>
</mk-profile-home-widget>

View file

@ -35,8 +35,7 @@
@mixin \update-avatar
@set = ~>
@update-avatar @I, (i) ~>
@update-i i
@update-avatar @I
@close = (e) ~>
e.prevent-default!

View file

@ -35,8 +35,7 @@
@mixin \update-banner
@set = ~>
@update-banner @I, (i) ~>
@update-i i
@update-banner @I
@close = (e) ~>
e.prevent-default!

View file

@ -250,12 +250,10 @@
@page = page
@avatar = ~>
@update-avatar @I, (i) ~>
@update-i i
@update-avatar @I
@wallpaper = ~>
@update-wallpaper @I, (i) ~>
@update-i i
@update-wallpaper @I
@update-account = ~>
@api \i/update do
@ -264,7 +262,6 @@
bio: @refs.account-bio.value
birthday: @refs.account-birthday.value
.then (i) ~>
@update-i i
alert \ok
.catch (err) ~>
console.error err
@ -274,23 +271,17 @@
@api \i/appdata/set do
data: JSON.stringify do
cache: @I.data.cache
.then ~>
@update-i!
@update-debug = ~>
@I.data.debug = !@I.data.debug
@api \i/appdata/set do
data: JSON.stringify do
debug: @I.data.debug
.then ~>
@update-i!
@update-nya = ~>
@I.data.nya = !@I.data.nya
@api \i/appdata/set do
data: JSON.stringify do
nya: @I.data.nya
.then ~>
@update-i!
</script>
</mk-settings>