robosats/chat/serializers.py

85 lines
2.1 KiB
Python
Raw Normal View History

from rest_framework import serializers
from decimal import Decimal
from chat.models import Message
class OutMessagesSerializer(serializers.ModelSerializer):
time = serializers.DateTimeField(source="created_at")
message = serializers.CharField(source="PGP_message")
nick = serializers.CharField(source="sender")
class Meta:
model = Message
fields = (
"index",
"time",
"message",
"nick",
)
depth = 0
2022-10-20 09:56:10 +00:00
class InMessageSerializer(serializers.ModelSerializer):
class Meta:
model = Message
fields = (
"index",
"created_at",
"PGP_message",
"sender",
)
depth = 0
2022-10-20 09:56:10 +00:00
class ChatSerializer(serializers.ModelSerializer):
2022-10-20 09:56:10 +00:00
offset = serializers.IntegerField(
allow_null=True,
default=None,
required=False,
min_value=Decimal(0),
2022-10-20 09:56:10 +00:00
help_text="Offset for message index to get as response",
)
Add turtle chat component Squashed commit of the following: commit f60870fcfe574dc4ab1343e25241b6ef7cc2721b Author: Reckless_Satoshi <reckless.satoshi@protonmail.com> Date: Thu Nov 10 10:30:42 2022 -0800 Fix internal error when entering chat commit f1eeb49f2a86575eb2e85cdff20460276e71b806 Author: Reckless_Satoshi <reckless.satoshi@protonmail.com> Date: Tue Nov 8 10:08:22 2022 -0800 Fix final serializer commit d0c08ba6ad4378a9539c0be83b6f4f8b958b532e Author: Reckless_Satoshi <reckless.satoshi@protonmail.com> Date: Tue Nov 8 09:44:57 2022 -0800 Chat API changes commit a66bf64edc06d936612db6bf75476b54e6a84334 Author: Reckless_Satoshi <reckless.satoshi@protonmail.com> Date: Tue Nov 8 09:28:29 2022 -0800 Fix param on post commit 60b18d13c2ec625497323371a2a6f64c9c911e47 Author: Reckless_Satoshi <reckless.satoshi@protonmail.com> Date: Tue Nov 8 08:56:25 2022 -0800 Fix serializer commit 11212d30eeffde37e07d2e6e5c1fb36df46916ad Author: KoalaSat <yv1vtrul@duck.com> Date: Sun Nov 6 21:07:18 2022 +0100 CR 2 commit c82790cb81dd9919de97c39f2553974784ffe92d Author: KoalaSat <yv1vtrul@duck.com> Date: Sun Nov 6 20:09:18 2022 +0100 Fix commit 605a3b69a1fcf795e45b2acba1e12436f8545f8a Author: KoalaSat <yv1vtrul@duck.com> Date: Sun Nov 6 14:44:42 2022 +0100 CR commit 09776e9c8fa85c253f28c75361829dab5df4d978 Author: KoalaSat <yv1vtrul@duck.com> Date: Wed Nov 2 18:12:29 2022 +0100 translations commit 432e4d23991164b164d2ab3e4f31790a992dc601 Author: KoalaSat <yv1vtrul@duck.com> Date: Wed Nov 2 17:39:02 2022 +0100 Switch and better UX commit df6e476613006f6a861bab68f8a4261bc8f641e0 Author: KoalaSat <yv1vtrul@duck.com> Date: Tue Nov 1 18:20:01 2022 +0100 Unused code commit 5b8d6b4d32980e31bb1d682444b53df1a8e16c47 Author: Reckless_Satoshi <reckless.satoshi@protonmail.com> Date: Mon Oct 31 09:20:20 2022 -0700 Add Chat Turtle Mode
2022-11-11 09:28:09 +00:00
peer_pubkey = serializers.CharField(
required=False,
help_text="Your peer's public PGP key",
)
peer_connected = serializers.BooleanField(
required=False,
help_text="Whether your peer has connected recently to the chatroom",
)
messages = serializers.ListField(child=OutMessagesSerializer(), required=False)
class Meta:
model = Message
fields = ("messages", "offset", "peer_connected", "peer_pubkey")
depth = 0
class PostMessageSerializer(serializers.ModelSerializer):
PGP_message = serializers.CharField(
required=True,
help_text="A new chat message",
)
Add turtle chat component Squashed commit of the following: commit f60870fcfe574dc4ab1343e25241b6ef7cc2721b Author: Reckless_Satoshi <reckless.satoshi@protonmail.com> Date: Thu Nov 10 10:30:42 2022 -0800 Fix internal error when entering chat commit f1eeb49f2a86575eb2e85cdff20460276e71b806 Author: Reckless_Satoshi <reckless.satoshi@protonmail.com> Date: Tue Nov 8 10:08:22 2022 -0800 Fix final serializer commit d0c08ba6ad4378a9539c0be83b6f4f8b958b532e Author: Reckless_Satoshi <reckless.satoshi@protonmail.com> Date: Tue Nov 8 09:44:57 2022 -0800 Chat API changes commit a66bf64edc06d936612db6bf75476b54e6a84334 Author: Reckless_Satoshi <reckless.satoshi@protonmail.com> Date: Tue Nov 8 09:28:29 2022 -0800 Fix param on post commit 60b18d13c2ec625497323371a2a6f64c9c911e47 Author: Reckless_Satoshi <reckless.satoshi@protonmail.com> Date: Tue Nov 8 08:56:25 2022 -0800 Fix serializer commit 11212d30eeffde37e07d2e6e5c1fb36df46916ad Author: KoalaSat <yv1vtrul@duck.com> Date: Sun Nov 6 21:07:18 2022 +0100 CR 2 commit c82790cb81dd9919de97c39f2553974784ffe92d Author: KoalaSat <yv1vtrul@duck.com> Date: Sun Nov 6 20:09:18 2022 +0100 Fix commit 605a3b69a1fcf795e45b2acba1e12436f8545f8a Author: KoalaSat <yv1vtrul@duck.com> Date: Sun Nov 6 14:44:42 2022 +0100 CR commit 09776e9c8fa85c253f28c75361829dab5df4d978 Author: KoalaSat <yv1vtrul@duck.com> Date: Wed Nov 2 18:12:29 2022 +0100 translations commit 432e4d23991164b164d2ab3e4f31790a992dc601 Author: KoalaSat <yv1vtrul@duck.com> Date: Wed Nov 2 17:39:02 2022 +0100 Switch and better UX commit df6e476613006f6a861bab68f8a4261bc8f641e0 Author: KoalaSat <yv1vtrul@duck.com> Date: Tue Nov 1 18:20:01 2022 +0100 Unused code commit 5b8d6b4d32980e31bb1d682444b53df1a8e16c47 Author: Reckless_Satoshi <reckless.satoshi@protonmail.com> Date: Mon Oct 31 09:20:20 2022 -0700 Add Chat Turtle Mode
2022-11-11 09:28:09 +00:00
order_id = serializers.IntegerField(
required=True,
min_value=Decimal(0),
help_text="Your peer's public key",
)
offset = serializers.IntegerField(
allow_null=True,
default=None,
required=False,
min_value=Decimal(0),
help_text="Offset for message index to get as response",
Add turtle chat component Squashed commit of the following: commit f60870fcfe574dc4ab1343e25241b6ef7cc2721b Author: Reckless_Satoshi <reckless.satoshi@protonmail.com> Date: Thu Nov 10 10:30:42 2022 -0800 Fix internal error when entering chat commit f1eeb49f2a86575eb2e85cdff20460276e71b806 Author: Reckless_Satoshi <reckless.satoshi@protonmail.com> Date: Tue Nov 8 10:08:22 2022 -0800 Fix final serializer commit d0c08ba6ad4378a9539c0be83b6f4f8b958b532e Author: Reckless_Satoshi <reckless.satoshi@protonmail.com> Date: Tue Nov 8 09:44:57 2022 -0800 Chat API changes commit a66bf64edc06d936612db6bf75476b54e6a84334 Author: Reckless_Satoshi <reckless.satoshi@protonmail.com> Date: Tue Nov 8 09:28:29 2022 -0800 Fix param on post commit 60b18d13c2ec625497323371a2a6f64c9c911e47 Author: Reckless_Satoshi <reckless.satoshi@protonmail.com> Date: Tue Nov 8 08:56:25 2022 -0800 Fix serializer commit 11212d30eeffde37e07d2e6e5c1fb36df46916ad Author: KoalaSat <yv1vtrul@duck.com> Date: Sun Nov 6 21:07:18 2022 +0100 CR 2 commit c82790cb81dd9919de97c39f2553974784ffe92d Author: KoalaSat <yv1vtrul@duck.com> Date: Sun Nov 6 20:09:18 2022 +0100 Fix commit 605a3b69a1fcf795e45b2acba1e12436f8545f8a Author: KoalaSat <yv1vtrul@duck.com> Date: Sun Nov 6 14:44:42 2022 +0100 CR commit 09776e9c8fa85c253f28c75361829dab5df4d978 Author: KoalaSat <yv1vtrul@duck.com> Date: Wed Nov 2 18:12:29 2022 +0100 translations commit 432e4d23991164b164d2ab3e4f31790a992dc601 Author: KoalaSat <yv1vtrul@duck.com> Date: Wed Nov 2 17:39:02 2022 +0100 Switch and better UX commit df6e476613006f6a861bab68f8a4261bc8f641e0 Author: KoalaSat <yv1vtrul@duck.com> Date: Tue Nov 1 18:20:01 2022 +0100 Unused code commit 5b8d6b4d32980e31bb1d682444b53df1a8e16c47 Author: Reckless_Satoshi <reckless.satoshi@protonmail.com> Date: Mon Oct 31 09:20:20 2022 -0700 Add Chat Turtle Mode
2022-11-11 09:28:09 +00:00
)
class Meta:
model = Message
fields = ("PGP_message", "order_id", "offset")
depth = 0