From 64928cf4ea0602b3c1e1ccfbe65d006108cffa07 Mon Sep 17 00:00:00 2001 From: Reckless_Satoshi Date: Sat, 4 Jun 2022 10:29:21 -0700 Subject: [PATCH] Fix profile not showing, fix not connected, fix auto scroll chat --- chat/consumers.py | 18 ++-- frontend/src/components/BottomBar.js | 4 +- frontend/src/components/Chat.js | 6 +- frontend/src/components/EncryptedChat.js | 115 +++++++++++------------ frontend/src/components/TradeBox.js | 3 + frontend/src/components/UserGenPage.js | 4 +- frontend/static/css/index.css | 16 ++++ 7 files changed, 89 insertions(+), 77 deletions(-) diff --git a/chat/consumers.py b/chat/consumers.py index a04b76be..e5472a1d 100644 --- a/chat/consumers.py +++ b/chat/consumers.py @@ -2,7 +2,6 @@ from channels.generic.websocket import AsyncWebsocketConsumer from channels.db import database_sync_to_async from api.models import Order from chat.models import ChatRoom, Message -from django.utils import timezone import json @@ -11,15 +10,14 @@ class ChatRoomConsumer(AsyncWebsocketConsumer): @database_sync_to_async def allow_in_chatroom(self): order = Order.objects.get(id=self.order_id) - - if not order.status in [Order.Status.CCA, Order.Status.FSE]: - print("Order not in chat status") - return False - + + if not order.status in [Order.Status.CHA, Order.Status.FSE]: + print("Order is not in chat status") + return False + if not (order.maker == self.user or order.taker == self.user): print("Not allowed in this chat") return False - return True @database_sync_to_async @@ -161,13 +159,14 @@ class ChatRoomConsumer(AsyncWebsocketConsumer): # Send peer PGP public keys peer_public_key = await self.get_peer_PGP_public_key() + peer_connected = await self.is_peer_connected() await self.channel_layer.group_send( self.room_group_name, { "type": "chatroom_message", "message": peer_public_key, "nick": self.scope["user"].username, - "peer_connected": None, + "peer_connected": peer_connected, }, ) @@ -215,6 +214,7 @@ class ChatRoomConsumer(AsyncWebsocketConsumer): elif message[0:23] == '-----SERVE HISTORY-----': # If there is any stored message, serve them. msgs = await self.get_all_PGP_messages() + peer_connected = await self.is_peer_connected() for msg in msgs: await self.channel_layer.group_send( self.room_group_name, @@ -224,7 +224,7 @@ class ChatRoomConsumer(AsyncWebsocketConsumer): "time": msg['time'], "message": msg['message'], "nick": msg['nick'], - "peer_connected": None, + "peer_connected": peer_connected, }, ) else: diff --git a/frontend/src/components/BottomBar.js b/frontend/src/components/BottomBar.js index 08f17e2e..e37c5ace 100644 --- a/frontend/src/components/BottomBar.js +++ b/frontend/src/components/BottomBar.js @@ -130,7 +130,7 @@ bottomBarDesktop =()=>{ -
+
{ -
+
diff --git a/frontend/src/components/Chat.js b/frontend/src/components/Chat.js index 170a71b3..6d54e3a5 100644 --- a/frontend/src/components/Chat.js +++ b/frontend/src/components/Chat.js @@ -6,7 +6,7 @@ import ReconnectingWebSocket from 'reconnecting-websocket'; class Chat extends Component { // Deprecated chat component // Will still be used for ~1 week, until users change to robots with PGP keys - + constructor(props) { super(props); } @@ -105,7 +105,7 @@ class Chat extends Component { - + {this.state.messages.map((message, index) =>
  • @@ -157,7 +157,7 @@ class Chat extends Component { this.setState({ value: e.target.value }); this.value = this.state.value; }} - sx={{width: 214}} + sx={{width: 244}} /> diff --git a/frontend/src/components/EncryptedChat.js b/frontend/src/components/EncryptedChat.js index 191452f2..ca9ab66a 100644 --- a/frontend/src/components/EncryptedChat.js +++ b/frontend/src/components/EncryptedChat.js @@ -35,6 +35,7 @@ class Chat extends Component { waitingEcho: false, lastSent: '---BLANK---', latestIndex: 0, + scrollNow:false, }; rws = new ReconnectingWebSocket('ws://' + window.location.host + '/ws/chat/' + this.props.orderId + '/'); @@ -43,13 +44,6 @@ class Chat extends Component { this.rws.addEventListener('open', () => { console.log('Connected!'); this.setState({connected: true}); - // if ( this.state.peer_pub_key == null){ - // this.rws.send(JSON.stringify({ - // type: "message", - // message: "----PLEASE SEND YOUR PUBKEY----", - // nick: this.props.ur_nick, - // })); - // } this.rws.send(JSON.stringify({ type: "message", message: this.state.own_pub_key, @@ -64,19 +58,11 @@ class Chat extends Component { console.log('PGP message index', dataFromServer.index, ' latestIndex ',this.state.latestIndex); if (dataFromServer){ console.log(dataFromServer) - + this.setState({peer_connected: dataFromServer.peer_connected}) + // If we receive our own key on a message if (dataFromServer.message == this.state.own_pub_key){console.log("OWN PUB KEY RECEIVED!!")} - // If we receive a request to send our public key - // if (dataFromServer.message == `----PLEASE SEND YOUR PUBKEY----`) { - // this.rws.send(JSON.stringify({ - // type: "message", - // message: this.state.own_pub_key, - // nick: this.props.ur_nick, - // })); - // } else - // If we receive a public key other than ours (our peer key!) if (dataFromServer.message.substring(0,36) == `-----BEGIN PGP PUBLIC KEY BLOCK-----` && dataFromServer.message != this.state.own_pub_key) { if (dataFromServer.message == this.state.peer_pub_key){ @@ -106,6 +92,7 @@ class Chat extends Component { .then((decryptedData) => this.setState((state) => ({ + scrollNow: true, waitingEcho: this.state.waitingEcho == true ? (decryptedData.decryptedMessage == this.state.lastSent ? false: true ) : false, lastSent: decryptedData.decryptedMessage == this.state.lastSent ? '----BLANK----': this.state.lastSent, latestIndex: dataFromServer.index > this.state.latestIndex ? dataFromServer.index : this.state.latestIndex, @@ -124,7 +111,6 @@ class Chat extends Component { }) )); } - this.setState({peer_connected: dataFromServer.peer_connected}) } }); @@ -139,7 +125,10 @@ class Chat extends Component { } componentDidUpdate() { - this.scrollToBottom(); + if (this.state.scrollNow){ + this.scrollToBottom(); + this.setState({scrollNow:false}) + } } scrollToBottom = () => { @@ -190,7 +179,7 @@ class Chat extends Component { style={{backgroundColor: props.cardColor}} title={ -
    +
    {props.message.userNick} {props.message.validSignature ? @@ -222,7 +211,7 @@ class Chat extends Component { } subheader={this.state.showPGP[props.index] ? {props.message.time}
    {"Valid signature: " + props.message.validSignature}
    {props.message.encryptedMessage}
    : props.message.plainTextMessage} - subheaderTypographyProps={{sx: {wordWrap: "break-word", width: '200px', color: '#444444', fontSize: this.state.showPGP[props.index]? 11 : null }}} + subheaderTypographyProps={{sx: {wordWrap: "break-word", width: '215px', color: '#444444', fontSize: this.state.showPGP[props.index]? 11 : null }}} /> ) @@ -231,7 +220,7 @@ class Chat extends Component { render() { const { t } = this.props; return ( - + @@ -251,48 +240,52 @@ class Chat extends Component { - - {this.state.messages.map((message, index) => -
  • - {message.userNick == this.props.ur_nick ? - - : - - } -
  • )} -
    { this.messagesEnd = el; }}>
    -
    -
    - - - { - this.setState({ value: e.target.value }); - this.value = this.state.value; - }} - sx={{width: 214}} - /> - - - + + } + )} +
    { this.messagesEnd = el; }}>
    + + + + + { + this.setState({ value: e.target.value }); + this.value = this.state.value; + }} + sx={{width: 232}} + /> + + + + -
    - + +
    +
    + {t("The RoboSats staff will examine the statements and evidence provided. You need to build a complete case, as the staff cannot read the chat. It is best to provide a burner contact method with your statement. The satoshis in the trade escrow will be sent to the dispute winner, while the dispute loser will lose the bond.")} + + {t("Make sure to EXPORT the chat log using the button. Staff might request your chat log in order to solve discrepancies. It is your responsibility to store it.")} + diff --git a/frontend/src/components/UserGenPage.js b/frontend/src/components/UserGenPage.js index 4dae0e63..7840fca3 100644 --- a/frontend/src/components/UserGenPage.js +++ b/frontend/src/components/UserGenPage.js @@ -275,10 +275,10 @@ class UserGenPage extends Component { - + - + diff --git a/frontend/static/css/index.css b/frontend/static/css/index.css index f3ef752d..7fa15585 100644 --- a/frontend/static/css/index.css +++ b/frontend/static/css/index.css @@ -137,6 +137,22 @@ input[type=number] { .MuiButton-textInherit {color : '#111111';} +::-webkit-scrollbar + { + width: 6px; /* for vertical scrollbars */ + height: 6px; /* for horizontal scrollbars */ + } + + ::-webkit-scrollbar-track + { + background: rgba(0, 0, 0, 0.1); + } + + ::-webkit-scrollbar-thumb + { + background: rgba(0, 0, 0, 0.5); + } + @media (max-width: 929px) { .MuiDataGrid-columnHeaders + div { width: auto !important;