mirror of
https://github.com/MrUnknownDE/VRCX.git
synced 2026-04-18 14:23:51 +02:00
Move feed logs to SQLite 1
This commit is contained in:
145
html/src/app.js
145
html/src/app.js
@@ -41,7 +41,6 @@ speechSynthesis.getVoices();
|
||||
);
|
||||
|
||||
await configRepository.init();
|
||||
await database.init();
|
||||
|
||||
if (configRepository.getBool('migrate_config_20201101') === null) {
|
||||
var legacyConfigKeys = [
|
||||
@@ -5665,39 +5664,34 @@ speechSynthesis.getVoices();
|
||||
location = '';
|
||||
}
|
||||
var worldName = await this.getWorldName(location);
|
||||
this.addFeed('Offline', ctx.ref, {
|
||||
location,
|
||||
worldName,
|
||||
time
|
||||
});
|
||||
database.addOnlineOfflineToDatabase({
|
||||
var feed = {
|
||||
created_at: new Date().toJSON(),
|
||||
type: 'Offline',
|
||||
userId: ctx.ref.id,
|
||||
displayName: ctx.ref.displayName,
|
||||
type: 'Offline',
|
||||
location,
|
||||
worldName,
|
||||
time
|
||||
});
|
||||
};
|
||||
this.addFeed(feed);
|
||||
database.addOnlineOfflineToDatabase(feed);
|
||||
}
|
||||
} else if (newState === 'online') {
|
||||
ctx.ref.$location_at = Date.now();
|
||||
ctx.ref.$online_for = Date.now();
|
||||
ctx.ref.$offline_for = '';
|
||||
var worldName = await this.getWorldName(ctx.ref.location);
|
||||
this.addFeed('Online', ctx.ref, {
|
||||
location: ctx.ref.location,
|
||||
worldName
|
||||
});
|
||||
database.addOnlineOfflineToDatabase({
|
||||
var feed = {
|
||||
created_at: new Date().toJSON(),
|
||||
type: 'Online',
|
||||
userId: ctx.ref.id,
|
||||
displayName: ctx.ref.displayName,
|
||||
type: 'Online',
|
||||
location,
|
||||
worldName,
|
||||
time: ''
|
||||
});
|
||||
};
|
||||
this.addFeed(feed);
|
||||
database.addOnlineOfflineToDatabase(feed);
|
||||
}
|
||||
}
|
||||
if (ctx.state === 'online') {
|
||||
@@ -6118,9 +6112,11 @@ speechSynthesis.getVoices();
|
||||
}
|
||||
|
||||
API.$on('LOGIN', async function (args) {
|
||||
await database.init(args.json.id);
|
||||
$app.feedTable.data = await database.getFeedDatabase();
|
||||
//$app.feedTable.data = VRCXStorage.GetArray(`${args.ref.id}_feedTable`);
|
||||
//$app.sweepFeed();
|
||||
$app.sweepFeed();
|
||||
//remove old table
|
||||
VRCXStorage.Remove(`${args.ref.id}_feedTable`);
|
||||
});
|
||||
|
||||
API.$on('USER:UPDATE', async function (args) {
|
||||
@@ -6134,39 +6130,40 @@ speechSynthesis.getVoices();
|
||||
(props.location[1] !== 'offline') &&
|
||||
(props.location[1] !== '')) {
|
||||
var worldName = await $app.getWorldName(props.location[0]);
|
||||
$app.addFeed('GPS', ref, {
|
||||
location: props.location[0],
|
||||
worldName,
|
||||
previousLocation: props.location[1],
|
||||
time: props.location[2]
|
||||
});
|
||||
database.addGPSToDatabase({
|
||||
var feed = {
|
||||
created_at: new Date().toJSON(),
|
||||
type: 'GPS',
|
||||
userId: ref.id,
|
||||
displayName: ref.displayName,
|
||||
location: props.location[0],
|
||||
worldName,
|
||||
previousLocation: props.location[1],
|
||||
time: props.location[2]
|
||||
});
|
||||
};
|
||||
$app.addFeed(feed);
|
||||
database.addGPSToDatabase(feed);
|
||||
$app.updateFriendGPS(ref.id);
|
||||
$app.feedDownloadWorldCache(ref.id, props.location[0]);
|
||||
}
|
||||
if (props.currentAvatarImageUrl ||
|
||||
props.currentAvatarThumbnailImageUrl) {
|
||||
var currentAvatarImageUrl = '';
|
||||
var previousCurrentAvatarImageUrl = '';
|
||||
var currentAvatarThumbnailImageUrl = '';
|
||||
var previousCurrentAvatarThumbnailImageUrl = '';
|
||||
if (props.currentAvatarImageUrl) {
|
||||
var currentAvatarImageUrl = props.currentAvatarImageUrl[0];
|
||||
var previousCurrentAvatarImageUrl = props.currentAvatarImageUrl[1];
|
||||
currentAvatarImageUrl = props.currentAvatarImageUrl[0];
|
||||
previousCurrentAvatarImageUrl = props.currentAvatarImageUrl[1];
|
||||
} else {
|
||||
var currentAvatarImageUrl = ref.currentAvatarImageUrl;
|
||||
var previousCurrentAvatarImageUrl = ref.currentAvatarImageUrl;
|
||||
currentAvatarImageUrl = ref.currentAvatarImageUrl;
|
||||
previousCurrentAvatarImageUrl = ref.currentAvatarImageUrl;
|
||||
}
|
||||
if (props.currentAvatarThumbnailImageUrl) {
|
||||
var currentAvatarThumbnailImageUrl = props.currentAvatarThumbnailImageUrl[0];
|
||||
var previousCurrentAvatarThumbnailImageUrl = props.currentAvatarThumbnailImageUrl[1];
|
||||
currentAvatarThumbnailImageUrl = props.currentAvatarThumbnailImageUrl[0];
|
||||
previousCurrentAvatarThumbnailImageUrl = props.currentAvatarThumbnailImageUrl[1];
|
||||
} else {
|
||||
var currentAvatarThumbnailImageUrl = ref.currentAvatarThumbnailImageUrl;
|
||||
var previousCurrentAvatarThumbnailImageUrl = ref.currentAvatarThumbnailImageUrl;
|
||||
currentAvatarThumbnailImageUrl = ref.currentAvatarThumbnailImageUrl;
|
||||
previousCurrentAvatarThumbnailImageUrl = ref.currentAvatarThumbnailImageUrl;
|
||||
}
|
||||
var avatarInfo = {
|
||||
ownerId: '',
|
||||
@@ -6176,16 +6173,9 @@ speechSynthesis.getVoices();
|
||||
avatarInfo = await $app.getAvatarName(currentAvatarImageUrl);
|
||||
} catch (err) {
|
||||
}
|
||||
$app.addFeed('Avatar', ref, {
|
||||
ownerId: avatarInfo.ownerId,
|
||||
avatarName: avatarInfo.avatarName,
|
||||
currentAvatarImageUrl,
|
||||
currentAvatarThumbnailImageUrl,
|
||||
previousCurrentAvatarImageUrl,
|
||||
previousCurrentAvatarThumbnailImageUrl
|
||||
});
|
||||
database.addAvatarToDatabase({
|
||||
var feed = {
|
||||
created_at: new Date().toJSON(),
|
||||
type: 'Avatar',
|
||||
userId: ref.id,
|
||||
displayName: ref.displayName,
|
||||
ownerId: avatarInfo.ownerId,
|
||||
@@ -6194,63 +6184,56 @@ speechSynthesis.getVoices();
|
||||
currentAvatarThumbnailImageUrl,
|
||||
previousCurrentAvatarImageUrl,
|
||||
previousCurrentAvatarThumbnailImageUrl
|
||||
});
|
||||
};
|
||||
$app.addFeed(feed);
|
||||
database.addAvatarToDatabase(feed);
|
||||
}
|
||||
if (props.status ||
|
||||
props.statusDescription) {
|
||||
var status = '';
|
||||
var previousStatus = '';
|
||||
var statusDescription = '';
|
||||
var previousStatusDescription = '';
|
||||
if (props.status) {
|
||||
var status = props.status[0];
|
||||
var previousStatus = props.status[1];
|
||||
if (props.status[0]) {
|
||||
status = props.status[0];
|
||||
}
|
||||
if (props.status[1]) {
|
||||
previousStatus = props.status[1];
|
||||
}
|
||||
} else {
|
||||
var status = ref.status;
|
||||
var previousStatus = ref.status;
|
||||
status = ref.status;
|
||||
previousStatus = ref.status;
|
||||
}
|
||||
if (props.statusDescription) {
|
||||
var statusDescription = props.statusDescription[0];
|
||||
var previousStatusDescription = props.statusDescription[1];
|
||||
if (props.statusDescription[0]) {
|
||||
statusDescription = props.statusDescription[0];
|
||||
}
|
||||
if (props.statusDescription[1]) {
|
||||
previousStatusDescription = props.statusDescription[1];
|
||||
}
|
||||
} else {
|
||||
var statusDescription = ref.statusDescription;
|
||||
var previousStatusDescription = ref.statusDescription;
|
||||
statusDescription = ref.statusDescription;
|
||||
previousStatusDescription = ref.statusDescription;
|
||||
}
|
||||
$app.addFeed('Status', ref, {
|
||||
status,
|
||||
statusDescription,
|
||||
previousStatus,
|
||||
previousStatusDescription
|
||||
});
|
||||
database.addStatusToDatabase({
|
||||
var feed = {
|
||||
created_at: new Date().toJSON(),
|
||||
type: 'Status',
|
||||
userId: ref.id,
|
||||
displayName: ref.displayName,
|
||||
status,
|
||||
statusDescription,
|
||||
previousStatus,
|
||||
previousStatusDescription
|
||||
});
|
||||
};
|
||||
$app.addFeed(feed);
|
||||
database.addStatusToDatabase(feed);
|
||||
}
|
||||
});
|
||||
|
||||
var saveFeedTimer = null;
|
||||
$app.methods.saveFeed = function () {
|
||||
if (saveFeedTimer !== null) {
|
||||
return;
|
||||
}
|
||||
saveFeedTimer = setTimeout(() => {
|
||||
saveFeedTimer = null;
|
||||
VRCXStorage.SetArray(`${API.currentUser.id}_feedTable`, this.feedTable.data);
|
||||
}, 1);
|
||||
};
|
||||
|
||||
$app.methods.addFeed = function (type, ref, extra) {
|
||||
this.feedTable.data.push({
|
||||
created_at: new Date().toJSON(),
|
||||
type,
|
||||
userId: ref.id,
|
||||
displayName: ref.displayName,
|
||||
...extra
|
||||
});
|
||||
//this.sweepFeed();
|
||||
//this.saveFeed();
|
||||
$app.methods.addFeed = function (feed) {
|
||||
this.feedTable.data.push(feed);
|
||||
this.sweepFeed();
|
||||
this.updateSharedFeed(false);
|
||||
this.notifyMenu('feed');
|
||||
};
|
||||
|
||||
@@ -1,23 +1,27 @@
|
||||
import sqliteService from '../service/sqlite.js';
|
||||
|
||||
class Database {
|
||||
async init() {
|
||||
async init(userId) {
|
||||
Database.userId = userId.replaceAll('-', '').replaceAll('_', '');
|
||||
await sqliteService.executeNonQuery(
|
||||
'CREATE TABLE IF NOT EXISTS feed_gps (id INTEGER PRIMARY KEY, created_at TEXT, user_id TEXT, display_name TEXT, location TEXT, world_name TEXT, previous_location TEXT, time INTEGER)'
|
||||
`CREATE TABLE IF NOT EXISTS ${Database.userId}_feed_gps (id INTEGER PRIMARY KEY, created_at TEXT, user_id TEXT, display_name TEXT, location TEXT, world_name TEXT, previous_location TEXT, time INTEGER)`
|
||||
);
|
||||
await sqliteService.executeNonQuery(
|
||||
'CREATE TABLE IF NOT EXISTS feed_status (id INTEGER PRIMARY KEY, created_at TEXT, user_id TEXT, display_name TEXT, status TEXT, status_description TEXT, previous_status TEXT, previous_status_description TEXT)'
|
||||
`CREATE TABLE IF NOT EXISTS ${Database.userId}_feed_status (id INTEGER PRIMARY KEY, created_at TEXT, user_id TEXT, display_name TEXT, status TEXT, status_description TEXT, previous_status TEXT, previous_status_description TEXT)`
|
||||
);
|
||||
await sqliteService.executeNonQuery(
|
||||
'CREATE TABLE IF NOT EXISTS feed_avatar (id INTEGER PRIMARY KEY, created_at TEXT, user_id TEXT, display_name TEXT, owner_id TEXT, avatar_name TEXT, current_avatar_image_url TEXT, current_avatar_thumbnail_image_url TEXT, previous_current_avatar_image_url TEXT, previous_current_avatar_thumbnail_image_url TEXT)'
|
||||
`CREATE TABLE IF NOT EXISTS ${Database.userId}_feed_avatar (id INTEGER PRIMARY KEY, created_at TEXT, user_id TEXT, display_name TEXT, owner_id TEXT, avatar_name TEXT, current_avatar_image_url TEXT, current_avatar_thumbnail_image_url TEXT, previous_current_avatar_image_url TEXT, previous_current_avatar_thumbnail_image_url TEXT)`
|
||||
);
|
||||
await sqliteService.executeNonQuery(
|
||||
'CREATE TABLE IF NOT EXISTS 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)`
|
||||
);
|
||||
}
|
||||
|
||||
async getFeedDatabase() {
|
||||
var feedDatabase = [];
|
||||
var date = new Date();
|
||||
date.setDate(date.getDate() - 3); // 3 day limit
|
||||
var dateOffset = date.toJSON();
|
||||
await sqliteService.execute((dbRow) => {
|
||||
var row = {
|
||||
created_at: dbRow[1],
|
||||
@@ -30,7 +34,7 @@ class Database {
|
||||
time: dbRow[7]
|
||||
};
|
||||
feedDatabase.unshift(row);
|
||||
}, 'SELECT * FROM feed_gps');
|
||||
}, `SELECT * FROM ${Database.userId}_feed_gps WHERE created_at >= date('${dateOffset}')`);
|
||||
await sqliteService.execute((dbRow) => {
|
||||
var row = {
|
||||
created_at: dbRow[1],
|
||||
@@ -43,7 +47,7 @@ class Database {
|
||||
previousStatusDescription: dbRow[7]
|
||||
};
|
||||
feedDatabase.unshift(row);
|
||||
}, 'SELECT * FROM feed_status');
|
||||
}, `SELECT * FROM ${Database.userId}_feed_status WHERE created_at >= date('${dateOffset}')`);
|
||||
await sqliteService.execute((dbRow) => {
|
||||
var row = {
|
||||
created_at: dbRow[1],
|
||||
@@ -58,7 +62,7 @@ class Database {
|
||||
previousCurrentAvatarThumbnailImageUrl: dbRow[9]
|
||||
};
|
||||
feedDatabase.unshift(row);
|
||||
}, 'SELECT * FROM feed_avatar');
|
||||
}, `SELECT * FROM ${Database.userId}_feed_avatar WHERE created_at >= date('${dateOffset}')`);
|
||||
await sqliteService.execute((dbRow) => {
|
||||
var row = {
|
||||
created_at: dbRow[1],
|
||||
@@ -70,7 +74,7 @@ class Database {
|
||||
time: dbRow[7]
|
||||
};
|
||||
feedDatabase.unshift(row);
|
||||
}, 'SELECT * FROM feed_online_offline');
|
||||
}, `SELECT * FROM ${Database.userId}_feed_online_offline WHERE created_at >= date('${dateOffset}')`);
|
||||
var compareByCreatedAt = function (a, b) {
|
||||
var A = a.created_at;
|
||||
var B = b.created_at;
|
||||
@@ -88,7 +92,7 @@ class Database {
|
||||
|
||||
addGPSToDatabase(entry) {
|
||||
sqliteService.executeNonQuery(
|
||||
'INSERT OR IGNORE INTO 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)`,
|
||||
{
|
||||
'@created_at': entry.created_at,
|
||||
'@user_id': entry.userId,
|
||||
@@ -103,7 +107,7 @@ class Database {
|
||||
|
||||
addStatusToDatabase(entry) {
|
||||
sqliteService.executeNonQuery(
|
||||
'INSERT OR IGNORE INTO feed_status (created_at, user_id, display_name, status, status_description, previous_status, previous_status_description) VALUES (@created_at, @user_id, @display_name, @status, @status_description, @previous_status, @previous_status_description)',
|
||||
`INSERT OR IGNORE INTO ${Database.userId}_feed_status (created_at, user_id, display_name, status, status_description, previous_status, previous_status_description) VALUES (@created_at, @user_id, @display_name, @status, @status_description, @previous_status, @previous_status_description)`,
|
||||
{
|
||||
'@created_at': entry.created_at,
|
||||
'@user_id': entry.userId,
|
||||
@@ -118,7 +122,7 @@ class Database {
|
||||
|
||||
addAvatarToDatabase(entry) {
|
||||
sqliteService.executeNonQuery(
|
||||
'INSERT OR IGNORE INTO feed_avatar (created_at, user_id, display_name, owner_id, avatar_name, current_avatar_image_url, current_avatar_thumbnail_image_url, previous_current_avatar_image_url, previous_current_avatar_thumbnail_image_url) VALUES (@created_at, @user_id, @display_name, @owner_id, @avatar_name, @current_avatar_image_url, @current_avatar_thumbnail_image_url, @previous_current_avatar_image_url, @previous_current_avatar_thumbnail_image_url)',
|
||||
`INSERT OR IGNORE INTO ${Database.userId}_feed_avatar (created_at, user_id, display_name, owner_id, avatar_name, current_avatar_image_url, current_avatar_thumbnail_image_url, previous_current_avatar_image_url, previous_current_avatar_thumbnail_image_url) VALUES (@created_at, @user_id, @display_name, @owner_id, @avatar_name, @current_avatar_image_url, @current_avatar_thumbnail_image_url, @previous_current_avatar_image_url, @previous_current_avatar_thumbnail_image_url)`,
|
||||
{
|
||||
'@created_at': entry.created_at,
|
||||
'@user_id': entry.userId,
|
||||
@@ -135,7 +139,7 @@ class Database {
|
||||
|
||||
addOnlineOfflineToDatabase(entry) {
|
||||
sqliteService.executeNonQuery(
|
||||
'INSERT OR IGNORE INTO feed_online_offline (created_at, user_id, display_name, type, location, world_name, time) VALUES (@created_at, @user_id, @display_name, @type, @location, @world_name, @time)',
|
||||
`INSERT OR IGNORE INTO ${Database.userId}_feed_online_offline (created_at, user_id, display_name, type, location, world_name, time) VALUES (@created_at, @user_id, @display_name, @type, @location, @world_name, @time)`,
|
||||
{
|
||||
'@created_at': entry.created_at,
|
||||
'@user_id': entry.userId,
|
||||
|
||||
Reference in New Issue
Block a user