Skip to content

Commit

Permalink
cap inbox small team size, and add a button to increase it (#21844)
Browse files Browse the repository at this point in the history
  • Loading branch information
mmaxim committed Dec 30, 2019
1 parent b0577fa commit 01897e2
Show file tree
Hide file tree
Showing 21 changed files with 218 additions and 32 deletions.
14 changes: 14 additions & 0 deletions go/chat/server.go
Expand Up @@ -175,6 +175,20 @@ func (h *Server) RequestInboxUnbox(ctx context.Context, convIDs []chat1.Conversa
return nil
}

func (h *Server) RequestInboxSmallIncrease(ctx context.Context) (err error) {
ctx = globals.ChatCtx(ctx, h.G(), keybase1.TLFIdentifyBehavior_CHAT_GUI, nil, nil)
defer h.Trace(ctx, func() error { return err }, "RequestInboxSmallIncrease")()
h.G().UIInboxLoader.UpdateLayoutFromSmallIncrease(ctx)
return nil
}

func (h *Server) RequestInboxSmallReset(ctx context.Context) (err error) {
ctx = globals.ChatCtx(ctx, h.G(), keybase1.TLFIdentifyBehavior_CHAT_GUI, nil, nil)
defer h.Trace(ctx, func() error { return err }, "RequestInboxSmallReset")()
h.G().UIInboxLoader.UpdateLayoutFromSmallReset(ctx)
return nil
}

func (h *Server) GetInboxNonblockLocal(ctx context.Context, arg chat1.GetInboxNonblockLocalArg) (res chat1.NonblockFetchRes, err error) {
var breaks []keybase1.TLFIdentifyFailure
ctx = globals.ChatCtx(ctx, h.G(), arg.IdentifyBehavior, &breaks, h.identNotifier)
Expand Down
2 changes: 2 additions & 0 deletions go/chat/types/interfaces.go
Expand Up @@ -565,6 +565,8 @@ type UIInboxLoader interface {
UpdateLayout(ctx context.Context, reselectMode chat1.InboxLayoutReselectMode, reason string)
UpdateLayoutFromNewMessage(ctx context.Context, conv RemoteConversation)
UpdateLayoutFromSubteamRename(ctx context.Context, convs []RemoteConversation)
UpdateLayoutFromSmallIncrease(ctx context.Context)
UpdateLayoutFromSmallReset(ctx context.Context)
UpdateConvs(ctx context.Context, convIDs []chat1.ConversationID) error
LoadNonblock(ctx context.Context, query *chat1.GetInboxLocalQuery, maxUnbox *int, skipUnverified bool) error
}
Expand Down
3 changes: 3 additions & 0 deletions go/chat/types/types.go
Expand Up @@ -647,6 +647,9 @@ func (d DummyUIInboxLoader) UpdateLayoutFromNewMessage(ctx context.Context, conv
func (d DummyUIInboxLoader) UpdateLayoutFromSubteamRename(ctx context.Context, convs []RemoteConversation) {
}

func (d DummyUIInboxLoader) UpdateLayoutFromSmallIncrease(ctx context.Context) {}
func (d DummyUIInboxLoader) UpdateLayoutFromSmallReset(ctx context.Context) {}

type DummyAttachmentUploader struct{}

var _ AttachmentUploader = (*DummyAttachmentUploader)(nil)
Expand Down
50 changes: 37 additions & 13 deletions go/chat/uiinboxloader.go
Expand Up @@ -31,14 +31,16 @@ type UIInboxLoader struct {
started bool
eg errgroup.Group

clock clockwork.Clock
transmitCh chan interface{}
layoutCh chan chat1.InboxLayoutReselectMode
bigTeamUnboxCh chan []chat1.ConversationID
convTransmitBatch map[string]chat1.ConversationLocal
batchDelay time.Duration
lastBatchFlush time.Time
lastLayoutFlush time.Time
clock clockwork.Clock
transmitCh chan interface{}
layoutCh chan chat1.InboxLayoutReselectMode
bigTeamUnboxCh chan []chat1.ConversationID
convTransmitBatch map[string]chat1.ConversationLocal
batchDelay time.Duration
lastBatchFlush time.Time
lastLayoutFlush time.Time
smallTeamBound int
defaultSmallTeamBound int

// layout tracking
lastLayoutMu sync.Mutex
Expand All @@ -49,12 +51,18 @@ type UIInboxLoader struct {
}

func NewUIInboxLoader(g *globals.Context) *UIInboxLoader {
defaultSmallTeamBound := 100
if g.IsMobileAppType() {
defaultSmallTeamBound = 50
}
return &UIInboxLoader{
Contextified: globals.NewContextified(g),
DebugLabeler: utils.NewDebugLabeler(g.GetLog(), "UIInboxLoader", false),
convTransmitBatch: make(map[string]chat1.ConversationLocal),
clock: clockwork.NewRealClock(),
batchDelay: 200 * time.Millisecond,
Contextified: globals.NewContextified(g),
DebugLabeler: utils.NewDebugLabeler(g.GetLog(), "UIInboxLoader", false),
convTransmitBatch: make(map[string]chat1.ConversationLocal),
clock: clockwork.NewRealClock(),
batchDelay: 200 * time.Millisecond,
smallTeamBound: defaultSmallTeamBound,
defaultSmallTeamBound: defaultSmallTeamBound,
}
}

Expand Down Expand Up @@ -469,6 +477,10 @@ func (h *UIInboxLoader) buildLayout(ctx context.Context, inbox types.Inbox,
return res.SmallTeams[i].Time.After(res.SmallTeams[j].Time)
})
res.BigTeams = btcollector.finalize(ctx)
res.TotalSmallTeams = len(res.SmallTeams)
if res.TotalSmallTeams > h.smallTeamBound {
res.SmallTeams = res.SmallTeams[:h.smallTeamBound]
}
if !selectedInLayout || reselectMode == chat1.InboxLayoutReselectMode_FORCE {
// select a new conv for the UI
var reselect chat1.UIInboxReselectInfo
Expand Down Expand Up @@ -667,3 +679,15 @@ func (h *UIInboxLoader) UpdateConvs(ctx context.Context, convIDs []chat1.Convers
}
return h.LoadNonblock(ctx, &query, nil, true)
}

func (h *UIInboxLoader) UpdateLayoutFromSmallIncrease(ctx context.Context) {
defer h.Trace(ctx, func() error { return nil }, "UpdateLayoutFromSmallIncrease")()
h.smallTeamBound += h.defaultSmallTeamBound
h.UpdateLayout(ctx, chat1.InboxLayoutReselectMode_DEFAULT, "small increase")
}

func (h *UIInboxLoader) UpdateLayoutFromSmallReset(ctx context.Context) {
defer h.Trace(ctx, func() error { return nil }, "UpdateLayoutFromSmallReset")()
h.smallTeamBound = h.defaultSmallTeamBound
h.UpdateLayout(ctx, chat1.InboxLayoutReselectMode_DEFAULT, "small reset")
}
10 changes: 6 additions & 4 deletions go/protocol/chat1/chat_ui.go

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

38 changes: 38 additions & 0 deletions go/protocol/chat1/local.go

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

1 change: 1 addition & 0 deletions protocol/avdl/chat1/chat_ui.avdl
Expand Up @@ -57,6 +57,7 @@ protocol chatUi {
}

record UIInboxLayout {
int totalSmallTeams;
array<UIInboxSmallTeamRow> smallTeams;
array<UIInboxBigTeamRow> bigTeams;
union { null, UIInboxReselectInfo } reselectInfo;
Expand Down
2 changes: 2 additions & 0 deletions protocol/avdl/chat1/local.avdl
Expand Up @@ -797,6 +797,8 @@ protocol local {
}
void requestInboxLayout(InboxLayoutReselectMode reselectMode);
void requestInboxUnbox(array<ConversationID> convIDs);
void requestInboxSmallIncrease();
void requestInboxSmallReset();
NonblockFetchRes getInboxNonblockLocal(int sessionID, union { null, int } maxUnbox, boolean skipUnverified, union { null, GetInboxLocalQuery} query, keybase1.TLFIdentifyBehavior identifyBehavior);

PostLocalRes postLocal(int sessionID, ConversationID conversationID, MessagePlaintext msg, union { null, MessageID } replyTo, keybase1.TLFIdentifyBehavior identifyBehavior);
Expand Down
2 changes: 2 additions & 0 deletions protocol/bin/enabled-calls.json
Expand Up @@ -54,6 +54,8 @@
"chat.1.local.removeBotMember": {"promise": true},
"chat.1.local.resolveMaybeMention": {"promise": true},
"chat.1.local.requestInboxLayout": {"promise": true},
"chat.1.local.requestInboxSmallIncrease": {"promise": true},
"chat.1.local.requestInboxSmallReset": {"promise": true},
"chat.1.local.requestInboxUnbox": {"promise": true},
"chat.1.local.resolveUnfurlPrompt": {"promise": true},
"chat.1.local.saveUnfurlSettings": {"promise": true},
Expand Down
4 changes: 4 additions & 0 deletions protocol/json/chat1/chat_ui.json

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

8 changes: 8 additions & 0 deletions protocol/json/chat1/local.json

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

25 changes: 25 additions & 0 deletions shared/actions/chat2-gen.tsx

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

18 changes: 18 additions & 0 deletions shared/actions/chat2/index.tsx
Expand Up @@ -102,6 +102,22 @@ const inboxRefresh = (
return actions
}

const inboxLoadMoreSmalls = async () => {
try {
await RPCChatTypes.localRequestInboxSmallIncreaseRpcPromise()
} catch (err) {
logger.info(`inboxLoadMoreSmalls: failed to increase smalls: ${err.message}`)
}
}

const inboxResetSmalls = async () => {
try {
await RPCChatTypes.localRequestInboxSmallResetRpcPromise()
} catch (err) {
logger.info(`inboxResetSmalls: failed to reset smalls: ${err.message}`)
}
}

// Only get the untrusted conversations out
const untrustedConversationIDKeys = (state: Container.TypedState, ids: Array<Types.ConversationIDKey>) =>
ids.filter(id => (state.chat2.metaMap.get(id) ?? {trustedState: 'untrusted'}).trustedState === 'untrusted')
Expand Down Expand Up @@ -3463,6 +3479,8 @@ function* chat2Saga() {
// Refresh the inbox
yield* Saga.chainAction2([Chat2Gen.inboxRefresh, EngineGen.chat1NotifyChatChatInboxStale], inboxRefresh)
yield* Saga.chainAction2([Chat2Gen.selectConversation, Chat2Gen.metasReceived], ensureSelectedTeamLoaded)
yield* Saga.chainAction(Chat2Gen.loadMoreSmalls, inboxLoadMoreSmalls)
yield* Saga.chainAction(Chat2Gen.resetSmalls, inboxResetSmalls)
// We've scrolled some new inbox rows into view, queue them up
yield* Saga.chainAction2(Chat2Gen.metaNeedsUpdating, queueMetaToRequest)
// We have some items in the queue to process
Expand Down
6 changes: 6 additions & 0 deletions shared/actions/json/chat2.json
Expand Up @@ -861,6 +861,12 @@
"username": "string",
"allowCommands": "boolean",
"allowMentions": "boolean"
},
"loadMoreSmalls": {
"_description": "Tell the service to give us more small teams"
},
"resetSmalls": {
"_description": "Tell the service to revert to default number of small teams"
}
}
}
2 changes: 2 additions & 0 deletions shared/actions/typed-actions-gen.tsx

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

0 comments on commit 01897e2

Please sign in to comment.