neilalexander / seaglass

A truly native Matrix client for macOS - written in Swift/Cocoa, with E2E encryption support
Other
529 stars 34 forks source link

Only attempt to show resend message dialog when a message failed to send #50

Closed pixlwave closed 6 years ago

pixlwave commented 6 years ago

Fixes a crash that occurred when clicking the padlock icon.

pixlwave commented 6 years ago

Oh, should mention: Please test with a failed message before merging as I wasn't sure how to do this.

neilalexander commented 6 years ago

A better approach that is less impacting might be something like this in MainViewRoomController.swift line 203:

            let messageSendErrorHandler = { (roomId, eventId, userId) in
                if roomId == nil || eventId == nil {
                    return
                }
                if (MatrixServices.inst.eventCache[roomId!]?.contains(where: { $0.eventId == eventId && $0.sentState == MXEventSentStateFailed }))! {
                    let sheet = self.storyboard?.instantiateController(withIdentifier: NSStoryboard.SceneIdentifier("MessageSendFailedSheet")) as! MainViewSendErrorController
                    sheet.roomId = roomId!
                    sheet.eventId = eventId!
                    self.presentViewControllerAsSheet(sheet)
                }
            } as (_: String?, _: String?, _: String?) -> ()
pixlwave commented 6 years ago

Sure I can update. I was wondering though if it makes sense to be setting this handler for all messages even if they didn't fail sending?

neilalexander commented 6 years ago

Indeed it doesn’t make sense - please feel free to improve upon!

pixlwave commented 6 years ago

Well that commit is very much more impacting, but I think that's how I'd do it. No offence if you'd rather not do that though 🙃

pixlwave commented 6 years ago

Thinking about it, creating the protocol might be a tad ott. I'd skip that part and just make the delegate type the controller.