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

emoji: Handle conflict with system emojis #518

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions src/mmemoji/emoji.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,19 @@ def create(
else:
raise EmojiAlreadyExists(self)

self._metadata = self._mm.emoji.create_custom_emoji(
emoji_name=self._name, files={"image": image}
)
try:
self._metadata = self._mm.emoji.create_custom_emoji(
emoji_name=self._name, files={"image": image}
)
except InvalidOrMissingParameters as e:
if e.args and "Name conflicts with existing system emoji name" in e.args[0]:
Copy link
Owner

Choose a reason for hiding this comment

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

The message field is internationalized, so it depends on the selected language. We should check the error id instead, model.emoji.system_emoji_name.app_error in this case.

The driver does not exposed it:

https://github.com/Vaelor/python-mattermost-driver/blob/c6ac437d351c32ea7bf1eca39846a6482c51bd01/src/mattermostdriver/client.py#L151

I am not sure if it is still maintained, I have opened an issue to investigate replacing it: #541. So I think we might be blocked here until we change the driver and the new one exposes the error ID

if no_clobber:
return False
else:
# cannot force
raise EmojiAlreadyExists(self)
else:
raise e
return True

def delete(self, force: bool = False) -> bool:
Expand Down