Skip to content

Commit

Permalink
Working merge reply with last post feature
Browse files Browse the repository at this point in the history
  • Loading branch information
rafalp committed Dec 16, 2024
1 parent c935fe8 commit 96c6199
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 4 deletions.
7 changes: 4 additions & 3 deletions misago/posting/state/reply.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@


class ReplyThreadState(PostingState):
# True if reply was instead appended to the recent post
# True if new reply was merged with the recent post
is_merged: bool

def __init__(self, request: HttpRequest, thread: Thread, post: Post | None = None):
Expand Down Expand Up @@ -55,8 +55,9 @@ def save_post(self):
self.post.last_editor = self.user
self.post.last_editor_name = self.user.username
self.post.last_editor_slug = self.user.slug

self.post.save()
else:
# Save new post so it exists before search vector setup
self.post.save()

update_post_checksum(self.post)
self.post.update_search_vector()
Expand Down
38 changes: 38 additions & 0 deletions misago/posting/tests/test_reply_thread_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,41 @@ def test_reply_thread_state_updates_user(user_request, other_user_thread, user):
user.refresh_from_db()
assert user.threads == 0
assert user.posts == 1


def test_reply_thread_state_updates_existing_post(user, user_request, user_thread):
post = user_thread.first_post

state = ReplyThreadState(user_request, user_thread, post)
state.set_post_message("Test reply")
state.save()

post.refresh_from_db()
assert post.original == "I am test message\n\nTest reply"
assert post.parsed == "<p>I am test message</p><p>Test reply</p>"
assert post.updated_on == state.timestamp
assert post.edits == 1
assert post.last_editor == user
assert post.last_editor_name == user.username
assert post.last_editor_slug == user.slug

user_thread.refresh_from_db()
assert user_thread.post_set.count() == 1
assert user_thread.replies == 0
assert user_thread.last_poster == user
assert user_thread.last_poster_name == user.username
assert user_thread.last_poster_slug == user.slug
assert user_thread.last_post_on == post.posted_on

category = state.category
category.refresh_from_db()
assert category.threads == 1
assert category.posts == 1
assert category.last_thread == state.thread
assert category.last_post_on == post.posted_on
assert category.last_poster == user
assert category.last_poster_name == user.username
assert category.last_poster_slug == user.slug

user.refresh_from_db()
assert user.posts == 0
2 changes: 1 addition & 1 deletion misago/threads/views/reply.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def post(self, request: HttpRequest, id: int, slug: str) -> HttpResponse:
request,
pgettext(
"thread reply posted",
"Your reply was automatically merged with your previous post",
"Reply was automatically merged with the previous post",
),
)
else:
Expand Down

0 comments on commit 96c6199

Please sign in to comment.