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

Resolve #5900
This commit is contained in:
syuilo 2020-02-10 07:23:43 +09:00
parent 3d1239c1b4
commit 62683d8878
7 changed files with 93 additions and 73 deletions

View file

@ -202,7 +202,7 @@ export default Vue.extend({
}, },
widgets(): any[] { widgets(): any[] {
return this.$store.state.settings.widgets; return this.$store.state.deviceUser.widgets;
} }
}, },
@ -233,7 +233,7 @@ export default Vue.extend({
this.connection.on('notification', this.onNotification); this.connection.on('notification', this.onNotification);
if (this.widgets.length === 0) { if (this.widgets.length === 0) {
this.$store.dispatch('settings/setWidgets', [{ this.$store.commit('deviceUser/setWidgets', [{
name: 'calendar', name: 'calendar',
id: 'a', data: {} id: 'a', data: {}
}, { }, {
@ -504,9 +504,10 @@ export default Vue.extend({
this.$store.dispatch('switchAccount', { this.$store.dispatch('switchAccount', {
...i, ...i,
token: token token: token
}); }).then(() => {
location.reload(); location.reload();
}); });
});
}, },
onNotification(notification) { onNotification(notification) {
@ -552,7 +553,7 @@ export default Vue.extend({
items: widgets.map(widget => ({ items: widgets.map(widget => ({
text: this.$t('_widgets.' + widget), text: this.$t('_widgets.' + widget),
action: () => { action: () => {
this.$store.dispatch('settings/addWidget', { this.$store.commit('deviceUser/addWidget', {
name: widget, name: widget,
id: uuid(), id: uuid(),
data: {} data: {}
@ -564,11 +565,11 @@ export default Vue.extend({
}, },
removeWidget(widget) { removeWidget(widget) {
this.$store.dispatch('settings/removeWidget', widget); this.$store.commit('deviceUser/removeWidget', widget);
}, },
saveHome() { saveHome() {
this.$store.dispatch('settings/setWidgets', this.widgets); this.$store.commit('deviceUser/setWidgets', this.widgets);
} }
} }
}); });

View file

@ -179,7 +179,7 @@ export default Vue.extend({
watch: { watch: {
localOnly() { localOnly() {
this.$store.commit('device/setLocalOnly', this.localOnly); this.$store.commit('deviceUser/setLocalOnly', this.localOnly);
} }
}, },
@ -215,9 +215,9 @@ export default Vue.extend({
} }
// //
this.applyVisibility(this.$store.state.settings.rememberNoteVisibility ? this.$store.state.device.visibility : this.$store.state.settings.defaultNoteVisibility); this.applyVisibility(this.$store.state.settings.rememberNoteVisibility ? this.$store.state.deviceUser.visibility : this.$store.state.settings.defaultNoteVisibility);
this.localOnly = this.$store.state.settings.rememberNoteVisibility ? this.$store.state.device.localOnly : this.$store.state.settings.defaultNoteLocalOnly; this.localOnly = this.$store.state.settings.rememberNoteVisibility ? this.$store.state.deviceUser.localOnly : this.$store.state.settings.defaultNoteLocalOnly;
// //
if (this.reply && ['home', 'followers', 'specified'].includes(this.reply.visibility)) { if (this.reply && ['home', 'followers', 'specified'].includes(this.reply.visibility)) {

View file

@ -56,14 +56,14 @@ export default Vue.extend({
}, },
data() { data() {
return { return {
v: this.$store.state.settings.rememberNoteVisibility ? this.$store.state.device.visibility : (this.currentVisibility || this.$store.state.settings.defaultNoteVisibility), v: this.$store.state.settings.rememberNoteVisibility ? this.$store.state.deviceUser.visibility : (this.currentVisibility || this.$store.state.settings.defaultNoteVisibility),
faGlobe, faUnlock, faEnvelope, faHome faGlobe, faUnlock, faEnvelope, faHome
} }
}, },
methods: { methods: {
choose(visibility) { choose(visibility) {
if (this.$store.state.settings.rememberNoteVisibility) { if (this.$store.state.settings.rememberNoteVisibility) {
this.$store.commit('device/setVisibility', visibility); this.$store.commit('deviceUser/setVisibility', visibility);
} }
this.$emit('chosen', visibility); this.$emit('chosen', visibility);
this.destroyDom(); this.destroyDom();

View file

@ -91,13 +91,12 @@ export default Vue.extend({
this.enableLocalTimeline = !meta.disableLocalTimeline || this.$store.state.i.isModerator || this.$store.state.i.isAdmin this.enableLocalTimeline = !meta.disableLocalTimeline || this.$store.state.i.isModerator || this.$store.state.i.isAdmin
) && ['local', 'social'].includes(this.src)) this.src = 'home'; ) && ['local', 'social'].includes(this.src)) this.src = 'home';
}); });
if (this.$store.state.device.tl) {
this.src = this.$store.state.device.tl.src; this.src = this.$store.state.deviceUser.tl.src;
if (this.src === 'list') { if (this.src === 'list') {
this.list = this.$store.state.device.tl.arg; this.list = this.$store.state.deviceUser.tl.arg;
} else if (this.src === 'antenna') { } else if (this.src === 'antenna') {
this.antenna = this.$store.state.device.tl.arg; this.antenna = this.$store.state.deviceUser.tl.arg;
}
} }
}, },
@ -164,7 +163,7 @@ export default Vue.extend({
}, },
saveSrc() { saveSrc() {
this.$store.commit('device/setTl', { this.$store.commit('deviceUser/setTl', {
src: this.src, src: this.src,
arg: this.src == 'list' ? this.list : this.antenna arg: this.src == 'list' ? this.list : this.antenna
}); });

View file

@ -16,7 +16,15 @@ const defaultSettings = {
wallpaper: null, wallpaper: null,
memo: null, memo: null,
reactions: ['👍', '❤️', '😆', '🤔', '😮', '🎉', '💢', '😥', '😇', '🍮'], reactions: ['👍', '❤️', '😆', '🤔', '😮', '🎉', '💢', '😥', '😇', '🍮'],
widgets: [] };
const defaultDeviceUserSettings = {
visibility: 'public',
localOnly: false,
widgets: [],
tl: {
src: 'home'
},
}; };
const defaultDeviceSettings = { const defaultDeviceSettings = {
@ -27,16 +35,19 @@ const defaultDeviceSettings = {
autoReload: false, autoReload: false,
accounts: [], accounts: [],
recentEmojis: [], recentEmojis: [],
visibility: 'public',
localOnly: false,
themes: [], themes: [],
theme: 'light', theme: 'light',
animation: true, animation: true,
userData: {},
}; };
function copy(data) {
return JSON.parse(JSON.stringify(data));
}
export default (os: MiOS) => new Vuex.Store({ export default (os: MiOS) => new Vuex.Store({
plugins: [createPersistedState({ plugins: [createPersistedState({
paths: ['i', 'device', 'settings'] paths: ['i', 'device', 'deviceUser', 'settings']
})], })],
state: { state: {
@ -58,10 +69,11 @@ export default (os: MiOS) => new Vuex.Store({
}, },
actions: { actions: {
login(ctx, i) { async login(ctx, i) {
ctx.commit('updateI', i); ctx.commit('updateI', i);
ctx.dispatch('settings/merge', i.clientData); ctx.commit('settings/init', i.clientData);
ctx.dispatch('addAcount', { id: i.id, i: localStorage.getItem('i') }); ctx.commit('deviceUser/init', ctx.state.device.userData[i.id] || {});
await ctx.dispatch('addAcount', { id: i.id, i: localStorage.getItem('i') });
}, },
addAcount(ctx, info) { addAcount(ctx, info) {
@ -74,14 +86,17 @@ export default (os: MiOS) => new Vuex.Store({
}, },
logout(ctx) { logout(ctx) {
ctx.commit('device/setUserData', { userId: ctx.state.i.id, data: ctx.state.deviceUser });
ctx.commit('updateI', null); ctx.commit('updateI', null);
ctx.commit('settings/init', {});
ctx.commit('deviceUser/init', {});
localStorage.removeItem('i'); localStorage.removeItem('i');
}, },
switchAccount(ctx, i) { async switchAccount(ctx, i) {
ctx.commit('updateI', i); ctx.commit('device/setUserData', { userId: ctx.state.i.id, data: ctx.state.deviceUser });
ctx.commit('settings/init', i.clientData);
localStorage.setItem('i', i.token); localStorage.setItem('i', i.token);
await ctx.dispatch('login', i);
}, },
mergeMe(ctx, me) { mergeMe(ctx, me) {
@ -90,7 +105,7 @@ export default (os: MiOS) => new Vuex.Store({
} }
if (me.clientData) { if (me.clientData) {
ctx.dispatch('settings/merge', me.clientData); ctx.commit('settings/init', me.clientData);
} }
}, },
}, },
@ -106,6 +121,32 @@ export default (os: MiOS) => new Vuex.Store({
state[x.key] = x.value; state[x.key] = x.value;
}, },
setUserData(state, x: { userId: string; data: any }) {
state.userData[x.userId] = copy(x.data);
},
}
},
deviceUser: {
namespaced: true,
state: defaultDeviceUserSettings,
mutations: {
init(state, x) {
for (const [key, value] of Object.entries(defaultDeviceUserSettings)) {
if (x[key]) {
state[key] = x[key];
} else {
state[key] = value;
}
}
},
set(state, x: { key: string; value: any }) {
state[x.key] = x.value;
},
setTl(state, x) { setTl(state, x) {
state.tl = { state.tl = {
src: x.src, src: x.src,
@ -120,6 +161,25 @@ export default (os: MiOS) => new Vuex.Store({
setLocalOnly(state, localOnly) { setLocalOnly(state, localOnly) {
state.localOnly = localOnly; state.localOnly = localOnly;
}, },
setWidgets(state, widgets) {
state.widgets = widgets;
},
addWidget(state, widget) {
state.widgets.unshift(widget);
},
removeWidget(state, widget) {
state.widgets = state.widgets.filter(w => w.id != widget.id);
},
updateWidget(state, x) {
const w = state.widgets.find(w => w.id == x.id);
if (w) {
w.data = x.data;
}
},
} }
}, },
@ -145,13 +205,6 @@ export default (os: MiOS) => new Vuex.Store({
}, },
actions: { actions: {
merge(ctx, settings) {
if (settings == null) return;
for (const [key, value] of Object.entries(settings)) {
ctx.commit('set', { key, value });
}
},
set(ctx, x) { set(ctx, x) {
ctx.commit('set', x); ctx.commit('set', x);
@ -162,41 +215,6 @@ export default (os: MiOS) => new Vuex.Store({
}); });
} }
}, },
setWidgets(ctx, widgets) {
ctx.state.widgets = widgets;
ctx.dispatch('updateWidgets');
},
addWidget(ctx, widget) {
ctx.state.widgets.unshift(widget);
ctx.dispatch('updateWidgets');
},
removeWidget(ctx, widget) {
ctx.state.widgets = ctx.state.widgets.filter(w => w.id != widget.id);
ctx.dispatch('updateWidgets');
},
updateWidget(ctx, x) {
const w = ctx.state.widgets.find(w => w.id == x.id);
if (w) {
w.data = x.data;
ctx.dispatch('updateWidgets');
}
},
updateWidgets(ctx) {
const widgets = ctx.state.widgets;
ctx.commit('set', {
key: 'widgets',
value: widgets
});
os.api('i/update-client-setting', {
name: 'widgets',
value: widgets
});
},
} }
} }
} }

View file

@ -51,7 +51,7 @@ export default function <T extends object>(data: {
}, },
save() { save() {
this.$store.dispatch('settings/updateWidget', this.widget); this.$store.commit('deviceUser/updateWidget', this.widget);
} }
} }
}); });

View file

@ -3,6 +3,8 @@ import { Note } from '../../models/entities/note';
import { User } from '../../models/entities/user'; import { User } from '../../models/entities/user';
import { NoteUnreads, Antennas, AntennaNotes, Users } from '../../models'; import { NoteUnreads, Antennas, AntennaNotes, Users } from '../../models';
// TODO: 状態が変化していない場合は各種イベントを送信しない
/** /**
* Mark a note as read * Mark a note as read
*/ */