Skip to content

Commit

Permalink
Improved group loading times
Browse files Browse the repository at this point in the history
  • Loading branch information
f-r00t committed May 23, 2024
1 parent cf3d40d commit 8646d6f
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 18 deletions.
50 changes: 35 additions & 15 deletions src/Database.js
Original file line number Diff line number Diff line change
Expand Up @@ -1417,13 +1417,8 @@ export async function getMessages(conversation=false, limit=25) {

export async function getGroupMessages(group=false, limit=25) {

const stack = new Error().stack;
const callerInfo = stack.split('\n');

if (limit < 25) limit = 25;

const starttime = Date.now();

const [data] = await database.executeSql(
`
SELECT
Expand Down Expand Up @@ -1459,6 +1454,8 @@ export async function getGroupMessages(group=false, limit=25) {

if (data && data.rows && data.rows.length) {
const res = [];
const replies = [];
const replyHashes = [];

for (let i = 0; i < data.rows.length; i++) {
const item = data.rows.item(i);
Expand All @@ -1479,17 +1476,35 @@ export async function getGroupMessages(group=false, limit=25) {
};

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

replies.push({op: item.reply, reply: item.hash});
replyHashes.push(item.reply);

}

res.push(thisMessage);

}
console.log(res);

if (replyHashes) {
const ops = await getGroupsMessage(replyHashes);

console.log('ops ', ops);

for (op in ops) {
const thisReply = ops[op];
for (message in res) {
const thisMessage = res[message];
if (thisMessage.reply == thisReply.hash) {
res[message].replyNickname = thisReply.nickname;
res[message].replyMessage = thisReply.message;
break;
}
}
}

}

return res.reverse();
} else {
console.log('No message le found!');
Expand Down Expand Up @@ -1666,23 +1681,28 @@ export async function getBoardsMessages(board='Home') {
return [];
}

export async function getGroupsMessage(hash) {
export async function getGroupsMessage(hashes) {

hashes = hashes.join('", "')
hashes = '"' + hashes + '"';

console.log(hashes);

const [data] = await database.executeSql(
`SELECT
*
FROM
privateboards_messages_db WHERE hash = '${hash}'`
privateboards_messages_db WHERE hash IN (${hashes})`
);

if (data && data.rows && data.rows.length) {
const res = [];

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

return res;
}

return false;
Expand Down
9 changes: 6 additions & 3 deletions src/Groups.js
Original file line number Diff line number Diff line change
Expand Up @@ -897,10 +897,13 @@ export class GroupChatScreenNoTranslation extends React.Component {
{thisMessage.type == 'failed' && <TouchableOpacity style={{marginBottom: 10}} onPress={() => {removeGroupMessage(thisMessage.timestamp); submitMessage(thisMessage.message)}}><Text style={{fontSize: 10}}>Message failed to send. Tap here to try again.</Text></TouchableOpacity>}
{thisMessage.replyMessage &&
<TouchableOpacity onPress={async () => {
console.log(thisMessage);

this.state.replies = await getReplies(thisMessage.reply);

this.setActivePost(await getGroupsMessage(thisMessage.reply));

let newActivePost = await getGroupsMessage([thisMessage.reply]);
newActivePost = newActivePost[0];

this.setActivePost(newActivePost);

this.setMessageModalVisible(true);

Expand Down

0 comments on commit 8646d6f

Please sign in to comment.