I've taken a look at all these Swift, and asp.net, and javascript questions.
Goal:
When I select a messages from the list of chat messages in the MessageListController
I want the opened session in the next ChatDetailController
to be the conversation that was selected.
I'm doing the same thing in this iOS image for my WatchKit app. The message with Sophia is selected and the chat with Sophia opens. [![enter image description here][6]][6]
I want to pass the json "message_id" i.e. the chatMessageId
property. I'm already passing the chatMessageId
from the MessageModel
to the ChatDetailController
as you can see in code.
Is it the chatMessageId
of the ChatModel
I need to pass? Or am I already passing the data that I need?
Passed context: Optional(HTWatch_Extension.MessageModel(partner: "9859", nickname: "Marco", message: "Have you seen is dog?", city: "Madrid", countryBadgeImageURL: https://i.stack.imgur.com/0Z3ZO.jpg, messageListImageURL: https://i.stack.imgur.com/0Z3ZO.jpg, chatMessageId: "Tva9d2OJyWHRC1AqEfKjclRwXnlRDQ", status: "offline"))
Attempt:
Do I need to take the do-catch block where I parse the ChatModel
out of the ChatDetailController
's awakeWithContext
method and put it in the didSelectRowAt
method of the MessageListController
?
MessageListController
// ...code...
var messageObject = [MessageModel]()
var chatObject = [ChatModel]()
// ...code...
override func table(_ table: WKInterfaceTable, didSelectRowAt rowIndex: Int) {
var messageContext = messageObject[rowIndex]
var chatContext = chatObject[rowIndex]
do {
guard let fileUrl = Bundle.main.url(forResource: "Chats", withExtension: "json") else {
print("File could not be located")
return
}
let data = try Data(contentsOf: fileUrl)
let decoder = JSONDecoder()
let msg = try decoder.decode([ChatModel].self, from: data)
self.chatObject = msg
} catch let error {
print(error)
}
messageContext.chatMessageId = (chatObject as AnyObject).filter { (dictionaryTemp:[String:String]) -> Bool in
return dictionaryTemp["message_id"] == chatContext.chatMessageId
}
// WatchKit's model presentation method.
presentController(withName: "ChatDetailController", context: messageContext)
}