Skip to content

Commit

Permalink
implement TlfVisibility filter on GetInbox (#4274)
Browse files Browse the repository at this point in the history
  • Loading branch information
songgao authored Sep 16, 2016
1 parent 9aa63e0 commit f76d84e
Show file tree
Hide file tree
Showing 10 changed files with 102 additions and 53 deletions.
51 changes: 39 additions & 12 deletions go/client/chat_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,22 @@ func makeChatListAndReadFlags(extras []cli.Flag) []cli.Flag {
Name: "time,since",
Usage: `Only show messages after certain time.`,
},
cli.BoolFlag{
Name: "public",
Usage: `Only select public conversations. Exclusive to --private`,
},
cli.BoolFlag{
Name: "private",
Usage: `Only select private conversations. Exclusive to --public`,
},
}...))
}

type conversationResolver struct {
TlfName string
TopicName string
TopicType chat1.TopicType
TlfName string
TopicName string
TopicType chat1.TopicType
Visibility chat1.TLFVisibility
}

func (r conversationResolver) Resolve(ctx context.Context, chatClient chat1.LocalInterface, tlfClient keybase1.TlfInterface) (conversations []chat1.ConversationInfoLocal, err error) {
Expand All @@ -55,9 +64,10 @@ func (r conversationResolver) Resolve(ctx context.Context, chatClient chat1.Loca
r.TlfName = string(cname)
}
conversations, err = chatClient.ResolveConversationLocal(ctx, chat1.ConversationInfoLocal{
TlfName: r.TlfName,
TopicName: r.TopicName,
TopicType: r.TopicType,
TlfName: r.TlfName,
TopicName: r.TopicName,
TopicType: r.TopicType,
Visibility: r.Visibility,
})
return conversations, err
}
Expand Down Expand Up @@ -87,6 +97,13 @@ func parseConversationResolver(ctx *cli.Context, tlfName string) (resolver conve
if resolver.TopicType, err = parseConversationTopicType(ctx); err != nil {
return resolver, err
}
if ctx.Bool("private") {
resolver.Visibility = chat1.TLFVisibility_PRIVATE
} else if ctx.Bool("public") {
resolver.Visibility = chat1.TLFVisibility_PUBLIC
} else {
resolver.Visibility = chat1.TLFVisibility_ANY
}
return resolver, nil
}

Expand Down Expand Up @@ -147,9 +164,10 @@ func (f messageFetcher) fetch(ctx context.Context, g *libkb.GlobalContext) (conv
}

type inboxFetcher struct {
topicType chat1.TopicType
limit int
since string
topicType chat1.TopicType
limit int
since string
visibility chat1.TLFVisibility

chatClient chat1.LocalInterface // for testing only
}
Expand All @@ -166,6 +184,14 @@ func makeInboxFetcherFromCli(ctx *cli.Context) (fetcher inboxFetcher, err error)
fetcher.limit = 0
}

if ctx.Bool("private") {
fetcher.visibility = chat1.TLFVisibility_PRIVATE
} else if ctx.Bool("public") {
fetcher.visibility = chat1.TLFVisibility_PUBLIC
} else {
fetcher.visibility = chat1.TLFVisibility_ANY
}

return fetcher, err
}

Expand All @@ -179,9 +205,10 @@ func (f inboxFetcher) fetch(ctx context.Context, g *libkb.GlobalContext) (conver
}

