Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Message Limit #8

Open
tomastiminskas opened this issue Jun 11, 2024 · 5 comments
Open

Message Limit #8

tomastiminskas opened this issue Jun 11, 2024 · 5 comments
Assignees

Comments

@tomastiminskas
Copy link
Contributor

We have a chars limit on the app side when sending a msg, but it seems different than the one the bindings has internally. So if you write a msg as long as the app allows you it will throw an error coming as an exception from the send binding.

We need to match the app message limit to the bindings limit which is 869 bytes

@ariel10aguero
Copy link

On Android the max byte array that could support thesend() binding is 594 byes starting the exception r=msg too long when msg is 595 byes

            editTextChatFooter.filters = arrayOf<InputFilter>(object : InputFilter {
                override fun filter(
                    source: CharSequence,
                    start: Int,
                    end: Int,
                    dest: Spanned,
                    dstart: Int,
                    dend: Int
                ): CharSequence {
                    val currentText = dest.toString()
                    val proposedText = currentText.substring(0, dstart) + source.subSequence(start, end) + currentText.substring(dend)

                    return if (proposedText.toByteArray().size > 594) {
                        // If the proposed text exceeds the limit, return an empty string to prevent the change
                        ""
                    } else {
                        // If the proposed text does not exceed the limit, allow the change
                        source.subSequence(start, end)

                    }
                }
            })

@ariel10aguero
Copy link

ariel10aguero commented Jun 21, 2024

So this is the longest text with 594 bytes:

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed viverra tincidunt nibh, congue maximus lorem congue suscipit. Morbi vitae lacus ut massa sagittis egestas. Sed porttitor tincidunt massa blandit dignissim. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Quisque ullamcorper non augue non mollis. In pretium, ipsum nec aliquam venenatis, dolor mi maximus velit, sit amet malesuada neque neque in ante. Praesent non tincidunt enim, vel viverra dui. Quisque mollis lectus id elit fermentum feugiat. Orci varius natoque penatibus et magnis dis leo.

@tomastiminskas
Copy link
Contributor Author

@Evanfeenstra can you confirm if the limit applies to the message content itself or to the msgJson con tent that we send in the send binding? If it's this second case then it will be complex to calculate that while use writes a text in the field.

In the other hand, is there any way to increase that limit? It seems a bit shorter right now

@tomastiminskas
Copy link
Contributor Author

@ariel10aguero replicate this logic:

func isMessageLengthValid(
        text: String,
        sendingAttachment: Bool,
        threadUUID: String?,
        replyUUID: String?
    ) -> Bool {
        let contentBytes: Int = 18
        let attachmentBytes: Int = 389
        let replyBytes: Int = 84
        let threadBytes: Int = 84
        
        var bytes = text.byteSize() + contentBytes
        
        if sendingAttachment {
            bytes += attachmentBytes
        }
        
        if replyUUID != nil {
            bytes += replyBytes
        }
        
        if threadUUID != nil {
            bytes += threadBytes
        }
        
        return bytes <= 869
    }

Calculate this while typing and avoid keep typing if size is invalid

@ariel10aguero
Copy link

ariel10aguero commented Sep 6, 2024

Checkout aa/feature/isMessageLengthValid branch

The implementation is working but the messages are not sending when they are in that limit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants