mirror of
https://github.com/ProtonMail/proton-bridge.git
synced 2025-12-12 21:56:44 +00:00
feat(GODT-2442): add notification and feedback to CLI.
This commit is contained in:
@ -304,3 +304,30 @@ func (f *frontendCLI) configureAppleMail(c *ishell.Context) {
|
|||||||
|
|
||||||
f.Printf("Apple Mail configured for %v with address %v\n", user.Username, user.Addresses[0])
|
f.Printf("Apple Mail configured for %v with address %v\n", user.Username, user.Addresses[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (f *frontendCLI) badEventSynchronize(c *ishell.Context) {
|
||||||
|
f.badEventFeedback(true)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f *frontendCLI) badEventLogout(c *ishell.Context) {
|
||||||
|
f.badEventFeedback(false)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f *frontendCLI) badEventFeedback(doResync bool) {
|
||||||
|
if f.badUserID == "" {
|
||||||
|
f.Printf("Error: There was no unresolved bad event.")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
action := "synchronize"
|
||||||
|
if !doResync {
|
||||||
|
action = "logout"
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := f.bridge.SendBadEventUserFeedback(context.Background(), f.badUserID, doResync); err != nil {
|
||||||
|
f.Printf("Error: failed to send %s feedback: %w", action, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
f.badUserID = ""
|
||||||
|
}
|
||||||
|
|||||||
@ -37,6 +37,8 @@ type frontendCLI struct {
|
|||||||
|
|
||||||
bridge *bridge.Bridge
|
bridge *bridge.Bridge
|
||||||
restarter *restarter.Restarter
|
restarter *restarter.Restarter
|
||||||
|
|
||||||
|
badUserID string
|
||||||
}
|
}
|
||||||
|
|
||||||
// New returns a new CLI frontend configured with the given options.
|
// New returns a new CLI frontend configured with the given options.
|
||||||
@ -45,6 +47,7 @@ func New(bridge *bridge.Bridge, restarter *restarter.Restarter, eventCh <-chan e
|
|||||||
Shell: ishell.New(),
|
Shell: ishell.New(),
|
||||||
bridge: bridge,
|
bridge: bridge,
|
||||||
restarter: restarter,
|
restarter: restarter,
|
||||||
|
badUserID: "",
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clear commands.
|
// Clear commands.
|
||||||
@ -256,6 +259,22 @@ func New(bridge *bridge.Bridge, restarter *restarter.Restarter, eventCh <-chan e
|
|||||||
Completer: fe.completeUsernames,
|
Completer: fe.completeUsernames,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
badEventCmd := &ishell.Cmd{
|
||||||
|
Name: "bad-event",
|
||||||
|
Help: "manage actions when bad event error occurs",
|
||||||
|
}
|
||||||
|
badEventCmd.AddCmd(&ishell.Cmd{
|
||||||
|
Name: "synchronize",
|
||||||
|
Help: "synchronize your local database to resolve the bad event error",
|
||||||
|
Func: fe.badEventSynchronize,
|
||||||
|
})
|
||||||
|
badEventCmd.AddCmd(&ishell.Cmd{
|
||||||
|
Name: "logout",
|
||||||
|
Help: "logout to deal with bad event error later",
|
||||||
|
Func: fe.badEventLogout,
|
||||||
|
})
|
||||||
|
fe.AddCmd(badEventCmd)
|
||||||
|
|
||||||
go fe.watchEvents(eventCh)
|
go fe.watchEvents(eventCh)
|
||||||
|
|
||||||
return fe
|
return fe
|
||||||
@ -301,7 +320,16 @@ func (f *frontendCLI) watchEvents(eventCh <-chan events.Event) { // nolint:funle
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
f.Printf("User %s received a bad event and was logged out.\n", user.Username)
|
f.badUserID = event.UserID
|
||||||
|
|
||||||
|
f.Printf("\nInternal Error\n\n")
|
||||||
|
f.Printf("Bridge ran into an internal error and it is not able proceed with %s.\n", user.Username)
|
||||||
|
f.Printf("Synchronize your local database now or logout to do it later.\n")
|
||||||
|
f.Printf("Synchronization time depends on the size of your mailbox.\n")
|
||||||
|
f.Printf("\n\n")
|
||||||
|
f.Printf("The allowed actions are:")
|
||||||
|
f.Printf("* bad-event synchronize")
|
||||||
|
f.Printf("* bad-event logout")
|
||||||
|
|
||||||
case events.UserAddressUpdated:
|
case events.UserAddressUpdated:
|
||||||
user, err := f.bridge.GetUserInfo(event.UserID)
|
user, err := f.bridge.GetUserInfo(event.UserID)
|
||||||
|
|||||||
Reference in New Issue
Block a user