Search in sources :

Example 1 with ChatThreadPropertiesUpdatedEvent

use of com.azure.android.communication.chat.models.ChatThreadPropertiesUpdatedEvent in project azure-sdk-for-android by Azure.

the class MainActivity method registerPushNotificationListener.

public void registerPushNotificationListener(View view) {
    logAndToast("Register push notification listeners");
    try {
        chatAsyncClient.addPushNotificationHandler(CHAT_MESSAGE_RECEIVED, (ChatEvent payload) -> {
            Log.i(TAG, "Push Notification CHAT_MESSAGE_RECEIVED.");
            ChatMessageReceivedEvent event = (ChatMessageReceivedEvent) payload;
            Log.i(TAG, "Message received!" + " ThreadId: " + event.getChatThreadId() + " MessageId: " + event.getId() + " Content: " + event.getContent() + " Priority: " + event.getPriority() + " SenderDisplayName: " + event.getSenderDisplayName() + " SenderMri: " + ((CommunicationUserIdentifier) event.getSender()).getId() + " Version: " + event.getVersion() + " CreatedOn: " + event.getCreatedOn() + " Type: " + event.getType() + " RecipientMri: " + ((CommunicationUserIdentifier) event.getRecipient()).getId());
        });
        chatAsyncClient.addPushNotificationHandler(CHAT_MESSAGE_EDITED, (ChatEvent payload) -> {
            Log.i(TAG, "Push Notification CHAT_MESSAGE_EDITED.");
            ChatMessageEditedEvent event = (ChatMessageEditedEvent) payload;
            Log.i(TAG, "Message edited!" + " ThreadId: " + event.getChatThreadId() + " MessageId: " + event.getId() + " Content: " + event.getContent() + " SenderDisplayName: " + event.getSenderDisplayName() + " SenderMri: " + ((CommunicationUserIdentifier) event.getSender()).getId() + " Version: " + event.getVersion() + " CreatedOn: " + event.getCreatedOn() + " EditedOn: " + event.getEditedOn() + " RecipientMri: " + ((CommunicationUserIdentifier) event.getRecipient()).getId());
        });
        chatAsyncClient.addPushNotificationHandler(CHAT_MESSAGE_DELETED, (ChatEvent payload) -> {
            Log.i(TAG, "Push Notification CHAT_MESSAGE_DELETED.");
            ChatMessageDeletedEvent event = (ChatMessageDeletedEvent) payload;
            Log.i(TAG, "Message deleted!" + " ThreadId: " + event.getChatThreadId() + " MessageId: " + event.getId() + " SenderDisplayName: " + event.getSenderDisplayName() + " SenderMri: " + ((CommunicationUserIdentifier) event.getSender()).getId() + " Version: " + event.getVersion() + " CreatedOn: " + event.getCreatedOn() + " DeletedOn: " + event.getDeletedOn() + " RecipientMri: " + ((CommunicationUserIdentifier) event.getRecipient()).getId());
        });
        chatAsyncClient.addPushNotificationHandler(CHAT_THREAD_CREATED, (ChatEvent payload) -> {
            Log.i(TAG, "Push Notification CHAT_THREAD_CREATED.");
            ChatThreadCreatedEvent event = (ChatThreadCreatedEvent) payload;
            Log.i(TAG, "Thread Created!" + " ThreadId: " + event.getChatThreadId() + " Properties_Id: " + event.getProperties().getId() + " Properties_Topic: " + event.getProperties().getTopic() + " Properties_CreatedOn: " + event.getProperties().getCreatedOn() + " Properties_CreatedByMri: " + ((CommunicationUserIdentifier) event.getProperties().getCreatedByCommunicationIdentifier()).getId() + " Participants_size: " + event.getParticipants().size() + " Version: " + event.getVersion() + " CreatedOn: " + event.getCreatedOn() + " CreatedBy_DisplayName: " + event.getCreatedBy().getDisplayName() + " CreatedBy_Mri: " + ((CommunicationUserIdentifier) event.getCreatedBy().getCommunicationIdentifier()).getId());
        });
        chatAsyncClient.addPushNotificationHandler(CHAT_THREAD_PROPERTIES_UPDATED, (ChatEvent payload) -> {
            Log.i(TAG, "Push Notification CHAT_THREAD_PROPERTIES_UPDATED.");
            ChatThreadPropertiesUpdatedEvent event = (ChatThreadPropertiesUpdatedEvent) payload;
            Log.i(TAG, "Thread Updated!" + " ThreadId: " + event.getChatThreadId() + " Properties_Id: " + event.getProperties().getId() + " Properties_Topic: " + event.getProperties().getTopic() + " Version: " + event.getVersion() + " UpdatedOn: " + event.getUpdatedOn() + " UpdatedBy_DisplayName: " + event.getUpdatedBy().getDisplayName() + " UpdatedBy_Mri: " + ((CommunicationUserIdentifier) event.getUpdatedBy().getCommunicationIdentifier()).getId());
        });
        chatAsyncClient.addPushNotificationHandler(CHAT_THREAD_DELETED, (ChatEvent payload) -> {
            Log.i(TAG, "Push Notification CHAT_THREAD_DELETED.");
            ChatThreadDeletedEvent event = (ChatThreadDeletedEvent) payload;
            Log.i(TAG, "Thread Deleted!" + " ThreadId: " + event.getChatThreadId() + " Version: " + event.getVersion() + " DeletedOn: " + event.getDeletedOn() + " DeletedBy_DisplayName: " + event.getDeletedBy().getDisplayName() + " DeletedBy_Mri: " + ((CommunicationUserIdentifier) event.getDeletedBy().getCommunicationIdentifier()).getId());
        });
        chatAsyncClient.addPushNotificationHandler(PARTICIPANTS_ADDED, (ChatEvent payload) -> {
            Log.i(TAG, "Push Notification PARTICIPANTS_ADDED.");
            ParticipantsAddedEvent event = (ParticipantsAddedEvent) payload;
            Log.i(TAG, "Participant Added!" + " ThreadId: " + event.getChatThreadId() + " ParticipantsAdded_size: " + event.getParticipantsAdded().size() + " Version: " + event.getVersion() + " AddedOn: " + event.getAddedOn() + " AddedBy_DisplayName: " + event.getAddedBy().getDisplayName() + " AddedBy_Mri: " + ((CommunicationUserIdentifier) event.getAddedBy().getCommunicationIdentifier()).getId());
        });
        chatAsyncClient.addPushNotificationHandler(PARTICIPANTS_REMOVED, (ChatEvent payload) -> {
            Log.i(TAG, "Push Notification PARTICIPANTS_REMOVED.");
            ParticipantsRemovedEvent event = (ParticipantsRemovedEvent) payload;
            Log.i(TAG, "Participant Removed!" + " ThreadId: " + event.getChatThreadId() + " ParticipantsRemoved_size: " + event.getParticipantsRemoved().size() + " Version: " + event.getVersion() + " RemovedOn: " + event.getRemovedOn() + " RemovedBy_DisplayName: " + event.getRemovedBy().getDisplayName() + " RemovedBy_Mri: " + ((CommunicationUserIdentifier) event.getRemovedBy().getCommunicationIdentifier()).getId());
        });
    } catch (IllegalStateException error) {
        Log.i(TAG, "Push Notification not start yet.");
    }
}
Also used : ChatThreadDeletedEvent(com.azure.android.communication.chat.models.ChatThreadDeletedEvent) ChatThreadPropertiesUpdatedEvent(com.azure.android.communication.chat.models.ChatThreadPropertiesUpdatedEvent) ChatEvent(com.azure.android.communication.chat.models.ChatEvent) ChatMessageEditedEvent(com.azure.android.communication.chat.models.ChatMessageEditedEvent) ChatMessageDeletedEvent(com.azure.android.communication.chat.models.ChatMessageDeletedEvent) ParticipantsRemovedEvent(com.azure.android.communication.chat.models.ParticipantsRemovedEvent) ParticipantsAddedEvent(com.azure.android.communication.chat.models.ParticipantsAddedEvent) ChatMessageReceivedEvent(com.azure.android.communication.chat.models.ChatMessageReceivedEvent) CommunicationUserIdentifier(com.azure.android.communication.common.CommunicationUserIdentifier) ChatThreadCreatedEvent(com.azure.android.communication.chat.models.ChatThreadCreatedEvent)

Example 2 with ChatThreadPropertiesUpdatedEvent

use of com.azure.android.communication.chat.models.ChatThreadPropertiesUpdatedEvent in project azure-sdk-for-android by Azure.

the class NotificationUtils method getChatThreadPropertiesUpdated.

private static ChatEvent getChatThreadPropertiesUpdated(String body) {
    try {
        ChatThreadPropertiesUpdatedEvent chatThreadPropertiesUpdatedEvent = JACKSON_SERDER.deserialize(body, ChatThreadPropertiesUpdatedEvent.class, SerdeEncoding.JSON);
        EventAccessorHelper.setChatThreadPropertiesUpdatedEvent(chatThreadPropertiesUpdatedEvent);
        return chatThreadPropertiesUpdatedEvent;
    } catch (IOException e) {
        CLIENT_LOGGER.error(e.getMessage());
        return null;
    }
}
Also used : ChatThreadPropertiesUpdatedEvent(com.azure.android.communication.chat.models.ChatThreadPropertiesUpdatedEvent) IOException(java.io.IOException)

Example 3 with ChatThreadPropertiesUpdatedEvent

use of com.azure.android.communication.chat.models.ChatThreadPropertiesUpdatedEvent in project azure-sdk-for-android by Azure.

the class MainActivity method registerRealTimeNotificationListener.

public void registerRealTimeNotificationListener(View view) {
    logAndToast("Register a test listener");
    RealTimeNotificationCallback messageReceivedHandler = (ChatEvent payload) -> {
        eventHandlerCalled++;
        Log.i(TAG, eventHandlerCalled + " messages handled.");
        ChatMessageReceivedEvent event = (ChatMessageReceivedEvent) payload;
        Log.i(TAG, "Message created! ThreadId: " + event.getChatThreadId());
    };
    chatAsyncClient.addEventHandler(CHAT_MESSAGE_RECEIVED, messageReceivedHandler);
    realTimeNotificationCallbacks.put(messageReceivedHandler, CHAT_MESSAGE_RECEIVED);
    RealTimeNotificationCallback messageEditedHandler = (ChatEvent payload) -> {
        eventHandlerCalled++;
        Log.i(TAG, eventHandlerCalled + " messages handled.");
        ChatMessageEditedEvent event = (ChatMessageEditedEvent) payload;
        Log.i(TAG, "Message edited! ThreadId: " + event.getChatThreadId());
    };
    chatAsyncClient.addEventHandler(CHAT_MESSAGE_EDITED, messageEditedHandler);
    realTimeNotificationCallbacks.put(messageEditedHandler, CHAT_MESSAGE_EDITED);
    RealTimeNotificationCallback messageDeletedHandler = (ChatEvent payload) -> {
        eventHandlerCalled++;
        Log.i(TAG, eventHandlerCalled + " messages handled.");
        ChatMessageDeletedEvent event = (ChatMessageDeletedEvent) payload;
        Log.i(TAG, "Message deleted! ThreadId: " + event.getChatThreadId());
    };
    chatAsyncClient.addEventHandler(CHAT_MESSAGE_DELETED, messageDeletedHandler);
    realTimeNotificationCallbacks.put(messageDeletedHandler, CHAT_MESSAGE_DELETED);
    RealTimeNotificationCallback typingIndicatorHandler = (ChatEvent payload) -> {
        eventHandlerCalled++;
        Log.i(TAG, eventHandlerCalled + " messages handled.");
        TypingIndicatorReceivedEvent event = (TypingIndicatorReceivedEvent) payload;
        Log.i(TAG, "Typing indicator received! ThreadId: " + event.getChatThreadId());
    };
    chatAsyncClient.addEventHandler(TYPING_INDICATOR_RECEIVED, typingIndicatorHandler);
    realTimeNotificationCallbacks.put(typingIndicatorHandler, TYPING_INDICATOR_RECEIVED);
    RealTimeNotificationCallback readReceiptHandler = (ChatEvent payload) -> {
        eventHandlerCalled++;
        Log.i(TAG, eventHandlerCalled + " messages handled.");
        ReadReceiptReceivedEvent event = (ReadReceiptReceivedEvent) payload;
        Log.i(TAG, "Read receipt received! ThreadId: " + event.getChatThreadId());
    };
    chatAsyncClient.addEventHandler(READ_RECEIPT_RECEIVED, readReceiptHandler);
    realTimeNotificationCallbacks.put(readReceiptHandler, READ_RECEIPT_RECEIVED);
    RealTimeNotificationCallback threadCreatedHandler = (ChatEvent payload) -> {
        eventHandlerCalled++;
        Log.i(TAG, eventHandlerCalled + " messages handled.");
        ChatThreadCreatedEvent event = (ChatThreadCreatedEvent) payload;
        Log.i(TAG, "Chat thread created! ThreadId: " + event.getChatThreadId());
    };
    chatAsyncClient.addEventHandler(CHAT_THREAD_CREATED, threadCreatedHandler);
    realTimeNotificationCallbacks.put(threadCreatedHandler, CHAT_THREAD_CREATED);
    RealTimeNotificationCallback threadDeletedHandler = (ChatEvent payload) -> {
        eventHandlerCalled++;
        Log.i(TAG, eventHandlerCalled + " messages handled.");
        ChatThreadDeletedEvent event = (ChatThreadDeletedEvent) payload;
        Log.i(TAG, "Chat thread deleted! ThreadId: " + event.getChatThreadId());
    };
    chatAsyncClient.addEventHandler(CHAT_THREAD_DELETED, threadDeletedHandler);
    realTimeNotificationCallbacks.put(threadDeletedHandler, CHAT_THREAD_DELETED);
    RealTimeNotificationCallback threadUpdatedHandler = (ChatEvent payload) -> {
        eventHandlerCalled++;
        Log.i(TAG, eventHandlerCalled + " messages handled.");
        ChatThreadPropertiesUpdatedEvent event = (ChatThreadPropertiesUpdatedEvent) payload;
        Log.i(TAG, "Chat thread properties updated! ThreadId: " + event.getChatThreadId());
    };
    chatAsyncClient.addEventHandler(CHAT_THREAD_PROPERTIES_UPDATED, threadUpdatedHandler);
    realTimeNotificationCallbacks.put(threadUpdatedHandler, CHAT_THREAD_PROPERTIES_UPDATED);
    RealTimeNotificationCallback participantAddedHandler = (ChatEvent payload) -> {
        eventHandlerCalled++;
        Log.i(TAG, eventHandlerCalled + " messages handled.");
        ParticipantsAddedEvent event = (ParticipantsAddedEvent) payload;
        Log.i(TAG, "Participants added! ThreadId: " + event.getChatThreadId());
    };
    chatAsyncClient.addEventHandler(PARTICIPANTS_ADDED, participantAddedHandler);
    realTimeNotificationCallbacks.put(participantAddedHandler, PARTICIPANTS_ADDED);
    RealTimeNotificationCallback participantRemovedHandler = (ChatEvent payload) -> {
        eventHandlerCalled++;
        Log.i(TAG, eventHandlerCalled + " messages handled.");
        ParticipantsRemovedEvent event = (ParticipantsRemovedEvent) payload;
        Log.i(TAG, "Participants removed! ThreadId: " + event.getChatThreadId());
    };
    chatAsyncClient.addEventHandler(PARTICIPANTS_REMOVED, participantRemovedHandler);
    realTimeNotificationCallbacks.put(participantRemovedHandler, PARTICIPANTS_REMOVED);
}
Also used : ChatThreadDeletedEvent(com.azure.android.communication.chat.models.ChatThreadDeletedEvent) ChatThreadPropertiesUpdatedEvent(com.azure.android.communication.chat.models.ChatThreadPropertiesUpdatedEvent) RealTimeNotificationCallback(com.azure.android.communication.chat.models.RealTimeNotificationCallback) ChatEvent(com.azure.android.communication.chat.models.ChatEvent) ChatMessageEditedEvent(com.azure.android.communication.chat.models.ChatMessageEditedEvent) ChatMessageDeletedEvent(com.azure.android.communication.chat.models.ChatMessageDeletedEvent) ReadReceiptReceivedEvent(com.azure.android.communication.chat.models.ReadReceiptReceivedEvent) ParticipantsRemovedEvent(com.azure.android.communication.chat.models.ParticipantsRemovedEvent) ParticipantsAddedEvent(com.azure.android.communication.chat.models.ParticipantsAddedEvent) TypingIndicatorReceivedEvent(com.azure.android.communication.chat.models.TypingIndicatorReceivedEvent) ChatMessageReceivedEvent(com.azure.android.communication.chat.models.ChatMessageReceivedEvent) ChatThreadCreatedEvent(com.azure.android.communication.chat.models.ChatThreadCreatedEvent)

Aggregations

ChatThreadPropertiesUpdatedEvent (com.azure.android.communication.chat.models.ChatThreadPropertiesUpdatedEvent)3 ChatEvent (com.azure.android.communication.chat.models.ChatEvent)2 ChatMessageDeletedEvent (com.azure.android.communication.chat.models.ChatMessageDeletedEvent)2 ChatMessageEditedEvent (com.azure.android.communication.chat.models.ChatMessageEditedEvent)2 ChatMessageReceivedEvent (com.azure.android.communication.chat.models.ChatMessageReceivedEvent)2 ChatThreadCreatedEvent (com.azure.android.communication.chat.models.ChatThreadCreatedEvent)2 ChatThreadDeletedEvent (com.azure.android.communication.chat.models.ChatThreadDeletedEvent)2 ParticipantsAddedEvent (com.azure.android.communication.chat.models.ParticipantsAddedEvent)2 ParticipantsRemovedEvent (com.azure.android.communication.chat.models.ParticipantsRemovedEvent)2 ReadReceiptReceivedEvent (com.azure.android.communication.chat.models.ReadReceiptReceivedEvent)1 RealTimeNotificationCallback (com.azure.android.communication.chat.models.RealTimeNotificationCallback)1 TypingIndicatorReceivedEvent (com.azure.android.communication.chat.models.TypingIndicatorReceivedEvent)1 CommunicationUserIdentifier (com.azure.android.communication.common.CommunicationUserIdentifier)1 IOException (java.io.IOException)1