steve228uk / MessengerKit

:speech_balloon: A UI framework for building messenger interfaces on iOS
MIT License
1.48k stars 129 forks source link

Load more messages (Pagination) #61

Open alperen23230 opened 4 years ago

alperen23230 commented 4 years ago

Does this library support the pagination in chat ? I'm using pagination in my chat app.

eftalersoy commented 4 years ago

hello same question for me. I am thinking using this but I can't find any documentation about how I can insert old messages for chat history.

I tried using func message(for indexPath: IndexPath) -> MSGMessage for detecting section 0 then making a call to get second history page.

func message(for indexPath: IndexPath) -> MSGMessage {
 if indexPath.section == 0{

//this will act like chat history api call (for test purposes)
            DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) {

                var messages =  [

                    MSGMessage(id: 2, body: .text("History add test 0"), user: self.steve, sentAt: Calendar.current.date(byAdding: .hour, value: -5, to: Date())!),
                    MSGMessage(id: 3, body: .text("History add test 1"), user: self.steve, sentAt: Calendar.current.date(byAdding: .hour, value: -5, to: Date())!),
                    MSGMessage(id: 2, body: .text("History add test 2"), user: self.tim, sentAt: Calendar.current.date(byAdding: .hour, value: -4, to: Date())!),
                    MSGMessage(id: 3, body: .text("History add test 3"), user: self.tim, sentAt: Calendar.current.date(byAdding: .hour, value: -4, to: Date())!)
                ]

                self.messages.insert(messages, at: 0)
                self.collectionView.reloadData()
            }
        }

        return messages[indexPath.section][indexPath.item]

But this somehow making it infinite loop. I will try to use collection view delegate methods now but if there is a better solution can somebody point me that direction.

Thanks

irfanabdulkhaliq commented 4 years ago

I am also using pagination in my chat , how I can load more message in chat