mirror of
https://github.com/MrUnknownDE/VRCX.git
synced 2026-05-07 06:56:04 +02:00
Move memos to SQLite
This commit is contained in:
+41
-8
@@ -5284,17 +5284,40 @@ speechSynthesis.getVoices();
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
$app.methods.loadMemo = function (id) {
|
$app.methods.migrateMemos = function () {
|
||||||
var key = `memo_${id}`;
|
//move memos from json to SQLite
|
||||||
return VRCXStorage.Get(key);
|
var json = JSON.parse(VRCXStorage.GetAll());
|
||||||
|
for (var line in json) {
|
||||||
|
if (line.substring(0, 8) === 'memo_usr') {
|
||||||
|
var userId = line.substring(5);
|
||||||
|
var memo = json[line];
|
||||||
|
if (memo) {
|
||||||
|
console.log(userId);
|
||||||
|
this.saveMemo(userId, memo);
|
||||||
|
VRCXStorage.Remove(`memo_${userId}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
$app.methods.loadMemo = async function (userId) {
|
||||||
|
try {
|
||||||
|
var row = await database.getMemo(userId);
|
||||||
|
return row.memo;
|
||||||
|
} catch (err) {
|
||||||
|
}
|
||||||
|
return '';
|
||||||
};
|
};
|
||||||
|
|
||||||
$app.methods.saveMemo = function (id, memo) {
|
$app.methods.saveMemo = function (id, memo) {
|
||||||
var key = `memo_${id}`;
|
|
||||||
if (memo) {
|
if (memo) {
|
||||||
VRCXStorage.Set(key, String(memo));
|
database.setMemo({
|
||||||
|
userId: id,
|
||||||
|
editedAt: new Date().toJSON(),
|
||||||
|
memo
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
VRCXStorage.Remove(key);
|
database.deleteMemo(id);
|
||||||
}
|
}
|
||||||
var ref = this.friends.get(id);
|
var ref = this.friends.get(id);
|
||||||
if (ref) {
|
if (ref) {
|
||||||
@@ -5478,8 +5501,11 @@ speechSynthesis.getVoices();
|
|||||||
ref,
|
ref,
|
||||||
name: '',
|
name: '',
|
||||||
no: ++this.friendsNo,
|
no: ++this.friendsNo,
|
||||||
memo: this.loadMemo(id)
|
memo: ''
|
||||||
};
|
};
|
||||||
|
this.loadMemo(id).then((memo) => {
|
||||||
|
ctx.memo = memo;
|
||||||
|
});
|
||||||
if (typeof ref === 'undefined') {
|
if (typeof ref === 'undefined') {
|
||||||
ref = this.friendLog[id];
|
ref = this.friendLog[id];
|
||||||
if (typeof ref !== 'undefined' &&
|
if (typeof ref !== 'undefined' &&
|
||||||
@@ -6117,6 +6143,7 @@ speechSynthesis.getVoices();
|
|||||||
$app.sweepFeed();
|
$app.sweepFeed();
|
||||||
//remove old table
|
//remove old table
|
||||||
VRCXStorage.Remove(`${args.ref.id}_feedTable`);
|
VRCXStorage.Remove(`${args.ref.id}_feedTable`);
|
||||||
|
$app.migrateMemos();
|
||||||
});
|
});
|
||||||
|
|
||||||
API.$on('USER:UPDATE', async function (args) {
|
API.$on('USER:UPDATE', async function (args) {
|
||||||
@@ -8591,7 +8618,13 @@ speechSynthesis.getVoices();
|
|||||||
D.userIcon = '';
|
D.userIcon = '';
|
||||||
D.id = userId;
|
D.id = userId;
|
||||||
D.treeData = [];
|
D.treeData = [];
|
||||||
D.memo = this.loadMemo(userId);
|
this.loadMemo(userId).then((memo) => {
|
||||||
|
D.memo = memo;
|
||||||
|
var ref = this.friends.get(userId);
|
||||||
|
if (ref) {
|
||||||
|
ref.memo = String(memo || '');
|
||||||
|
}
|
||||||
|
});
|
||||||
D.visible = true;
|
D.visible = true;
|
||||||
D.loading = true;
|
D.loading = true;
|
||||||
D.avatars = [];
|
D.avatars = [];
|
||||||
|
|||||||
@@ -15,6 +15,9 @@ class Database {
|
|||||||
await sqliteService.executeNonQuery(
|
await sqliteService.executeNonQuery(
|
||||||
`CREATE TABLE IF NOT EXISTS ${Database.userId}_feed_online_offline (id INTEGER PRIMARY KEY, created_at TEXT, user_id TEXT, display_name TEXT, type TEXT, location TEXT, world_name TEXT, time INTEGER)`
|
`CREATE TABLE IF NOT EXISTS ${Database.userId}_feed_online_offline (id INTEGER PRIMARY KEY, created_at TEXT, user_id TEXT, display_name TEXT, type TEXT, location TEXT, world_name TEXT, time INTEGER)`
|
||||||
);
|
);
|
||||||
|
await sqliteService.executeNonQuery(
|
||||||
|
`CREATE TABLE IF NOT EXISTS memos (user_id TEXT PRIMARY KEY, edited_at TEXT, memo TEXT)`
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async getFeedDatabase() {
|
async getFeedDatabase() {
|
||||||
@@ -90,6 +93,38 @@ class Database {
|
|||||||
return feedDatabase;
|
return feedDatabase;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async getMemo(userId) {
|
||||||
|
var row = {};
|
||||||
|
await sqliteService.execute((dbRow, userId) => {
|
||||||
|
row = {
|
||||||
|
userId: dbRow[0],
|
||||||
|
editedAt: dbRow[1],
|
||||||
|
memo: dbRow[2]
|
||||||
|
};
|
||||||
|
}, `SELECT * FROM memos WHERE user_id = '${userId}'`);
|
||||||
|
return row;
|
||||||
|
}
|
||||||
|
|
||||||
|
setMemo(entry) {
|
||||||
|
sqliteService.executeNonQuery(
|
||||||
|
`INSERT OR REPLACE INTO memos (user_id, edited_at, memo) VALUES (@user_id, @edited_at, @memo)`,
|
||||||
|
{
|
||||||
|
'@user_id': entry.userId,
|
||||||
|
'@edited_at': entry.editedAt,
|
||||||
|
'@memo': entry.memo
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
deleteMemo(userId) {
|
||||||
|
sqliteService.executeNonQuery(
|
||||||
|
`DELETE FROM memos WHERE user_id = @user_id`,
|
||||||
|
{
|
||||||
|
'@user_id': userId
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
addGPSToDatabase(entry) {
|
addGPSToDatabase(entry) {
|
||||||
sqliteService.executeNonQuery(
|
sqliteService.executeNonQuery(
|
||||||
`INSERT OR IGNORE INTO ${Database.userId}_feed_gps (created_at, user_id, display_name, location, world_name, previous_location, time) VALUES (@created_at, @user_id, @display_name, @location, @world_name, @previous_location, @time)`,
|
`INSERT OR IGNORE INTO ${Database.userId}_feed_gps (created_at, user_id, display_name, location, world_name, previous_location, time) VALUES (@created_at, @user_id, @display_name, @location, @world_name, @previous_location, @time)`,
|
||||||
|
|||||||
Reference in New Issue
Block a user