Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions src/analytics/metrics/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -586,9 +586,80 @@ export type Events = {
| 'SendViaChatDialog'
| 'ConvoSettings'
}

// Group chat adoption
'groupchat:create': {
logContext: 'NewChatDialog'
}
'groupchat:landingPage:view': {
hasSession: boolean
}
'groupchat:inviteLink:redeem': {
isNewAccount: boolean
}

// Group chat user interactions
'groupchat:message:send': {
convoId: string
isOwner: boolean
}
'groupchat:mute': {
convoId: string
}
'groupchat:unmute': {
convoId: string
}
'groupchat:leave': {
convoId: string
isOwner: boolean
}
'groupchat:settings:view': {
convoId: string
isOwner: boolean
}
'groupchat:inviteLink:shareButton:press': {
convoId: string
method: 'post' | 'copy' | 'native'
}
'groupchat:inviteLink:shared': {
convoId: string
method: 'post' | 'dm'
}

// Group chat owner actions
'groupchat:owner:editName': {
convoId: string
}
'groupchat:owner:lock': {
convoId: string
}
'groupchat:owner:unlock': {
convoId: string
}
'groupchat:owner:kickMember': {
convoId: string
}
'groupchat:owner:inviteMember': {
convoId: string
}
'groupchat:owner:joinRequest:accept': {
convoId: string
}
'groupchat:owner:joinRequest:reject': {
convoId: string
}
'groupchat:owner:inviteLink:create': {
convoId: string
}
'groupchat:owner:inviteLink:disable': {
convoId: string
}

// Group chat problems
'groupchat:join:memberLimitReached': {
convoId: string
}

