# How to Retrieve Undelivered Messages Saved in the Database for a Blocked User in SendBird?

**URL:** <https://community.sendbird.com/t/how-to-retrieve-undelivered-messages-saved-in-the-database-for-a-blocked-user-in-sendbird/10353>\
**Category:** Android\
**Tags:** group-channel, chatsdk\
**Created:** [November 27, 2024, 5:56pm UTC](https://community.sendbird.com/t/how-to-retrieve-undelivered-messages-saved-in-the-database-for-a-blocked-user-in-sendbird/10353 "2024-11-27T17:56:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Muhammad\_Waqas](https://sea2.discourse-cdn.com/flex020/user_avatar/community.sendbird.com/muhammad_waqas/32/5598_2.png) [@Muhammad\_Waqas](https://community.sendbird.com/u/Muhammad_Waqas)\
**Post date:** [November 27, 2024, 5:56pm UTC](https://community.sendbird.com/t/how-to-retrieve-undelivered-messages-saved-in-the-database-for-a-blocked-user-in-sendbird/10353/1 "2024-11-27T17:56:35Z")

</div>

**[Question]**  
I am working with the SendBird Android SDK, and my use case involves sending messages in a group channel. If the recipient has blocked me, the messages are not delivered to the channel, which aligns with the documentation:

_“Even though messages sent from the blocked user aren’t delivered to the channel, they are saved in the database and are only displayed in the blocked user’s channel view. This means that the blocked user isn’t aware of their blocked status”_

My question is: since these messages are saved in the database, how can I retrieve them when fetching all the messages for the group channel?

I am using below code to retrieve messages in a channel, but these undelivered messages are not being retrieved with this

```auto
messageCollection?.initialize(
                        MessageCollectionInitPolicy.CACHE_AND_REPLACE_BY_API,
                        object : MessageCollectionInitHandler {
                            private var shouldSendErrorOnApiFail = true
                            override fun onApiResult(apiResultList: List<BaseMessage>?, e: SendbirdException?) {
                                if (e != null) {
                                
                                } 
                                val messagesList = mutableListOf<ChatBaseMessage>()
                                apiResultList?.map { baseMessage ->
                                    val chatMessage: ChatBaseMessage? =
                                        chatMapper.mapToChatMessage(baseMessage)
                                    chatMessage?.let { messagesList.add(it) }
                                }
                            }

                            override fun onCacheResult(cachedList: List<BaseMessage>?, e: SendbirdException?) {
                            }
                        }
                    )

```

---

<div class="post-metadata">

**Author:** ![jonathan58](https://avatars.discourse-cdn.com/v4/letter/j/4da419/32.png) [@jonathan58](https://community.sendbird.com/u/jonathan58)\
**Post date:** [December 11, 2024, 4:10am UTC](https://community.sendbird.com/t/how-to-retrieve-undelivered-messages-saved-in-the-database-for-a-blocked-user-in-sendbird/10353/2 "2024-12-11T04:10:41Z")

</div>

To retrieve messages sent by a blocked user, you need to use the `MessageListParams` to include messages from blocked users[.](https://unscrambleit.net/vertex-nytimes/) By default, these messages are not included. Adjust your code to include all messages, regardless of block status:

```auto
val params = MessageListParams().apply {
    includeMetaArray = true
    includeReactions = true
    reverse = false
    nextResultSize = 100
    isInclusive = true
    // This is the key part; ensure it's set to true
    includeMessagesFromBlockedUsers = true
}

messageCollection?.initialize(
    MessageCollectionInitPolicy.CACHE_AND_REPLACE_BY_API,
    object : MessageCollectionInitHandler {
        override fun onApiResult(apiResultList: List<BaseMessage>?, e: SendbirdException?) {
            if (e != null) {
                // Handle error
                return
            } 
            val messagesList = mutableListOf<ChatBaseMessage>()
            apiResultList?.map { baseMessage ->
                val chatMessage: ChatBaseMessage? = chatMapper.mapToChatMessage(baseMessage)
                chatMessage?.let { messagesList.add(it) }
            }
        }

        override fun onCacheResult(cachedList: List<BaseMessage>?, e: SendbirdException?) {
            // Handle cached result if needed
        }
    }
)

```

Ensure you set `includeMessagesFromBlockedUsers` to `true` when using `MessageListParams`. This will allow you to fetch all messages, including those sent by blocked users.

---

<div class="post-metadata">

**Author:** ![Muhammad\_Waqas](https://sea2.discourse-cdn.com/flex020/user_avatar/community.sendbird.com/muhammad_waqas/32/5598_2.png) [@Muhammad\_Waqas](https://community.sendbird.com/u/Muhammad_Waqas)\
**Post date:** [December 11, 2024, 1:38pm UTC](https://community.sendbird.com/t/how-to-retrieve-undelivered-messages-saved-in-the-database-for-a-blocked-user-in-sendbird/10353/3 "2024-12-11T13:38:31Z")

</div>

Hi @jonathan58, thanks for your response, but these attributes are not available:

```auto
val params = MessageListParams().apply {
            includeMetaArray = true
            includeReactions = true
            reverse = false
            nextResultSize = 100
            isInclusive = true
            // This is the key part; ensure it's set to true
            includeMessagesFromBlockedUsers = true
        }

```

from above code base, includeMetaArray, includeReactions, isInclusive, includeMessagesFromBlockedUsers attributes are not available

---

<div class="post-metadata">

**Author:** ![jonathan58](https://avatars.discourse-cdn.com/v4/letter/j/4da419/32.png) [@jonathan58](https://community.sendbird.com/u/jonathan58)\
**Post date:** [December 12, 2024, 4:10am UTC](https://community.sendbird.com/t/how-to-retrieve-undelivered-messages-saved-in-the-database-for-a-blocked-user-in-sendbird/10353/4 "2024-12-12T04:10:29Z")

</div>

If the attributes you’re trying to use in `MessageListParams` are not available, it might be due to the version of the library you’re using or they might not be supported in your current setup[.](https://unsentmessageto.com/) Here’s a revised approach that you can try if those attributes are missing:

```auto
val params = MessageListParams().apply {
    // Check the documentation or API for available attributes
    reverse = false
    nextResultSize = 100
    
    // If includeMessagesFromBlockedUsers is not available, you may need to handle this differently,
    // possibly by adjusting your API settings or checking for updates in the SDK.
}

// Initialize the message collection as before
messageCollection?.initialize(
    MessageCollectionInitPolicy.CACHE_AND_REPLACE_BY_API,
    object : MessageCollectionInitHandler {
        override fun onApiResult(apiResultList: List<BaseMessage>?, e: SendbirdException?) {
            if (e != null) {
                // Handle error
                return
            }
            val messagesList = mutableListOf<ChatBaseMessage>()
            apiResultList?.map { baseMessage ->
                val chatMessage: ChatBaseMessage? = chatMapper.mapToChatMessage(baseMessage)
                chatMessage?.let { messagesList.add(it) }
            }
        }

        override fun onCacheResult(cachedList: List<BaseMessage>?, e: SendbirdException?) {
            // Handle cached result if needed
        }
    }
)

```

### Suggestions:

Ensure you are using the latest version of the SDK and consult its documentation. Sometimes, attributes might be added or removed in newer versions.
