--- Key handling ---
(msg tea.KeyPressMsg)
| 230 | } |
| 231 | } |
| 232 | |
| 233 | // --- Update --- |
| 234 | |
| 235 | func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { |
| 236 | switch msg := msg.(type) { |
| 237 | case viewGenerationMsg: |
| 238 | if msg.generation != m.viewGeneration { |
| 239 | return m, nil |
| 240 | } |
| 241 | return m.Update(msg.msg) |
| 242 | |
| 243 | case notifyMsg: |
| 244 | return m, m.showToast(msg) |
| 245 | |
| 246 | case OpenRequest: |
| 247 | return m.openRequest(msg) |
| 248 | |
| 249 | case toastExpiredMsg: |
| 250 | if msg.id == m.toastID { |
| 251 | m.toast = notifyMsg{} |
| 252 | } |
| 253 | return m, nil |
| 254 | |
| 255 | case mailAccountsLoadedMsg: |
| 256 | if msg.err != nil { |
| 257 | m.mailAccountDiscoveryErr = errorNotice("Could not load the mail accounts", msg.err) |
| 258 | m.updateHelpBindings() |
| 259 | return m, nil |
| 260 | } |
| 261 | m.mailAccountsLoaded = true |
| 262 | m.mailAccountDiscoveryErr = "" |
| 263 | m.mailAccounts = msg.accounts |
| 264 | m.mailAccountUnavailable = msg.selectedUnavailable |
| 265 | if msg.selectedUnavailable { |
| 266 | m.loading = false |
| 267 | m.mailAccountErr = fmt.Sprintf("Selected mail account %d is no longer available", m.mailAccount.id) |
| 268 | m.err = errors.New(m.mailAccountErr) |
| 269 | } else if msg.loaded && msg.selected >= 0 && msg.selected < len(msg.accounts) { |
| 270 | m.mailAccount = msg.accounts[msg.selected] |
| 271 | m.mailAccountCursor = msg.selected |
| 272 | } |
| 273 | m.updateHelpBindings() |
| 274 | if m.pendingOpen != nil { |
| 275 | request := *m.pendingOpen |
| 276 | return m.openRequest(request) |
| 277 | } |
| 278 | return m, nil |
| 279 | |
| 280 | case mailAccountSwitchedMsg: |
| 281 | if msg.requestID != m.mailAccountRequestID { |
| 282 | return m, nil |
| 283 | } |
| 284 | m.mailAccountSwitching = false |
| 285 | if msg.err != nil { |
| 286 | m.mailAccountErr = errorNotice("Could not switch account", msg.err) |
| 287 | opening := m.pendingOpen != nil |
| 288 | m.pendingOpen = nil |
| 289 | m.updateHelpBindings() |
no test coverage detected