chat-sdk / chat-sdk-ios

Chat SDK iOS - Open Source Mobile Messenger
http://sdk.chat
Other
913 stars 276 forks source link

Listen to income messages in iOS #491

Closed ahmadrushdie closed 2 years ago

ahmadrushdie commented 2 years ago

i am trying to listen to incomming messages in the controller using doc in the documentation they mention

[_notificationList add:[[NSNotificationCenter defaultCenter] addObserverForName:bNotificationMessageAdded object:Nil queue:Nil usingBlock:^(NSNotification * notification) {
    dispatch_async(dispatch_get_main_queue(), ^{
        id<PMessage> messageModel = notification.userInfo[bNotificationMessageAddedKeyMessage];
    });
**}]];

any complete example how to use in swift ?

bensmiley commented 2 years ago

This is an old method.. where did you find it?

The current docs are here:

https://chat-sdk.gitbook.io/chat-sdk/guides/api-cheatsheet#messaging-server-notifications

ahmadrushdie commented 2 years ago

@bensmiley how to achive like this on IOS

ChatSDK.events().sourceOnMain() .filter(NetworkEvent.filterType(EventType.MessageAdded))

            .filter(NetworkEvent.filterThreadEntityID(thread[0].entityID))
            .subscribe {
                val message: Message = it.message
                messagesAdapter.addItem(message)
                Handler().postDelayed(Runnable {
                    binding.rcMessages.smoothScrollToPosition(messagesAdapter.messages.size + 1)
                }, 100)
            }

Listen to income messages for spesific thread?

bensmiley commented 2 years ago

@ahmadrushdie it's in the same document... Look at hooks, ios.

public static String MessageReceived = "MessageReceived";