github.com/keybase/client/go@v0.0.0-20240309051027-028f7c731f8b/chat/commands/conv.go (about) 1 package commands 2 3 import ( 4 "context" 5 "errors" 6 "strings" 7 8 "github.com/keybase/client/go/chat/globals" 9 "github.com/keybase/client/go/chat/types" 10 "github.com/keybase/client/go/protocol/chat1" 11 "github.com/keybase/client/go/protocol/gregor1" 12 "github.com/keybase/client/go/protocol/keybase1" 13 ) 14 15 func getConvByID(ctx context.Context, g *globals.Context, uid gregor1.UID, convID chat1.ConversationID) (res types.RemoteConversation, err error) { 16 ib, err := g.InboxSource.ReadUnverified(ctx, uid, types.InboxSourceDataSourceAll, 17 &chat1.GetInboxQuery{ 18 ConvID: &convID, 19 }) 20 if err != nil { 21 return res, err 22 } 23 if len(ib.ConvsUnverified) == 0 { 24 return res, errors.New("conv not found") 25 } 26 return ib.ConvsUnverified[0], nil 27 } 28 29 func getConvByName(ctx context.Context, g *globals.Context, uid gregor1.UID, name string) (res chat1.ConversationLocal, err error) { 30 find := func(mt chat1.ConversationMembersType, name string, topicName *string) (conv chat1.ConversationLocal, err error) { 31 convs, err := g.ChatHelper.FindConversations(ctx, name, topicName, 32 chat1.TopicType_CHAT, mt, keybase1.TLFVisibility_PRIVATE) 33 if err != nil { 34 return res, err 35 } 36 if len(convs) == 0 { 37 return res, errors.New("conversation not found") 38 } 39 return convs[0], nil 40 } 41 if strings.Contains(name, "#") { 42 toks := strings.Split(name, "#") 43 return find(chat1.ConversationMembersType_TEAM, toks[0], &toks[1]) 44 } 45 if res, err = find(chat1.ConversationMembersType_IMPTEAMNATIVE, name, nil); err != nil { 46 return find(chat1.ConversationMembersType_TEAM, name, nil) 47 } 48 return res, nil 49 }