This commit is contained in:
syuilo 2018-02-24 07:49:03 +09:00
parent 482c86a25a
commit a2ed259501
6 changed files with 86 additions and 6 deletions

View file

@ -3,6 +3,7 @@
*/ */
import $ from 'cafy'; import $ from 'cafy';
import User from '../../models/user'; import User from '../../models/user';
import event from '../../event';
module.exports = async (params, user) => new Promise(async (res, rej) => { module.exports = async (params, user) => new Promise(async (res, rej) => {
// Get 'home' parameter // Get 'home' parameter
@ -30,6 +31,10 @@ module.exports = async (params, user) => new Promise(async (res, rej) => {
}); });
res(); res();
event(user._id, 'home_updated', {
home
});
} else { } else {
if (id == null && data == null) return rej('you need to set id and data params if home param unset'); if (id == null && data == null) return rej('you need to set id and data params if home param unset');
@ -47,5 +52,9 @@ module.exports = async (params, user) => new Promise(async (res, rej) => {
}); });
res(); res();
event(user._id, 'home_updated', {
id, data
});
} }
}); });

View file

@ -3,6 +3,7 @@
*/ */
import $ from 'cafy'; import $ from 'cafy';
import User from '../../models/user'; import User from '../../models/user';
import event from '../../event';
module.exports = async (params, user) => new Promise(async (res, rej) => { module.exports = async (params, user) => new Promise(async (res, rej) => {
// Get 'home' parameter // Get 'home' parameter
@ -29,6 +30,10 @@ module.exports = async (params, user) => new Promise(async (res, rej) => {
}); });
res(); res();
event(user._id, 'mobile_home_updated', {
home
});
} else { } else {
if (id == null && data == null) return rej('you need to set id and data params if home param unset'); if (id == null && data == null) return rej('you need to set id and data params if home param unset');
@ -46,5 +51,9 @@ module.exports = async (params, user) => new Promise(async (res, rej) => {
}); });
res(); res();
event(user._id, 'mobile_home_updated', {
id, data
});
} }
}); });

View file

@ -21,7 +21,9 @@ export default function<T extends object>(data: {
}, },
data() { data() {
return { return {
props: data.props ? data.props() : {} as T props: data.props ? data.props() : {} as T,
bakedOldProps: null,
preventSave: false
}; };
}, },
created() { created() {
@ -33,26 +35,40 @@ export default function<T extends object>(data: {
}); });
} }
this.bakeProps();
this.$watch('props', newProps => { this.$watch('props', newProps => {
const w = (this as any).os.i.client_settings.mobile_home.find(w => w.id == this.id); if (this.preventSave) {
this.preventSave = false;
return;
}
if (this.bakedOldProps == JSON.stringify(newProps)) return;
this.bakeProps();
if (this.isMobile) { if (this.isMobile) {
(this as any).api('i/update_mobile_home', { (this as any).api('i/update_mobile_home', {
id: this.id, id: this.id,
data: newProps data: newProps
}).then(() => { }).then(() => {
w.data = newProps; (this as any).os.i.client_settings.mobile_home.find(w => w.id == this.id).data = newProps;
}); });
} else { } else {
(this as any).api('i/update_home', { (this as any).api('i/update_home', {
id: this.id, id: this.id,
data: newProps data: newProps
}).then(() => { }).then(() => {
w.data = newProps; (this as any).os.i.client_settings.home.find(w => w.id == this.id).data = newProps;
}); });
} }
}, { }, {
deep: true deep: true
}); });
},
methods: {
bakeProps() {
this.bakedOldProps = JSON.stringify(this.props);
}
} }
}); });
} }

View file

