Skip to content
New issue

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

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

Already on GitHub? # to your account

Image index fix #15525

Merged
merged 3 commits into from
Mar 29, 2023
Merged

Image index fix #15525

merged 3 commits into from
Mar 29, 2023

Conversation

OmarBasem
Copy link
Contributor

fixes: #15391

@status-im-auto
Copy link
Member

status-im-auto commented Mar 28, 2023

Jenkins Builds

Click to see older builds (4)
Commit #️⃣ Finished (UTC) Duration Platform Result
✔️ b772885 #2 2023-03-28 18:09:06 ~7 min tests 📄log
✔️ b772885 #2 2023-03-28 18:09:31 ~7 min android-e2e 🤖apk 📲
✔️ b772885 #2 2023-03-28 18:09:46 ~7 min ios 📱ipa 📲
✔️ b772885 #2 2023-03-28 18:09:54 ~8 min android 🤖apk 📲
Commit #️⃣ Finished (UTC) Duration Platform Result
✔️ b18de99 #4 2023-03-29 09:52:12 ~5 min tests 📄log
✔️ b18de99 #4 2023-03-29 09:53:48 ~7 min android-e2e 🤖apk 📲
✔️ b18de99 #4 2023-03-29 09:54:35 ~8 min android 🤖apk 📲
✔️ b18de99 #4 2023-03-29 09:56:39 ~10 min ios 📱ipa 📲
✔️ 025df7a #5 2023-03-29 17:48:57 ~7 min tests 📄log
✔️ 025df7a #5 2023-03-29 17:48:57 ~7 min android-e2e 🤖apk 📲
✔️ 025df7a #5 2023-03-29 17:49:28 ~8 min ios 📱ipa 📲
✔️ 025df7a #5 2023-03-29 17:50:24 ~8 min android 🤖apk 📲

@OmarBasem OmarBasem requested a review from ibrkhalil March 28, 2023 18:12
@@ -130,7 +130,7 @@
;; The initial value of data is the image that was pressed (and not the whole album) in order
;; for the transition animation to execute properly, otherwise it would animate towards
;; outside the screen (even if we have `initialScrollIndex` set).
data (reagent/atom [(nth messages index)])
data (reagent/atom (if (number? index) [(nth messages index)] []))
Copy link
Contributor

Choose a reason for hiding this comment

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

Interestingly, similar to what we have in other functions like safe-trim, safe-replace, we could have safe-nth, so we can reduce the chance of this kind of bug in the future, which is quite easy to happen again, since nth doesn't accept nil and many things can be nil in Clojure.

Copy link
Contributor Author

@OmarBasem OmarBasem Mar 29, 2023

Choose a reason for hiding this comment

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

@ilmotta that's right.

But here I do not want to call nth at all if index is not number. So if we have something like:

(defn safe-nth
  [coll index]
  (when (number? index)
    (nth coll index)))

And then use it as: (reagent/atom [(utils/safe-nth messages index)])

If index is not a number, the atom will become [nil], but I want it to be [].

Copy link
Contributor

Choose a reason for hiding this comment

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

Here you can evolve the function to respect the last argument of nth, which is the default value.

Something like this. It's also interesting to name the arguments just like the core function nth does.

(defn safe-nth
  ([coll n]
   (safe-nth coll n nil))
  ([coll n not-found]
   (if (number? n)
     (nth coll n not-found)
     not-found)))

So now you call it:

(safe-nth messages index [])

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looks good! Thanks @ilmotta

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ilmotta but this will make it [[]], right?

(reagent/atom [(utils/safe-nth messages index [])])

Copy link
Contributor

Choose a reason for hiding this comment

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

So maybe what you want is different @OmarBasem.

(into [] [1 2 3]) ; => [1 2 3]
(into [] []) ; => []
(into [] nil) ; => []

;; No need for the default value.
(reagent/atom (into [] (utils/safe-nth messages-index)))

Please double-check, I'm not 100% the code above works.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ilmotta so this works (into [] (safe-nth [1 2] nil)) -> []
and this works (safe-nth [1 2] 0) -> 1
but this does not work (into [] (safe-nth [1 2] 0)) -> Execution error (IllegalArgumentException) at user/eval146 (REPL:1). Don't know how to create ISeq from: java.lang.Long

I think I can just keep it as an if condition :)

Copy link
Contributor

Choose a reason for hiding this comment

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

Damn, you're right, the wheel keeps turning and going back to the original code. into likes sequences.

@status-im-auto
Copy link
Member

93% of end-end tests have passed

Total executed tests: 29
Failed tests: 2
Passed tests: 27
IDs of failed tests: 702808,702838 

Failed tests (2)

