AmityCollection.observe not getting triggered when receiving a new message

Hi

I am having an issue with the LiveCollection. I tried to implement everything that is stated on the documentation, including the requirement to retain the AmityNotificationToken. But, when I try to send a message to an iOS client, the observe block is not getting called. Could you help me with this?

It used to work fine for iOS SDK version 5. But when I upgraded to iOS SDK 6, it is not working anymore. Here is the snippet of the code.

-- ** AmitySDK Version: 6.41.0 Build: 1 ** --

public class ChatChannelRepository {
    private var client: AmityClient
    private var repository: AmityChannelRepository
    private var collection: AmityCollection<AmityChannel>?
    private var token: AmityNotificationToken?
    
    init(client: AmityClient) {
        self.client = client
        self.repository = AmityChannelRepository(client: client)
    }
    
    public func getChannels(observer: @escaping ([AmityChannel]) -> Void) {
        let query = AmityChannelQuery()
        query.types = [AmityChannelQueryType.community]
        query.filter = .userIsMember
        query.includeDeleted = false
        
        self.collection = repository.getChannels(with: query)
        self.token = self.collection?.observe({ collection, change, error in
            if error == nil {
                observer(collection.snapshots)
            }
        })
    }
}

@amitysupport any suggestions?

@amitysupport @AmityAsk @cijin This is also an issue with the Message Repository. Observe block is not getting called once a message is received.

public class ChatMessageRepository {
    var client : AmityClient
    var repository : AmityMessageRepository
    var channelId : String
    var collection : AmityCollection<AmityMessage>?
    var token : AmityNotificationToken?
    var messages : [AmityMessage]?
    
    init(client: AmityClient, channelId : String) {
        self.client = client
        self.repository = AmityMessageRepository(client: self.client)
        self.channelId = channelId
    }
    
    public func getMessages(observer: @escaping ([AmityMessage], String) -> Void) {
        let query = AmityMessageQueryOptions(subChannelId: self.channelId, messageParentFilter: .noParent, sortOption: .lastCreated)
        self.repository = AmityMessageRepository(client: self.client)
        self.collection = repository.getMessages(options: query)
        self.token = self.collection?.observe({ collection, change, error in
            if collection.dataStatus == .fresh {
                observer(collection.snapshots, self.channelId)
            }
        })
    }
}

For this issue, we need more information to proceed with further checks. Could you please provide server region ?

@amitysupport Server Region is US.

@amitysupport Is it server related or is there something wrong with my implementation?

Hello @EmmanKusumi , Thank you for providing all the necessary information. We have forwarded it to the team for further investigation. We will keep you updated on the progress.

Hello @EmmanKusumi ,

Our team has resolved the issue on our backend. Could you please try again? If the issue still persists, please let me know.

Thank you!

I am still having issues here, but when I switched to the Singapore server, everything is working fine now.

1 Like

Hello @EmmanKusumi , We have sent you an email at ekusumi.procuro@outlook.com
to request additional information.

Thank you!!