@ -60,7 +60,7 @@
</template> </template>
<template v-else> <template v-else>
<div v-for="place in ['left', 'right']" :class="place"> <div v-for="place in ['left', 'right']" :class="place">
<component v-for="widget in widgets[place]" :is="`mkw-${widget.name}`" :key="widget.id" :widget="widget" @chosen="warp"/> <component v-for="widget in widgets[place]" :is="`mkw-${widget.name}`" :key="widget.id" :ref="widget.id" :widget="widget" @chosen="warp"/>
</div> </div>
<div class="main"> <div class="main">
<mk-post-form v-if="os.i.client_settings.showPostFormOnTopOfTl"/> <mk-post-form v-if="os.i.client_settings.showPostFormOnTopOfTl"/>
@ -90,6 +90,8 @@ export default Vue.extend({
}, },
data() { data() {
return { return {
connection: null,
connectionId: null,
widgetAdderSelected: null, widgetAdderSelected: null,
trash: [], trash: [],
widgets: { widgets: {
@ -131,6 +133,16 @@ export default Vue.extend({
deep: true deep: true
}); });
}, },
mounted() {
this.connection = (this as any).os.stream.getConnection();
this.connectionId = (this as any).os.stream.use();
this.connection.on('home_updated', this.onHomeUpdated);
},
beforeDestroy() {
this.connection.off('home_updated', this.onHomeUpdated);
(this as any).os.stream.dispose(this.connectionId);
},
methods: { methods: {
hint() { hint() {
(this as any).apis.dialog({ (this as any).apis.dialog({
@ -147,6 +159,22 @@ export default Vue.extend({
onTlLoaded() { onTlLoaded() {
this.$emit('loaded'); this.$emit('loaded');
}, },
onHomeUpdated(data) {
if (data.home) {
(this as any).os.i.client_settings.home = data.home;
this.widgets.left = data.home.filter(w => w.place == 'left');
this.widgets.right = data.home.filter(w => w.place == 'right');
} else {
const w = (this as any).os.i.client_settings.home.find(w => w.id == data.id);
if (w != null) {
w.data = data.data;
this.$refs[w.id][0].preventSave = true;
this.$refs[w.id][0].props = w.data;
this.widgets.left = (this as any).os.i.client_settings.home.filter(w => w.place == 'left');
this.widgets.right = (this as any).os.i.client_settings.home.filter(w => w.place == 'right');
}
}
},
onWidgetContextmenu(widgetId) { onWidgetContextmenu(widgetId) {
const w = (this.$refs[widgetId] as any)[0]; const w = (this.$refs[widgetId] as any)[0];
if (w.func) w.func(); if (w.func) w.func();

View file

@ -39,6 +39,7 @@ import wPolls from './widgets/polls.vue';
import wPostForm from './widgets/post-form.vue'; import wPostForm from './widgets/post-form.vue';
import wMessaging from './widgets/messaging.vue'; import wMessaging from './widgets/messaging.vue';
import wChannel from './widgets/channel.vue'; import wChannel from './widgets/channel.vue';
import wProfile from './widgets/profile.vue';
//#endregion //#endregion
Vue.component('mk-ui', ui); Vue.component('mk-ui', ui);
@ -80,4 +81,5 @@ Vue.component('mkw-polls', wPolls);
Vue.component('mkw-post-form', wPostForm); Vue.component('mkw-post-form', wPostForm);
Vue.component('mkw-messaging', wMessaging); Vue.component('mkw-messaging', wMessaging);
Vue.component('mkw-channel', wChannel); Vue.component('mkw-channel', wChannel);
Vue.component('mkw-profile', wProfile);
//#endregion //#endregion

View file

@ -51,7 +51,7 @@
</x-draggable> </x-draggable>
</template> </template>
<template v-else> <template v-else>
<component class="widget" v-for="widget in widgets" :is="`mkw-${widget.name}`" :key="widget.id" :widget="widget" :is-mobile="true" @chosen="warp"/> <component class="widget" v-for="widget in widgets" :is="`mkw-${widget.name}`" :key="widget.id" :ref="widget.id" :widget="widget" :is-mobile="true" @chosen="warp"/>
</template> </template>
</div> </div>
</main> </main>
@ -124,12 +124,14 @@ export default Vue.extend({
this.connectionId = (this as any).os.stream.use(); this.connectionId = (this as any).os.stream.use();
this.connection.on('post', this.onStreamPost); this.connection.on('post', this.onStreamPost);
this.connection.on('mobile_home_updated', this.onHomeUpdated);
document.addEventListener('visibilitychange', this.onVisibilitychange, false); document.addEventListener('visibilitychange', this.onVisibilitychange, false);
Progress.start(); Progress.start();
}, },
beforeDestroy() { beforeDestroy() {
this.connection.off('post', this.onStreamPost); this.connection.off('post', this.onStreamPost);
this.connection.off('mobile_home_updated', this.onHomeUpdated);
(this as any).os.stream.dispose(this.connectionId); (this as any).os.stream.dispose(this.connectionId);
document.removeEventListener('visibilitychange', this.onVisibilitychange); document.removeEventListener('visibilitychange', this.onVisibilitychange);
}, },
@ -152,6 +154,20 @@ export default Vue.extend({
document.title = 'Misskey'; document.title = 'Misskey';
} }
}, },
onHomeUpdated(data) {
if (data.home) {
(this as any).os.i.client_settings.mobile_home = data.home;
this.widgets = data.home;
} else {
const w = (this as any).os.i.client_settings.mobile_home.find(w => w.id == data.id);
if (w != null) {
w.data = data.data;
this.$refs[w.id][0].preventSave = true;
this.$refs[w.id][0].props = w.data;
this.widgets = (this as any).os.i.client_settings.mobile_home;
}
}
},
hint() { hint() {
alert('ウィジェットを追加/削除したり並べ替えたりできます。ウィジェットを移動するには「三」をドラッグします。ウィジェットを削除するには「x」をタップします。いくつかのウィジェットはタップすることで表示を変更できます。'); alert('ウィジェットを追加/削除したり並べ替えたりできます。ウィジェットを移動するには「三」をドラッグします。ウィジェットを削除するには「x」をタップします。いくつかのウィジェットはタップすることで表示を変更できます。');
}, },