Click to expand
  • Rerun failed tests

  • Class TestGroupChatMultipleDeviceMergedNewUI:

    1. test_group_chat_offline_pn, id: 702808

    Device 3: Looking for a message by text: message from old member
    Device 3: Looking for a message by text: message from new member

    critical/chats/test_group_chat.py:261: in test_group_chat_offline_pn
        self.errors.verify_no_errors()
    base_test_case.py:184: in verify_no_errors
        pytest.fail('\n '.join([self.errors.pop(0) for _ in range(len(self.errors))]))
     message from new member PN was not fetched from offline
    



    Device sessions

    Class TestCommunityMultipleDeviceMerged:

    1. test_community_message_send_check_timestamps_sender_username, id: 702838

    Device 2: Find Username by xpath: //*[starts-with(@text,'hello')]/ancestor::android.view.ViewGroup[@content-desc='chat-item']/android.view.ViewGroup/android.widget.TextView[1]
    Device 2: Username is Pastel Elegant Fugu

    critical/test_public_chat_browsing.py:421: in test_community_message_send_check_timestamps_sender_username
        self.errors.verify_no_errors()
    base_test_case.py:184: in verify_no_errors
        pytest.fail('\n '.join([self.errors.pop(0) for _ in range(len(self.errors))]))
     Timestamp is not shown, expected: '10:05 AM, 10:04 AM, 10:03 AM', in fact: '10:02 AM' 
    

    [[blocked by 14797]]

    Device sessions

    Passed tests (27)

    Click to expand

    Class TestGroupChatMultipleDeviceMergedNewUI:

    1. test_group_chat_pin_messages, id: 702732
    Device sessions

    2. test_group_chat_join_send_text_messages_push, id: 702807
    Device sessions

    Class TestCommunityMultipleDeviceMerged:

    1. test_community_emoji_send_copy_paste_reply, id: 702840
    Device sessions

    2. test_community_links_with_previews_github_youtube_twitter_gif_send_enable, id: 702844
    Device sessions

    3. test_community_mentions_push_notification, id: 702786
    Device sessions

    4. test_community_contact_block_unblock_offline, id: 702894
    Device sessions

    5. test_community_leave, id: 702845
    Device sessions

    6. test_community_unread_messages_badge, id: 702841
    Device sessions

    7. test_community_message_delete, id: 702839
    Device sessions

    8. test_community_message_edit, id: 702843
    Device sessions

    Class TestActivityCenterContactRequestMultipleDevicePR:

    1. test_activity_center_contact_request_decline, id: 702850
    Device sessions

    2. test_activity_center_contact_request_accept_swipe_mark_all_as_read, id: 702851
    Device sessions

    Class TestCommunityOneDeviceMerged:

    1. test_community_navigate_to_channel_when_relaunch, id: 702846
    Device sessions

    2. test_community_copy_and_paste_message_in_chat_input, id: 702742
    Device sessions

    Class TestOneToOneChatMultipleSharedDevicesNewUi:

    1. test_1_1_chat_text_message_delete_push_disappear, id: 702733
    Device sessions

    2. test_1_1_chat_edit_message, id: 702855
    Device sessions

    3. test_1_1_chat_non_latin_messages_stack_update_profile_photo, id: 702745
    Device sessions

    4. test_1_1_chat_message_reaction, id: 702730
    Device sessions

    5. test_1_1_chat_emoji_send_reply_and_open_link, id: 702782
    Device sessions

    6. test_1_1_chat_is_shown_message_sent_delivered_from_offline, id: 702783
    Device sessions

    7. test_1_1_chat_pin_messages, id: 702731
    Device sessions

    8. test_1_1_chat_push_emoji, id: 702813
    Device sessions

    9. test_1_1_chat_delete_via_long_press_relogin, id: 702784
    Device sessions

    Class TestActivityMultipleDevicePR:

    1. test_activity_center_reply_read_unread_delete_filter_swipe, id: 702947
    Device sessions

    2. test_activity_center_admin_notification_accept_swipe, id: 702958
    Device sessions

    3. test_navigation_jump_to, id: 702936
    Device sessions

    4. test_activity_center_mentions, id: 702957
    Device sessions

    @VolodLytvynenko VolodLytvynenko self-assigned this Mar 29, 2023
    @VolodLytvynenko VolodLytvynenko removed their assignment Mar 29, 2023
    @VolodLytvynenko VolodLytvynenko self-assigned this Mar 29, 2023
    @VolodLytvynenko
    Copy link
    Contributor

    hi, @OmarBasem thank you for the fix. No issues from my side. PR is ready o be merged

    @OmarBasem OmarBasem merged commit 0503f5c into develop Mar 29, 2023
    @OmarBasem OmarBasem deleted the image-fixes branch March 29, 2023 18:12
    # for free to join this conversation on GitHub. Already have an account? # to comment
    Projects
    No open projects
    Archived in project
    Development

    Successfully merging this pull request may close these issues.

    "Index argument nth must be a number" error appears randomly on closing lightbox screen
    5 participants