Get memos in bulk

This commit is contained in:
Natsumi
2022-05-18 11:29:11 +12:00
parent dd06090682
commit f710f1f55b
2 changed files with 39 additions and 6 deletions
+24 -6
View File
@@ -6329,6 +6329,21 @@ speechSynthesis.getVoices();
} }
}; };
$app.methods.getAllMemos = async function () {
var memeos = await database.getAllMemos();
memeos.forEach((memo) => {
var ref = $app.friends.get(memo.userId);
if (typeof ref !== 'undefined') {
ref.memo = memo.memo;
ref.$nickName = '';
if (memo.memo) {
var array = memo.memo.split('\n');
ref.$nickName = array[0];
}
}
});
};
// App: Friends // App: Friends
$app.data.friends = new Map(); $app.data.friends = new Map();
@@ -6530,14 +6545,16 @@ speechSynthesis.getVoices();
memo: '', memo: '',
$nickName: '' $nickName: ''
}; };
this.getMemo(id).then((memo) => { if (this.friendLogInitStatus) {
ctx.memo = memo; this.getMemo(id).then((memo) => {
ctx.$nickName = ''; ctx.memo = memo;
ctx.$nickName = '';
if (memo) { if (memo) {
var array = memo.split('\n'); var array = memo.split('\n');
ctx.$nickName = array[0]; ctx.$nickName = array[0];
} }
}); });
}
if (typeof ref === 'undefined') { if (typeof ref === 'undefined') {
ref = this.friendLog.get(id); ref = this.friendLog.get(id);
if (typeof ref !== 'undefined' && ref.displayName) { if (typeof ref !== 'undefined' && ref.displayName) {
@@ -7394,6 +7411,7 @@ speechSynthesis.getVoices();
} else { } else {
await $app.initFriendLog(args.json.id); await $app.initFriendLog(args.json.id);
} }
$app.getAllMemos();
if ($app.randomUserColours) { if ($app.randomUserColours) {
$app.getNameColour(this.currentUser.id).then((colour) => { $app.getNameColour(this.currentUser.id).then((colour) => {
this.currentUser.$userColour = colour; this.currentUser.$userColour = colour;
+15
View File
@@ -158,6 +158,21 @@ class Database {
return row; return row;
} }
async getAllMemos() {
var memos = [];
await sqliteService.execute(
(dbRow) => {
var row = {
userId: dbRow[0],
memo: dbRow[1]
};
memos.push(row);
},
'SELECT user_id, memo FROM memos'
);
return memos;
}
setMemo(entry) { setMemo(entry) {
sqliteService.executeNonQuery( sqliteService.executeNonQuery(
`INSERT OR REPLACE INTO memos (user_id, edited_at, memo) VALUES (@user_id, @edited_at, @memo)`, `INSERT OR REPLACE INTO memos (user_id, edited_at, memo) VALUES (@user_id, @edited_at, @memo)`,