Fix last_login for tokeauth, replace maker/taker_last seen for last_login

This commit is contained in:
Reckless_Satoshi 2023-05-07 04:54:09 -07:00
parent f2de58ca36
commit 8434a256cf
No known key found for this signature in database
GPG Key ID: 9C4585B561315571
7 changed files with 13 additions and 21 deletions

View File

@ -157,8 +157,6 @@ class Order(models.Model):
default=None,
blank=True,
) # unique = True, a taker can only take one order
maker_last_seen = models.DateTimeField(null=True, default=None, blank=True)
taker_last_seen = models.DateTimeField(null=True, default=None, blank=True)
# When collaborative cancel is needed and one partner has cancelled.
maker_asked_cancel = models.BooleanField(default=False, null=False)

View File

@ -256,20 +256,12 @@ class OrderView(viewsets.ViewSet):
)
# WRITE Update last_seen for maker and taker.
# Note down that the taker/maker was here recently, so counterpart knows if the user is paying attention.
data["maker_nick"] = str(order.maker)
if order.maker == request.user:
order.maker_last_seen = timezone.now()
order.save()
if order.taker == request.user:
order.taker_last_seen = timezone.now()
order.save()
# Add activity status of participants based on last_seen
if order.taker_last_seen is not None:
data["taker_status"] = Logics.user_activity_status(order.taker_last_seen)
if order.maker_last_seen is not None:
data["maker_status"] = Logics.user_activity_status(order.maker_last_seen)
data["maker_status"] = Logics.user_activity_status(order.maker.last_login)
if order.taker is not None:
data["taker_status"] = Logics.user_activity_status(order.taker.last_login)
# 3.b) Non participants can view details (but only if PUB)
if not data["is_participant"] and order.status == Order.Status.PUB:
@ -904,7 +896,7 @@ class BookView(ListAPIView):
data["satoshis_now"] = Logics.satoshis_now(order)
# Compute current premium for those orders that are explicitly priced.
data["price"], data["premium"] = Logics.price_and_premium_now(order)
data["maker_status"] = Logics.user_activity_status(order.maker_last_seen)
data["maker_status"] = Logics.user_activity_status(order.maker.last_login)
for key in (
"status",
"taker",

View File

@ -72,7 +72,7 @@ class ChatView(viewsets.ViewSet):
# Poor idea: is_peer_connected() mockup. Update connection status based on last time a GET request was sent
if chatroom.maker == request.user:
chatroom.taker_connected = order.taker_last_seen > (
chatroom.taker_connected = order.taker.last_login > (
timezone.now() - timedelta(minutes=1)
)
chatroom.maker_connected = True
@ -80,7 +80,7 @@ class ChatView(viewsets.ViewSet):
peer_connected = chatroom.taker_connected
peer_public_key = order.taker.robot.public_key
elif chatroom.taker == request.user:
chatroom.maker_connected = order.maker_last_seen > (
chatroom.maker_connected = order.maker.last_login > (
timezone.now() - timedelta(minutes=1)
)
chatroom.taker_connected = True

View File

@ -308,7 +308,7 @@ const OrderDetails = ({
<ListItem>
<ListItemIcon sx={{ position: 'relative', left: '0.3em' }}>
<SendReceiveIcon
sx={{ transform: 'scaleX(-1)', width: '0.9em', opacity: 0.7 }}
sx={{ transform: 'scaleX(-1)', width: '0.9em', opacity: 0.9 }}
color='secondary'
/>
</ListItemIcon>
@ -318,7 +318,7 @@ const OrderDetails = ({
<ListItem>
<ListItemIcon sx={{ position: 'relative', left: '0.3em' }}>
<SendReceiveIcon
sx={{ left: '0.1em', width: '0.9em', opacity: 0.7 }}
sx={{ left: '0.1em', width: '0.9em', opacity: 0.9 }}
color='primary'
/>
</ListItemIcon>

View File

@ -76,6 +76,7 @@ const EncryptedSocketChat: React.FC<Props> = ({
// On component unmount close reconnecting-websockets
return () => {
connection?.close();
setConnection(undefined);
};
}, []);

View File

@ -207,7 +207,7 @@ const EncryptedTurtleChat: React.FC<Props> = ({
order_id: orderId,
offset: lastIndex,
},
robot.tokenSHA256,
{ tokenSHA256: robot.tokenSHA256 },
)
.then((response) => {
if (response != null) {

View File

@ -4,7 +4,7 @@ from pathlib import Path
from channels.db import database_sync_to_async
from channels.middleware import BaseMiddleware
from django.conf import settings
from django.contrib.auth.models import AnonymousUser, User
from django.contrib.auth.models import AnonymousUser, User, update_last_login
from django.db import IntegrityError
from rest_framework.authtoken.models import Token
from rest_framework.exceptions import AuthenticationFailed
@ -64,7 +64,8 @@ class RobotTokenSHA256AuthenticationMiddleWare:
# Check if it is an existing robot.
try:
Token.objects.get(key=token_sha256_b91)
token = Token.objects.get(key=token_sha256_b91)
update_last_login(None, token.user)
except Token.DoesNotExist:
# If we get here the user does not have a robot on this coordinator