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

use convIDs for api listen filters #19435

Merged
merged 3 commits into from Sep 10, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
49 changes: 9 additions & 40 deletions go/client/chat_api_listen_display.go
@@ -1,7 +1,6 @@
package client

import (
"fmt"
"strings"

"github.com/keybase/client/go/libkb"
Expand All @@ -15,7 +14,7 @@ type chatNotificationDisplay struct {
svc *chatServiceHandler
showLocal bool
hideExploding bool
filtersNormalized []ChatChannel
filtersNormalized []chat1.ConversationID
}

func newChatNotificationDisplay(g *libkb.GlobalContext, showLocal, hideExploding bool) *chatNotificationDisplay {
Expand All @@ -37,22 +36,12 @@ func newMsgNotification(source string) *chat1.MsgNotification {
}

func (d *chatNotificationDisplay) setupFilters(ctx context.Context, channelFilters []ChatChannel) error {
d.filtersNormalized = channelFilters
for i, v := range channelFilters {
v.MembersType = strings.ToUpper(v.MembersType)
v.TopicType = strings.ToUpper(v.TopicType)
if v.MembersType != "TEAM" {
// We are looking in inbox for conversations between users
// to normalize display name without using resolve RPC.
conv, _, err := d.svc.findConversation(ctx, "", v)
if err != nil {
return fmt.Errorf("Unable to find chat channel for %q: %s", v.Name, err.Error())
}
v.Name = conv.Info.TlfName
} else {
v.Name = strings.ToLower(v.Name)
for _, v := range channelFilters {
conv, _, err := d.svc.findConversation(ctx, "", v)
mmaxim marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return err
}
d.filtersNormalized[i] = v
d.filtersNormalized = append(d.filtersNormalized, conv.GetConvID())
}
return nil
}
Expand Down Expand Up @@ -112,33 +101,13 @@ func (d *chatNotificationDisplay) formatMessage(inMsg chat1.IncomingMessage) *ch
}
}

func matchMembersTypeToFilter(filter ChatChannel, typ chat1.ConversationMembersType) bool {
if filter.MembersType == "" {
// Default empty value matches to any non-team convo.
switch typ {
case chat1.ConversationMembersType_KBFS, chat1.ConversationMembersType_IMPTEAMNATIVE, chat1.ConversationMembersType_IMPTEAMUPGRADE:
return true
default:
return false
}
}
return filter.MembersType == typ.String()
}

func (d *chatNotificationDisplay) matchFilters(conv *chat1.InboxUIItem) bool {
func (d *chatNotificationDisplay) matchFilters(convID chat1.ConversationID) bool {
if len(d.filtersNormalized) == 0 {
// No filters - every message is relayed.
return true
}
for _, v := range d.filtersNormalized {
if matchMembersTypeToFilter(v, conv.MembersType) && v.Name == strings.ToLower(conv.Name) {
// If any of the following were specified by user and differ from
// what was received, filter the msg out.
if (v.TopicType != "" && conv.TopicType.String() != v.TopicType) ||
(v.TopicName != "" && conv.Channel != v.TopicName) {
continue
}
// It's a match.
if convID.Eq(v) {
return true
}
}
Expand All @@ -163,7 +132,7 @@ func (d *chatNotificationDisplay) NewChatActivity(ctx context.Context, arg chat1
// Skip exploding message
return nil
}
if !d.matchFilters(inMsg.Conv) {
if !d.matchFilters(inMsg.ConvID) {
// Skip filtered out message.
return nil
}
Expand Down
105 changes: 0 additions & 105 deletions go/client/chat_api_listen_display_test.go

This file was deleted.