-
Notifications
You must be signed in to change notification settings - Fork 194
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
84 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
src/main/java/it/auties/whatsapp/model/request/UserChosenNameRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package it.auties.whatsapp.model.request; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
import java.util.List; | ||
|
||
public record UserChosenNameRequest(List<Variable> variables) { | ||
public record Variable(@JsonProperty("user_id") String userId) { | ||
|
||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
src/main/java/it/auties/whatsapp/model/response/ContactAboutResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package it.auties.whatsapp.model.response; | ||
|
||
import com.fasterxml.jackson.core.type.TypeReference; | ||
import it.auties.whatsapp.model.node.Node; | ||
import it.auties.whatsapp.util.Clock; | ||
import it.auties.whatsapp.util.Json; | ||
|
||
import java.time.ZonedDateTime; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
|
||
public record ContactAboutResponse(Optional<String> about, Optional<ZonedDateTime> timestamp) { | ||
public static ContactAboutResponse ofNode(Node source) { | ||
return new ContactAboutResponse( | ||
source.contentAsString(), | ||
Clock.parseSeconds(source.attributes().getLong("t")) | ||
); | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
public static Optional<ContactAboutResponse> ofJson(String json) { | ||
try { | ||
var parsedJson = Json.readValue(json, new TypeReference<Map<String, Object>>() {}); | ||
var data = (Map<String, ?>) parsedJson.get("data"); | ||
var updates = (List<?>) data.get("xwa2_users_updates_since"); | ||
var latestUpdate = (Map<String, ?>) updates.getFirst(); | ||
var updatesData = (List<?>) latestUpdate.get("updates"); | ||
var latestUpdateData = (Map<String, ?>) updatesData.getFirst(); | ||
return Optional.of(new ContactAboutResponse(Optional.ofNullable((String) latestUpdateData.get("text")), Optional.empty())); | ||
} catch (Throwable throwable) { | ||
return Optional.empty(); | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/main/java/it/auties/whatsapp/model/response/UserChosenNameResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package it.auties.whatsapp.model.response; | ||
|
||
import com.fasterxml.jackson.core.type.TypeReference; | ||
import it.auties.whatsapp.util.Json; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
|
||
public record UserChosenNameResponse(Optional<String> name) { | ||
|
||
@SuppressWarnings("unchecked") | ||
public static Optional<UserChosenNameResponse> ofJson(String json) { | ||
try { | ||
var parsedJson = Json.readValue(json, new TypeReference<Map<String, Object>>() {}); | ||
var data = (Map<String, ?>) parsedJson.get("data"); | ||
var updates = (List<?>) data.get("xwa2_users_updates_since"); | ||
var latestUpdate = (Map<String, ?>) updates.getFirst(); | ||
var updatesData = (List<?>) latestUpdate.get("updates"); | ||
var latestUpdateData = (Map<String, ?>) updatesData.getFirst(); | ||
return Optional.of(new UserChosenNameResponse(Optional.ofNullable((String) latestUpdateData.get("text")))); | ||
} catch (Throwable throwable) { | ||
return Optional.empty(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters