def check_add_realm_emoji(realm: Realm, name: str, author: UserProfile, image_file: File) -> Optional[RealmEmoji]:
    realm_emoji = RealmEmoji(realm=realm, name=name, author=author)
    realm_emoji.full_clean()
    realm_emoji.save()
    emoji_file_name = get_emoji_file_name(image_file.name, realm_emoji.id)
    emoji_file_name = mark_sanitized(emoji_file_name)
    emoji_uploaded_successfully = False
    try:
        upload_emoji_image(image_file, emoji_file_name, author)
        emoji_uploaded_successfully = True
    finally:
        if (not emoji_uploaded_successfully):
            realm_emoji.delete()
            return None
        else:
            realm_emoji.file_name = emoji_file_name
            realm_emoji.save(update_fields=['file_name'])
            notify_realm_emoji(realm_emoji.realm)
    return realm_emoji
def check_add_realm_emoji(realm: Realm, name: str, author: UserProfile, image_file: File) -> Optional[RealmEmoji]:
    realm_emoji = RealmEmoji(realm=realm, name=name, author=author)
    realm_emoji.full_clean()
    realm_emoji.save()
    emoji_file_name = get_emoji_file_name(image_file.name, realm_emoji.id)
    emoji_file_name = mark_sanitized(emoji_file_name)
    emoji_uploaded_successfully = False
    try:
        upload_emoji_image(image_file, emoji_file_name, author)
        emoji_uploaded_successfully = True
    finally:
        if (not emoji_uploaded_successfully):
            realm_emoji.delete()
            return None
        else:
            realm_emoji.file_name = emoji_file_name
            realm_emoji.save(update_fields=['file_name'])
            notify_realm_emoji(realm_emoji.realm)
    return realm_emoji