Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

type ids exposed by the api #21975

Merged
merged 7 commits into from
Jan 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions go/badges/badgestate.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,8 @@ type BadgeState struct {
env *libkb.Env
state keybase1.BadgeState

inboxVers chat1.InboxVers
// Map from ConversationID.String to BadgeConversationInfo.
chatUnreadMap map[string]keybase1.BadgeConversationInfo
inboxVers chat1.InboxVers
chatUnreadMap map[chat1.ConvIDStr]keybase1.BadgeConversationInfo

walletUnreadMap map[stellar1.AccountID]int
}
Expand All @@ -63,7 +62,7 @@ func newBadgeState(log logger.Logger, env *libkb.Env) *BadgeState {
log: log,
env: env,
inboxVers: chat1.InboxVers(0),
chatUnreadMap: make(map[string]keybase1.BadgeConversationInfo),
chatUnreadMap: make(map[chat1.ConvIDStr]keybase1.BadgeConversationInfo),
walletUnreadMap: make(map[stellar1.AccountID]int),
localChatState: dummyLocalChatState{},
}
Expand Down Expand Up @@ -426,7 +425,7 @@ func (b *BadgeState) UpdateWithChatFull(ctx context.Context, update chat1.Unread
case chat1.SyncInboxResType_CURRENT:
case chat1.SyncInboxResType_INCREMENTAL:
case chat1.SyncInboxResType_CLEAR:
b.chatUnreadMap = make(map[string]keybase1.BadgeConversationInfo)
b.chatUnreadMap = make(map[chat1.ConvIDStr]keybase1.BadgeConversationInfo)
}

for _, upd := range update.Updates {
Expand All @@ -442,7 +441,7 @@ func (b *BadgeState) Clear() {

b.state = keybase1.BadgeState{}
b.inboxVers = chat1.InboxVers(0)
b.chatUnreadMap = make(map[string]keybase1.BadgeConversationInfo)
b.chatUnreadMap = make(map[chat1.ConvIDStr]keybase1.BadgeConversationInfo)
b.walletUnreadMap = make(map[stellar1.AccountID]int)
}

Expand Down
22 changes: 11 additions & 11 deletions go/bind/extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,24 +96,24 @@ func (n *extensionNotifyListener) NewChatActivity(uid keybase1.UID, activity cha
// skip pending message notification
return
}
strConvID := activity.IncomingMessage().ConvID.String()
convID := activity.IncomingMessage().ConvID.String()
outboxID := msg.GetOutboxID()
if outboxID != nil {
n.trigger(*outboxID)
}
extensionPushResult(nil, strConvID, "message")
extensionPushResult(nil, convID, "message")
case chat1.ChatActivityType_FAILED_MESSAGE:
err := errors.New("message failed")
recs := activity.FailedMessage().OutboxRecords
for _, r := range recs {
strConvID := r.ConvID.String()
convID := r.ConvID.String()
n.trigger(r.OutboxID)
extensionPushResult(err, strConvID, "message")
extensionPushResult(err, convID, "message")
}
for _, r := range recs {
strConvID := r.ConvID.String()
convID := r.ConvID.String()
strOutboxID := r.OutboxID.String()
extensionRegisterFailure(ctx, n.G(), err, strConvID, strOutboxID)
extensionRegisterFailure(ctx, n.G(), err, convID, strOutboxID)
}
}
}
Expand Down Expand Up @@ -321,12 +321,12 @@ func extensionRegisterSendNonblock(ctx context.Context, gc *globals.Context, con
}(bctx)
}

