Skip to content

Commit

Permalink
fix(notification): fix classmethod to staticmethod
Browse files Browse the repository at this point in the history
  • Loading branch information
injoonH committed Mar 12, 2024
1 parent d367801 commit c38b81e
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions apps/core/models/notification.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import TYPE_CHECKING

from django.db import models
from django.utils.functional import cached_property

Expand All @@ -6,6 +8,9 @@
from ara.db.models import MetaDataModel
from ara.firebase import fcm_notify_comment

if TYPE_CHECKING:
from apps.user.models import UserProfile

TYPE_CHOICES = (
("default", "default"),
("article_commented", "article_commented"),
Expand Down Expand Up @@ -58,25 +63,22 @@ def data(self) -> dict:
"click_action": "",
}

@classmethod
def check_username(article: Article, comment: Comment, title: str) -> str:
@staticmethod
def get_display_name(article: Article, profile: UserProfile):
if article.name_type == NameType.REALNAME:
title.format(user=comment.created_by.profile.realname)
return profile.realname
elif article.name_type == NameType.REGULAR:
title.format(user=comment.created_by.profile.nickname)
return profile.nickname
else:
title.format(user="익명")

return title
return "익명"

@classmethod
def notify_commented(cls, comment):
from apps.core.models import NotificationReadLog

def notify_article_commented(_parent_article: Article, _comment: Comment):
title = cls.check_username(
_parent_article, _comment, "{user} 님이 새로운 댓글을 작성했습니다."
)
name = cls.get_display_name(_parent_article, _comment.created_by.profile)
title = f"{name} 님이 새로운 댓글을 작성했습니다."

NotificationReadLog.objects.create(
read_by=_parent_article.created_by,
Expand All @@ -96,9 +98,9 @@ def notify_article_commented(_parent_article: Article, _comment: Comment):
)

def notify_comment_commented(_parent_article: Article, _comment: Comment):
title = cls.check_username(
_parent_article, _comment, "{user} 님이 새로운 대댓글을 작성했습니다."
)
name = cls.get_display_name(_parent_article, _comment.created_by.profile)
title = f"{name} 님이 새로운 대댓글을 작성했습니다."

NotificationReadLog.objects.create(
read_by=_comment.parent_comment.created_by,
notification=cls.objects.create(
Expand Down

0 comments on commit c38b81e

Please sign in to comment.