Skip to content

Commit

Permalink
Improved replies and aligned look to desktop
Browse files Browse the repository at this point in the history
  • Loading branch information
f-r00t committed Apr 26, 2024
1 parent 5ff05e5 commit 2c511d5
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 28 deletions.
45 changes: 19 additions & 26 deletions src/Database.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,8 @@ async function createTables(DB) {
read BOOLEAN default 1,
hash TEXT,
reply TEXT,
replies INT default 0,
UNIQUE (timestamp)
replies INT default 0
)`
);

Expand Down Expand Up @@ -1366,7 +1366,7 @@ export async function getGroupMessages(group=false, limit=25) {

const [count] = await database.executeSql(
`
SELECT COUNT(*) FROM privateboards_messages_db WHERE reply = ''${group ? ' AND board = "' + group + '"' : ''}
SELECT COUNT(*) FROM privateboards_messages_db ${group ? ' WHERE board = "' + group + '"' : ''}
`
);

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

res.push({
thisMessage = {
nickname: item.nickname,
type: item.type,
message: item.message,
Expand All @@ -1402,9 +1402,20 @@ export async function getGroupMessages(group=false, limit=25) {
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);
return res.reverse();
} else {
console.log('No message le found!');
Expand Down Expand Up @@ -1585,14 +1596,7 @@ export async function getGroupsMessage(hash) {

const [data] = await database.executeSql(
`SELECT
nickname,
type,
message,
timestamp,
board,
address,
hash,
reply
*
FROM
privateboards_messages_db WHERE hash = '${hash}'`
);
Expand All @@ -1602,23 +1606,12 @@ export async function getGroupsMessage(hash) {

for (let i = 0; i < data.rows.length; i++) {
const item = data.rows.item(i);
console.log(item);
res.push({
message: item.message,
address: item.address,
board: item.board,
timestamp: item.timestamp,
nickname: item.nickname,
reply: item.reply,
hash: item.hash,
sent: item.type
});
return item;
}

return res;
}

return [];
return false;
}

export async function getBoardRecommendations() {
Expand Down
25 changes: 23 additions & 2 deletions src/Groups.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ import {intToRGB, hashCode, get_avatar, sendGroupsMessage, createGroup, getBoard

import {toastPopUp} from './Utilities';

import { loadGroupsDataFromDatabase, subscribeToGroup, markGroupConversationAsRead, getGroupMessages, getReplies, saveGroupMessage, removeGroupMessage} from './Database';
import { getGroupsMessage, loadGroupsDataFromDatabase, subscribeToGroup, markGroupConversationAsRead, getGroupMessages, getReplies, saveGroupMessage, removeGroupMessage} from './Database';

import './i18n.js';
import { withTranslation } from 'react-i18next';
Expand Down Expand Up @@ -895,7 +895,28 @@ export class GroupChatScreenNoTranslation extends React.Component {

{thisMessage.type == 'processing' && <View style={{position: 'absolute', top: 5, right: 5}}><ActivityIndicator /></View>}
{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));

this.setMessageModalVisible(true);

}}>
<View style={{flexDirection:"row", marginBottom: 10}}>
<View style={{marginTop: 8, marginRight: 5, width: 10, height: 10, borderTopLeftRadius: 4, borderColor: 'rgba(255,255,255,0.5)', borderLeftWidth: 1, borderTopWidth: 1}}></View>
<Text numberOfLines={1} ellipsizeMode={'tail'} style={{
color: '#ffffff',
fontSize: 12,
fontFamily: "Montserrat-SemiBold"
}}>{thisMessage.replyNickname ? thisMessage.replyNickname : t('Anonymous')}
</Text>
<Text selectable style={{ fontFamily: "Montserrat-Regular", fontSize: 12, paddingLeft: 5 }} >{thisMessage.replyMessage}</Text>
</View>
</TouchableOpacity>
}
<View style={{flexDirection:"row", marginBottom: 10}}>
<Image
style={{width: 30, height: 30, marginTop: -5}}
Expand Down

0 comments on commit 2c511d5

Please sign in to comment.