Search in sources :

Example 11 with CommunicationIdentifier

use of com.azure.android.communication.common.CommunicationIdentifier in project azure-sdk-for-android by Azure.

the class ParticipantsAddedEvent method setAddedBy.

/**
 * Sets the addedBy of the thread.
 */
ParticipantsAddedEvent setAddedBy() {
    this.addedBy = new ChatParticipant();
    try {
        JSONObject addedByJsonObject = new JSONObject(this.addedByJsonString);
        CommunicationIdentifier addedByCommunicationIdentifier = NotificationUtils.getCommunicationIdentifier(addedByJsonObject.getString("participantId"));
        this.addedBy.setCommunicationIdentifier(addedByCommunicationIdentifier).setDisplayName(addedByJsonObject.getString("displayName"));
    } catch (JSONException e) {
        return this;
    }
    return this;
}
Also used : JSONObject(org.json.JSONObject) CommunicationIdentifier(com.azure.android.communication.common.CommunicationIdentifier) JSONException(org.json.JSONException)

Example 12 with CommunicationIdentifier

use of com.azure.android.communication.common.CommunicationIdentifier in project azure-sdk-for-android by Azure.

the class CommunicationIdentifierConverterTests method deserializeUnknown.

@Test
public void deserializeUnknown() {
    CommunicationIdentifier unknownIdentifier = CommunicationIdentifierConverter.convert(new CommunicationIdentifierModel().setRawId(rawId), logger);
    assertEquals(UnknownIdentifier.class, unknownIdentifier.getClass());
    assertEquals(rawId, ((UnknownIdentifier) unknownIdentifier).getId());
}
Also used : CommunicationIdentifier(com.azure.android.communication.common.CommunicationIdentifier) CommunicationIdentifierModel(com.azure.android.communication.chat.implementation.models.CommunicationIdentifierModel) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 13 with CommunicationIdentifier

use of com.azure.android.communication.common.CommunicationIdentifier in project azure-sdk-for-android by Azure.

the class ParticipantsAddedEvent method setParticipantsAdded.

/**
 * Sets the participants added to the thread.
 */
ParticipantsAddedEvent setParticipantsAdded() {
    this.participantsAdded = new ArrayList<>();
    try {
        JSONArray participantsAddedJsonArray = new JSONArray(this.participantsAddedJsonString);
        for (int i = 0; i < participantsAddedJsonArray.length(); i++) {
            JSONObject participant = participantsAddedJsonArray.getJSONObject(i);
            CommunicationIdentifier communicationUser = NotificationUtils.getCommunicationIdentifier(participant.getString("participantId"));
            ChatParticipant chatParticipant = new ChatParticipant();
            chatParticipant.setCommunicationIdentifier(communicationUser);
            chatParticipant.setDisplayName(participant.getString("displayName"));
            chatParticipant.setShareHistoryTime(NotificationUtils.parseEpochTime(participant.getLong("shareHistoryTime")));
            this.participantsAdded.add(chatParticipant);
        }
    } catch (JSONException e) {
        return this;
    }
    return this;
}
Also used : JSONObject(org.json.JSONObject) CommunicationIdentifier(com.azure.android.communication.common.CommunicationIdentifier) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException)

Example 14 with CommunicationIdentifier

use of com.azure.android.communication.common.CommunicationIdentifier in project azure-sdk-for-android by Azure.

the class ParticipantsRemovedEvent method setRemovedBy.

/**
 * Sets the removedBy of the thread.
 */
ParticipantsRemovedEvent setRemovedBy() {
    this.removedBy = new ChatParticipant();
    try {
        JSONObject removedByJsonObject = new JSONObject(this.removedByJsonString);
        CommunicationIdentifier removedByCommunicationIdentifier = NotificationUtils.getCommunicationIdentifier(removedByJsonObject.getString("participantId"));
        this.removedBy.setCommunicationIdentifier(removedByCommunicationIdentifier).setDisplayName(removedByJsonObject.getString("displayName"));
    } catch (JSONException e) {
        return this;
    }
    return this;
}
Also used : JSONObject(org.json.JSONObject) CommunicationIdentifier(com.azure.android.communication.common.CommunicationIdentifier) JSONException(org.json.JSONException)

Example 15 with CommunicationIdentifier

use of com.azure.android.communication.common.CommunicationIdentifier in project azure-sdk-for-android by Azure.

the class ParticipantsRemovedEvent method setParticipantsRemoved.

/**
 * Sets the participants removed from the thread.
 */
ParticipantsRemovedEvent setParticipantsRemoved() {
    this.participantsRemoved = new ArrayList<>();
    try {
        JSONArray participantsRemovedJsonArray = new JSONArray(this.participantsRemovedJsonString);
        for (int i = 0; i < participantsRemovedJsonArray.length(); i++) {
            JSONObject participant = participantsRemovedJsonArray.getJSONObject(i);
            CommunicationIdentifier communicationUser = NotificationUtils.getCommunicationIdentifier(participant.getString("participantId"));
            ChatParticipant chatParticipant = new ChatParticipant();
            chatParticipant.setCommunicationIdentifier(communicationUser);
            chatParticipant.setDisplayName(participant.getString("displayName"));
            chatParticipant.setShareHistoryTime(NotificationUtils.parseEpochTime(participant.getLong("shareHistoryTime")));
            this.participantsRemoved.add(chatParticipant);
        }
    } catch (JSONException e) {
        return this;
    }
    return this;
}
Also used : JSONObject(org.json.JSONObject) CommunicationIdentifier(com.azure.android.communication.common.CommunicationIdentifier) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException)

Aggregations

CommunicationIdentifier (com.azure.android.communication.common.CommunicationIdentifier)21 Test (org.junit.jupiter.api.Test)13 JSONException (org.json.JSONException)8 JSONObject (org.json.JSONObject)8 CommunicationUserIdentifier (com.azure.android.communication.common.CommunicationUserIdentifier)4 MicrosoftTeamsUserIdentifier (com.azure.android.communication.common.MicrosoftTeamsUserIdentifier)4 CommunicationIdentifierModel (com.azure.android.communication.chat.implementation.models.CommunicationIdentifierModel)3 JSONArray (org.json.JSONArray)3 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 CommunicationUserIdentifierModel (com.azure.android.communication.chat.implementation.models.CommunicationUserIdentifierModel)1 PhoneNumberIdentifierModel (com.azure.android.communication.chat.implementation.models.PhoneNumberIdentifierModel)1 PhoneNumberIdentifier (com.azure.android.communication.common.PhoneNumberIdentifier)1 UnknownIdentifier (com.azure.android.communication.common.UnknownIdentifier)1