Skip to content

Commit 0cdd644

Browse files
authored
Type IDs exposed by API (keybase#22050)
* type ids exposed by the api * ConvIDStr * refactor * cleanup * revert bot settings change * kbfs * bind * Revert "bind" This reverts commit 0fb6cf80830230fa46eb66302093265bcff91506. * Revert "kbfs" This reverts commit 3062df90d23539d591ad8b43d04744108ea076b8. * Revert "revert bot settings change" This reverts commit 443160b261d043558826520f885ff99baaa83ee6. * Revert "cleanup" This reverts commit e65cded180e9ac72951cbea2d4bd421137e1da06. * Revert "refactor" This reverts commit 76d1505bee6476f6455eb3f0cd890567cad54787. * type maps with ConvIDStr * cleanup * fix test * ConvIDStr
1 parent 8c1979e commit 0cdd644

60 files changed

Lines changed: 648 additions & 586 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎go/badges/badgestate.go‎

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,8 @@ type BadgeState struct {
4040
env *libkb.Env
4141
state keybase1.BadgeState
4242

43-
inboxVers chat1.InboxVers
44-
// Map from ConversationID.String to BadgeConversationInfo.
45-
chatUnreadMap map[string]keybase1.BadgeConversationInfo
43+
inboxVers chat1.InboxVers
44+
chatUnreadMap map[chat1.ConvIDStr]keybase1.BadgeConversationInfo
4645

4746
walletUnreadMap map[stellar1.AccountID]int
4847
}
@@ -63,7 +62,7 @@ func newBadgeState(log logger.Logger, env *libkb.Env) *BadgeState {
6362
log: log,
6463
env: env,
6564
inboxVers: chat1.InboxVers(0),
66-
chatUnreadMap: make(map[string]keybase1.BadgeConversationInfo),
65+
chatUnreadMap: make(map[chat1.ConvIDStr]keybase1.BadgeConversationInfo),
6766
walletUnreadMap: make(map[stellar1.AccountID]int),
6867
localChatState: dummyLocalChatState{},
6968
}
@@ -171,7 +170,7 @@ func homeStateLessThan(a *homeStateBody, b homeStateBody) bool {
171170
return false
172171
}
173172

174-
func (b *BadgeState) ConversationBadgeStr(ctx context.Context, convIDStr string,
173+
func (b *BadgeState) ConversationBadgeStr(ctx context.Context, convIDStr chat1.ConvIDStr,
175174
deviceType keybase1.DeviceType) int {
176175
b.Lock()
177176
defer b.Unlock()
@@ -183,7 +182,7 @@ func (b *BadgeState) ConversationBadgeStr(ctx context.Context, convIDStr string,
183182

184183
func (b *BadgeState) ConversationBadge(ctx context.Context, convID chat1.ConversationID,
185184
deviceType keybase1.DeviceType) int {
186-
return b.ConversationBadgeStr(ctx, convID.String(), deviceType)
185+
return b.ConversationBadgeStr(ctx, convID.ConvIDStr(), deviceType)
187186
}
188187

189188
// UpdateWithGregor updates the badge state from a gregor state.
@@ -433,7 +432,7 @@ func (b *BadgeState) UpdateWithChatFull(ctx context.Context, update chat1.Unread
433432
case chat1.SyncInboxResType_CURRENT:
434433
case chat1.SyncInboxResType_INCREMENTAL:
435434
case chat1.SyncInboxResType_CLEAR:
436-
b.chatUnreadMap = make(map[string]keybase1.BadgeConversationInfo)
435+
b.chatUnreadMap = make(map[chat1.ConvIDStr]keybase1.BadgeConversationInfo)
437436
}
438437

439438
for _, upd := range update.Updates {
@@ -449,14 +448,14 @@ func (b *BadgeState) Clear() {
449448

450449
b.state = keybase1.BadgeState{}
451450
b.inboxVers = chat1.InboxVers(0)
452-
b.chatUnreadMap = make(map[string]keybase1.BadgeConversationInfo)
451+
b.chatUnreadMap = make(map[chat1.ConvIDStr]keybase1.BadgeConversationInfo)
453452
b.walletUnreadMap = make(map[stellar1.AccountID]int)
454453
}
455454

456455
func (b *BadgeState) updateWithChat(ctx context.Context, update chat1.UnreadUpdate) {
457456
b.log.CDebugf(ctx, "updateWithChat: %s", update)
458457
if update.Diff {
459-
cur := b.chatUnreadMap[update.ConvID.String()]
458+
cur := b.chatUnreadMap[update.ConvID.ConvIDStr()]
460459
cur.ConvID = keybase1.ChatConversationID(update.ConvID)
461460
cur.UnreadMessages += update.UnreadMessages
462461
if cur.BadgeCounts == nil {
@@ -465,9 +464,9 @@ func (b *BadgeState) updateWithChat(ctx context.Context, update chat1.UnreadUpda
465464
for dt, c := range update.UnreadNotifyingMessages {
466465
cur.BadgeCounts[dt] += c
467466
}
468-
b.chatUnreadMap[update.ConvID.String()] = cur
467+
b.chatUnreadMap[update.ConvID.ConvIDStr()] = cur
469468
} else {
470-
b.chatUnreadMap[update.ConvID.String()] = keybase1.BadgeConversationInfo{
469+
b.chatUnreadMap[update.ConvID.ConvIDStr()] = keybase1.BadgeConversationInfo{
471470
ConvID: keybase1.ChatConversationID(update.ConvID),
472471
UnreadMessages: update.UnreadMessages,
473472
BadgeCounts: update.UnreadNotifyingMessages,

‎go/bind/extension.go‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -96,24 +96,24 @@ func (n *extensionNotifyListener) NewChatActivity(uid keybase1.UID, activity cha
9696
// skip pending message notification
9797
return
9898
}
99-
strConvID := activity.IncomingMessage().ConvID.String()
99+
convID := activity.IncomingMessage().ConvID.ConvIDStr()
100100
outboxID := msg.GetOutboxID()
101101
if outboxID != nil {
102102
n.trigger(*outboxID)
103103
}
104-
extensionPushResult(nil, strConvID, "message")
104+
extensionPushResult(nil, convID, "message")
105105
case chat1.ChatActivityType_FAILED_MESSAGE:
106106
err := errors.New("message failed")
107107
recs := activity.FailedMessage().OutboxRecords
108108
for _, r := range recs {
109-
strConvID := r.ConvID.String()
109+
convID := r.ConvID.ConvIDStr()
110110
n.trigger(r.OutboxID)
111-
extensionPushResult(err, strConvID, "message")
111+
extensionPushResult(err, convID, "message")
112112
}
113113
for _, r := range recs {
114-
strConvID := r.ConvID.String()
114+
convID := r.ConvID.ConvIDStr()
115115
strOutboxID := r.OutboxID.String()
116-
extensionRegisterFailure(ctx, n.G(), err, strConvID, strOutboxID)
116+
extensionRegisterFailure(ctx, n.G(), err, convID, strOutboxID)
117117
}
118118
}
119119
}
@@ -321,12 +321,12 @@ func extensionRegisterSendNonblock(ctx context.Context, gc *globals.Context, con
321321
}(bctx)
322322
}
323323

324-
func extensionRegisterFailure(ctx context.Context, gc *globals.Context, err error, strConvID,
324+
func extensionRegisterFailure(ctx context.Context, gc *globals.Context, err error, strConvID chat1.ConvIDStr,
325325
strOutboxID string) {
326326
if err == nil {
327327
return
328328
}
329-
convID, err := chat1.MakeConvID(strConvID)
329+
convID, err := chat1.MakeConvID(strConvID.String())
330330
if err != nil {
331331
kbCtx.Log.CDebugf(ctx, "extensionRegisterFailure: invalid convID: %s", err)
332332
return
@@ -476,14 +476,14 @@ func ExtensionPostText(strConvID, name string, public bool, membersType int, bod
476476
return nil
477477
}
478478

479-
func extensionPushResult(err error, strConvID, typ string) {
479+
func extensionPushResult(err error, convID chat1.ConvIDStr, typ string) {
480480
var msg string
481481
if err != nil {
482482
msg = fmt.Sprintf("We could not send your %s. Please try from the Keybase app.", typ)
483483
} else {
484484
msg = fmt.Sprintf("Your %s was shared successfully.", typ)
485485
}
486-
extensionPusher.LocalNotification("extension", msg, -1, "default", strConvID, "chat.extension")
486+
extensionPusher.LocalNotification("extension", msg, -1, "default", convID.String(), "chat.extension")
487487
}
488488

489489
func extensionCreateUploadTemp(ctx context.Context, gc *globals.Context, outboxID chat1.OutboxID,
@@ -689,7 +689,7 @@ func savedConvFile() *encrypteddb.EncryptedFile {
689689

690690
func putSavedConv(ctx context.Context, strConvID, name string, public bool, membersType int) {
691691
item := storage.SharedInboxItem{
692-
ConvID: strConvID,
692+
ConvID: chat1.ConvIDStr(strConvID),
693693
Name: name,
694694
Public: public,
695695
MembersType: chat1.ConversationMembersType(membersType),

‎go/chat/bots/commands.go‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ type CachingBotCommandManager struct {
6464
edb *encrypteddb.EncryptedDB
6565
commandUpdateCh chan *commandUpdaterJob
6666
queuedUpdatedMu sync.Mutex
67-
queuedUpdates map[string]*commandUpdaterJob
67+
queuedUpdates map[chat1.ConvIDStr]*commandUpdaterJob
6868
}
6969

7070
func NewCachingBotCommandManager(g *globals.Context, ri func() chat1.RemoteInterface) *CachingBotCommandManager {
@@ -80,7 +80,7 @@ func NewCachingBotCommandManager(g *globals.Context, ri func() chat1.RemoteInter
8080
ri: ri,
8181
edb: encrypteddb.New(g.ExternalG(), dbFn, keyFn),
8282
commandUpdateCh: make(chan *commandUpdaterJob, 100),
83-
queuedUpdates: make(map[string]*commandUpdaterJob),
83+
queuedUpdates: make(map[chat1.ConvIDStr]*commandUpdaterJob),
8484
}
8585
}
8686

@@ -355,15 +355,15 @@ func (b *CachingBotCommandManager) runCommandUpdateUI(ctx context.Context, job *
355355
func (b *CachingBotCommandManager) queueCommandUpdate(ctx context.Context, job *commandUpdaterJob) error {
356356
b.queuedUpdatedMu.Lock()
357357
defer b.queuedUpdatedMu.Unlock()
358-
if curJob, ok := b.queuedUpdates[job.convID.String()]; ok {
358+
if curJob, ok := b.queuedUpdates[job.convID.ConvIDStr()]; ok {
359359
b.Debug(ctx, "queueCommandUpdate: skipping already queued: %s", job.convID)
360360
curJob.completeChs = append(curJob.completeChs, job.completeChs...)
361361
return nil
362362
}
363363
select {
364364
case b.commandUpdateCh <- job:
365365
go b.runCommandUpdateUI(globals.BackgroundChatCtx(ctx, b.G()), job)
366-
b.queuedUpdates[job.convID.String()] = job
366+
b.queuedUpdates[job.convID.ConvIDStr()] = job
367367
default:
368368
return errors.New("queue full")
369369
}
@@ -459,7 +459,7 @@ func (b *CachingBotCommandManager) commandUpdate(ctx context.Context, job *comma
459459
defer b.Trace(ctx, func() error { return err }, "commandUpdate")()
460460
defer func() {
461461
b.queuedUpdatedMu.Lock()
462-
delete(b.queuedUpdates, job.convID.String())
462+
delete(b.queuedUpdates, job.convID.ConvIDStr())
463463
b.queuedUpdatedMu.Unlock()
464464
job.uiCh <- err
465465
for _, completeCh := range job.completeChs {

‎go/chat/commands/giphy.go‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ func (d defaultGiphySearcher) Search(mctx libkb.MetaContext, apiKeySource types.
2727
type Giphy struct {
2828
sync.Mutex
2929
*baseCommand
30-
shownResults map[string]*string
31-
shownWindow map[string]bool
30+
shownResults map[chat1.ConvIDStr]*string
31+
shownWindow map[chat1.ConvIDStr]bool
3232
currentOpCancelFn context.CancelFunc
3333
currentOpDoneCb chan struct{}
3434
searcher giphySearcher
@@ -38,8 +38,8 @@ func NewGiphy(g *globals.Context) *Giphy {
3838
usage := "Search for and post GIFs"
3939
return &Giphy{
4040
baseCommand: newBaseCommand(g, "giphy", "[search terms]", usage, true),
41-
shownResults: make(map[string]*string),
42-
shownWindow: make(map[string]bool),
41+
shownResults: make(map[chat1.ConvIDStr]*string),
42+
shownWindow: make(map[chat1.ConvIDStr]bool),
4343
searcher: defaultGiphySearcher{},
4444
}
4545
}
@@ -112,19 +112,19 @@ func (s *Giphy) Preview(ctx context.Context, uid gregor1.UID, convID chat1.Conve
112112
defer close(s.currentOpDoneCb)
113113

114114
if !s.Match(ctx, text) {
115-
if _, ok := s.shownWindow[convID.String()]; ok {
115+
if _, ok := s.shownWindow[convID.ConvIDStr()]; ok {
116116
// tell UI to clear
117117
err := s.getChatUI().ChatGiphyToggleResultWindow(ctx, convID, false, false)
118118
if err != nil {
119119
s.Debug(ctx, "Preview: error on toggle result: %+v", err)
120120
}
121-
delete(s.shownResults, convID.String())
122-
delete(s.shownWindow, convID.String())
121+
delete(s.shownResults, convID.ConvIDStr())
122+
delete(s.shownWindow, convID.ConvIDStr())
123123
}
124124
return
125125
}
126126
query := s.getQuery(text)
127-
if shown, ok := s.shownResults[convID.String()]; ok && s.queryEqual(query, shown) {
127+
if shown, ok := s.shownResults[convID.ConvIDStr()]; ok && s.queryEqual(query, shown) {
128128
s.Debug(ctx, "Preview: same query given, skipping")
129129
return
130130
}
@@ -133,7 +133,7 @@ func (s *Giphy) Preview(ctx context.Context, uid gregor1.UID, convID chat1.Conve
133133
s.Debug(ctx, "Preview: error on toggle result: %+v", err)
134134
}
135135

136-
s.shownWindow[convID.String()] = true
136+
s.shownWindow[convID.ConvIDStr()] = true
137137

138138
results, err := s.searcher.Search(libkb.NewMetaContext(ctx, s.G().ExternalG()),
139139
s.G().ExternalAPIKeySource, query, s.getLimit(), s.G().AttachmentURLSrv)
@@ -150,5 +150,5 @@ func (s *Giphy) Preview(ctx context.Context, uid gregor1.UID, convID chat1.Conve
150150
return
151151
}
152152

153-
s.shownResults[convID.String()] = query
153+
s.shownResults[convID.ConvIDStr()] = query
154154
}

‎go/chat/ephemeral_purger.go‎

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,14 @@ func (q *queueItem) String() string {
3636
type priorityQueue struct {
3737
sync.RWMutex
3838

39-
queue []*queueItem
40-
// convID -> *queueItem
41-
itemMap map[string]*queueItem
39+
queue []*queueItem
40+
itemMap map[chat1.ConvIDStr]*queueItem
4241
}
4342

4443
func newPriorityQueue() *priorityQueue {
4544
return &priorityQueue{
4645
queue: []*queueItem{},
47-
itemMap: make(map[string]*queueItem),
46+
itemMap: make(map[chat1.ConvIDStr]*queueItem),
4847
}
4948
}
5049

@@ -82,7 +81,7 @@ func (pq *priorityQueue) Push(x interface{}) {
8281
item := x.(*queueItem)
8382
item.index = len(pq.queue)
8483
pq.queue = append(pq.queue, item)
85-
pq.itemMap[item.purgeInfo.ConvID.String()] = item
84+
pq.itemMap[item.purgeInfo.ConvID.ConvIDStr()] = item
8685
}
8786

8887
func (pq *priorityQueue) Pop() interface{} {
@@ -93,7 +92,7 @@ func (pq *priorityQueue) Pop() interface{} {
9392
item := pq.queue[n-1]
9493
item.index = -1 // for safety
9594
pq.queue = pq.queue[:n-1]
96-
delete(pq.itemMap, item.purgeInfo.ConvID.String())
95+
delete(pq.itemMap, item.purgeInfo.ConvID.ConvIDStr())
9796
return item
9897
}
9998

@@ -187,7 +186,7 @@ func (b *BackgroundEphemeralPurger) Queue(ctx context.Context, purgeInfo chat1.E
187186
}
188187

189188
// skip duplicate items
190-
item, ok := b.pq.itemMap[purgeInfo.ConvID.String()]
189+
item, ok := b.pq.itemMap[purgeInfo.ConvID.ConvIDStr()]
191190
if ok && item.purgeInfo.Eq(purgeInfo) {
192191
return nil
193192
}
@@ -243,7 +242,7 @@ func (b *BackgroundEphemeralPurger) initQueue(ctx context.Context) {
243242
}
244243

245244
func (b *BackgroundEphemeralPurger) updateQueue(purgeInfo chat1.EphemeralPurgeInfo) {
246-
item, ok := b.pq.itemMap[purgeInfo.ConvID.String()]
245+
item, ok := b.pq.itemMap[purgeInfo.ConvID.ConvIDStr()]
247246
if ok {
248247
item.purgeInfo = purgeInfo
249248
heap.Fix(b.pq, item.index)

‎go/chat/flip/chat_test.go‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ type chatClient struct {
2929
ch chan GameMessageWrappedEncoded
3030
server *chatServer
3131
dealer *Dealer
32-
history map[string]bool
32+
history map[chat1.ConvIDStr]bool
3333
clock clockwork.FakeClock
3434
deliver func(m GameMessageWrappedEncoded)
3535
}
@@ -123,7 +123,7 @@ func (s *chatServer) newClient() *chatClient {
123123
me: newTestUser(),
124124
ch: make(chan GameMessageWrappedEncoded, 1000),
125125
server: s,
126-
history: make(map[string]bool),
126+
history: make(map[chat1.ConvIDStr]bool),
127127
}
128128
ret.dealer = NewDealer(ret)
129129
ret.deliver = func(m GameMessageWrappedEncoded) {
@@ -142,7 +142,7 @@ func (c *chatClient) run(ctx context.Context, ch chat1.ConversationID) {
142142
case <-c.shutdownCh:
143143
return
144144
case msg := <-c.ch:
145-
chKey := ch.String()
145+
chKey := ch.ConvIDStr()
146146
_ = c.dealer.InjectIncomingChat(ctx, msg.Sender, ch, msg.GameID, msg.Body, !c.history[chKey])
147147
c.history[chKey] = true
148148
}
@@ -575,7 +575,7 @@ func TestRepeatedGame(t *testing.T) {
575575
defer srv.stopClients()
576576

577577
gameID := GenerateGameID()
578-
forAllClients(clients[1:], func(c *chatClient) { c.history[conversationID.String()] = true })
578+
forAllClients(clients[1:], func(c *chatClient) { c.history[conversationID.ConvIDStr()] = true })
579579
start := NewStartWithBigInt(srv.clock.Now(), pi(), 5)
580580
_, err := clients[0].dealer.startFlipWithGameID(ctx, start, conversationID, gameID)
581581
require.NoError(t, err)

0 commit comments

Comments
 (0)