1

Currently I've included a display name and a phone number as shown in the code. But when I'm showing the message to the user it should show @displayName, and when sending the message to the server it should go as @phoneNumber. How to have this functionality?

I'm returning a text and a context with AutoCompletion object in autocompleteManager, how do I retrieve this context and send it to server

current autocompleteManager function

   func autocompleteManager(_ manager: AutocompleteManager, autocompleteSourceFor prefix: String) -> [AutocompleteCompletion] {
       if prefix == "@" {
           return self.contactsArray
               .map { user in
                   return AutocompleteCompletion(text: user.displayName,
                                                 context: ["id": user.phoneNumber,"text":user.displayName])
           }
       }else if prefix == "#" {
           return self.tasks
               .map { task in
                   return AutocompleteCompletion(text: task.title, context: ["id":task.documentID])
           }
       }
       return []
   }

input bar didPressSendButtonWith

    func inputBar(_ inputBar: InputBarAccessoryView, didPressSendButtonWith text: String) {
        if let text = inputBar.inputTextView.text  {
            guard let id = serviceManager?.discussionService?.addMessage() else { return }
            let textWithNumber = replaceUserName(text: text)
            let message = DisscussionMessage(text: textWithNumber, user: (serviceManager?.authService?.getCurrentUser())!, messageId: id, date: Date(), groupId: self.group?.documentID ?? "")

            self.saveMessage(message)
        }
        inputBar.inputTextView.text = ""
        messagesCollectionView.scrollToBottom()
    }

In the replaceUserName() function I'm taking the text and replacing the name which has an @ in the beginning.

senuraa
  • 133
  • 1
  • 5

0 Answers0