mirror of
https://github.com/RoboSats/robosats.git
synced 2025-07-19 09:13:28 +00:00
Fix chatroom names. Fix users entering old chats
This commit is contained in:
22
api/views.py
22
api/views.py
@ -635,14 +635,14 @@ class UserView(APIView):
|
|||||||
encrypted_private_key = serializer.data.get("encrypted_private_key")
|
encrypted_private_key = serializer.data.get("encrypted_private_key")
|
||||||
ref_code = serializer.data.get("ref_code")
|
ref_code = serializer.data.get("ref_code")
|
||||||
|
|
||||||
valid, bad_keys_context, public_key, encrypted_private_key = Logics.validate_pgp_keys(public_key, encrypted_private_key)
|
|
||||||
if not valid:
|
|
||||||
return Response(bad_keys_context, status.HTTP_400_BAD_REQUEST)
|
|
||||||
|
|
||||||
if not public_key or not encrypted_private_key:
|
if not public_key or not encrypted_private_key:
|
||||||
context["bad_request"] = "Must provide valid 'pub' and 'enc_priv' PGP keys"
|
context["bad_request"] = "Must provide valid 'pub' and 'enc_priv' PGP keys"
|
||||||
return Response(context, status.HTTP_400_BAD_REQUEST)
|
return Response(context, status.HTTP_400_BAD_REQUEST)
|
||||||
|
|
||||||
|
valid, bad_keys_context, public_key, encrypted_private_key = Logics.validate_pgp_keys(public_key, encrypted_private_key)
|
||||||
|
if not valid:
|
||||||
|
return Response(bad_keys_context, status.HTTP_400_BAD_REQUEST)
|
||||||
|
|
||||||
# Now the server only receives a hash of the token. So server trusts the client
|
# Now the server only receives a hash of the token. So server trusts the client
|
||||||
# with computing length, counts and unique_values to confirm the high entropy of the token
|
# with computing length, counts and unique_values to confirm the high entropy of the token
|
||||||
# In any case, it is up to the client if they want to create a bad high entropy token.
|
# In any case, it is up to the client if they want to create a bad high entropy token.
|
||||||
@ -698,8 +698,13 @@ class UserView(APIView):
|
|||||||
context['referral_code'] = token_urlsafe(8)
|
context['referral_code'] = token_urlsafe(8)
|
||||||
user.profile.referral_code = context['referral_code']
|
user.profile.referral_code = context['referral_code']
|
||||||
user.profile.avatar = "static/assets/avatars/" + nickname + ".png"
|
user.profile.avatar = "static/assets/avatars/" + nickname + ".png"
|
||||||
user.profile.public_key = public_key
|
|
||||||
user.profile.encrypted_private_key = encrypted_private_key
|
# Noticed some PGP keys replaced at re-login. Should not happen.
|
||||||
|
# Let's implement this sanity check "If profile has not keys..."
|
||||||
|
if not user.profile.public_key:
|
||||||
|
user.profile.public_key = public_key
|
||||||
|
if not user.profile.encrypted_private_key:
|
||||||
|
user.profile.encrypted_private_key = encrypted_private_key
|
||||||
|
|
||||||
# If the ref_code was created by another robot, this robot was referred.
|
# If the ref_code was created by another robot, this robot was referred.
|
||||||
queryset = Profile.objects.filter(referral_code=ref_code)
|
queryset = Profile.objects.filter(referral_code=ref_code)
|
||||||
@ -805,10 +810,7 @@ class BookView(ListAPIView):
|
|||||||
order)
|
order)
|
||||||
data["maker_status"] = Logics.user_activity_status(
|
data["maker_status"] = Logics.user_activity_status(
|
||||||
order.maker_last_seen)
|
order.maker_last_seen)
|
||||||
for key in (
|
for key in ("status","taker"): # Non participants should not see the status or who is the taker
|
||||||
"status",
|
|
||||||
"taker",
|
|
||||||
): # Non participants should not see the status or who is the taker
|
|
||||||
del data[key]
|
del data[key]
|
||||||
|
|
||||||
book_data.append(data)
|
book_data.append(data)
|
||||||
|
@ -11,9 +11,15 @@ class ChatRoomConsumer(AsyncWebsocketConsumer):
|
|||||||
@database_sync_to_async
|
@database_sync_to_async
|
||||||
def allow_in_chatroom(self):
|
def allow_in_chatroom(self):
|
||||||
order = Order.objects.get(id=self.order_id)
|
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.maker == self.user or order.taker == self.user):
|
if not (order.maker == self.user or order.taker == self.user):
|
||||||
print("Not allowed in this chat")
|
print("Not allowed in this chat")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@database_sync_to_async
|
@database_sync_to_async
|
||||||
@ -165,21 +171,6 @@ class ChatRoomConsumer(AsyncWebsocketConsumer):
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
# If there is any stored message, serve them.
|
|
||||||
msgs = await self.get_all_PGP_messages()
|
|
||||||
for msg in msgs:
|
|
||||||
await self.channel_layer.group_send(
|
|
||||||
self.room_group_name,
|
|
||||||
{
|
|
||||||
"type": "PGP_message",
|
|
||||||
"index": msg['index'],
|
|
||||||
"time": msg['time'],
|
|
||||||
"message": msg['message'],
|
|
||||||
"nick": msg['nick'],
|
|
||||||
"peer_connected": None,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
async def disconnect(self, close_code):
|
async def disconnect(self, close_code):
|
||||||
await self.save_disconnect_user()
|
await self.save_disconnect_user()
|
||||||
await self.channel_layer.group_discard(self.room_group_name,
|
await self.channel_layer.group_discard(self.room_group_name,
|
||||||
@ -220,6 +211,22 @@ class ChatRoomConsumer(AsyncWebsocketConsumer):
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Encrypted messages are served when the user requests them
|
||||||
|
elif message[0:23] == '-----SERVE HISTORY-----':
|
||||||
|
# If there is any stored message, serve them.
|
||||||
|
msgs = await self.get_all_PGP_messages()
|
||||||
|
for msg in msgs:
|
||||||
|
await self.channel_layer.group_send(
|
||||||
|
self.room_group_name,
|
||||||
|
{
|
||||||
|
"type": "PGP_message",
|
||||||
|
"index": msg['index'],
|
||||||
|
"time": msg['time'],
|
||||||
|
"message": msg['message'],
|
||||||
|
"nick": msg['nick'],
|
||||||
|
"peer_connected": None,
|
||||||
|
},
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
await self.channel_layer.group_send(
|
await self.channel_layer.group_send(
|
||||||
self.room_group_name,
|
self.room_group_name,
|
||||||
|
@ -44,7 +44,7 @@ class ChatRoom(models.Model):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return f"Chat:{str(self.order.id)}"
|
return f"Chat:{str(self.id)}"
|
||||||
|
|
||||||
class Message(models.Model):
|
class Message(models.Model):
|
||||||
class Meta:
|
class Meta:
|
||||||
@ -85,4 +85,4 @@ class Message(models.Model):
|
|||||||
created_at = models.DateTimeField(default=timezone.now)
|
created_at = models.DateTimeField(default=timezone.now)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return f"Chat:{str(self.order.id)} - Idx:{self.index}"
|
return f"Chat:{str(self.chatroom.id)} - Idx:{self.index}"
|
||||||
|
Reference in New Issue
Block a user