diff --git a/src/main/java/fr/delthas/skype/NotifConnector.java b/src/main/java/fr/delthas/skype/NotifConnector.java index 6fe5b90..c112442 100644 --- a/src/main/java/fr/delthas/skype/NotifConnector.java +++ b/src/main/java/fr/delthas/skype/NotifConnector.java @@ -824,11 +824,7 @@ private String getXMLField(String XML, String fieldName) throws ParseException { } private String getSelfLiveUsername() { - if (microsoft) { - return "live:" + username.substring(0, username.indexOf('@')); - } else { - return username; - } + return skype.getUser(username).getLiveUsername(); } private static class Packet { diff --git a/src/main/java/fr/delthas/skype/Presence.java b/src/main/java/fr/delthas/skype/Presence.java index 3ed6a23..8f91fba 100644 --- a/src/main/java/fr/delthas/skype/Presence.java +++ b/src/main/java/fr/delthas/skype/Presence.java @@ -12,6 +12,10 @@ public enum Presence { * Away / Be Right Back (orange clock on Skype) */ AWAY("AWY"), + /** + * Idle / Absent + */ + IDLE("IDL"), /** * Busy / Do Not Disturb (red sign on Skype) */ diff --git a/src/main/java/fr/delthas/skype/Skype.java b/src/main/java/fr/delthas/skype/Skype.java index d72e064..54d6414 100644 --- a/src/main/java/fr/delthas/skype/Skype.java +++ b/src/main/java/fr/delthas/skype/Skype.java @@ -48,6 +48,7 @@ public final class Skype { private boolean connecting = false; private volatile long expires; private IOException exceptionDuringConnection; + private User me; // --- Public API (except listeners add/remove methods) --- // diff --git a/src/main/java/fr/delthas/skype/User.java b/src/main/java/fr/delthas/skype/User.java index a6ea569..5ec177b 100644 --- a/src/main/java/fr/delthas/skype/User.java +++ b/src/main/java/fr/delthas/skype/User.java @@ -21,6 +21,7 @@ public class User { private String city; private String displayName; private String avatarUrl; + private String liveUsername; private Presence presence = Presence.OFFLINE; User(Skype skype, String username) { @@ -247,6 +248,14 @@ void setPresence(Presence presence, boolean triggerListeners) { } } + public String getLiveUsername() { + return liveUsername; + } + + public void setLiveUsername(String liveUsername) { + this.liveUsername = liveUsername; + } + @Override public int hashCode() { final int prime = 31; diff --git a/src/main/java/fr/delthas/skype/WebConnector.java b/src/main/java/fr/delthas/skype/WebConnector.java index dbda162..f7a30db 100644 --- a/src/main/java/fr/delthas/skype/WebConnector.java +++ b/src/main/java/fr/delthas/skype/WebConnector.java @@ -86,10 +86,12 @@ private void updateContacts() throws IOException { updated = true; String selfResponse = sendRequest(Method.GET, "/users/self/profile").body(); JSONObject selfJSON = new JSONObject(selfResponse); - updateUser(selfJSON, false); + + User loggedUser = updateUser(selfJSON, false, username); String profilesResponse = - sendRequest(Method.GET, "https://contacts.skype.com/contacts/v2/users/" + getSelfLiveUsername() + "/contacts", true).body(); + sendRequest(Method.GET, "https://contacts.skype.com/contacts/v2/users/" + loggedUser.getLiveUsername() + "/contacts", true).body(); + try { JSONObject json = new JSONObject(profilesResponse); if (json.optString("message", null) != null) { @@ -108,6 +110,10 @@ private void updateContacts() throws IOException { } private User updateUser(JSONObject userJSON, boolean newContactType) throws ParseException { + return updateUser(userJSON, newContactType, null); + } + + private User updateUser(JSONObject userJSON, boolean newContactType, String username) throws ParseException { String userUsername; String userFirstName = null; String userLastName = null; @@ -146,9 +152,15 @@ private User updateUser(JSONObject userJSON, boolean newContactType) throws Pars userUsername = mri.substring(senderBegin + 1); userDisplayName = userJSON.optString("display_name", null); JSONObject profileJSON = userJSON.getJSONObject("profile"); - JSONObject nameJSON = profileJSON.getJSONObject("name"); - userFirstName = nameJSON.optString("first", null); - userLastName = nameJSON.optString("surname", null); + + userFirstName = userUsername; + userLastName = ""; + if (profileJSON.has("name")) { + JSONObject nameJSON = profileJSON.getJSONObject("name"); + userFirstName = nameJSON.optString("first", null); + userLastName = nameJSON.optString("surname", null); + } + userMood = profileJSON.optString("mood", null); if (profileJSON.has("locations")) { JSONObject locationJSON = profileJSON.optJSONArray("locations").optJSONObject(0); @@ -162,7 +174,7 @@ private User updateUser(JSONObject userJSON, boolean newContactType) throws Pars } catch (JSONException e) { throw new ParseException(e); } - User user = skype.getUser(userUsername); + User user = skype.getUser(username != null ? username : userUsername); user.setCity(getPlaintext(userCity)); user.setCountry(getPlaintext(userCountry)); user.setDisplayName(getPlaintext(userDisplayName)); @@ -170,6 +182,7 @@ private User updateUser(JSONObject userJSON, boolean newContactType) throws Pars user.setLastName(getPlaintext(userLastName)); user.setMood(getPlaintext(userMood)); user.setAvatarUrl(userAvatarUrl); + user.setLiveUsername(userUsername); return user; } @@ -231,12 +244,4 @@ private Response sendRequest(Method method, String apiPath, boolean absoluteApiP private Response sendRequest(Method method, String apiPath, String... keyval) throws IOException { return sendRequest(method, apiPath, false, keyval); } - - private String getSelfLiveUsername() { - if (username.contains("@")) { - return "live:" + username.substring(0, username.indexOf('@')); - } else { - return username; - } - } -} +} \ No newline at end of file