2018-04-29 03:17:15 -05:00
|
|
|
import Vuex from 'vuex';
|
2018-05-20 12:13:39 -05:00
|
|
|
import createPersistedState from 'vuex-persistedstate';
|
2018-08-21 19:10:39 -05:00
|
|
|
import * as nestedProperty from 'nested-property';
|
2018-05-20 12:13:39 -05:00
|
|
|
|
2018-04-29 07:37:51 -05:00
|
|
|
import MiOS from './mios';
|
2018-09-06 10:02:55 -05:00
|
|
|
import { erase } from '../../prelude/array';
|
2018-10-19 00:34:51 -05:00
|
|
|
import getNoteSummary from '../../misc/get-note-summary';
|
2018-04-29 03:17:15 -05:00
|
|
|
|
|
|
|
const defaultSettings = {
|
2019-01-23 05:43:06 -06:00
|
|
|
keepCw: false,
|
2018-09-16 19:00:20 -05:00
|
|
|
tagTimelines: [],
|
2018-04-29 03:17:15 -05:00
|
|
|
fetchOnScroll: true,
|
2018-11-16 08:13:37 -06:00
|
|
|
remainDeletedNote: false,
|
2018-04-29 03:17:15 -05:00
|
|
|
showPostFormOnTopOfTl: false,
|
2018-08-16 16:03:03 -05:00
|
|
|
suggestRecentHashtags: true,
|
2018-08-28 17:10:42 -05:00
|
|
|
showClockOnHeader: true,
|
2018-04-29 03:17:15 -05:00
|
|
|
circleIcons: true,
|
2018-09-06 15:45:13 -05:00
|
|
|
contrastedAcct: true,
|
2018-09-14 06:33:27 -05:00
|
|
|
showFullAcct: false,
|
2018-11-09 06:10:21 -06:00
|
|
|
showVia: true,
|
2018-04-29 03:17:15 -05:00
|
|
|
showReplyTarget: true,
|
|
|
|
showMyRenotes: true,
|
2018-05-25 06:19:14 -05:00
|
|
|
showRenotedMyNotes: true,
|
2018-08-16 09:59:22 -05:00
|
|
|
showLocalRenotes: true,
|
2018-05-25 06:19:14 -05:00
|
|
|
loadRemoteMedia: true,
|
2018-05-27 08:39:20 -05:00
|
|
|
disableViaMobile: false,
|
2018-06-18 03:25:20 -05:00
|
|
|
memo: null,
|
2018-06-23 02:55:52 -05:00
|
|
|
iLikeSushi: false,
|
2018-09-07 07:13:15 -05:00
|
|
|
rememberNoteVisibility: false,
|
|
|
|
defaultNoteVisibility: 'public',
|
2019-04-17 00:30:31 -05:00
|
|
|
wallpaper: null,
|
2018-11-28 20:05:17 -06:00
|
|
|
webSearchEngine: 'https://www.google.com/?#q={{query}}',
|
2018-11-11 06:17:51 -06:00
|
|
|
mutedWords: [],
|
2018-08-21 19:10:39 -05:00
|
|
|
games: {
|
|
|
|
reversi: {
|
|
|
|
showBoardLabels: false,
|
2018-12-29 23:05:13 -06:00
|
|
|
useAvatarStones: true,
|
2018-08-21 19:10:39 -05:00
|
|
|
}
|
|
|
|
}
|
2018-04-29 03:17:15 -05:00
|
|
|
};
|
|
|
|
|
2018-05-20 12:13:39 -05:00
|
|
|
const defaultDeviceSettings = {
|
2019-04-07 07:50:36 -05:00
|
|
|
home: null,
|
|
|
|
mobileHome: [],
|
2019-02-25 04:45:00 -06:00
|
|
|
deck: null,
|
|
|
|
deckMode: false,
|
|
|
|
deckColumnAlign: 'center',
|
|
|
|
deckColumnWidth: 'normal',
|
2019-02-25 23:28:38 -06:00
|
|
|
useShadow: false,
|
|
|
|
roundedCorners: true,
|
2018-09-16 07:40:48 -05:00
|
|
|
reduceMotion: false,
|
2019-02-25 23:28:38 -06:00
|
|
|
darkmode: true,
|
2019-03-17 06:48:55 -05:00
|
|
|
darkTheme: 'bb5a8287-a072-4b0a-8ae5-ea2a0d33f4f2',
|
2018-09-28 10:01:11 -05:00
|
|
|
lightTheme: 'light',
|
2018-12-30 09:59:13 -06:00
|
|
|
lineWidth: 1,
|
2019-02-28 17:08:08 -06:00
|
|
|
fontSize: 0,
|
2018-09-28 10:01:11 -05:00
|
|
|
themes: [],
|
2018-05-20 12:13:39 -05:00
|
|
|
enableSounds: true,
|
|
|
|
soundVolume: 0.5,
|
2019-02-03 04:33:23 -06:00
|
|
|
mediaVolume: 0.5,
|
2018-05-20 12:13:39 -05:00
|
|
|
lang: null,
|
|
|
|
debug: false,
|
|
|
|
lightmode: false,
|
2018-05-25 06:19:14 -05:00
|
|
|
loadRawImages: false,
|
2018-09-14 01:14:59 -05:00
|
|
|
alwaysShowNsfw: false,
|
2018-09-04 23:47:26 -05:00
|
|
|
postStyle: 'standard',
|
2018-10-14 05:44:30 -05:00
|
|
|
navbar: 'top',
|
2018-10-18 16:18:33 -05:00
|
|
|
mobileNotificationPosition: 'bottom',
|
2019-02-04 12:51:54 -06:00
|
|
|
useOsDefaultEmojis: false,
|
2019-02-23 19:38:53 -06:00
|
|
|
disableShowingAnimatedImages: false,
|
|
|
|
expandUsersPhotos: true,
|
|
|
|
expandUsersActivity: true,
|
2018-05-20 12:13:39 -05:00
|
|
|
};
|
|
|
|
|
2018-04-29 03:17:15 -05:00
|
|
|
export default (os: MiOS) => new Vuex.Store({
|
2018-05-26 23:49:09 -05:00
|
|
|
plugins: [createPersistedState({
|
|
|
|
paths: ['i', 'device', 'settings']
|
2018-05-20 12:13:39 -05:00
|
|
|
})],
|
2018-04-29 03:17:15 -05:00
|
|
|
|
|
|
|
state: {
|
2018-05-26 23:49:09 -05:00
|
|
|
i: null,
|
2018-05-17 09:53:55 -05:00
|
|
|
indicate: false,
|
2018-10-18 16:18:33 -05:00
|
|
|
uiHeaderHeight: 0,
|
2018-10-19 00:34:51 -05:00
|
|
|
behindNotes: []
|
2018-04-29 03:17:15 -05:00
|
|
|
},
|
|
|
|
|
2018-05-26 23:49:09 -05:00
|
|
|
getters: {
|
|
|
|
isSignedIn: state => state.i != null
|
|
|
|
},
|
|
|
|
|
2018-04-29 03:17:15 -05:00
|
|
|
mutations: {
|
2018-05-26 23:49:09 -05:00
|
|
|
updateI(state, x) {
|
|
|
|
state.i = x;
|
|
|
|
},
|
|
|
|
|
|
|
|
updateIKeyValue(state, x) {
|
|
|
|
state.i[x.key] = x.value;
|
|
|
|
},
|
|
|
|
|
2018-05-17 09:53:55 -05:00
|
|
|
indicate(state, x) {
|
|
|
|
state.indicate = x;
|
|
|
|
},
|
|
|
|
|
2018-04-29 03:17:15 -05:00
|
|
|
setUiHeaderHeight(state, height) {
|
|
|
|
state.uiHeaderHeight = height;
|
2018-10-18 16:18:33 -05:00
|
|
|
},
|
|
|
|
|
2018-10-19 00:34:51 -05:00
|
|
|
pushBehindNote(state, note) {
|
|
|
|
if (note.userId === state.i.id) return;
|
|
|
|
if (state.behindNotes.some(n => n.id === note.id)) return;
|
|
|
|
state.behindNotes.push(note);
|
|
|
|
document.title = `(${state.behindNotes.length}) ${getNoteSummary(note)}`;
|
|
|
|
},
|
|
|
|
|
|
|
|
clearBehindNotes(state) {
|
|
|
|
state.behindNotes = [];
|
|
|
|
document.title = os.instanceName;
|
2018-04-29 03:17:15 -05:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2018-05-26 23:49:09 -05:00
|
|
|
actions: {
|
|
|
|
login(ctx, i) {
|
|
|
|
ctx.commit('updateI', i);
|
2019-04-07 07:50:36 -05:00
|
|
|
ctx.dispatch('settings/merge', i.clientData);
|
2018-05-26 23:49:09 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
logout(ctx) {
|
|
|
|
ctx.commit('updateI', null);
|
2018-12-11 05:59:25 -06:00
|
|
|
document.cookie = 'i=;';
|
2018-11-28 01:19:02 -06:00
|
|
|
localStorage.removeItem('i');
|
2018-05-26 23:49:09 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
mergeMe(ctx, me) {
|
2018-12-11 05:36:55 -06:00
|
|
|
for (const [key, value] of Object.entries(me)) {
|
2018-05-26 23:49:09 -05:00
|
|
|
ctx.commit('updateIKeyValue', { key, value });
|
2018-12-11 05:36:55 -06:00
|
|
|
}
|
2018-05-26 23:49:09 -05:00
|
|
|
|
2019-04-07 07:50:36 -05:00
|
|
|
if (me.clientData) {
|
|
|
|
ctx.dispatch('settings/merge', me.clientData);
|
2018-05-26 23:49:09 -05:00
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2018-04-29 03:17:15 -05:00
|
|
|
modules: {
|
2018-05-20 12:13:39 -05:00
|
|
|
device: {
|
|
|
|
namespaced: true,
|
|
|
|
|
|
|
|
state: defaultDeviceSettings,
|
|
|
|
|
|
|
|
mutations: {
|
|
|
|
set(state, x: { key: string; value: any }) {
|
|
|
|
state[x.key] = x.value;
|
2018-05-26 10:18:44 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
setTl(state, x) {
|
|
|
|
state.tl = {
|
|
|
|
src: x.src,
|
|
|
|
arg: x.arg
|
|
|
|
};
|
2018-08-17 02:35:04 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
setVisibility(state, visibility) {
|
|
|
|
state.visibility = visibility;
|
2018-06-05 15:18:08 -05:00
|
|
|
},
|
|
|
|
|
2019-04-07 07:50:36 -05:00
|
|
|
setHome(state, data) {
|
|
|
|
state.home = data;
|
|
|
|
},
|
|
|
|
|
|
|
|
addHomeWidget(state, widget) {
|
|
|
|
state.home.unshift(widget);
|
|
|
|
},
|
|
|
|
|
|
|
|
setMobileHome(state, data) {
|
|
|
|
state.mobileHome = data;
|
|
|
|
},
|
|
|
|
|
|
|
|
updateWidget(state, x) {
|
|
|
|
let w;
|
|
|
|
|
|
|
|
//#region Desktop home
|
|
|
|
if (state.home) {
|
|
|
|
w = state.home.find(w => w.id == x.id);
|
|
|
|
if (w) {
|
|
|
|
w.data = x.data;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//#endregion
|
|
|
|
|
|
|
|
//#region Mobile home
|
|
|
|
if (state.mobileHome) {
|
|
|
|
w = state.mobileHome.find(w => w.id == x.id);
|
|
|
|
if (w) {
|
|
|
|
w.data = x.data;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//#endregion
|
|
|
|
},
|
|
|
|
|
|
|
|
addMobileHomeWidget(state, widget) {
|
|
|
|
state.mobileHome.unshift(widget);
|
|
|
|
},
|
|
|
|
|
|
|
|
removeMobileHomeWidget(state, widget) {
|
|
|
|
state.mobileHome = state.mobileHome.filter(w => w.id != widget.id);
|
|
|
|
},
|
|
|
|
|
2018-06-05 15:18:08 -05:00
|
|
|
addDeckColumn(state, column) {
|
2019-02-25 04:45:00 -06:00
|
|
|
if (column.name == undefined) column.name = null;
|
2018-06-05 15:18:08 -05:00
|
|
|
state.deck.columns.push(column);
|
2018-06-07 14:21:06 -05:00
|
|
|
state.deck.layout.push([column.id]);
|
2018-06-05 15:18:08 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
removeDeckColumn(state, id) {
|
|
|
|
state.deck.columns = state.deck.columns.filter(c => c.id != id);
|
2018-09-06 10:02:55 -05:00
|
|
|
state.deck.layout = state.deck.layout.map(ids => erase(id, ids));
|
2018-06-09 08:25:15 -05:00
|
|
|
state.deck.layout = state.deck.layout.filter(ids => ids.length > 0);
|
2018-06-05 15:18:08 -05:00
|
|
|
},
|
|
|
|
|
2018-06-07 18:38:32 -05:00
|
|
|
swapDeckColumn(state, x) {
|
|
|
|
const a = x.a;
|
|
|
|
const b = x.b;
|
|
|
|
const aX = state.deck.layout.findIndex(ids => ids.indexOf(a) != -1);
|
|
|
|
const aY = state.deck.layout[aX].findIndex(id => id == a);
|
|
|
|
const bX = state.deck.layout.findIndex(ids => ids.indexOf(b) != -1);
|
|
|
|
const bY = state.deck.layout[bX].findIndex(id => id == b);
|
|
|
|
state.deck.layout[aX][aY] = b;
|
|
|
|
state.deck.layout[bX][bY] = a;
|
|
|
|
},
|
|
|
|
|
2018-06-05 15:18:08 -05:00
|
|
|
swapLeftDeckColumn(state, id) {
|
2018-06-07 14:21:06 -05:00
|
|
|
state.deck.layout.some((ids, i) => {
|
|
|
|
if (ids.indexOf(id) != -1) {
|
|
|
|
const left = state.deck.layout[i - 1];
|
2018-06-05 15:18:08 -05:00
|
|
|
if (left) {
|
2019-02-25 04:45:00 -06:00
|
|
|
// https://vuejs.org/v2/guide/list.html#Caveats
|
|
|
|
//state.deck.layout[i - 1] = state.deck.layout[i];
|
|
|
|
//state.deck.layout[i] = left;
|
|
|
|
state.deck.layout.splice(i - 1, 1, state.deck.layout[i]);
|
|
|
|
state.deck.layout.splice(i, 1, left);
|
2018-06-05 15:18:08 -05:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
swapRightDeckColumn(state, id) {
|
2018-06-07 14:21:06 -05:00
|
|
|
state.deck.layout.some((ids, i) => {
|
|
|
|
if (ids.indexOf(id) != -1) {
|
|
|
|
const right = state.deck.layout[i + 1];
|
2018-06-05 15:18:08 -05:00
|
|
|
if (right) {
|
2019-02-25 04:45:00 -06:00
|
|
|
// https://vuejs.org/v2/guide/list.html#Caveats
|
|
|
|
//state.deck.layout[i + 1] = state.deck.layout[i];
|
|
|
|
//state.deck.layout[i] = right;
|
|
|
|
state.deck.layout.splice(i + 1, 1, state.deck.layout[i]);
|
|
|
|
state.deck.layout.splice(i, 1, right);
|
2018-06-05 15:18:08 -05:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
2018-06-06 05:22:45 -05:00
|
|
|
},
|
|
|
|
|
2018-06-07 14:34:15 -05:00
|
|
|
swapUpDeckColumn(state, id) {
|
|
|
|
const ids = state.deck.layout.find(ids => ids.indexOf(id) != -1);
|
|
|
|
ids.some((x, i) => {
|
|
|
|
if (x == id) {
|
|
|
|
const up = ids[i - 1];
|
|
|
|
if (up) {
|
2019-02-25 04:45:00 -06:00
|
|
|
// https://vuejs.org/v2/guide/list.html#Caveats
|
|
|
|
//ids[i - 1] = id;
|
|
|
|
//ids[i] = up;
|
|
|
|
ids.splice(i - 1, 1, id);
|
|
|
|
ids.splice(i, 1, up);
|
2018-06-07 14:34:15 -05:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
swapDownDeckColumn(state, id) {
|
|
|
|
const ids = state.deck.layout.find(ids => ids.indexOf(id) != -1);
|
|
|
|
ids.some((x, i) => {
|
|
|
|
if (x == id) {
|
|
|
|
const down = ids[i + 1];
|
|
|
|
if (down) {
|
2019-02-25 04:45:00 -06:00
|
|
|
// https://vuejs.org/v2/guide/list.html#Caveats
|
|
|
|
//ids[i + 1] = id;
|
|
|
|
//ids[i] = down;
|
|
|
|
ids.splice(i + 1, 1, id);
|
|
|
|
ids.splice(i, 1, down);
|
2018-06-07 14:34:15 -05:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2018-06-07 14:21:06 -05:00
|
|
|
stackLeftDeckColumn(state, id) {
|
|
|
|
const i = state.deck.layout.findIndex(ids => ids.indexOf(id) != -1);
|
2018-09-06 10:02:55 -05:00
|
|
|
state.deck.layout = state.deck.layout.map(ids => erase(id, ids));
|
2018-06-07 14:21:06 -05:00
|
|
|
const left = state.deck.layout[i - 1];
|
|
|
|
if (left) state.deck.layout[i - 1].push(id);
|
|
|
|
state.deck.layout = state.deck.layout.filter(ids => ids.length > 0);
|
|
|
|
},
|
|
|
|
|
|
|
|
popRightDeckColumn(state, id) {
|
|
|
|
const i = state.deck.layout.findIndex(ids => ids.indexOf(id) != -1);
|
2018-09-06 10:02:55 -05:00
|
|
|
state.deck.layout = state.deck.layout.map(ids => erase(id, ids));
|
2018-06-07 14:21:06 -05:00
|
|
|
state.deck.layout.splice(i + 1, 0, [id]);
|
|
|
|
state.deck.layout = state.deck.layout.filter(ids => ids.length > 0);
|
|
|
|
},
|
|
|
|
|
2018-06-06 05:22:45 -05:00
|
|
|
addDeckWidget(state, x) {
|
|
|
|
const column = state.deck.columns.find(c => c.id == x.id);
|
|
|
|
if (column == null) return;
|
|
|
|
column.widgets.unshift(x.widget);
|
|
|
|
},
|
|
|
|
|
|
|
|
removeDeckWidget(state, x) {
|
|
|
|
const column = state.deck.columns.find(c => c.id == x.id);
|
|
|
|
if (column == null) return;
|
|
|
|
column.widgets = column.widgets.filter(w => w.id != x.widget.id);
|
2018-06-06 16:13:57 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
renameDeckColumn(state, x) {
|
|
|
|
const column = state.deck.columns.find(c => c.id == x.id);
|
|
|
|
if (column == null) return;
|
|
|
|
column.name = x.name;
|
2018-04-29 03:54:50 -05:00
|
|
|
},
|
|
|
|
|
2019-02-25 04:45:00 -06:00
|
|
|
updateDeckColumn(state, x) {
|
|
|
|
let column = state.deck.columns.find(c => c.id == x.id);
|
|
|
|
if (column == null) return;
|
|
|
|
column = x;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2018-04-29 03:17:15 -05:00
|
|
|
|
2019-02-25 04:45:00 -06:00
|
|
|
settings: {
|
|
|
|
namespaced: true,
|
2018-04-29 03:17:15 -05:00
|
|
|
|
2019-02-25 04:45:00 -06:00
|
|
|
state: defaultSettings,
|
2018-06-05 15:18:08 -05:00
|
|
|
|
2019-02-25 04:45:00 -06:00
|
|
|
mutations: {
|
|
|
|
set(state, x: { key: string; value: any }) {
|
|
|
|
nestedProperty.set(state, x.key, x.value);
|
2018-06-06 05:22:45 -05:00
|
|
|
},
|
2019-02-25 04:45:00 -06:00
|
|
|
},
|
2018-06-07 14:21:06 -05:00
|
|
|
|
2019-02-25 04:45:00 -06:00
|
|
|
actions: {
|
|
|
|
merge(ctx, settings) {
|
|
|
|
if (settings == null) return;
|
|
|
|
for (const [key, value] of Object.entries(settings)) {
|
|
|
|
ctx.commit('set', { key, value });
|
|
|
|
}
|
2018-06-06 05:22:45 -05:00
|
|
|
},
|
|
|
|
|
2019-02-25 04:45:00 -06:00
|
|
|
set(ctx, x) {
|
|
|
|
ctx.commit('set', x);
|
2018-06-05 15:18:08 -05:00
|
|
|
|
2019-02-25 04:45:00 -06:00
|
|
|
if (ctx.rootGetters.isSignedIn) {
|
2019-04-18 07:36:44 -05:00
|
|
|
os.api('i/update-client-setting', {
|
2019-02-25 04:45:00 -06:00
|
|
|
name: x.key,
|
|
|
|
value: x.value
|
|
|
|
});
|
|
|
|
}
|
2018-06-06 16:13:57 -05:00
|
|
|
},
|
2018-04-29 03:17:15 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|