Search in sources :

Example 6 with CommunicationIdentifier

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

the class NotificationUtilsTest method canParsePhoneNumberRawId.

@Test
public void canParsePhoneNumberRawId() {
    final String phoneNumber = "+1234567890";
    final String phoneNumberRawId = "4:" + phoneNumber;
    CommunicationIdentifier communicationIdentifier = NotificationUtils.getCommunicationIdentifier(phoneNumberRawId);
    assertNotNull(communicationIdentifier);
    assertTrue(communicationIdentifier instanceof PhoneNumberIdentifier);
    PhoneNumberIdentifier phoneNumberIdentifier = (PhoneNumberIdentifier) communicationIdentifier;
    assertEquals(phoneNumber, phoneNumberIdentifier.getPhoneNumber());
    assertEquals(phoneNumberRawId, phoneNumberIdentifier.getRawId());
}
Also used : CommunicationIdentifier(com.azure.android.communication.common.CommunicationIdentifier) PhoneNumberIdentifier(com.azure.android.communication.common.PhoneNumberIdentifier) Test(org.junit.jupiter.api.Test)

Example 7 with CommunicationIdentifier

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

the class NotificationUtilsTest method canParseTeamsVisitorUserRawId.

@Test
public void canParseTeamsVisitorUserRawId() {
    final String teamsVisitorUserRawId = "8:teamsvisitor:" + USER_ID;
    CommunicationIdentifier communicationIdentifier = NotificationUtils.getCommunicationIdentifier(teamsVisitorUserRawId);
    assertNotNull(communicationIdentifier);
    assertTrue(communicationIdentifier instanceof MicrosoftTeamsUserIdentifier);
    MicrosoftTeamsUserIdentifier microsoftTeamsUserIdentifier = (MicrosoftTeamsUserIdentifier) communicationIdentifier;
    assertEquals(CommunicationCloudEnvironment.PUBLIC, microsoftTeamsUserIdentifier.getCloudEnvironment());
    assertTrue(microsoftTeamsUserIdentifier.isAnonymous());
    assertEquals(USER_ID, microsoftTeamsUserIdentifier.getUserId());
    assertEquals(teamsVisitorUserRawId, microsoftTeamsUserIdentifier.getRawId());
}
Also used : MicrosoftTeamsUserIdentifier(com.azure.android.communication.common.MicrosoftTeamsUserIdentifier) CommunicationIdentifier(com.azure.android.communication.common.CommunicationIdentifier) Test(org.junit.jupiter.api.Test)

Example 8 with CommunicationIdentifier

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

the class ChatThreadCreatedEvent method setParticipants.

/**
 * Sets the participants of the thread.
 */
ChatThreadCreatedEvent setParticipants() {
    this.participants = new ArrayList<>();
    try {
        JSONArray participantsJsonArray = new JSONArray(this.participantsJsonString);
        for (int i = 0; i < participantsJsonArray.length(); i++) {
            JSONObject participant = participantsJsonArray.getJSONObject(i);
            CommunicationIdentifier communicationUser = NotificationUtils.getCommunicationIdentifier(participant.getString("participantId"));
            ChatParticipant chatParticipant = new ChatParticipant();
            chatParticipant.setCommunicationIdentifier(communicationUser);
            chatParticipant.setDisplayName(participant.getString("displayName"));
            this.participants.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 9 with CommunicationIdentifier

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

the class ChatThreadDeletedEvent method setDeletedBy.

/**
 * Sets the deletedBy of the thread.
 */
ChatThreadDeletedEvent setDeletedBy() {
    this.deletedBy = new ChatParticipant();
    try {
        JSONObject deletedByJsonObject = new JSONObject(this.deletedByJsonString);
        CommunicationIdentifier deletedByCommunicationIdentifier = NotificationUtils.getCommunicationIdentifier(deletedByJsonObject.getString("participantId"));
        this.deletedBy.setCommunicationIdentifier(deletedByCommunicationIdentifier).setDisplayName(deletedByJsonObject.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 10 with CommunicationIdentifier

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

the class ChatThreadPropertiesUpdatedEvent method setUpdatedBy.

/**
 * Sets the updatedBy of the thread.
 */
ChatThreadPropertiesUpdatedEvent setUpdatedBy() {
    this.updatedBy = new ChatParticipant();
    try {
        JSONObject updatedByJsonObject = new JSONObject(this.updatedByJsonString);
        CommunicationIdentifier updatedByCommunicationIdentifier = NotificationUtils.getCommunicationIdentifier(updatedByJsonObject.getString("participantId"));
        this.updatedBy.setCommunicationIdentifier(updatedByCommunicationIdentifier).setDisplayName(updatedByJsonObject.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)

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