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

[tr064] Merge duplicate phone book entries #9739

Merged
merged 2 commits into from
Jan 9, 2021
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,25 @@ private void getPhonebook() {
phonebook = phonebooksType.getPhonebook().getContact().stream().map(contact -> {
String contactName = contact.getPerson().getRealName();
return contact.getTelephony().getNumber().stream()
.collect(Collectors.toMap(number -> normalizeNumber(number.getValue()), number -> contactName));
.collect(Collectors.toMap(number -> normalizeNumber(number.getValue()), number -> contactName,
this::mergeSameContactNames));
}).collect(HashMap::new, HashMap::putAll, HashMap::putAll);
logger.debug("Downloaded phonebook {}: {}", phonebookName, phonebook);
} catch (JAXBException | InterruptedException | ExecutionException | TimeoutException e) {
logger.warn("Failed to get phonebook with URL {}:", phonebookUrl, e);
}
}

// in case there are multiple phone entries with same number -> name mapping, i.e. in phonebooks exported from
// mobiles containing multiple accounts like: local, cloudprovider1, messenger1, messenger2,...
private String mergeSameContactNames(String nameA, String nameB) {
if (nameA != null && nameA.equals(nameB)) {
return nameA;
}
throw new IllegalStateException(
"Found different names for the same number: '" + nameA + "' and '" + nameB + "'");
}

@Override
public String getName() {
return phonebookName;
Expand Down