Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix: Fix topic editing if topic unchanged #1056

Merged
merged 2 commits into from
Jul 3, 2021

Conversation

neiljp
Copy link
Collaborator

@neiljp neiljp commented Jun 25, 2021

Recent work in resolved/unresolved topics has caused a change in the server (not yet in a release), where it more strictly enforces that if a topic is provided but unchanged in stream message editing/updating, then the propagate mode must be set to change_one - otherwise the edit does not proceed.

This PR works around this and has scope to be expanded towards resolving part or all of #1014.

The need for this was discussed in #design>closing/solving a topic (#11154).

I've not added tests for this change in behavior (yet, at least) - we don't seem to have tests for the existing behavior.

@neiljp neiljp added the bug Something isn't working label Jun 25, 2021
@neiljp neiljp added this to the Next Release milestone Jun 25, 2021
@zulipbot zulipbot added the size: L [Automatic label added by zulipbot] label Jun 25, 2021
@neiljp neiljp added the high priority should be done as soon as possible label Jun 25, 2021
Copy link
Member

@preetmishra preetmishra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@neiljp Thanks for pushing a patch! It seems to work well locally. 👍

Re the state data structure, fetching individual items from a tuple (using indices) doesn't tell much about what is being extracted out of the tuple. What do you think about a dict instead?

I have left a minor comment regarding a FIXME comment.

@@ -539,10 +539,15 @@ def keypress(self, size: urwid_Size, key: str) -> Optional[str]:
topic = self.title_write_box.edit_text

if self.msg_edit_state is not None:
if topic == self.msg_edit_state[1]: # FIXME need strip?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For a topic change from "Test" to "Test ", it says invalid prop mode. I think we need to strip here.

The id is now within a namedtuple, which will be extended in future.

Also explicitly update checks for the value versus None, rather than
using truthiness.

Tests amended.
@neiljp neiljp force-pushed the 2021-06-24-bugfix-edit-content-only branch from c9173ee to 2fd6254 Compare July 2, 2021 23:24
@neiljp
Copy link
Collaborator Author

neiljp commented Jul 2, 2021

Just returned to this after my time away as it blocks our use on czo with simple editing.

@preetmishra Just pushed an updated version addressing your points:

  • using a namedtuple instead of a simple tuple (dicts are OK but are more verbose and less constrained unless one uses typeddict, and that's only enforced via mypy)
  • uses the trimmed topic for comparison purposes (with notes to explain why - I checked the server code)

The namedtuple change actually found a minor test change that was missing too, so thanks for the suggestion to avoid indices (even if internal to the WriteBox)

@neiljp neiljp requested a review from preetmishra July 3, 2021 07:05
Copy link
Member

@preetmishra preetmishra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@neiljp Thanks for pushing the updates! 👍

The PR doesn't work currently but that's due to a small mishap (see my in-line comment). Other than that, the changes look good to me.

NamedTuple is even better with strict checking. Thanks for moving ahead with it. I second your decision regarding only using a trimmed topic name for equality and sending the topic as is until we have a guideline from the server.

args = dict(
message_id=self.msg_edit_state.message_id,
topic=topic,
topic=topic, # NOTE: Send untrimmed topic always for now
propagate_mode=self.edit_mode_button.mode,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be propagate_mode=propagate_mode.

The intent of the edit/update message API has recently been clarified
that if the topic is unchanged (even if sent) that the propagate_mode
should be set to change_one. This was previously not enforced by the
server but was changed to do so in
zulip/zulip@e231a03

Since our propagate_mode defaults to change_later via the UI element,
the above change to the server leads to errors upon attempting
content-only edits.

To resolve this, the original topic is added to the new tuple form of
msg_edit_state, allowing detection of whether the topic has changed and
setting of propagate_mode as appropriate.

The decision to use change_one is dependent upon the trimmed new topic
since otherwise the edit can confusingly fail since trimming is checked
on the server end and results in the same propagate error message.

Tests updated.
@neiljp neiljp force-pushed the 2021-06-24-bugfix-edit-content-only branch from 2fd6254 to 415aeb5 Compare July 3, 2021 15:37
@neiljp
Copy link
Collaborator Author

neiljp commented Jul 3, 2021

@preetmishra Thanks for the reviews! Merging this now so I can get back to editing messages! 🎉

@neiljp neiljp merged commit a586f15 into zulip:main Jul 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working high priority should be done as soon as possible size: L [Automatic label added by zulipbot]
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants