Search in sources :

Example 1 with TypingIndicatorReceivedEvent

use of com.azure.android.communication.chat.models.TypingIndicatorReceivedEvent 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)

Example 2 with TypingIndicatorReceivedEvent

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

the class NotificationUtils method getTypingIndicatorReceived.

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

Aggregations

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