diff --git a/lambda/app/bee_slack_app/view/home.py b/lambda/app/bee_slack_app/view/home.py index f4428ae2..92b92df9 100644 --- a/lambda/app/bee_slack_app/view/home.py +++ b/lambda/app/bee_slack_app/view/home.py @@ -16,6 +16,7 @@ def home( # pylint: disable=too-many-locals post_review_action_id: str, list_user_posted_review_action_id: str, user_info_action_id: str, + list_posted_review_action_id: str, total_review_count: int, user_name: str, recommend_timestamp: str, @@ -30,6 +31,7 @@ def home( # pylint: disable=too-many-locals post_review_action_id: 「レビューを投稿する」ボタンのaction_id list_user_posted_review_action_id: 「レビューを投稿したユーザ」ボタンのaction_id user_info_action_id: 「プロフィール」ボタンのaction_id + list_posted_review_action_id: 「投稿したレビュー」ボタンのaction_id total_review_count: 表示する「レビュー投稿数」 user_name:表示する「ユーザ名」 recommend_timestamp:MLのjsonファイルを作成した日時 @@ -172,6 +174,16 @@ def home( # pylint: disable=too-many-locals "value": "dummy_value", "action_id": user_info_action_id, }, + { + "type": "button", + "text": { + "type": "plain_text", + "text": "投稿したレビュー", + "emoji": True, + }, + "value": "dummy_value", + "action_id": list_posted_review_action_id, + }, ], }, {"type": "divider"}, diff --git a/lambda/app/bee_slack_app/view_controller/home.py b/lambda/app/bee_slack_app/view_controller/home.py index afcad9c1..c269ff75 100644 --- a/lambda/app/bee_slack_app/view_controller/home.py +++ b/lambda/app/bee_slack_app/view_controller/home.py @@ -65,6 +65,7 @@ def update_home_view(ack, event, client): recommended_books=recommended_result["recommended_books"], list_user_posted_review_action_id="list_user_posted_review_action", user_info_action_id="user_info_action", + list_posted_review_action_id="list_posted_review_action", total_review_count=total_review_count, user_name=user_name, recommend_timestamp=parse(recommended_result["created_at"]), @@ -126,6 +127,7 @@ def home_move_to_next_action(ack, client, body): # pylint: disable=too-many-loc recommended_books=recommended_result["recommended_books"], list_user_posted_review_action_id="list_user_posted_review_action", user_info_action_id="user_info_action", + list_posted_review_action_id="list_posted_review_action", total_review_count=total_review_count, user_name=user_name, recommend_timestamp=parse(recommended_result["created_at"]), @@ -187,6 +189,7 @@ def home_move_to_back_action(ack, client, body): # pylint: disable=too-many-loc recommended_books=recommended_result["recommended_books"], list_user_posted_review_action_id="list_user_posted_review_action", user_info_action_id="user_info_action", + list_posted_review_action_id="list_posted_review_action", total_review_count=total_review_count, user_name=user_name, recommend_timestamp=parse(recommended_result["created_at"]), @@ -269,6 +272,7 @@ def handle_update_button_action( recommended_books=recommended_books, list_user_posted_review_action_id="list_user_posted_review_action", user_info_action_id="user_info_action", + list_posted_review_action_id="list_posted_review_action", total_review_count=total_review_count, user_name=user_name, recommend_timestamp=parse(recommended_result["created_at"]), diff --git a/lambda/app/bee_slack_app/view_controller/user.py b/lambda/app/bee_slack_app/view_controller/user.py index 413c26eb..1c23ff0d 100644 --- a/lambda/app/bee_slack_app/view_controller/user.py +++ b/lambda/app/bee_slack_app/view_controller/user.py @@ -3,9 +3,11 @@ from slack_bolt import App -from bee_slack_app.model import User -from bee_slack_app.service import user_action_service, user_service -from bee_slack_app.view import user_profile_modal +from bee_slack_app.model import Review, ReviewPagination, User +from bee_slack_app.service import review_service, user_action_service, user_service +from bee_slack_app.view import review_of_user_modal, simple_modal, user_profile_modal + +BOOK_NUMBER_PER_PAGE = 20 def user_controller(app: App) -> None: @@ -94,6 +96,75 @@ def handle_submission(ack, body, _, view): payload={"user": user}, ) + @app.action("list_posted_review_action") + def list_posted_review_action(ack, body, client): + ack() + user_id = body["user"]["id"] + + review_items = review_service.get_next_reviews_by_user_id( + user_id=user_id, limit=BOOK_NUMBER_PER_PAGE, keys=[] + ) + + reviews = [] + + if review_items: + reviews = review_items["items"] + reviews = _make_review_contents_list_comment_short(reviews) + + reviews_param: ReviewPagination = { + "reviews": reviews, + "show_move_to_back": False, + "show_move_to_next": review_items["has_next"], + } + # メタデータに変換する + metadata_str = _PrivateMetadataConvertor.to_private_metadata( + keys=review_items["keys"], + ) + + user_action_service.record_user_action( + user_id=user_id, + action_name="list_posted_review_action", + payload={"reviews": reviews}, + ) + + if not reviews: + client.views_open( + trigger_id=body["trigger_id"], + view=simple_modal(title="エラー", text="レビュー取得でエラーが発生しました"), + ) + return + + client.views_open( + trigger_id=body["trigger_id"], + view=review_of_user_modal( + callback_id="review_of_user_modal", + reviews_param=reviews_param, + private_metadata=metadata_str, + ), + ) + + +def _make_review_contents_list_comment_short( + review_contents_list: list[Review], +) -> list[Review]: + """ + レビューのコメントを、一覧表示用に短くする + """ + comment_len = 20 + + for review_contents in review_contents_list: + review_comment = review_contents["review_comment"] + if review_comment: + review_contents["review_comment"] = ( + review_comment[0:comment_len] + "..." + if len(review_comment) > comment_len + else review_comment + ) + else: + review_contents["review_comment"] = "-" + + return review_contents_list + class _PrivateMetadataConvertor: class _MetadataDict(TypedDict):