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

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

View File

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

View File

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

View File

@ -9,10 +9,3 @@ module.exports = (me) ->
if @SIGNIN if @SIGNIN
@on \mount ~> me.on \updated @update @on \mount ~> me.on \updated @update
@on \unmount ~> me.off \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 get-state = ~> state
event.on \i_updated (data) ~> event.on \i_updated me.update
Object.assign me, data
me.trigger \updated
{ {
state-ev state-ev

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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