Skip to content

Commit cf3c2a4

Browse files
authored
Add icons to ProofSuggestions, ID3, priority (keybase#15868)
* add icons to suggestions * test * id3 icons * time travel * feedback * ID3 icons (keybase#15881) * Revert "time travel" This reverts commit fc66265. * adapter * catch * ID3 display priority (keybase#15888) * id3 display priority * feedback * test
1 parent a72acea commit cf3c2a4

15 files changed

Lines changed: 264 additions & 94 deletions

File tree

‎go/externals/icon.go‎

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package externals
2+
3+
import (
4+
"fmt"
5+
"strings"
6+
7+
"github.com/keybase/client/go/libkb"
8+
"github.com/keybase/client/go/protocol/keybase1"
9+
)
10+
11+
func normalizeIconKey(key string) string {
12+
switch key {
13+
case "bitcoin":
14+
return "btc"
15+
case "zcash.t", "zcash.z", "zcash.s":
16+
return "zcash"
17+
case "http", "https", "dns":
18+
return "web"
19+
default:
20+
return key
21+
}
22+
}
23+
24+
func ServiceHasFullIcon(key string) bool {
25+
switch normalizeIconKey(key) {
26+
case "btc", "facebook", "github", "hackernews", "pgp", "reddit", "rooter",
27+
"stellar", "twitter", "web", "zcash":
28+
return false
29+
}
30+
// Parameterized proofs should have full icons.
31+
return true
32+
}
33+
34+
func MakeIcons(mctx libkb.MetaContext, serviceKey, imgName string, size int) (res []keybase1.SizedImage) {
35+
for _, factor := range []int{1, 2} {
36+
factorix := ""
37+
if factor > 1 {
38+
factorix = fmt.Sprintf("@%vx", factor)
39+
}
40+
41+
res = append(res, keybase1.SizedImage{
42+
Path: strings.Join([]string{
43+
libkb.SiteURILookup[mctx.G().Env.GetRunMode()],
44+
"images/paramproofs/services",
45+
normalizeIconKey(serviceKey),
46+
fmt.Sprintf("%v_%v%v.png", imgName, size, factorix),
47+
}, "/"),
48+
Width: size * factor,
49+
})
50+
}
51+
return res
52+
}

‎go/identify3/adapter.go‎

Lines changed: 94 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,12 @@ type UIAdapter struct {
2222
username string
2323
iFollowThem bool
2424
sentResult bool
25+
// An upcall is when the service initiates the ID interaction.
26+
// An downcall is when the frontend initiates the ID.
27+
// Probably as directed by KBFS or the CLI.
28+
// "Tell Nojima we're about to hit him."
2529
isUpcall bool
30+
priorityMap map[string]int // map from proof key to display priority
2631
}
2732

2833
var _ libkb.IdentifyUI = (*UIAdapter)(nil)
@@ -32,6 +37,7 @@ func NewUIAdapter(mctx libkb.MetaContext, ui keybase1.Identify3UiInterface) (*UI
3237
MetaContextified: libkb.NewMetaContextified(mctx),
3338
ui: ui,
3439
}
40+
ret.initPriorityMap()
3541
return ret, nil
3642
}
3743

@@ -93,6 +99,39 @@ func (i *UIAdapter) Start(user string, reason keybase1.IdentifyReason, force boo
9399
return err
94100
}
95101

102+
func (i *UIAdapter) initPriorityMap() {
103+
i.priorityMap = make(map[string]int)
104+
for _, displayConfig := range i.M().G().GetProofServices().ListDisplayConfigs() {
105+
i.priorityMap[displayConfig.Key] = displayConfig.Priority
106+
var altKey string
107+
switch displayConfig.Key {
108+
case "zcash.t", "zcash.z", "zcash.s":
109+
altKey = "zcash"
110+
case "bitcoin":
111+
altKey = "btc"
112+
case "http", "https", "dns":
113+
altKey = "web"
114+
}
115+
if len(altKey) > 0 {
116+
if _, ok := i.priorityMap[altKey]; !ok {
117+
i.priorityMap[altKey] = displayConfig.Priority
118+
}
119+
}
120+
}
121+
}
122+
123+
func (i *UIAdapter) priority(key string) int {
124+
if i.priorityMap == nil {
125+
return 0 // should be impossible but don't crash.
126+
}
127+
p, ok := i.priorityMap[key]
128+
if !ok {
129+
// Put it at the bottom of the list.
130+
return 9999999
131+
}
132+
return p
133+
}
134+
96135
// return true if we need an upgrade
97136
func (i *UIAdapter) setRowStatus(arg *keybase1.Identify3UpdateRowArg, lcr keybase1.LinkCheckResult) bool {
98137

@@ -162,64 +201,76 @@ func (i *UIAdapter) setRowStatus(arg *keybase1.Identify3UpdateRowArg, lcr keybas
162201
return needUpgrade
163202
}
164203

165-
func (i *UIAdapter) finishRemoteCheck(proof keybase1.RemoteProof, lcr keybase1.LinkCheckResult) error {
166-
if lcr.BreaksTracking {
167-
i.session.SetTrackBroken()
168-
}
169-
170-
arg := keybase1.Identify3UpdateRowArg{
171-
Key: proof.Key,
172-
Value: proof.Value,
173-
SigID: proof.SigID,
204+
func (i *UIAdapter) rowPartial(proof keybase1.RemoteProof, lcr *keybase1.LinkCheckResult) (row keybase1.Identify3UpdateRowArg) {
205+
row = keybase1.Identify3UpdateRowArg{
206+
Key: proof.Key,
207+
Value: proof.Value,
208+
SigID: proof.SigID,
209+
Priority: i.priority(proof.Key),
174210
}
175211

176212
var humanURLOrSigchainURL string
177-
if lcr.Hint != nil {
213+
if lcr != nil && lcr.Hint != nil {
178214
humanURLOrSigchainURL = lcr.Hint.HumanUrl
179215
}
180216
if len(humanURLOrSigchainURL) == 0 {
181217
humanURLOrSigchainURL = i.makeSigchainViewURL(proof.SigID)
182218
}
183219

184-
arg.ProofURL = humanURLOrSigchainURL
220+
iconKey := proof.Key
221+
row.ProofURL = humanURLOrSigchainURL
185222
switch proof.ProofType {
186223
case keybase1.ProofType_TWITTER:
187-
arg.SiteURL = fmt.Sprintf("https://twitter.com/%v", proof.Value)
224+
row.SiteURL = fmt.Sprintf("https://twitter.com/%v", proof.Value)
225+
iconKey = "twitter"
188226
case keybase1.ProofType_GITHUB:
189-
arg.SiteURL = fmt.Sprintf("https://github.com/%v", proof.Value)
227+
row.SiteURL = fmt.Sprintf("https://github.com/%v", proof.Value)
228+
iconKey = "github"
190229
case keybase1.ProofType_REDDIT:
191-
arg.SiteURL = fmt.Sprintf("https://reddit.com/user/%v", proof.Value)
230+
row.SiteURL = fmt.Sprintf("https://reddit.com/user/%v", proof.Value)
231+
iconKey = "reddit"
192232
case keybase1.ProofType_HACKERNEWS:
193-
arg.SiteURL = fmt.Sprintf("https://news.ycombinator.com/user?id=%v", proof.Value)
233+
row.SiteURL = fmt.Sprintf("https://news.ycombinator.com/user?id=%v", proof.Value)
234+
iconKey = "hackernews"
194235
case keybase1.ProofType_FACEBOOK:
195-
arg.SiteURL = fmt.Sprintf("https://facebook.com/%v", proof.Value)
236+
row.SiteURL = fmt.Sprintf("https://facebook.com/%v", proof.Value)
237+
iconKey = "facebook"
196238
case keybase1.ProofType_GENERIC_SOCIAL:
197-
arg.SiteURL = humanURLOrSigchainURL
239+
row.SiteURL = humanURLOrSigchainURL
198240
serviceType := i.G().GetProofServices().GetServiceType(proof.Key)
199241
if serviceType != nil {
200242
if serviceType, ok := serviceType.(*externals.GenericSocialProofServiceType); ok {
201243
profileURL, err := serviceType.ProfileURL(proof.Value)
202244
if err == nil {
203-
arg.SiteURL = profileURL
245+
row.SiteURL = profileURL
204246
}
205247
}
206248
}
207-
arg.ProofURL = i.makeSigchainViewURL(proof.SigID)
249+
row.ProofURL = i.makeSigchainViewURL(proof.SigID)
208250
case keybase1.ProofType_GENERIC_WEB_SITE:
209251
protocol := "https"
210252
if proof.Key != "https" {
211253
protocol = "http"
212254
}
213-
arg.SiteURL = fmt.Sprintf("%v://%v", protocol, proof.Value)
255+
row.SiteURL = fmt.Sprintf("%v://%v", protocol, proof.Value)
256+
iconKey = "web"
214257
case keybase1.ProofType_DNS:
215-
arg.SiteURL = fmt.Sprintf("http://%v", proof.Value)
216-
arg.ProofURL = i.makeSigchainViewURL(proof.SigID)
258+
row.SiteURL = fmt.Sprintf("http://%v", proof.Value)
259+
row.ProofURL = i.makeSigchainViewURL(proof.SigID)
260+
iconKey = "web"
217261
default:
218-
if lcr.Hint != nil {
219-
arg.SiteURL = humanURLOrSigchainURL
220-
}
262+
row.SiteURL = humanURLOrSigchainURL
263+
}
264+
row.SiteIcon = externals.MakeIcons(i.M(), iconKey, "logo_black", 16)
265+
return row
266+
}
267+
268+
func (i *UIAdapter) finishRemoteCheck(proof keybase1.RemoteProof, lcr keybase1.LinkCheckResult) error {
269+
if lcr.BreaksTracking {
270+
i.session.SetTrackBroken()
221271
}
222272

273+
arg := i.rowPartial(proof, &lcr)
223274
needUpgrade := i.setRowStatus(&arg, lcr)
224275
if needUpgrade {
225276
i.session.SetNeedUpgrade()
@@ -266,12 +317,14 @@ func (i *UIAdapter) displayKey(key keybase1.IdentifyKey) {
266317
}
267318

268319
arg := keybase1.Identify3UpdateRowArg{
269-
Key: "pgp",
270-
Value: hex.EncodeToString(key.PGPFingerprint),
271-
SigID: key.SigID,
272-
SiteURL: i.makeKeybaseProfileURL(),
320+
Key: "pgp",
321+
Value: hex.EncodeToString(key.PGPFingerprint),
322+
SigID: key.SigID,
323+
Priority: i.priority("pgp"),
324+
SiteURL: i.makeKeybaseProfileURL(),
273325
// key.SigID is blank if the PGP key was there pre-sigchain
274326
ProofURL: i.makeSigchainViewURL(key.SigID),
327+
SiteIcon: externals.MakeIcons(i.M(), "pgp", "logo_black", 16),
275328
}
276329

277330
switch {
@@ -316,13 +369,10 @@ func (i *UIAdapter) plumbUncheckedProofs(proofs []keybase1.IdentifyRow) {
316369
}
317370

318371
func (i *UIAdapter) plumbUncheckedProof(row keybase1.IdentifyRow) {
319-
i.updateRow(keybase1.Identify3UpdateRowArg{
320-
Key: row.Proof.Key,
321-
Value: row.Proof.Value,
322-
State: keybase1.Identify3RowState_CHECKING,
323-
Color: keybase1.Identify3RowColor_GRAY,
324-
SigID: row.Proof.SigID,
325-
})
372+
arg := i.rowPartial(row.Proof, nil)
373+
arg.State = keybase1.Identify3RowState_CHECKING
374+
arg.Color = keybase1.Identify3RowColor_GRAY
375+
i.updateRow(arg)
326376
}
327377

328378
func (i *UIAdapter) updateRow(arg keybase1.Identify3UpdateRowArg) error {
@@ -399,10 +449,12 @@ func (i *UIAdapter) plumbCryptocurrency(crypto keybase1.Cryptocurrency) {
399449
i.updateRow(keybase1.Identify3UpdateRowArg{
400450
Key: key,
401451
Value: crypto.Address,
452+
Priority: i.priority(key),
402453
State: keybase1.Identify3RowState_VALID,
403454
Color: keybase1.Identify3RowColor_GREEN,
404455
SigID: crypto.SigID,
405456
SiteURL: i.makeSigchainViewURL(crypto.SigID),
457+
SiteIcon: externals.MakeIcons(i.M(), key, "logo_black", 16),
406458
ProofURL: i.makeSigchainViewURL(crypto.SigID),
407459
})
408460
}
@@ -411,21 +463,21 @@ func (i *UIAdapter) plumbStellarAccount(str keybase1.StellarAccount) {
411463
i.updateRow(keybase1.Identify3UpdateRowArg{
412464
Key: "stellar",
413465
Value: str.FederationAddress,
466+
Priority: i.priority("stellar"),
414467
State: keybase1.Identify3RowState_VALID,
415468
Color: keybase1.Identify3RowColor_GREEN,
416469
SigID: str.SigID,
417470
SiteURL: i.makeSigchainViewURL(str.SigID),
471+
SiteIcon: externals.MakeIcons(i.M(), "stellar", "logo_black", 16),
418472
ProofURL: i.makeSigchainViewURL(str.SigID),
419473
})
420474
}
421475

422476
func (i *UIAdapter) plumbRevoked(row keybase1.RevokedProof) {
423-
i.updateRow(keybase1.Identify3UpdateRowArg{
424-
Key: row.Proof.Key,
425-
Value: row.Proof.Value,
426-
State: keybase1.Identify3RowState_REVOKED,
427-
Color: keybase1.Identify3RowColor_RED,
428-
})
477+
arg := i.rowPartial(row.Proof, nil)
478+
arg.State = keybase1.Identify3RowState_REVOKED
479+
arg.Color = keybase1.Identify3RowColor_RED
480+
i.updateRow(arg)
429481
}
430482

431483
func (i *UIAdapter) plumbRevokeds(rows []keybase1.RevokedProof) {

‎go/identify3/identify3_test.go‎

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package identify3
22

33
import (
4+
"io/ioutil"
5+
"net/http"
46
"sync"
57
"testing"
68

@@ -245,7 +247,6 @@ func TestFollowUnfollowTracy(t *testing.T) {
245247
}
246248

247249
func runID3(t *testing.T, mctx libkb.MetaContext, user string, follow bool) id3results {
248-
249250
guiid, err := libkb.NewIdentify3GUIID()
250251
require.NoError(t, err)
251252
resultCh := make(chan keybase1.Identify3ResultType)
@@ -261,7 +262,14 @@ func runID3(t *testing.T, mctx libkb.MetaContext, user string, follow bool) id3r
261262
Follow: follow,
262263
})
263264
require.NoError(t, err)
264-
return fakeUI3.results()
265+
res := fakeUI3.results()
266+
for _, row := range res.rows {
267+
checkIcon(t, row.Key, row.SiteIcon)
268+
if row.Priority == 0 || row.Priority == 9999999 {
269+
t.Fatalf("unexpected priority %v %v", row.Key, row.Priority)
270+
}
271+
}
272+
return res
265273
}
266274

267275
func TestFollowResetFollow(t *testing.T) {
@@ -287,3 +295,25 @@ func TestFollowResetFollow(t *testing.T) {
287295
res = runID3(t, mctx, alice.Username, true)
288296
require.False(t, res.userWasReset)
289297
}
298+
299+
func checkIcon(t testing.TB, service string, icon []keybase1.SizedImage) {
300+
if service == "theqrl.org" {
301+
// Skip checking for logos for this one.
302+
return
303+
}
304+
require.Len(t, icon, 2, "%v", service)
305+
for _, icon := range icon {
306+
if icon.Width < 2 {
307+
t.Fatalf("unreasonable icon size")
308+
}
309+
resp, err := http.Get(icon.Path)
310+
require.NoError(t, err, "%v", service)
311+
require.Equal(t, 200, resp.StatusCode, "icon file should be reachable")
312+
require.NoError(t, err)
313+
body, err := ioutil.ReadAll(resp.Body)
314+
require.NoError(t, err)
315+
if len(body) < 150 {
316+
t.Fatalf("unreasonable icon payload size")
317+
}
318+
}
319+
}

‎go/protocol/keybase1/common.go‎

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎go/protocol/keybase1/identify3_ui.go‎

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)