Skip to content

Commit

Permalink
journeycard welcome gate (keybase#21305)
Browse files Browse the repository at this point in the history
* proto

* gate welcome on readerinfo

* debug

* debugging

* undebug
  • Loading branch information
mlsteele authored Dec 3, 2019
1 parent 266205f commit 820ed5e
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 13 deletions.
33 changes: 26 additions & 7 deletions go/chat/journey_card_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,17 @@ func (cc *JourneyCardManagerSingleUser) PickCard(ctx context.Context,
var convInner convForJourneycardInner
var untrustedTeamRole keybase1.TeamRole
var tlfID chat1.TLFID
var welcomeEligible bool
if convLocalOptional != nil {
convInner = convLocalOptional
tlfID = convLocalOptional.Info.Triple.Tlfid
untrustedTeamRole = convLocalOptional.ReaderInfo.UntrustedTeamRole
if convLocalOptional.ReaderInfo.Journeycard != nil {
welcomeEligible = convLocalOptional.ReaderInfo.Journeycard.WelcomeEligible
if convInner.GetTopicName() == globals.DefaultTeamTopic {
debugDebug(ctx, "welcomeEligible: convLocalOptional has ReaderInfo.Journeycard: %v", welcomeEligible)
}
}
} else {
convFromCache, err := utils.GetUnverifiedConv(ctx, cc.G(), cc.uid, convID, types.InboxSourceDataSourceLocalOnly)
if err != nil {
Expand All @@ -230,6 +237,12 @@ func (cc *JourneyCardManagerSingleUser) PickCard(ctx context.Context,
tlfID = convFromCache.Conv.Metadata.IdTriple.Tlfid
if convFromCache.Conv.ReaderInfo != nil {
untrustedTeamRole = convFromCache.Conv.ReaderInfo.UntrustedTeamRole
if convFromCache.Conv.ReaderInfo.Journeycard != nil {
welcomeEligible = convFromCache.Conv.ReaderInfo.Journeycard.WelcomeEligible
if convInner.GetTopicName() == globals.DefaultTeamTopic {
debugDebug(ctx, "welcomeEligible: convFromCache has ReaderInfo.Journeycard: %v", welcomeEligible)
}
}
}
}

Expand All @@ -239,6 +252,7 @@ func (cc *JourneyCardManagerSingleUser) PickCard(ctx context.Context,
IsGeneralChannel: convInner.GetTopicName() == globals.DefaultTeamTopic,
UntrustedTeamRole: untrustedTeamRole,
TlfID: tlfID,
WelcomeEligible: welcomeEligible,
}

if !(conv.GetTopicType() == chat1.TopicType_CHAT &&
Expand Down Expand Up @@ -340,7 +354,7 @@ func (cc *JourneyCardManagerSingleUser) PickCard(ctx context.Context,
type cardCondition func(context.Context) bool
cardConditionTODO := func(ctx context.Context) bool { return false }
cardConditions := map[chat1.JourneycardType]cardCondition{
chat1.JourneycardType_WELCOME: func(ctx context.Context) bool { return cc.cardWelcome(ctx, convID, conv, jcd) },
chat1.JourneycardType_WELCOME: func(ctx context.Context) bool { return cc.cardWelcome(ctx, convID, conv, jcd, debugDebug) },
chat1.JourneycardType_POPULAR_CHANNELS: func(ctx context.Context) bool { return cc.cardPopularChannels(ctx, convID, conv, jcd, debugDebug) },
chat1.JourneycardType_ADD_PEOPLE: func(ctx context.Context) bool { return cc.cardAddPeople(ctx, conv, jcd, debugDebug) },
chat1.JourneycardType_CREATE_CHANNELS: func(ctx context.Context) bool { return cc.cardCreateChannels(ctx, convID, jcd) },
Expand Down Expand Up @@ -379,9 +393,8 @@ func (cc *JourneyCardManagerSingleUser) PickCard(ctx context.Context,
cc.Debug(ctx, "non-latest page maxvis:%v end1:%v end2:%v", conv.MaxVisibleMsgID(), end1, end2)
}
}
if latestPage != thread.Pagination.FirstPage() {
cc.Debug(ctx, "latestPage:%v != FirstPage:%v", latestPage, thread.Pagination.FirstPage())
}
// One might expect thread.Pagination.FirstPage() to be used instead of latestPage.
// But FirstPage seems to return false often when latestPage is true.

if latestPage {
// Prefer showing new "linear" cards. Do not show cards that are prior to one that has been shown.
Expand Down Expand Up @@ -427,10 +440,15 @@ func (cc *JourneyCardManagerSingleUser) PickCard(ctx context.Context,

// Card type: WELCOME (1 on design)
// Condition: Only in #general channel
func (cc *JourneyCardManagerSingleUser) cardWelcome(ctx context.Context, convID chat1.ConversationID, conv convForJourneycard, jcd journeyCardConvData) bool {
func (cc *JourneyCardManagerSingleUser) cardWelcome(ctx context.Context, convID chat1.ConversationID, conv convForJourneycard, jcd journeyCardConvData, debugDebug logFn) bool {
// TODO PICNIC-593 Welcome's interaction with existing system message
// TODO PICNIC-593 Welcome cards should not show for all pre-existing teams when a client upgrades. That would be a bad transition. May require server support.
return conv.IsGeneralChannel && false
// Welcome cards show not show for all pre-existing teams when a client upgrades to first support journey cards. That would be a bad transition.
// The server gates whether welcome cards are allowed for a conv. After MarkAsRead-ing a conv, welcome cards are banned.
if !conv.IsGeneralChannel {
return false
}
debugDebug(ctx, "cardWelcome: welcomeEligible: %v", conv.WelcomeEligible)
return conv.IsGeneralChannel && conv.WelcomeEligible
}

// Card type: POPULAR_CHANNELS (2 on design)
Expand Down Expand Up @@ -970,4 +988,5 @@ type convForJourneycard struct {
IsGeneralChannel bool
UntrustedTeamRole keybase1.TeamRole
TlfID chat1.TLFID
WelcomeEligible bool
}
28 changes: 23 additions & 5 deletions go/protocol/chat1/common.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions go/service/debugging_devel.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,11 @@ func (t *DebuggingHandler) Script(ctx context.Context, arg keybase1.ScriptArg) (
}
err = teams.ReAddMemberAfterReset(ctx, m.G(), teamID, "ireset1")
return "", err
case "journeycard":
log("journeycard-fastforward [days]")
log("journeycard-resetall")
log("journeycard-state <conv-id>")
return "", nil
case "journeycard-fastforward":
uidGregor := gregor1.UID(m.G().ActiveDevice.UID().ToBytes())
advance := 24 * time.Hour
Expand Down
7 changes: 7 additions & 0 deletions protocol/avdl/chat1/common.avdl
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,13 @@
MessageID maxMsgid; // The max message ID in the convo
ConversationMemberStatus status; // The status of the membership to the convo
keybase1.TeamRole untrustedTeamRole; // gregor's view of your role in the team. This value is purely server trust, use with caution.
@mpackkey("jc") @jsonkey("jc")
union { null, ConversationJourneycardInfo } journeycard;
}

record ConversationJourneycardInfo {
@mpackkey("w") @jsonkey("w")
boolean welcomeEligible; // whether showing a "welcome" card is allowed
}

record ConversationCreatorInfo {
Expand Down
21 changes: 21 additions & 0 deletions protocol/json/chat1/common.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion shared/constants/types/rpc-chat-gen.tsx

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 820ed5e

Please sign in to comment.