All Downloads are FREE. Search and download functionalities are using the official Maven repository.

it.auties.whatsapp.model.response.UserChosenNameResponse Maven / Gradle / Ivy

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 name) {

    @SuppressWarnings("unchecked")
    public static Optional ofJson(String json) {
        try {
            var parsedJson = Json.readValue(json, new TypeReference>() {
            });
            var data = (Map) parsedJson.get("data");
            var updates = (List) data.get("xwa2_users_updates_since");
            var latestUpdate = (Map) updates.getFirst();
            var updatesData = (List) latestUpdate.get("updates");
            var latestUpdateData = (Map) updatesData.getFirst();
            return Optional.of(new UserChosenNameResponse(Optional.ofNullable((String) latestUpdateData.get("text"))));
        } catch (Throwable throwable) {
            return Optional.empty();
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy