@@ -51,10 +51,89 @@ func (h *tlfHandler) PublicCanonicalTLFNameAndID(ctx context.Context, arg keybas
5151}
5252
5353func (h * tlfHandler ) CompleteAndCanonicalizePrivateTlfName (ctx context.Context , arg keybase1.TLFQuery ) (res keybase1.CanonicalTLFNameAndIDWithBreaks , err error ) {
54+ << << << < HEAD
5455 defer h .Trace (ctx , func () error { return err },
5556 fmt .Sprintf ("CompleteAndCanonicalizePrivateTlfName(tlf=%s,mode=%v)" , arg .TlfName ,
5657 arg .IdentifyBehavior ))()
5758 var breaks []keybase1.TLFIdentifyFailure
5859 ctx = chat .Context (ctx , arg .IdentifyBehavior , & breaks , chat .NewIdentifyNotifier (h .G ()))
5960 return h .tlfInfoSource .CompleteAndCanonicalizePrivateTlfName (ctx , arg .TlfName )
61+ == == == =
62+ username := h .G ().Env .GetUsername ()
63+ if len (username ) == 0 {
64+ return keybase1.CanonicalTLFNameAndIDWithBreaks {}, libkb.LoginRequiredError {}
65+ }
66+
67+ // Prepend username in case it's not present. We don't need to check if it
68+ // exists already since CryptKeys calls below transforms the TLF name into a
69+ // canonical one.
70+ //
71+ // This makes username a writer on this TLF, which might be unexpected.
72+ // TODO: We should think about how to handle read-only TLFs.
73+ arg .TlfName = string (username ) + "," + arg .TlfName
74+
75+ // TODO: do some caching so we don't end up calling this RPC
76+ // unnecessarily too often
77+ resp , err := h .CryptKeys (ctx , arg )
78+ if err != nil {
79+ return keybase1.CanonicalTLFNameAndIDWithBreaks {}, err
80+ }
81+
82+ return resp .NameIDBreaks , nil
83+ }
84+
85+ func (h * tlfHandler ) identifyTLF (ctx context.Context , arg keybase1.TLFQuery , private bool ) ([]keybase1.TLFIdentifyFailure , error ) {
86+ var fails []keybase1.TLFIdentifyFailure
87+ pieces := strings .Split (arg .TlfName , "," )
88+ for _ , p := range pieces {
89+ f , err := h .identifyUser (ctx , p , private , arg .IdentifyBehavior )
90+ if err != nil {
91+ return nil , err
92+ }
93+ fails = append (fails , f )
94+ }
95+ return fails , nil
96+ }
97+
98+ func (h * tlfHandler ) identifyUser (ctx context.Context , assertion string , private bool , idBehavior keybase1.TLFIdentifyBehavior ) (keybase1.TLFIdentifyFailure , error ) {
99+ reason := "You accessed a public conversation."
100+ if private {
101+ reason = fmt .Sprintf ("You accessed a private conversation with %s." , assertion )
102+ }
103+
104+ arg := keybase1.Identify2Arg {
105+ UserAssertion : assertion ,
106+ UseDelegateUI : true ,
107+ Reason : keybase1.IdentifyReason {Reason : reason },
108+ CanSuppressUI : true ,
109+ IdentifyBehavior : idBehavior ,
110+ }
111+
112+ // no sessionID as this can be called anywhere, not just as a client action
113+ sessionID := 0
114+ ectx := engine.Context {
115+ LogUI : h .getLogUI (sessionID ),
116+ IdentifyUI : h .NewRemoteIdentifyUI (sessionID , h .G ()),
117+ SessionID : sessionID ,
118+ NetContext : ctx ,
119+ }
120+
121+ eng := engine .NewResolveThenIdentify2 (h .G (), & arg )
122+ err := engine .RunEngine (eng , & ectx )
123+ if err != nil {
124+ return keybase1.TLFIdentifyFailure {}, err
125+ }
126+ resp := eng .Result ()
127+
128+ var frep keybase1.TLFIdentifyFailure
129+ if resp != nil {
130+ frep .User = keybase1.User {
131+ Uid : resp .Upk .Uid ,
132+ Username : resp .Upk .Username ,
133+ }
134+ frep .Breaks = resp .TrackBreaks
135+ }
136+
137+ return frep , nil
138+ >> >> >> > c33db3128 ... WIP
60139}
0 commit comments