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

make block buttons go away on chatting #21345

Merged
merged 5 commits into from Dec 3, 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
26 changes: 26 additions & 0 deletions go/protocol/keybase1/user.go

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

34 changes: 34 additions & 0 deletions go/service/user.go
Expand Up @@ -6,6 +6,7 @@ package service
import (
"errors"
"fmt"
"github.com/keybase/client/go/protocol/gregor1"
"sort"
"strings"
"time"
Expand Down Expand Up @@ -662,6 +663,39 @@ func (h *UserHandler) SetUserBlocks(ctx context.Context, arg keybase1.SetUserBlo

}

const blockButtonsGregorPrefix = "blockButtons."

func (h *UserHandler) DismissBlockButtons(ctx context.Context, tlfID keybase1.TLFID) (err error) {
mctx := libkb.NewMetaContext(ctx, h.G())
defer mctx.TraceTimed(
fmt.Sprintf("UserHandler#DismissBlockButtons(TLF=%s)", tlfID),
func() error { return err })()

// Find the gregor item for this TLF ID's block buttons
state, err := h.G().GregorState.State(ctx)
if err != nil {
return err
}
category, err := gregor1.ObjFactory{}.MakeCategory(fmt.Sprintf("%s%s", blockButtonsGregorPrefix, tlfID.String()))
jakob223 marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return err
}
gregorItems, err := state.ItemsInCategory(category)
if err != nil {
return err
}

// Dismiss it
for _, item := range gregorItems {
err = h.G().GregorState.DismissItem(ctx, nil, item.Metadata().MsgID())
if err != nil {
return err
}
}

return nil
}

func (h *UserHandler) GetUserBlocks(ctx context.Context, arg keybase1.GetUserBlocksArg) (res []keybase1.UserBlock, err error) {
mctx := libkb.NewMetaContext(ctx, h.G())

Expand Down
2 changes: 2 additions & 0 deletions protocol/avdl/keybase1/user.avdl
Expand Up @@ -256,6 +256,8 @@ protocol user {
void reportUser(int sessionID, string username, string reason, string comment,
boolean includeTranscript, union { null, string } convID);

void dismissBlockButtons(TLFID tlfID);

// Legacy user blocking:
void blockUser(string username);
void unblockUser(string username);
Expand Down
1 change: 1 addition & 0 deletions protocol/bin/enabled-calls.json
Expand Up @@ -278,6 +278,7 @@
"keybase.1.user.unblockUser": {"promise": true},
"keybase.1.user.setUserBlocks": {"promise": true},
"keybase.1.user.getUserBlocks": {"promise": true},
"keybase.1.user.dismissBlockButtons": {"promise": true},
"keybase.1.user.reportUser": {"promise": true},
"keybase.1.user.userCard": {"promise": true},
"keybase.1.userSearch.getNonUserDetails": {"promise": true},
Expand Down
9 changes: 9 additions & 0 deletions protocol/json/keybase1/user.json

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

16 changes: 15 additions & 1 deletion shared/actions/chat2-gen.tsx

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

36 changes: 33 additions & 3 deletions shared/actions/chat2/index.tsx
Expand Up @@ -1767,6 +1767,11 @@ function* messageSend(state: TypedState, action: Chat2Gen.MessageSendPayload, lo
logger.info('error')
}

// If there are block buttons on this conversation, clear them.
if (state.chat2.blockButtonsMap.has(meta.teamID)) {
yield Saga.put(Chat2Gen.createDismissBlockButtons({teamID: meta.teamID}))
}

// Do some logging to track down the root cause of a bug causing
// messages to not send. Do this after creating the objects above to
// narrow down the places where the action can possibly stop.
Expand Down Expand Up @@ -1801,6 +1806,11 @@ const messageSendByUsernames = async (
},
action.payload.waitingKey
)

// If there are block buttons on this conversation, clear them.
if (state.chat2.blockButtonsMap.has(result.conv.info.triple.tlfid.toString('hex'))) {
return Chat2Gen.createDismissBlockButtons({teamID: result.conv.info.triple.tlfid.toString('hex')})
}
} catch (e) {
logger.warn('Could not send in messageSendByUsernames', e)
}
Expand Down Expand Up @@ -3189,19 +3199,29 @@ const gregorPushState = (state: TypedState, action: GregorGen.PushStatePayload,
const isSearchNew = !items.some(i => i.item.category === Constants.inboxSearchNewKey)
actions.push(Chat2Gen.createSetInboxShowIsNew({isNew: isSearchNew}))

// TODO: clear the block buttons in case you've followed someone or chatted them?
const blockButtons = items.some(i => i.item.category.startsWith(Constants.blockButtonsGregorPrefix))
if (blockButtons) {
if (blockButtons || state.chat2.blockButtonsMap.size > 0) {
const shouldKeepExistingBlockButtons = new Map<string, boolean>()
state.chat2.blockButtonsMap.forEach((_, teamID: string) =>
shouldKeepExistingBlockButtons.set(teamID, false)
)
items
.filter(i => i.item.category.startsWith(Constants.blockButtonsGregorPrefix))
.forEach(i => {
const teamID = i.item.category.substr(Constants.blockButtonsGregorPrefix.length)
if (!state.chat2.blockButtonsMap.get(teamID)) {
const body: {adder: string} = JSON.parse(i.item.body.toString())
const adder = body.adder
actions.push(Chat2Gen.createUpdateBlockButtons({adder, teamID}))
actions.push(Chat2Gen.createUpdateBlockButtons({adder, show: true, teamID}))
} else {
shouldKeepExistingBlockButtons.set(teamID, true)
}
})
shouldKeepExistingBlockButtons.forEach((keep, teamID) => {
if (!keep) {
actions.push(Chat2Gen.createUpdateBlockButtons({show: false, teamID}))
}
})
}
return actions
}
Expand Down Expand Up @@ -3274,6 +3294,14 @@ const onMarkInboxSearchOld = (state: TypedState) =>
state.chat2.inboxShowNew &&
GregorGen.createUpdateCategory({body: 'true', category: Constants.inboxSearchNewKey})

const dismissBlockButtons = async (_: TypedState, action: Chat2Gen.DismissBlockButtonsPayload) => {
try {
await RPCTypes.userDismissBlockButtonsRpcPromise({tlfID: action.payload.teamID})
} catch (err) {
logger.error(`Couldn't dismiss block buttons: ${err.message}`)
}
}

const createConversationFromTeamBuilder = (
state: TypedState,
{payload: {namespace}}: TeamBuildingGen.FinishedTeamBuildingPayload
Expand Down Expand Up @@ -3692,6 +3720,8 @@ function* chat2Saga() {
yield* Saga.chainAction2(Chat2Gen.setInboxNumSmallRows, setInboxNumSmallRows)
yield* Saga.chainAction2(ConfigGen.bootstrapStatusLoaded, getInboxNumSmallRows)

yield* Saga.chainAction2(Chat2Gen.dismissBlockButtons, dismissBlockButtons)

yield* chatTeamBuildingSaga()
yield* Saga.chainAction2(EngineGen.chat1NotifyChatChatConvUpdate, onChatConvUpdate, 'onChatConvUpdate')
}
Expand Down
6 changes: 5 additions & 1 deletion shared/actions/json/chat2.json
Expand Up @@ -778,7 +778,11 @@
"updateBlockButtons": {
"_description": "Show or hide invitation to block for a given team ID",
"teamID": "RPCTypes.TeamID",
"adder": "string"
"adder?": "string",
"show": "boolean"
},
"dismissBlockButtons": {
"teamID": "RPCTypes.TeamID"
},
"setInboxNumSmallRows": {
"ignoreWrite?": "boolean",
Expand Down
1 change: 1 addition & 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.

2 changes: 1 addition & 1 deletion shared/chat/blocking/invitation-to-block.tsx
Expand Up @@ -33,7 +33,7 @@ const BlockButtons = (props: Props) => {
{team ? `${adder} added you to this team.` : `You don't seem to know ${adder}.`}
</Kb.Text>
{!team && <WaveButton usernames={[adder, ...(others || [])].join(',')} style={styles.button} />}
{!team && !others && (
{!team && others.length === 0 && (
<Kb.Button
label="View Profile"
style={styles.button}
Expand Down
5 changes: 5 additions & 0 deletions shared/constants/types/rpc-gen.tsx

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

6 changes: 5 additions & 1 deletion shared/reducers/chat2.tsx
Expand Up @@ -1029,7 +1029,11 @@ const reducer = Container.makeReducer<Actions, Types.State>(initialState, {
}
},
[Chat2Gen.updateBlockButtons]: (draftState, action) => {
draftState.blockButtonsMap.set(action.payload.teamID, {adder: action.payload.adder})
if (action.payload.show) {
draftState.blockButtonsMap.set(action.payload.teamID, {adder: action.payload.adder || ''})
} else {
draftState.blockButtonsMap.delete(action.payload.teamID)
}
},
[Chat2Gen.updateReactions]: (draftState, action) => {
const {conversationIDKey, updates} = action.payload
Expand Down