Skip to content

Commit

Permalink
Merge branch 'master' into feat/components
Browse files Browse the repository at this point in the history
  • Loading branch information
f-r00t authored May 16, 2024
2 parents 12da54a + d22c61f commit 25934c5
Show file tree
Hide file tree
Showing 5 changed files with 258 additions and 121 deletions.
108 changes: 103 additions & 5 deletions src/Database.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,10 +267,11 @@ async function createTables(DB) {
)`
);

tx.executeSql(
`CREATE TABLE IF NOT EXISTS misc (
lastSyncGroup TEXT
lastSyncDM TEXT
tx.executeSql(
`CREATE TABLE IF NOT EXISTS sync_status (
id INTEGER PRIMARY KEY,
lastSyncGroup INT default 0,
lastSyncDM INT default 0
)`
);

Expand Down Expand Up @@ -641,6 +642,77 @@ export async function saveMessage(conversation, type, message, timestamp, read =

}

export async function setLastSyncGroup(timestamp) {

console.log('Setting last group msg synced to ', timestamp );

await database.transaction((tx) => {
tx.executeSql(
`UPDATE sync_status
SET lastSyncGroup = ? WHERE id = 1`,
[
timestamp
]
);

});

}



export async function setLastSyncDM(timestamp) {

console.log('Setting last DM msg synced to ', timestamp );

await database.transaction((tx) => {
tx.executeSql(
`UPDATE sync_status
SET lastSyncDM = ? WHERE id = 1`,
[
timestamp
]
);

});

}


export async function getLastSync() {

const [data] = await database.executeSql(
`SELECT lastSyncDM, lastSyncGroup FROM sync_status`
);

console.log('lastSync', data);

if (data && data.rows && data.rows.length) {

return data.rows.item(0);

} else {

await database.transaction((tx) => {
tx.executeSql(
`INSERT INTO sync_status
(lastSyncDM, lastSyncGroup)
VALUES
(?, ?)`,
[
0,0
]
);
});

return await getLastSync();

}

}



export async function updateMessage(temp_timestamp, type) {

console.log('Updating message', temp_timestamp, type);
Expand Down Expand Up @@ -1412,7 +1484,33 @@ export async function getGroupMessages(group = false, limit = 25) {
}
}

res.push(thisMessage);
for (let i = 0; i < data.rows.length; i++) {
const item = data.rows.item(i);

console.log(item);

const thisMessage = {
nickname: item.nickname,
type: item.type,
message: item.message,
timestamp: item.timestamp,
group: item.board,
address: item.address,
hash: item.hash,
reply: item.reply,
replies: item.replies,
count: count_raw,
};

if (thisMessage.reply != '') {
const thisOP = await getGroupsMessage(thisMessage.reply);
if (thisOP) {
thisMessage.replyNickname = thisOP.nickname;
thisMessage.replyMessage = thisOP.message;
}
}

res.push(thisMessage);

}
console.log(res);
Expand Down
24 changes: 14 additions & 10 deletions src/Globals.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@ import NetInfo from "@react-native-community/netinfo";

import { deleteUserPinCode } from '@haskkor/react-native-pincode';

import {
openDB, deleteDB, getKnownTransactions, getUnreadMessages, getGroupMessages, saveGroupToDatabase, loadPayeeDataFromDatabase, savePayeeToDatabase, removePayeeFromDatabase,
loadTransactionDetailsFromDatabase, saveTransactionDetailsToDatabase, removeGroupFromDatabase, getMessages, getBoardsMessages, getBoardSubscriptions, loadGroupsDataFromDatabase
} from './Database';
import { getLastSync, setHaveWallet, openDB, deleteDB, getKnownTransactions, getUnreadMessages, getGroupMessages, saveGroupToDatabase, removeMessages, loadPayeeDataFromDatabase, savePayeeToDatabase, removePayeeFromDatabase,
loadTransactionDetailsFromDatabase, saveTransactionDetailsToDatabase, removeGroupFromDatabase, getMessages, getLatestMessages, getBoardsMessages, getBoardSubscriptions, loadGroupsDataFromDatabase } from './Database';
import Config from './Config';
import { Logger } from './Logger';
import { makePostRequest } from './NativeCode';
Expand Down Expand Up @@ -171,11 +169,11 @@ class globals {
this.updateMessages();
}

removePayee(nickname, removeMessages) {
_.remove(Globals.payees, (item) => item.nickname === nickname);
removePayeeFromDatabase(nickname, removeMessages);
this.update();
}
updateGroupsFunction() {
Globals.updateGroupsFunctions.forEach((f) => {
f();
});
}

update() {
Globals.updatePayeeFunctions.forEach((f) => {
Expand Down Expand Up @@ -211,7 +209,8 @@ class globals {

async updateGroups() {

const groups = await loadGroupsDataFromDatabase();
// this.groupMessages = await getGroupMessages();
this.updateGroupsFunction();

if (groups !== undefined) {
Globals.groups = groups;
Expand Down Expand Up @@ -442,4 +441,9 @@ export async function initGlobals() {
await Globals.updateNodeList();
await Globals.updateGroupsList();

let lastSync = await getLastSync();

console.log('lastSync', lastSync);


}
7 changes: 6 additions & 1 deletion src/Groups.js
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,12 @@ export class GroupChatScreenNoTranslation extends React.Component {

markGroupConversationAsRead(this.state.key);

let messages = await getGroupMessages(this.state.key, 25);

Globals.updateGroupsFunctions.push(async () => {
this.setState({
messages: await getGroupMessages(this.state.key, Globals.messagesLoaded)
})
});

Globals.updateGroupsFunctions.push(async () => {
this.setState({
Expand Down
Loading

0 comments on commit 25934c5

Please sign in to comment.