Refactor Duplicated Code in KDE Connect Android-side SMS Helper
ClosedPublic

Authored by alexkovrigin on Nov 19 2018, 4:37 AM.

Details

Summary

In src/org/kde/kdeconnect/Helpers/SMSHelper.java:
getMessagesWithFilter() and getConversations() functions are now both using new function: getMessages().

Test Plan
  • Build android app and run it on android phone
  • Pair it with the desktop and open sms app (kdeconnect-sms).
  • Everything works as earlier, but now with refactored code.

Diff Detail

Repository
R225 KDE Connect - Android application
Branch
master
Lint
No Linters Available
Unit
No Unit Test Coverage
Build Status
Buildable 5141
Build 5159: arc lint + arc unit
alexkovrigin created this revision.Nov 19 2018, 4:37 AM
Restricted Application added a project: KDE Connect. · View Herald TranscriptNov 19 2018, 4:37 AM
Restricted Application added a subscriber: kdeconnect. · View Herald Transcript
alexkovrigin requested review of this revision.Nov 19 2018, 4:37 AM

This is good work! Thank you. Were you able to get the app with this patch working for your own phone? If not, could you share the full stack trace (paste.kde.org) so I can have a look?
Don't forget to mark the GCi task as completed so I can approve it once we get this merged.

src/org/kde/kdeconnect/Helpers/SMSHelper.java
122–123

I missed this before (sorry). These comments still refer to one of the earlier revisions

141–142

This variable is unused because we pull threadID from the Message later, so might as well get rid of it

152–158

A common way to do this same check is:

if (!toReturn.containsKey(threadID)) {
  toReturn.put(threadID, new ArrayList<Message>());
}
toReturn.get(threadID).add(message);

The code you currently have is fine, and if you like it this way then you should leave it this way. I only mention this because you are working on GCi, so I should share my wisdom :)

157–158

Even though you can have an else with no braces, I strongly recommend against it. The problem is that a future programmer might come along and try to add to this block (maybe he is more experienced with Python than C++) and the code will not get executed where he expects it to. Moreover, there is a possibility that could get get inserted by mistake, for instance by a git merge
For a real-world example of where this resulted in a serious disaster, see this article: https://nakedsecurity.sophos.com/2014/02/24/anatomy-of-a-goto-fail-apples-ssl-bug-explained-plus-an-unofficial-patch/

  • Refactor Duplicated Code in KDE Connect Android-side SMS Helper v2

Small fixes, suggested by sredman, were made.

sredman accepted this revision.Nov 19 2018, 5:18 PM

This is great. Thank you very much!

This revision is now accepted and ready to land.Nov 19 2018, 5:18 PM
sredman closed this revision.Nov 19 2018, 5:21 PM