From 8bb96b00c336fc63ce05117f9384162c484320f7 Mon Sep 17 00:00:00 2001 From: heronhaye Date: Thu, 9 Jan 2020 10:22:32 -0500 Subject: [PATCH] notify chat subsystem on external identifies (#21910) --- go/engine/identify2_with_uid.go | 53 ++++++++++++++++++++++++++++++--- go/libkb/identify_outcome.go | 4 +-- go/protocol/keybase1/extras.go | 12 ++++++++ 3 files changed, 63 insertions(+), 6 deletions(-) diff --git a/go/engine/identify2_with_uid.go b/go/engine/identify2_with_uid.go index c4e7c25b27b9..b590eb4c4fa6 100644 --- a/go/engine/identify2_with_uid.go +++ b/go/engine/identify2_with_uid.go @@ -223,8 +223,8 @@ func (i *identifyUser) trackChainLinkFor(m libkb.MetaContext, name libkb.Normali // - Work back in the identify card // -// Identify2WithUID is the Identify engine used in KBFS and as a subroutine -// of command-line crypto. +// Identify2WithUID is the Identify engine used in KBFS, chat, and as a +// subroutine of command-line crypto. type Identify2WithUID struct { libkb.Contextified @@ -343,10 +343,53 @@ func (e *Identify2WithUID) Run(m libkb.MetaContext) (err error) { return err } +func (e *Identify2WithUID) notifyChat(m libkb.MetaContext, inErr error) error { + m.Debug("Identify2WithUID.run: notifyChat") + if !e.arg.IdentifyBehavior.ShouldRefreshChatView() { + return nil + } + if e.them == nil { + return fmt.Errorf("nil user") + } + nun := e.them.GetNormalizedName() + if nun.IsNil() { + return fmt.Errorf("no username for user") + } + // Don't notify if there's a non-identity proof error. + if inErr != nil && !libkb.IsIdentifyProofError(inErr) { + return nil + } + + res, err := e.Result(m) + if err != nil { + return err + } + + update := keybase1.CanonicalTLFNameAndIDWithBreaks{ + CanonicalName: keybase1.CanonicalTlfName(nun), + } + if libkb.IsIdentifyProofError(inErr) { + update.Breaks = keybase1.TLFBreak{Breaks: []keybase1.TLFIdentifyFailure{ + { + User: *e.them.Export(), + Breaks: res.TrackBreaks, + }, + }} + } + m.Debug("Identify2WithUID.run: running HandleChatIdentifyUpdate: %#v", update) + m.G().NotifyRouter.HandleChatIdentifyUpdate(m.Ctx(), update) + + return nil +} + func (e *Identify2WithUID) run(m libkb.MetaContext) { err := e.runReturnError(m) e.unblock(m /* isFinal */, true, err) + if notifyChatErr := e.notifyChat(m, err); notifyChatErr != nil { + m.Warning("failed to notify chat of identify result: %s", notifyChatErr) + } + // always cancel IdentifyUI to allow clients to clean up. // If no identifyUI was specified (because running the background) // then don't do anything. @@ -530,7 +573,7 @@ func (e *Identify2WithUID) runReturnError(m libkb.MetaContext) (err error) { m = m.BackgroundWithLogTags() if (!e.useTracking && !e.useRemoteAssertions() && e.allowEarlyOuts()) || e.arg.IdentifyBehavior.UnblockThenForceIDTable() { - e.unblock(m /* isFinal */, false, nil) + e.unblock(m, false /* isFinal */, nil /* err */) } return e.runIdentifyUI(m) @@ -841,7 +884,7 @@ func (e *Identify2WithUID) runIdentifyUI(m libkb.MetaContext) (err error) { identifyTableMode = libkb.IdentifyTableModePassive } - // When we get a callback from IDTabe().Identify, we don't get to thread our metacontext + // When we get a callback from IDTable().Identify, we don't get to thread our metacontext // through (for now), so stash it in the this. e.metaContext = m if them.IDTable() == nil { @@ -883,6 +926,8 @@ func (e *Identify2WithUID) runIdentifyUI(m libkb.MetaContext) (err error) { err = e.checkRemoteAssertions([]keybase1.ProofState{keybase1.ProofState_OK}) e.maybeCacheResult(m) + m.Debug("| IdentifyUI: checked remote assertions (%s)", e.them.GetName()) + if err == nil && !e.arg.NoErrorOnTrackFailure { // We only care about tracking errors in this case; hence GetErrorLax _, err = e.state.Result().GetErrorLax() diff --git a/go/libkb/identify_outcome.go b/go/libkb/identify_outcome.go index 85142d99a4dd..5056a4a2439f 100644 --- a/go/libkb/identify_outcome.go +++ b/go/libkb/identify_outcome.go @@ -254,10 +254,10 @@ func (i IdentifyOutcome) GetErrorAndWarnings(strict bool) (warnings Warnings, er } func (i IdentifyOutcome) GetError() error { - _, e := i.GetErrorAndWarnings(true) + _, e := i.GetErrorAndWarnings(true /*strict */) return e } func (i IdentifyOutcome) GetErrorLax() (Warnings, error) { - return i.GetErrorAndWarnings(false) + return i.GetErrorAndWarnings(false /*strict */) } diff --git a/go/protocol/keybase1/extras.go b/go/protocol/keybase1/extras.go index 7a31b77db8c1..c96d7be3318b 100644 --- a/go/protocol/keybase1/extras.go +++ b/go/protocol/keybase1/extras.go @@ -1401,6 +1401,18 @@ func (b TLFIdentifyBehavior) SkipExternalChecks() bool { } } +// ShouldRefreshChatView indicates that when the identify is complete, we +// should update the chat system's view of the computed track breaks (also +// affects username coloring in the GUI). +func (b TLFIdentifyBehavior) ShouldRefreshChatView() bool { + switch b { + case TLFIdentifyBehavior_GUI_PROFILE, TLFIdentifyBehavior_CLI: + return true + default: + return false + } +} + func (c CanonicalTLFNameAndIDWithBreaks) Eq(r CanonicalTLFNameAndIDWithBreaks) bool { if c.CanonicalName != r.CanonicalName { return false