func extensionRegisterFailure(ctx context.Context, gc *globals.Context, err error, strConvID,
func extensionRegisterFailure(ctx context.Context, gc *globals.Context, err error, convIDStr chat1.ConvIDStr,
strOutboxID string) {
if err == nil {
return
}
convID, err := chat1.MakeConvID(strConvID)
convID, err := chat1.MakeConvID(convIDStr.String())
if err != nil {
kbCtx.Log.CDebugf(ctx, "extensionRegisterFailure: invalid convID: %s", err)
return
Expand Down Expand Up @@ -476,14 +476,14 @@ func ExtensionPostText(strConvID, name string, public bool, membersType int, bod
return nil
}

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

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

func putSavedConv(ctx context.Context, strConvID, name string, public bool, membersType int) {
item := storage.SharedInboxItem{
ConvID: strConvID,
ConvID: chat1.ConvIDStr(strConvID),
Name: name,
Public: public,
MembersType: chat1.ConversationMembersType(membersType),
Expand Down
2 changes: 1 addition & 1 deletion go/bind/keybase.go
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ func pushPendingMessageFailure(obrs []chat1.OutboxRecord, pusher PushNotifier) {
kbCtx.Log.Debug("pushPendingMessageFailure: pushing convID: %s", obr.ConvID)
pusher.LocalNotification("failedpending",
"Heads up! Your message hasn't sent yet, tap here to retry.",
-1, "default", obr.ConvID.String(), "chat.failedpending")
-1, "default", obr.ConvID.String().String(), "chat.failedpending")
return
}
}
Expand Down
2 changes: 1 addition & 1 deletion go/chat/botcommands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func TestBotCommandManager(t *testing.T) {
require.Equal(t, "status", cmds[0].Name)

// test team
teamID, err := keybase1.TeamIDFromString(teamConv.Triple.Tlfid.String())
teamID, err := keybase1.TeamIDFromString(teamConv.Triple.Tlfid.String().String())
require.NoError(t, err)
pollForSeqno := func(expectedSeqno keybase1.Seqno) {
found := false
Expand Down
4 changes: 2 additions & 2 deletions go/chat/bots/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ type CachingBotCommandManager struct {
edb *encrypteddb.EncryptedDB
commandUpdateCh chan *commandUpdaterJob
queuedUpdatedMu sync.Mutex
queuedUpdates map[string]*commandUpdaterJob
queuedUpdates map[chat1.ConvIDStr]*commandUpdaterJob
}

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

Expand Down
8 changes: 4 additions & 4 deletions go/chat/commands/giphy.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ func (d defaultGiphySearcher) Search(mctx libkb.MetaContext, apiKeySource types.
type Giphy struct {
sync.Mutex
*baseCommand
shownResults map[string]*string
shownWindow map[string]bool
shownResults map[chat1.ConvIDStr]*string
shownWindow map[chat1.ConvIDStr]bool
currentOpCancelFn context.CancelFunc
currentOpDoneCb chan struct{}
searcher giphySearcher
Expand All @@ -38,8 +38,8 @@ func NewGiphy(g *globals.Context) *Giphy {
usage := "Search for and post GIFs"
return &Giphy{
baseCommand: newBaseCommand(g, "giphy", "[search terms]", usage, true),
shownResults: make(map[string]*string),
shownWindow: make(map[string]bool),
shownResults: make(map[chat1.ConvIDStr]*string),
shownWindow: make(map[chat1.ConvIDStr]bool),
searcher: defaultGiphySearcher{},
}
}
Expand Down
2 changes: 1 addition & 1 deletion go/chat/convsource.go
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ func (s *HybridConversationSource) Push(ctx context.Context, convID chat1.Conver
return decmsg, continuousUpdate, err
}
if msg.ClientHeader.Sender.Eq(uid) && conv.GetMembersType() == chat1.ConversationMembersType_TEAM {
teamID, err := keybase1.TeamIDFromString(conv.Conv.Metadata.IdTriple.Tlfid.String())
teamID, err := keybase1.TeamIDFromString(conv.Conv.Metadata.IdTriple.Tlfid.String().String())
if err != nil {
s.Debug(ctx, "Push: failed to get team ID: %v", err)
} else {
Expand Down
7 changes: 3 additions & 4 deletions go/chat/ephemeral_purger.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,14 @@ func (q *queueItem) String() string {
type priorityQueue struct {
sync.RWMutex

queue []*queueItem
// convID -> *queueItem
itemMap map[string]*queueItem
queue []*queueItem
itemMap map[chat1.ConvIDStr]*queueItem
}

func newPriorityQueue() *priorityQueue {
return &priorityQueue{
queue: []*queueItem{},
itemMap: make(map[string]*queueItem),
itemMap: make(map[chat1.ConvIDStr]*queueItem),
}
}

Expand Down
4 changes: 2 additions & 2 deletions go/chat/flip/chat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type chatClient struct {
ch chan GameMessageWrappedEncoded
server *chatServer
dealer *Dealer
history map[string]bool
history map[chat1.ConvIDStr]bool
clock clockwork.FakeClock
deliver func(m GameMessageWrappedEncoded)
}
Expand Down Expand Up @@ -123,7 +123,7 @@ func (s *chatServer) newClient() *chatClient {
me: newTestUser(),
ch: make(chan GameMessageWrappedEncoded, 1000),
server: s,
history: make(map[string]bool),
history: make(map[chat1.ConvIDStr]bool),
}
ret.dealer = NewDealer(ret)
ret.deliver = func(m GameMessageWrappedEncoded) {
Expand Down
2 changes: 1 addition & 1 deletion go/chat/flip/dealer.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (m GameMessageWrapped) GameMetadata() GameMetadata {
}

func (g GameMetadata) ToKey() GameKey {
return GameKey(strings.Join([]string{g.Initiator.U.String(), g.Initiator.D.String(), g.ConversationID.String(), g.GameID.String()}, ","))
return GameKey(strings.Join([]string{g.Initiator.U.String(), g.Initiator.D.String(), g.ConversationID.String().String(), g.GameID.String().String()}, ","))
}

func (g GameMetadata) String() string {
Expand Down
10 changes: 5 additions & 5 deletions go/chat/flipmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ type FlipManager struct {

gamesMu sync.Mutex
games *lru.Cache
dirtyGames map[string]chat1.FlipGameID
dirtyGames map[chat1.FlipGameIDStr]chat1.FlipGameID
flipConvs *lru.Cache
gameMsgIDs *lru.Cache
gameOutboxIDMu sync.Mutex
Expand All @@ -155,7 +155,7 @@ type FlipManager struct {
partMu sync.Mutex
maxConvParticipations int
maxConvParticipationsReset time.Duration
convParticipations map[string]convParticipationsRateLimit
convParticipations map[chat1.ConvIDStr]convParticipationsRateLimit

// testing only
testingServerClock clockwork.Clock
Expand All @@ -172,10 +172,10 @@ func NewFlipManager(g *globals.Context, ri func() chat1.RemoteInterface) *FlipMa
ri: ri,
clock: clockwork.NewRealClock(),
games: games,
dirtyGames: make(map[string]chat1.FlipGameID),
dirtyGames: make(map[chat1.FlipGameIDStr]chat1.FlipGameID),
forceCh: make(chan struct{}, 10),
loadGameCh: make(chan loadGameJob, 200),
convParticipations: make(map[string]convParticipationsRateLimit),
convParticipations: make(map[chat1.ConvIDStr]convParticipationsRateLimit),
maxConvParticipations: 1000,
maxConvParticipationsReset: 5 * time.Minute,
visualizer: NewFlipVisualizer(128, 80),
Expand Down Expand Up @@ -276,7 +276,7 @@ func (m *FlipManager) notifyDirtyGames() {
return
}
dirtyGames := m.dirtyGames
m.dirtyGames = make(map[string]chat1.FlipGameID)
m.dirtyGames = make(map[chat1.FlipGameIDStr]chat1.FlipGameID)
m.gamesMu.Unlock()

ctx := m.makeBkgContext()
Expand Down
2 changes: 1 addition & 1 deletion go/chat/flipmanager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
)

func consumeFlipToResult(t *testing.T, ui *kbtest.ChatUI, listener *serverChatListener,
gameID string, numUsers int) string {
gameID chat1.FlipGameIDStr, numUsers int) string {
timeout := 20 * time.Second
consumeNewMsgRemote(t, listener, chat1.MessageType_FLIP) // host msg
for {
Expand Down
2 changes: 1 addition & 1 deletion go/chat/globals/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func CtxRateLimits(ctx context.Context) (res []chat1.RateLimit) {

func CtxAddMessageCacheSkips(ctx context.Context, convID chat1.ConversationID, msgs []chat1.MessageUnboxed) {
val := ctx.Value(messageSkipsKey)
if existingSkips, ok := val.(map[string]MessageCacheSkip); ok {
if existingSkips, ok := val.(map[chat1.ConvIDStr]MessageCacheSkip); ok {
existingSkips[convID.String()] = MessageCacheSkip{
ConvID: convID,
Msgs: append(existingSkips[convID.String()].Msgs, msgs...),
Expand Down
21 changes: 10 additions & 11 deletions go/chat/inboxsource.go
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,7 @@ func (s *HybridInboxSource) ApplyLocalChatState(ctx context.Context, infos []key
}

// convID -> isRead
readConvMap := make(map[string]bool)
readConvMap := make(map[chat1.ConvIDStr]bool)
for _, conv := range convs {
if conv.IsLocallyRead() {
readConvMap[conv.ConvIDStr] = true
Expand All @@ -770,10 +770,8 @@ func (s *HybridInboxSource) ApplyLocalChatState(ctx context.Context, infos []key
s.Debug(ctx, "ApplyLocalChatState: failed to get outbox: %v", oerr)
}

// convID -> unreadCount
failedOutboxMap := make(map[string]int)
// convID -> mtime
localUpdates := make(map[string]chat1.LocalMtimeUpdate)
failedOutboxMap := make(map[chat1.ConvIDStr]int)
localUpdates := make(map[chat1.ConvIDStr]chat1.LocalMtimeUpdate)
s.Debug(ctx, "ApplyLocalChatState: looking through %d outbox items for badgable errors", len(obrs))
for _, obr := range obrs {
if topicType := obr.Msg.ClientHeader.Conv.TopicType; !(obr.Msg.IsBadgableType() && topicType == chat1.TopicType_CHAT) {
Expand All @@ -793,17 +791,18 @@ func (s *HybridInboxSource) ApplyLocalChatState(ctx context.Context, infos []key
if !isBadgableError {
continue
}
if update, ok := localUpdates[obr.ConvID.String()]; ok {
convIDStr := obr.ConvID.String()
if update, ok := localUpdates[convIDStr]; ok {
if ctime.After(update.Mtime) {
localUpdates[obr.ConvID.String()] = update
localUpdates[convIDStr] = update
}
} else {
localUpdates[obr.ConvID.String()] = chat1.LocalMtimeUpdate{
localUpdates[convIDStr] = chat1.LocalMtimeUpdate{
ConvID: obr.ConvID,
Mtime: ctime,
}
}
failedOutboxMap[obr.ConvID.String()]++
failedOutboxMap[convIDStr]++
}
}

Expand All @@ -817,7 +816,7 @@ func (s *HybridInboxSource) ApplyLocalChatState(ctx context.Context, infos []key

res = make([]keybase1.BadgeConversationInfo, 0, len(infos)+len(failedOutboxMap))
for _, info := range infos {
convIDStr := info.ConvID.String()
convIDStr := chat1.ConvIDStr(info.ConvID.String())
// mark this conv as read
if readConvMap[convIDStr] {
info = makeBadgeConversationInfo(info.ConvID, 0)
Expand All @@ -838,7 +837,7 @@ func (s *HybridInboxSource) ApplyLocalChatState(ctx context.Context, infos []key

// apply any new failed outbox items
for convIDStr, failedCount := range failedOutboxMap {
convID, err := chat1.MakeConvID(convIDStr)
convID, err := chat1.MakeConvID(convIDStr.String())
if err != nil {
s.Debug(ctx, "ApplyLocalChatState: Unable to make convID: %v", err)
continue
Expand Down
Loading