Fixes for API chatroom initialization

This commit is contained in:
Reckless_Satoshi 2022-11-15 08:38:31 -08:00
parent edc9659beb
commit c2fb0e27a0
No known key found for this signature in database
GPG Key ID: 9C4585B561315571
5 changed files with 38 additions and 15 deletions

View File

@ -48,7 +48,17 @@ class ChatView(viewsets.ViewSet):
)
queryset = Message.objects.filter(order=order, index__gt=offset)
chatroom = ChatRoom.objects.get(order=order)
chatroom, created = ChatRoom.objects.get_or_create(
id=order_id,
order=order,
room_group_name=f"chat_order_{order_id}",
defaults={
"maker": order.maker,
"maker_connected": order.maker == request.user,
"taker": order.taker,
"taker_connected": order.taker == request.user,
},
)
# Poor idea: is_peer_connected() mockup. Update connection status based on last time a GET request was sent
if chatroom.maker == request.user:
@ -171,7 +181,7 @@ class ChatView(viewsets.ViewSet):
# if offset is given, reply with messages
offset = serializer.data.get("offset", None)
if offset:
if offset or offset == 0:
queryset = Message.objects.filter(order=order, index__gt=offset)
messages = []
for message in queryset:

View File

@ -333,7 +333,13 @@ const Main = ({ settings, setSettings }: MainProps): JSX.Element => {
appear={slideDirection.in != undefined}
>
<div>
<OrderPage theme={theme} history={history} {...props} baseUrl={baseUrl} />
<OrderPage
theme={theme}
history={history}
{...props}
setPage={setPage}
baseUrl={baseUrl}
/>
</div>
</Slide>
)}

View File

@ -514,11 +514,11 @@ class OrderPage extends Component {
};
tokenDialog = () => {
return systemClient.getCookie('robot_token') ? (
return systemClient.getItem('robot_token') ? (
<StoreTokenDialog
open={this.state.openStoreToken}
onClose={() => this.setState({ openStoreToken: false })}
onClickCopy={() => systemClient.copyToClipboard(systemClient.getCookie('robot_token'))}
onClickCopy={() => systemClient.copyToClipboard(systemClient.getItem('robot_token'))}
copyIconColor={this.props.copiedToken ? 'inherit' : 'primary'}
onClickBack={() => this.setState({ openStoreToken: false })}
onClickDone={() =>
@ -532,6 +532,7 @@ class OrderPage extends Component {
<NoRobotDialog
open={this.state.openStoreToken}
onClose={() => this.setState({ openStoreToken: false })}
setPage={this.props.setPage}
/>
);
};

View File

@ -169,12 +169,14 @@ const EncryptedTurtleChat: React.FC<Props> = ({
apiClient
.post(baseUrl, `/api/chat`, {
PGP_message: value,
offset: lastIndex
offset: lastIndex,
})
.then((response) => {
if (response) {
if (response) {
setPeerConnected(response.peer_connected);
setServerMessages(response.messages);
if (response.messages) {
setServerMessages(response.messages);
}
}
})
.finally(() => {
@ -192,12 +194,14 @@ const EncryptedTurtleChat: React.FC<Props> = ({
.post(baseUrl, `/api/chat/`, {
PGP_message: encryptedMessage.toString().split('\n').join('\\'),
order_id: orderId,
offset: lastIndex
offset: lastIndex,
})
.then((response) => {
if (response) {
if (response) {
setPeerConnected(response.peer_connected);
setServerMessages(response.messages);
if (response.messages) {
setServerMessages(response.messages);
}
}
})
.finally(() => {

View File

@ -74,7 +74,7 @@ class TradeBox extends Component {
badInvoice: false,
badAddress: false,
badStatement: false,
turtleMode: window.ReactNativeWebView !== undefined
turtleMode: window.ReactNativeWebView !== undefined,
};
}
@ -1245,7 +1245,7 @@ class TradeBox extends Component {
return (
<Grid container spacing={1}>
<Grid item xs={12} align='center'>
<Button
<LoadingButton
loading={this.state.loadingButtonFiatSent}
defaultValue='confirm'
variant='contained'
@ -1265,7 +1265,7 @@ class TradeBox extends Component {
),
),
})}
</Button>
</LoadingButton>
</Grid>
</Grid>
);
@ -1467,7 +1467,9 @@ class TradeBox extends Component {
</div>
</Tooltip>
</div>
) : <></>}
) : (
<></>
)}
<Typography variant='subtitle1'>
<b>
{' '}