res, err := chatClient.GetInboxSummaryLocal(ctx, chat1.GetInboxSummaryLocalArg{
TopicType: f.topicType,
After: f.since,
Limit: f.limit,
TopicType: f.topicType,
After: f.since,
Limit: f.limit,
Visibility: f.visibility,
})
if err != nil {
return nil, nil, moreTotal, err
Expand Down
18 changes: 9 additions & 9 deletions go/protocol/chat1/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,21 +82,21 @@ type RateLimit struct {
type TLFVisibility int

const (
TLFVisibility_PUBLIC TLFVisibility = 0
TLFVisibility_PRIVATE TLFVisibility = 1
TLFVisibility_ANY TLFVisibility = 2
TLFVisibility_ANY TLFVisibility = 0
TLFVisibility_PUBLIC TLFVisibility = 1
TLFVisibility_PRIVATE TLFVisibility = 2
)

var TLFVisibilityMap = map[string]TLFVisibility{
"PUBLIC": 0,
"PRIVATE": 1,
"ANY": 2,
"ANY": 0,
"PUBLIC": 1,
"PRIVATE": 2,
}

var TLFVisibilityRevMap = map[TLFVisibility]string{
0: "PUBLIC",
1: "PRIVATE",
2: "ANY",
0: "ANY",
1: "PUBLIC",
2: "PRIVATE",
}

type GetInboxQuery struct {
Expand Down
18 changes: 10 additions & 8 deletions go/protocol/chat1/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,10 +344,11 @@ type MessageSelector struct {
}

type ConversationInfoLocal struct {
Id ConversationID `codec:"id" json:"id"`
TlfName string `codec:"tlfName" json:"tlfName"`
TopicName string `codec:"topicName" json:"topicName"`
TopicType TopicType `codec:"topicType" json:"topicType"`
Id ConversationID `codec:"id" json:"id"`
TlfName string `codec:"tlfName" json:"tlfName"`
TopicName string `codec:"topicName" json:"topicName"`
TopicType TopicType `codec:"topicType" json:"topicType"`
Visibility TLFVisibility `codec:"visibility" json:"visibility"`
}

type ConversationLocal struct {
Expand Down Expand Up @@ -396,10 +397,11 @@ type GetMessagesLocalArg struct {
}

type GetInboxSummaryLocalArg struct {
TopicType TopicType `codec:"topicType" json:"topicType"`
After string `codec:"after" json:"after"`
Before string `codec:"before" json:"before"`
Limit int `codec:"limit" json:"limit"`
TopicType TopicType `codec:"topicType" json:"topicType"`
After string `codec:"after" json:"after"`
Before string `codec:"before" json:"before"`
Limit int `codec:"limit" json:"limit"`
Visibility TLFVisibility `codec:"visibility" json:"visibility"`
}

type LocalInterface interface {
Expand Down
13 changes: 10 additions & 3 deletions go/service/chat_local.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,9 @@ func (h *chatLocalHandler) GetInboxSummaryLocal(ctx context.Context, arg chat1.G
if arg.TopicType != chat1.TopicType_NONE {
query.TopicType = &arg.TopicType
}
if arg.Visibility != chat1.TLFVisibility_ANY {
query.TlfVisibility = &arg.Visibility
}
rpcArg.Query = &query

iview, err := h.GetInboxLocal(ctx, rpcArg)
Expand Down Expand Up @@ -266,10 +269,14 @@ func (h *chatLocalHandler) resolveConversations(ctx context.Context, criteria ch
criteria.TlfName = string(resp.CanonicalName)

tlfID := chat1.TLFID(tlfIDb)
query := &chat1.GetInboxQuery{
TlfID: &tlfID,
}
if criteria.Visibility != chat1.TLFVisibility_ANY {
query.TlfVisibility = &criteria.Visibility
}
conversationsRemote, err := h.remoteClient().GetInboxRemote(ctx, chat1.GetInboxRemoteArg{
Query: &chat1.GetInboxQuery{
TlfID: &tlfID,
},
Query: query,
Pagination: nil,
})
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions protocol/avdl/chat1/common.avdl
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ protocol common {
}

enum TLFVisibility {
PUBLIC_0,
PRIVATE_1,
ANY_2
ANY_0,
PUBLIC_1,
PRIVATE_2
}

record GetInboxQuery {
Expand Down
3 changes: 2 additions & 1 deletion protocol/avdl/chat1/local.avdl
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ protocol local {
string tlfName;
string topicName;
TopicType topicType;
TLFVisibility visibility;
}

record ConversationLocal {
Expand Down Expand Up @@ -152,5 +153,5 @@ protocol local {
}

// if since is given, limit is ignored
GetInboxSummaryLocalRes getInboxSummaryLocal(TopicType topicType, string after, string before, int limit);
GetInboxSummaryLocalRes getInboxSummaryLocal(TopicType topicType, string after, string before, int limit, TLFVisibility visibility);
}
16 changes: 9 additions & 7 deletions protocol/js/flow-types-chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ export const CommonMessageType = {
}

export const CommonTLFVisibility = {
public: 0,
private: 1,
any: 2,
any: 0,
public: 1,
private: 2,
}

export const CommonTopicType = {
Expand Down Expand Up @@ -219,6 +219,7 @@ export type ConversationInfoLocal = {
tlfName: string,
topicName: string,
topicType: TopicType,
visibility: TLFVisibility,
}

export type ConversationLocal = {
Expand Down Expand Up @@ -463,9 +464,9 @@ export type SignatureInfo = {
export type TLFID = bytes

export type TLFVisibility =
0 // PUBLIC_0
| 1 // PRIVATE_1
| 2 // ANY_2
0 // ANY_0
| 1 // PUBLIC_1
| 2 // PRIVATE_2

export type ThreadID = bytes

Expand Down Expand Up @@ -495,7 +496,8 @@ export type localGetInboxSummaryLocalRpcParam = Exact<{
topicType: TopicType,
after: string,
before: string,
limit: int
limit: int,
visibility: TLFVisibility
}>

export type localGetMessagesLocalRpcParam = Exact<{
Expand Down
6 changes: 3 additions & 3 deletions protocol/json/chat1/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@
"type": "enum",
"name": "TLFVisibility",
"symbols": [
"PUBLIC_0",
"PRIVATE_1",
"ANY_2"
"ANY_0",
"PUBLIC_1",
"PRIVATE_2"
]
},
{
Expand Down
8 changes: 8 additions & 0 deletions protocol/json/chat1/local.json
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,10 @@
{
"type": "TopicType",
"name": "topicType"
},
{
"type": "TLFVisibility",
"name": "visibility"
}
]
},
Expand Down Expand Up @@ -539,6 +543,10 @@
{
"name": "limit",
"type": "int"
},
{
"name": "visibility",
"type": "TLFVisibility"
}
],
"response": "GetInboxSummaryLocalRes"
Expand Down
16 changes: 9 additions & 7 deletions shared/constants/types/flow-types-chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ export const CommonMessageType = {
}

export const CommonTLFVisibility = {
public: 0,
private: 1,
any: 2,
any: 0,
public: 1,
private: 2,
}

export const CommonTopicType = {
Expand Down Expand Up @@ -219,6 +219,7 @@ export type ConversationInfoLocal = {
tlfName: string,
topicName: string,
topicType: TopicType,
visibility: TLFVisibility,
}

export type ConversationLocal = {
Expand Down Expand Up @@ -463,9 +464,9 @@ export type SignatureInfo = {
export type TLFID = bytes

export type TLFVisibility =
0 // PUBLIC_0
| 1 // PRIVATE_1
| 2 // ANY_2
0 // ANY_0
| 1 // PUBLIC_1
| 2 // PRIVATE_2

export type ThreadID = bytes

Expand Down Expand Up @@ -495,7 +496,8 @@ export type localGetInboxSummaryLocalRpcParam = Exact<{
topicType: TopicType,
after: string,
before: string,
limit: int
limit: int,
visibility: TLFVisibility
}>

export type localGetMessagesLocalRpcParam = Exact<{
Expand Down

0 comments on commit f76d84e

Please sign in to comment.