Skip to content
This repository has been archived by the owner on Jan 7, 2022. It is now read-only.

Commit

Permalink
Merge pull request #140 from ZbayApp/fix/onion
Browse files Browse the repository at this point in the history
Fix/onion
  • Loading branch information
vinkabuki authored Dec 17, 2020
2 parents eab605b + b9b9e63 commit bfa898b
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 58 deletions.
1 change: 1 addition & 0 deletions src/main/websockets/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export const connect = address =>
console.log(err)
})
socket.on('open', async function (a) {
console.log('opened websocket client connection')
const privKey = identity.signerPrivKey
const message = messages.createMessage({
messageData: {
Expand Down
89 changes: 42 additions & 47 deletions src/renderer/components/widgets/channels/ChannelMessages.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -179,89 +179,84 @@ export const ChannelMessages: React.FC<IChannelMessagesProps> = ({
ref={scrollbarRef}
autoHideTimeout={500}
renderView={renderView}
onScrollFrame={onScrollFrame}
>
onScrollFrame={onScrollFrame}>
<List
disablePadding
ref={msgRef}
id="messages-scroll"
id='messages-scroll'
className={classes.list}
style={{ marginTop: offset }}
>
{isOwner && <WelcomeMessage message={welcomeMessages["main"]} />}

style={{ marginTop: offset }}>
{isOwner && <WelcomeMessage message={welcomeMessages['main']} />}

{!isRescanned && !isDM && <RescanMessage />}
{/* {isOffer && !showLoader && (
<WelcomeMessage message={welcomeMessages['offer'](tag, username)} />
)} */}
{Object.keys(groupedMessages || []).map((key, i) => {
const messagesArray = groupedMessages[key];
const today = DateTime.utc();
const groupName = DateTime.fromSeconds(parseInt(key)).toFormat(
"cccc, LLL d"
);
const displayTitle = DateTime.fromSeconds(parseInt(key)).hasSame(
today,
"day"
)
? "Today"
: groupName;
const messagesArray = groupedMessages[key]
const today = DateTime.utc()
const groupName = DateTime.fromSeconds(parseInt(key)).toFormat('cccc, LLL d')
const displayTitle = DateTime.fromSeconds(parseInt(key)).hasSame(today, 'day')
? 'Today'
: groupName
return (
<>
<MessagesDivider title={displayTitle} />
{messagesArray.map((msg) => {
const MessageComponent = typeToMessageComponent[msg.type];
{messagesArray.map(msg => {
const MessageComponent = typeToMessageComponent[msg.type]
if (!msg.type) {
if (msg.keys) {
return (
<ChannelRegisteredMessage
message={msg}
address={
users[msg.owner] ? users[msg.owner].address : ""
}
address={users[msg.owner] ? users[msg.owner].address : ''}
username={
users[msg.owner]
? users[msg.owner].nickname
: `anon${msg.owner.substring(0, 16)}`
}
onChannelClick={() => {
onLinkedChannel(publicChannels[msg.name]);
onLinkedChannel(publicChannels[msg.name])
}}
/>
);
)
} else {
return <UserRegisteredMessage message={msg} />;
return <UserRegisteredMessage message={msg} />
}
}
return (
<MessageComponent
key={msg.id}
message={msg}
contactId={contactId}
/>
);
return <MessageComponent key={msg.id} message={msg} contactId={contactId} />
})}
</>
);
)
})}
{ isDM && ( <Grid container className={classes.root}>
<Grid item xs className={classes.item}>
<Typography variant='caption' className={classes.info}>
{isConnected ? <span>Connected to <span className={classes.bold}>@{name}</span> via Tor. Your message will be sent directly, not via Zcash memo.</span> : <span>Disconnected from <span className={classes.bold}>@{name}</span>. Your message will be sent via Zcash memo.</span>}
</Typography>
{isDM && name && (
<Grid container className={classes.root}>
<Grid item xs className={classes.item}>
<Typography variant='caption' className={classes.info}>
{isConnected ? (
<span>
Connected to <span className={classes.bold}>@{name}</span> via Tor. Your message
will be sent directly, not via Zcash memo.
</span>
) : (
<span>
Disconnected from <span className={classes.bold}>@{name}</span>. Your message
will be sent via Zcash memo.
</span>
)}
</Typography>
</Grid>
</Grid>
</Grid>
)
}
)}
{isNewUser && (
<WelcomeMessage
message={
<span>
Welcome to Zbay! To start quickly, Zbay includes username and
channel registration data in the app itself. To verify this
data, which takes ~1 hour but may add some security,
Welcome to Zbay! To start quickly, Zbay includes username and channel registration
data in the app itself. To verify this data, which takes ~1 hour but may add some
security,
<span className={classes.link} onClick={onRescan}>
{" "}
{' '}
restart & re-sync
</span>
. Otherwise, say hi and introduce yourself!
Expand All @@ -271,7 +266,7 @@ export const ChannelMessages: React.FC<IChannelMessagesProps> = ({
)}
</List>
</Scrollbars>
);
)
};

const typeToMessageComponent = {
Expand Down
28 changes: 17 additions & 11 deletions src/renderer/store/handlers/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -608,12 +608,23 @@ export const handleWebsocketMessage = data => async (dispatch, getState) => {
}
publicKey = getPublicKeysFromSignature(message).toString('hex')
const contact = contactsSelectors.contact(publicKey)(getState())
if (type === messageType.CONNECTION_ESTABLISHED) {
if (!contact.connected) {
//dispatch(contactsHandlers.actions.setContactConnected({ connected: true, key: publicKey }))
dispatch(contactsHandlers.epics.connectWsContacts(publicKey))
if (contact) {
dispatch(
contactsHandlers.actions.setTypingIndicator({
typingIndicator: !!typeIndicator,
contactAddress: publicKey
})
)
console.log('Received connection established message')
if (type === messageType.CONNECTION_ESTABLISHED) {
console.log('Contact exist')
if (!contact.connected) {
console.log('Contact is not connected, initializing connection')
//dispatch(contactsHandlers.actions.setContactConnected({ connected: true, key: publicKey }))
dispatch(contactsHandlers.epics.connectWsContacts(publicKey))
}
return
}
return
}
if (users !== undefined) {
const fromUser = users[publicKey]
Expand All @@ -631,12 +642,6 @@ export const handleWebsocketMessage = data => async (dispatch, getState) => {
isUnregistered = true
}
}
dispatch(
contactsHandlers.actions.setTypingIndicator({
typingIndicator: !!typeIndicator,
contactAddress: publicKey
})
)
} catch (err) {
console.warn(err)
return null
Expand Down Expand Up @@ -719,6 +724,7 @@ export const handleWebsocketMessage = data => async (dispatch, getState) => {
username: msg.sender.username
})
)
dispatch(contactsHandlers.epics.connectWsContacts(publicKey))
}
dispatch(
contactsHandlers.actions.addMessage({
Expand Down
2 changes: 2 additions & 0 deletions src/renderer/store/handlers/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,9 @@ export const registerOnionAddress = torStatus => async (dispatch, getState) => {
})
// dispatch(actionCreators.closeModal('accountSettingsModal')())
const txid = await client.sendTransaction(transfer)
console.log('sending transaction with onion address')
if (txid.error) {
console.log('error while sending transaction with onion address')
throw new Error(txid.error)
}
dispatch(
Expand Down

0 comments on commit bfa898b

Please sign in to comment.