'starterPack:addUser': {
starterPack?: string
}
Expand Down
26 changes: 25 additions & 1 deletion src/components/intents/GroupChatJoinDialog.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {useEffect} from 'react'
import {View} from 'react-native'
import {
ChatBskyGroupDefs,
Expand All @@ -10,6 +11,7 @@ import {useNavigation} from '@react-navigation/native'
import {useQueryClient} from '@tanstack/react-query'

import {createSanitizedDisplayName} from '#/lib/moderation/create-sanitized-display-name'
import {useCallOnce} from '#/lib/once'
import {makeProfileLink} from '#/lib/routes/links'
import {type NavigationProp} from '#/lib/routes/types'
import {isNetworkError} from '#/lib/strings/errors'
Expand Down Expand Up @@ -45,6 +47,7 @@ import {InlineLinkText} from '#/components/Link'
import {Loader} from '#/components/Loader'
import * as Toast from '#/components/Toast'
import {Text} from '#/components/Typography'
import {useAnalytics} from '#/analytics'
import {ProfileBadges} from '../ProfileBadges'

export function GroupChatJoinDialog() {
Expand Down Expand Up @@ -78,11 +81,21 @@ function GroupChatJoinDialogInner({code}: {code?: string}) {
function GroupChatJoinDialogContent({code}: {code?: string}) {
const t = useTheme()
const {t: l} = useLingui()
const {groupChatJoinDialogControl: control} = useIntentDialogs()
const {groupChatJoinDialogControl: control, groupChatJoinState} =
useIntentDialogs()
const isNewAccount = groupChatJoinState?.createdAccount ?? false
const {hasSession} = useSession()
const moderationOpts = useModerationOpts()
const navigation = useNavigation<NavigationProp>()
const queryClient = useQueryClient()
const ax = useAnalytics()

const logViewOnce = useCallOnce()
useEffect(() => {
logViewOnce(() => {
ax.metric('groupchat:landingPage:view', {hasSession})
})
}, [ax, hasSession, logViewOnce])
Comment thread
ds-boyce marked this conversation as resolved.
Resolved

const {data, error, isLoading} = useJoinLinkPreviewsQuery({
codes: code ? [code] : undefined,
Expand All @@ -96,6 +109,7 @@ function GroupChatJoinDialogContent({code}: {code?: string}) {
if (code) void invalidateJoinLinkPreviewsForCode(queryClient, code)
switch (data.status) {
case 'pending':
ax.metric('groupchat:inviteLink:redeem', {isNewAccount})
control.close(() => {
Toast.show(
l`Access requested! The group owner will review your request.`,
Expand All @@ -104,6 +118,7 @@ function GroupChatJoinDialogContent({code}: {code?: string}) {
break
case 'joined': {
if (data.convo && data.convo.id) {
ax.metric('groupchat:inviteLink:redeem', {isNewAccount})
control.close(() => {
Toast.show(l`Successfully joined the group chat!`)
navigation.navigate('MessagesConversation', {
Expand Down Expand Up @@ -140,6 +155,15 @@ function GroupChatJoinDialogContent({code}: {code?: string}) {
error instanceof ChatBskyGroupRequestJoin.MemberLimitReachedError
) {
errorMessage = l`The member limit has been reached.`
const preview = data?.joinLinkPreviews[0]
if (
ChatBskyGroupDefs.isJoinLinkPreviewView(preview) &&
preview.convo?.id
) {
ax.metric('groupchat:join:memberLimitReached', {
convoId: preview.convo.id,
})
}
} else if (error instanceof ChatBskyGroupRequestJoin.UserKickedError) {
errorMessage = l`You have been previously removed from this group and can’t join it using this link.`
}
Expand Down
11 changes: 7 additions & 4 deletions src/components/intents/IntentDialogs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ interface Context {
verifyEmailState: {code: string} | undefined
setVerifyEmailState: (state: {code: string} | undefined) => void
groupChatJoinDialogControl: DialogControlProps
groupChatJoinState: {code: string} | undefined
setGroupChatJoinState: (state: {code: string} | undefined) => void
groupChatJoinState: {code: string; createdAccount?: boolean} | undefined
setGroupChatJoinState: (
state: {code: string; createdAccount?: boolean} | undefined,
) => void
}

const Context = createContext({} as Context)
Expand All @@ -38,7 +40,7 @@ export function Provider({children}: {children: React.ReactNode}) {
>()
const groupChatJoinDialogControl = Dialog.useDialogControl()
const [groupChatJoinState, setGroupChatJoinState] = useState<
{code: string} | undefined
{code: string; createdAccount?: boolean} | undefined
>()

const {hasSession} = useSession()
Expand All @@ -51,6 +53,7 @@ export function Provider({children}: {children: React.ReactNode}) {
if (hasSession && groupChatLanding && !landingHandledRef.current) {
landingHandledRef.current = true
const code = groupChatLanding.code
const createdAccount = groupChatLanding.createdAccount
setActiveLanding(undefined)
const prefetch = prefetchJoinLinkPreviews({
codes: [code],
Expand All @@ -60,7 +63,7 @@ export function Provider({children}: {children: React.ReactNode}) {
prefetch,
new Promise(res => setTimeout(res, 200)),
]).finally(() => {
setGroupChatJoinState({code})
setGroupChatJoinState({code, createdAccount})
groupChatJoinDialogControl.open()
})
}
Expand Down
3 changes: 3 additions & 0 deletions src/screens/Messages/ConversationSettings/AddMembersLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {PlusLarge_Stroke2_Corner0_Rounded as PlusIcon} from '#/components/icons/
import {Loader} from '#/components/Loader'
import * as Toast from '#/components/Toast'
import {Text} from '#/components/Typography'
import {useAnalytics} from '#/analytics'

export function AddMembersLink({
convo,
Expand All @@ -25,6 +26,7 @@ export function AddMembersLink({
}) {
const t = useTheme()
const {t: l} = useLingui()
const ax = useAnalytics()

const addMembersControl = Dialog.useDialogControl()

Expand All @@ -33,6 +35,7 @@ export function AddMembersLink({
convoId,
{
onSuccess: data => {
ax.metric('groupchat:owner:inviteMember', {convoId})
addMembersControl.close(() => {
const members = data.addedMembers ?? []

Expand Down
3 changes: 3 additions & 0 deletions src/screens/Messages/ConversationSettings/MemberMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ export function MemberMenu({
})
const convoId = convo.view.id
const {mutate: removeMembers} = useRemoveFromGroupChat(convoId, {
onSuccess: () => {
ax.metric('groupchat:owner:kickMember', {convoId})
},
onError: e => {
logger.error('Failed to remove group chat member', {message: e})
Toast.show(l`Failed to remove group chat member`, {type: 'error'})
Expand Down
50 changes: 32 additions & 18 deletions src/screens/Messages/ConversationSettings/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {useState} from 'react'
import {useEffect, useState} from 'react'
import {Pressable, View} from 'react-native'
import {
ChatBskyActorDefs,
Expand All @@ -12,6 +12,7 @@ import {HITSLOP_10} from '#/lib/constants'
import {useBottomBarOffset} from '#/lib/hooks/useBottomBarOffset'
import {useInitialNumToRender} from '#/lib/hooks/useInitialNumToRender'
import {isBlockedOrBlocking} from '#/lib/moderation/blocked-and-muted'
import {useCallOnce} from '#/lib/once'
import {
type CommonNavigatorParams,
type NativeStackScreenProps,
Expand Down Expand Up @@ -55,6 +56,7 @@ import {Loader} from '#/components/Loader'
import * as Prompt from '#/components/Prompt'
import * as Toast from '#/components/Toast'
import {Text} from '#/components/Typography'
import {useAnalytics} from '#/analytics'
import {IS_WEB} from '#/env'
import * as bsky from '#/types/bsky'
import {InviteLinkDialog} from '../components/InviteLinkDialog'
Expand Down Expand Up @@ -344,9 +346,12 @@ function SettingsHeader({
}) {
const t = useTheme()
const {i18n, t: l} = useLingui()
const ax = useAnalytics()

const navigation = useNavigation<NavigationProp>()

const convoId = convo.view.id

const groupName = convo.details.name
const [newGroupName, setNewGroupName] = useState(groupName)

Expand All @@ -357,9 +362,17 @@ function SettingsHeader({

const reportSubjectDid = convo.primaryMember?.did

const logViewOnce = useCallOnce()
useEffect(() => {
logViewOnce(() => {
ax.metric('groupchat:settings:view', {convoId, isOwner})
})
}, [ax, convoId, isOwner, logViewOnce])

const {mutate: editGroupName, isPending: isEditingName} =
useEditGroupChatName(convo.view.id, {
useEditGroupChatName(convoId, {
onSuccess: () => {
ax.metric('groupchat:owner:editName', {convoId})
Toast.show(l({message: 'Group chat name updated', context: 'toast'}))
},
onError: e => {
Expand All @@ -369,11 +382,13 @@ function SettingsHeader({
},
})

const {mutate: muteConvo, isPending: isMuting} = useMuteConvo(convo.view.id, {
const {mutate: muteConvo, isPending: isMuting} = useMuteConvo(convoId, {
onSuccess: data => {
if (data.convo.muted) {
ax.metric('groupchat:mute', {convoId})
Toast.show(l({message: 'Group chat muted', context: 'toast'}))
} else {
ax.metric('groupchat:unmute', {convoId})
Toast.show(l({message: 'Group chat unmuted', context: 'toast'}))
}
},
Expand All @@ -383,33 +398,32 @@ function SettingsHeader({
},
})

const {mutate: leaveConvo, isPending: isLeaving} = useLeaveConvo(
convo.view.id,
{
onSuccess: () => {
navigation.replace('Messages', {animation: 'pop'})
},
onError: e => {
logger.error('Failed to leave group chat', {message: e})
Toast.show(
l({message: 'Failed to leave group chat', context: 'toast'}),
{type: 'error'},
)
},
const {mutate: leaveConvo, isPending: isLeaving} = useLeaveConvo(convoId, {
onSuccess: () => {
ax.metric('groupchat:leave', {convoId, isOwner})
navigation.replace('Messages', {animation: 'pop'})
},
)
onError: e => {
logger.error('Failed to leave group chat', {message: e})
Toast.show(l({message: 'Failed to leave group chat', context: 'toast'}), {
type: 'error',
})
},
})

const {
mutate: lockConvo,
mutateAsync: lockConvoAsync,
isPending: isLocking,
} = useLockConvo(convo.view.id, {
} = useLockConvo(convoId, {
onSuccess: (data, {silent}) => {
if (!ChatBskyConvoDefs.isGroupConvo(data.convo.kind)) return
if (silent) return
if (data.convo.kind.lockStatus === 'locked') {
ax.metric('groupchat:owner:lock', {convoId})
Toast.show(l({message: 'Group chat locked', context: 'toast'}))
} else {
ax.metric('groupchat:owner:unlock', {convoId})
Toast.show(l({message: 'Group chat unlocked', context: 'toast'}))
}
},
Expand Down
Loading
Loading