Code Monkey home page Code Monkey logo

Comments (6)

ikaru19 avatar ikaru19 commented on August 12, 2024

And sometimes the translated message wont load until i pressed back and then reopen the channel. Is it known bug or already solved? Thanks

from stream-chat-swift.

nuno-vieira avatar nuno-vieira commented on August 12, 2024

Hi @ikaru19,

Can you please provide your customization code? Otherwise I can't pinpoint if there is any issue.

Best,
Nuno

from stream-chat-swift.

ikaru19 avatar ikaru19 commented on August 12, 2024

here is the code when i listen to the new message update when there is new translated or updated message

func eventsController(_ controller: EventsController, didReceiveEvent event: Event) {
    // Handle any event received
    switch event {
    case let data as MessageUpdatedEvent:
        let message: ChatMessage = data.message
        if let messageIndexPath = super.getIndexPath(forMessageId: message.id),
           let cid = message.cid {
            ChatClient.shared.messageController(cid: cid, messageId: message.id).synchronize(){[weak self] _ in
                self?.updateMessage(at: messageIndexPath, with: message)
                var cell  = self?.listView.cellForRow(at: messageIndexPath) as! ChatMessageCell
                cell.messageContentView?.content = message
                cell.messageContentView?.updateContent()
                cell.updateDataCell(data: message)
            }
            
            let changes: [ListChange<ChatMessage>] = [
                .update(message, index: messageIndexPath)
            ]
            super.updateMessages(with: changes)
            listView.reloadData()
        }
        break
    case let data as MessageDeletedEvent:
        let message: ChatMessage = data.message
        
        if let messageIndexPath = super.getIndexPath(forMessageId: message.id),
           let cid = message.cid {
            ChatClient.shared.messageController(cid: cid, messageId: message.id).synchronize(){[weak self] _ in
                self?.deleteMessage(at: messageIndexPath)
            }
        }
        break
    default:
        break
    }
} 

// Here is how handle on the ChatMessageContentView
func updateContent(with message: ChatMessage) {
    if let languageCode = getUserLanguageCodeFromCache(),
       let languageName = getUserLanguageNameFromCache(),
       let translations = message.translations,
       let resultTranslation = translations[languageCode]
    {
        textView?.text = resultTranslation
        let translationSuffix = " - Translated to \(languageName)"
        if let timestampLabelText = timestampLabel?.text,
           !timestampLabelText.contains("- Translated to") {
            timestampLabel?.text?.append(translationSuffix)
            translationLabel?.removeFromSuperview()
        }
        self.footnoteContainer?.isHidden = false
        seeOriginalLabel?.isHidden = false
        isOriginalMessage = false
    }
    
    updateSeeOriginalLabel()
}

func updateSeeOriginalLabel() {
        seeOriginalLabel?.text = isOriginalMessage ? "See Translated" : "See Original"
    }

from stream-chat-swift.

nuno-vieira avatar nuno-vieira commented on August 12, 2024

Hi @ikaru19,

You don't need to do the didReceiveEvent changes. Whenever the message is updated, the cell will be automatically updated. You should not be doing this manually yourself. I can see that in fact, we have an issue that the cell might not update when new translations are inserted, so we need to fix this on our side.

Besides this, the way you determine how to show the original or the translated message is not correct. Creating a property in the cell like you are doing isOriginalMessage won't work because if the cell is reloaded, you lose the state. So you will need to create a property in extraData like shouldShowOriginalMessage: Bool to control this. Whenever the user selects "showOriginal" or "showTranslated" you need to change to update this extra data property.

We will make sure we fix the issue of new translations not updating the cell, but you also need to update your implemention of showing the original message.

Best,
Nuno

from stream-chat-swift.

nuno-vieira avatar nuno-vieira commented on August 12, 2024

Hi @ikaru19,

The fix I mentioned above will be available on the 4.51.0 Release. Please, keep an eye on the new releases.

Thank you for the report!

Best,
Nuno

from stream-chat-swift.

laevandus avatar laevandus commented on August 12, 2024

Hello @ikaru19, we have released a new iOS SDK version 4.51.0 which addresses this issue. Thank you for reporting it.

from stream-chat-swift.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.