apps-android-commons icon indicating copy to clipboard operation
apps-android-commons copied to clipboard

[Bug]: "copy the wikitext to the clipboard" produces different results depending on timing

Open mnalis opened this issue 2 years ago • 35 comments

Summary

Pressing the button copy the wikitext to the clipboard produces a different result depending if the upload is still in progress (wrong result), or whether the upload has finished (correct result).

Steps to reproduce

  1. have a slow network connection
  2. add new picture, fill metadata and submit
  3. while the picture is still uploading (i.e. a progress bar is being shown), click on the copy the wikitext to the clipboard button and paste the result somewhere
  4. wait until the upload finishes
  5. click on the copy the wikitext to the clipboard button again and paste the result somewhere

Expected behaviour

the first and second value copied are the same.

Actual behaviour

The first and second results differ. For example, for this file: https://commons.wikimedia.org/wiki/File:Knafel%C4%8Deva_markacija_na_odrezanoj_grani,_Prvi%C4%87.jpg the first copy/paste produces:

[[Knafelčeva markacija na odrezanoj grani, Prvić.jpg|thumb|]]

(which is wrong) while the second copy/paste produces (correct!):

[[File:Knafelčeva markacija na odrezanoj grani, Prvić.jpg|thumb|]]

i.e. the first one misses File: (which then makes problems when one pastes it to the app that expects standard commons format, like e.g. EveryDoor). Especially annoying when the mobile internet is slow, as one is forced to either wait a long time, or manually fix every image name.

Device name

Huawei P30Pro

Android version

Android 10 (EMUI 12)

Commons app version

4.1.0 (latest f-droid)

Device logs

No response

Screen-shots

https://github.com/commons-app/apps-android-commons/assets/156656/71de16af-e770-4aeb-961f-eadd9d19228d

Would you like to work on the issue?

None

mnalis avatar Sep 27 '23 04:09 mnalis

hello @nicolas-raoul, i am new to the project and exploring the project. Since it is a good-first-issue, can i give it a try?

Kshitiz-Mhto avatar Sep 28 '23 11:09 Kshitiz-Mhto

@Kshitiz-Mhto It is yours, thanks! Please let us know about your progress every few days. 🙂

nicolas-raoul avatar Sep 28 '23 14:09 nicolas-raoul

actually my exams are ongoing ryt now, so i am giveing as much as free time i have on this. so my response might be delay hope you understand.

i did find this code that casing the issue, i m workng on it. thanks you

file -> fr.free.nrw.commons.media.MediaDetailFragment

Screenshot from 2023-10-01 14-39-26

Kshitiz-Mhto avatar Oct 01 '23 08:10 Kshitiz-Mhto

@Kshitiz-Mhto Sure no worries, please focus on your exams, letting us know every 2 weeks is fine. :-)

nicolas-raoul avatar Oct 01 '23 10:10 nicolas-raoul

@Kshitiz-Mhto are you still working on this? @nicolas-raoul Can I please give this a try? This is my first open source contribution. I will try my best and I think I would be able to finish this within two weeks 😄

TaiHaDev avatar Oct 15 '23 08:10 TaiHaDev

@TaiHaDev How about #5263? :-)

nicolas-raoul avatar Oct 15 '23 09:10 nicolas-raoul

Hi @nicolas-raoul, I had a look at the issue but I couldn't reproduce but I found an interesting one #5212 that I can reproduce the bug . Can I give it a try?😁 I will regularly update my progress. Thank you!

TaiHaDev avatar Oct 15 '23 10:10 TaiHaDev

@TaiHaDev Sure! Please comment there, as I can't assign you unless you comment. Thanks! :-)

nicolas-raoul avatar Oct 15 '23 11:10 nicolas-raoul

my exam r over now, i m all good to go now, i will finish this as soon as i can. thank u!

Kshitiz-Mhto avatar Oct 16 '23 03:10 Kshitiz-Mhto

Any luck @Kshitiz-Mhto ?

mnalis avatar Nov 09 '23 23:11 mnalis

Hello! I'm new to the open source community and exploring the project. I saw this is a good first issue. Could I give it a try?

axelthepony27 avatar Dec 26 '23 17:12 axelthepony27

Hello! I'm new to the Open Source Contribution

annuk123 avatar Dec 26 '23 17:12 annuk123

@axelthepony27 It is yours, please let us know about your progress every week or so, thanks! 🙂

nicolas-raoul avatar Dec 27 '23 06:12 nicolas-raoul

@annuk123 How about https://github.com/commons-app/apps-android-commons/issues/5194 for instance? 🙂

nicolas-raoul avatar Dec 27 '23 06:12 nicolas-raoul

@nicolas-raoul Thanks! I forked the repo and cloned it to my locale, but the file fr.free.nrw.commons.media.MediaDetailFragment appears to have an import that doesn't exist. Is this a problem of mine, or do you know what else could be causing this? image

axelthepony27 avatar Dec 27 '23 19:12 axelthepony27

@axelthepony27 And what happens when you try to compile? Do you get some error, or does it just work?

For me, GitHub workflow seems to compile latest main just fine, e.g. https://github.com/mnalis/apps-android-commons/actions/runs/7346949892/job/20002559077

mnalis avatar Dec 28 '23 00:12 mnalis

@mnalis When I try to build, I get this error. Perhaps I missed a step in the configuration? Is there something else I should do? I followed the steps described in the quick guide verbatim (at least to my knowledge). image

axelthepony27 avatar Dec 28 '23 04:12 axelthepony27

@axelthepony27 well, I don't really know (I don't even have local Android SDK installed - I just use GitHub to build it).

But:

  • the "failed to find Platform SDK with path" (which is the real error) seems to me unrelated to the originally reported error ("missing fr.free.nrw.commons.BuildConfig", which seems to be a red herring)
  • it seems related to your build toolkit, not to Commons app itself. Have you been successfully building any other Android projects on that setup?
  • my first guess would be that the "platforms;android-33" part of the error might indicate you need to download that correct platform? e.g. via menu > Tools > SDK Manager ? As shown in screenshot here
  • if that doesn't help, I'd try searching the web for the web for similar errors

mnalis avatar Dec 28 '23 12:12 mnalis

@mnalis Thanks! Indeed, the problem was solved by installing the correct SDK. I'll get to work on the issue now, it does appear to concern to the fragment of code that @Kshitiz-Mhto mentioned.

axelthepony27 avatar Dec 28 '23 16:12 axelthepony27

Doing some tests, I found out that the "description" metadata also changes if copied during upload. Do we know if this is expected, or is it also part of the issue? In the following SS, the first line of text was copied during upload, and the second one once it was done. We can noties that, indeed, the File: substring is missing, but there are also some dangling {} and en|1= that aren't present in the expected result. image

axelthepony27 avatar Dec 29 '23 18:12 axelthepony27

Great finding!

Ideally File: should be present even when copied during upload.

The second line's syntax is the right one.

nicolas-raoul avatar Dec 29 '23 22:12 nicolas-raoul

@annuk123 How about #5194 for instance? 🙂

Thanks 😇

annuk123 avatar Dec 31 '23 08:12 annuk123

@annuk123 That one got taken quickly, but how about https://github.com/commons-app/apps-android-commons/issues/5413 ?

nicolas-raoul avatar Dec 31 '23 12:12 nicolas-raoul

Well, doing some tests, I determined the problem lies on the media.getFilename() and media.getFallbackDescription() methods. Something happens between when the upload is in progress and when it is done that changes the outputs of those methods. I, however, was unable to locate where, as those attributes come from the file Media.kt, and don't have explicit getters. Does anyone have any idea where the problem might originate? Perhaps on the code that manages the upload of files.

axelthepony27 avatar Jan 02 '24 20:01 axelthepony27

@axelthepony27 perhaps you can add the debug code around places where this gets called to get more precise idea when and where exactly the value changes? That should be instructional to finding the cause of the issue (and thus, the fix).

mnalis avatar Jan 20 '24 01:01 mnalis

@mnalis Thanks, I'll try that. I went on vacation for a couple of weeks, but I'll retake the issue this week

axelthepony27 avatar Jan 23 '24 17:01 axelthepony27

Doing some more tests, I noticed that, while an image is still uploading, the "Description" field presents the text in the wrong format, like this: image

However, after the image has finished uploading, the description text is correct: image

This leads me to believe that the error doesn't lie in the copy method itself, onCopyWikicodeClicked(), as originally thought, but rather on something else: perhaps the the code that generates the text fields on the image's card in the first place. Does anyone know where that happens, so that I could have a better-guided debugging? I can't seem to find where it happends, or another good place to look for the bug.

axelthepony27 avatar Jan 23 '24 18:01 axelthepony27

Well, I found the bit of code that formats the "Description" part only. It seems to happen during upload. The upload process formats the filename and description of an upload differently than when an upload is done. I think after an upload has finished, the details panel pulls the filename and description from some other place. However, I'm unable to find where exactly. In any case, what might be happening could be fixed by one of two ways:

  1. Find when and from where the filename and description fields pull the text, and agree them so that they pull the text from only one place (the correct one). I still, however, would need to find when and where it happens exactly.
  2. Agree the formats both during upload and when the upload is done. This, however, doesn't seem like a good solution, as the description of method formatDescriptions() in class Contribution.kt says it "Formats the list of descriptions into the format Commons requires for uploads."

image

Testing it, this method definitively is where the "wrong" format takes place: image

I would like a little more guidance on how to proceed, if anyone could lend me a hand.

axelthepony27 avatar Jan 23 '24 20:01 axelthepony27

Hi @nicolas-raoul , I just started to look for issues so that I can contribute, since it is a good first issue can i give it a try

Get4nik avatar Feb 02 '24 13:02 Get4nik

Hi, @nicolas-raoul @mnalis. Just following up on this, did you have the chance to check out my questions?

axelthepony27 avatar Feb 27 '24 17:02 axelthepony27