Skip to content

Commit

Permalink
notify chat subsystem on external identifies (#21910)
Browse files Browse the repository at this point in the history
  • Loading branch information
heronhaye committed Jan 9, 2020
1 parent 289cff8 commit 8bb96b0
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 6 deletions.
53 changes: 49 additions & 4 deletions go/engine/identify2_with_uid.go
Expand Up @@ -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

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions go/libkb/identify_outcome.go
Expand Up @@ -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 */)
}
12 changes: 12 additions & 0 deletions go/protocol/keybase1/extras.go
Expand Up @@ -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
Expand Down

0 comments on commit 8bb96b0

Please sign in to comment.