Fix some migration bugs

This commit is contained in:
Natsumi
2021-08-03 20:10:06 +12:00
parent a66ff77fce
commit c0b1b2d094
2 changed files with 13 additions and 29 deletions

View File

@@ -6181,7 +6181,7 @@ speechSynthesis.getVoices();
if (configRepository.getBool(`friendLogInit_${args.json.id}`)) {
$app.getFriendLog();
} else {
$app.initFriendLog();
$app.initFriendLog(args.json.id);
}
//remove old data from json file and migrate to SQLite
if (VRCXStorage.Get(`${args.json.id}_friendLogUpdatedAt`)) {
@@ -7161,14 +7161,7 @@ speechSynthesis.getVoices();
$app.data.friendLogInitStatus = false;
$app.methods.initFriendLog = async function () {
if (this.friendLogInitStatus) {
return;
}
if (configRepository.getBool(`friendLogInit_${API.currentUser.id}`)) {
this.friendLogInitStatus = true;
return;
}
$app.methods.initFriendLog = async function (userId) {
var sqlValues = [];
var friends = await API.refreshFriends();
for (var friend of friends) {
@@ -7182,32 +7175,17 @@ speechSynthesis.getVoices();
sqlValues.unshift(row);
}
database.setFriendLogCurrentArray(sqlValues);
configRepository.setBool(`friendLogInit_${API.currentUser.id}`, true);
configRepository.setBool(`friendLogInit_${userId}`, true);
this.friendLogInitStatus = true;
};
$app.methods.migrateFriendLog = function (userId) {
VRCXStorage.Remove(`${userId}_friendLogUpdatedAt`);
this.friendLog = new Map();
var oldFriendLog = VRCXStorage.GetObject(`${userId}_friendLog`);
var friendLogCurrentValues = [];
for (var i in oldFriendLog) {
var friend = oldFriendLog[i];
var row = {
userId: friend.id,
displayName: friend.displayName,
trustLevel: friend.trustLevel
};
this.friendLog.set(friend.id, row);
friendLogCurrentValues.unshift(row);
}
database.setFriendLogCurrentArray(friendLogCurrentValues);
VRCXStorage.Remove(`${userId}_friendLog`);
this.friendLogTable.data = VRCXStorage.GetArray(`${userId}_friendLogTable`);
database.addFriendLogHistoryArray(this.friendLogTable.data);
VRCXStorage.Remove(`${userId}_friendLogTable`);
configRepository.setBool(`friendLogInit_${API.currentUser.id}`, true);
this.friendLogInitStatus = true;
configRepository.setBool(`friendLogInit_${userId}`, true);
};
$app.methods.getFriendLog = async function () {

View File

@@ -168,12 +168,15 @@ class Database {
}
setFriendLogCurrentArray(inputData) {
if (inputData.length === 0) {
return;
}
var sqlValues = '';
var items = ['userId', 'displayName', 'trustLevel'];
for (var line of inputData) {
var field = {};
for (var item of items) {
var field = {};
if (typeof line[item] !== 'undefined') {
if (typeof line[item] === 'string') {
field[item] = line[item].replace(/'/g, "\''");
} else {
field[item] = '';
@@ -233,6 +236,9 @@ class Database {
}
addFriendLogHistoryArray(inputData) {
if (inputData.length === 0) {
return;
}
var sqlValues = '';
var items = ['created_at', 'type', 'userId', 'displayName', 'previousDisplayName', 'trustLevel', 'previousTrustLevel'];
for (var i = 0; i < inputData.length; ++i) {
@@ -241,7 +247,7 @@ class Database {
for (var k = 0; k < items.length; ++k) {
var item = items[k];
var field = '';
if (typeof line[item] !== 'undefined') {
if (typeof line[item] === 'string') {
field = `'${line[item].replace(/'/g, "\''")}'`;
} else {
field = null;