From 185c2f86cde60e1ea394a2c32f38dab5e5d8da94 Mon Sep 17 00:00:00 2001 From: Jyong <76649700+JohnJyong@users.noreply.github.com> Date: Tue, 19 Dec 2023 17:47:25 +0800 Subject: [PATCH] Compatible with the situation where there is no user information. (#1792) Co-authored-by: jyong --- api/fields/conversation_fields.py | 5 +++-- api/models/model.py | 11 ++++++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/api/fields/conversation_fields.py b/api/fields/conversation_fields.py index 5e8412ef84..661cb0ea73 100644 --- a/api/fields/conversation_fields.py +++ b/api/fields/conversation_fields.py @@ -31,8 +31,9 @@ annotation_fields = { } annotation_hit_history_fields = { - 'annotation_id': fields.String, - 'annotation_create_account': fields.Nested(account_fields, allow_null=True) + 'annotation_id': fields.String(attribute='id'), + 'annotation_create_account': fields.Nested(account_fields, allow_null=True), + 'created_at': TimestampField } message_file_fields = { diff --git a/api/models/model.py b/api/models/model.py index 1805f0bb33..df27edb9a5 100644 --- a/api/models/model.py +++ b/api/models/model.py @@ -531,7 +531,11 @@ class Message(db.Model): def annotation_hit_history(self): annotation_history = (db.session.query(AppAnnotationHitHistory) .filter(AppAnnotationHitHistory.message_id == self.id).first()) - return annotation_history + if annotation_history: + annotation = (db.session.query(MessageAnnotation). + filter(MessageAnnotation.id == annotation_history.annotation_id).first()) + return annotation + return None @property def app_model_config(self): @@ -659,6 +663,11 @@ class MessageAnnotation(db.Model): account = db.session.query(Account).filter(Account.id == self.account_id).first() return account + @property + def annotation_create_account(self): + account = db.session.query(Account).filter(Account.id == self.account_id).first() + return account + class AppAnnotationHitHistory(db.Model): __tablename__ = 'app_annotation_hit_histories'