Skip to content

Commit

Permalink
feat: return agents list when notifying discussions
Browse files Browse the repository at this point in the history
  • Loading branch information
helllllllder committed Nov 16, 2023
1 parent eb8a186 commit f48e500
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
4 changes: 2 additions & 2 deletions chats/apps/discussions/models/discussion.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ def sector(self):

@property
def serialized_ws_data(self):
from ..serializers.discussions import DiscussionListSerializer # noqa
from ..serializers.discussions import DiscussionWSSerializer # noqa

return DiscussionListSerializer(self).data
return DiscussionWSSerializer(self).data

def base_notification(self, content, action):
if self.user:
Expand Down
31 changes: 31 additions & 0 deletions chats/apps/discussions/serializers/discussions.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,16 @@ def create(self, validated_data):
return discussion


class DiscussionUserEmailListSerializer(serializers.ModelSerializer):
email = serializers.CharField(source="permission.user.email", read_only=True)

class Meta:
model = DiscussionUser
fields = [
"email",
]


class DiscussionListSerializer(serializers.ModelSerializer):
contact = serializers.CharField(source="room.contact.name", read_only=True)

Expand All @@ -89,6 +99,27 @@ class Meta:
]


class DiscussionWSSerializer(DiscussionListSerializer):
added_agents = serializers.SerializerMethodField()

class Meta:
model = Discussion
fields = [
"uuid",
"subject",
"created_by",
"contact",
"created_on",
"is_active",
"is_queued",
"added_agents",
]

def get_added_agents(self, discussion: Discussion):
agents = discussion.added_users.all().values_list("permission__user", flat=True)
return agents


class DiscussionUserListSerializer(serializers.ModelSerializer):
first_name = serializers.CharField(
source="permission.user.first_name", read_only=True
Expand Down

0 comments on commit f48e500

Please sign in to comment.