Skip to content

Commit 801c42a

Browse files
authored
feat: Team mention (#6755)
1 parent 8942057 commit 801c42a

File tree

7 files changed

+185
-90
lines changed

7 files changed

+185
-90
lines changed

app/containers/markdown/Markdown.stories.tsx

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -69,29 +69,19 @@ export const Preview = () => (
6969
</View>
7070
);
7171

72+
const msgMentions = '@rocket.cat @name1 @all @here @unknown @team';
73+
const mentions = [
74+
{ _id: 'random', name: 'Rocket Cat', username: 'rocket.cat', type: 'user' },
75+
{ _id: 'random2', name: 'Name', username: 'name1', type: 'user' },
76+
{ _id: 'here', username: 'here', type: 'user' },
77+
{ _id: 'all', username: 'all', type: 'user' },
78+
{ _id: 'team', name: 'team', type: 'team' }
79+
];
80+
7281
export const Mentions = () => (
7382
<ScrollView style={styles.container}>
74-
<Markdown
75-
msg='@rocket.cat @name1 @all @here @unknown'
76-
mentions={[
77-
{ _id: 'random', name: 'Rocket Cat', username: 'rocket.cat' },
78-
{ _id: 'random2', name: 'Name', username: 'name1' },
79-
{ _id: 'here', username: 'here' },
80-
{ _id: 'all', username: 'all' }
81-
]}
82-
username='rocket.cat'
83-
/>
84-
<Markdown
85-
msg='@rocket.cat @name1 @all @here @unknown'
86-
mentions={[
87-
{ _id: 'random', name: 'Rocket Cat', username: 'rocket.cat' },
88-
{ _id: 'random2', name: 'Name', username: 'name1' },
89-
{ _id: 'here', username: 'here' },
90-
{ _id: 'all', username: 'all' }
91-
]}
92-
username='rocket.cat'
93-
useRealName
94-
/>
83+
<Markdown msg={msgMentions} mentions={mentions} username='rocket.cat' />
84+
<Markdown msg={msgMentions} mentions={mentions} username='rocket.cat' useRealName />
9585
</ScrollView>
9686
);
9787

app/containers/markdown/__snapshots__/Markdown.test.tsx.snap

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2999,6 +2999,41 @@ exports[`Story Snapshots: Mentions should match snapshot 1`] = `
29992999
>
30003000
@unknown
30013001
</Text>
3002+
<Text
3003+
accessibilityLabel=" "
3004+
style={
3005+
[
3006+
{
3007+
"flexShrink": 1,
3008+
"fontSize": 16,
3009+
"lineHeight": 22,
3010+
},
3011+
{
3012+
"color": "#2F343D",
3013+
},
3014+
]
3015+
}
3016+
>
3017+
3018+
</Text>
3019+
<Text
3020+
style={
3021+
[
3022+
{
3023+
"backgroundColor": "transparent",
3024+
"fontFamily": "Inter",
3025+
"fontSize": 16,
3026+
"fontWeight": "600",
3027+
"textAlign": "left",
3028+
},
3029+
{
3030+
"color": "#8E6300",
3031+
},
3032+
]
3033+
}
3034+
>
3035+
team
3036+
</Text>
30023037
</Text>
30033038
</Text>
30043039
</View>
@@ -3198,6 +3233,41 @@ exports[`Story Snapshots: Mentions should match snapshot 1`] = `
31983233
>
31993234
@unknown
32003235
</Text>
3236+
<Text
3237+
accessibilityLabel=" "
3238+
style={
3239+
[
3240+
{
3241+
"flexShrink": 1,
3242+
"fontSize": 16,
3243+
"lineHeight": 22,
3244+
},
3245+
{
3246+
"color": "#2F343D",
3247+
},
3248+
]
3249+
}
3250+
>
3251+
3252+
</Text>
3253+
<Text
3254+
style={
3255+
[
3256+
{
3257+
"backgroundColor": "transparent",
3258+
"fontFamily": "Inter",
3259+
"fontSize": 16,
3260+
"fontWeight": "600",
3261+
"textAlign": "left",
3262+
},
3263+
{
3264+
"color": "#8E6300",
3265+
},
3266+
]
3267+
}
3268+
>
3269+
team
3270+
</Text>
32013271
</Text>
32023272
</Text>
32033273
</View>

app/containers/markdown/components/mentions/AtMention.tsx

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,25 +50,33 @@ const AtMention = React.memo(({ mention, mentions, username, navToRoomInfo, styl
5050
};
5151
}
5252

53-
const user = mentions?.find?.((m: any) => m && m.username === mention);
53+
const atMentioned = mentions?.find?.((m: any) => m && (m.username === mention || m.name === mention));
5454

5555
const handlePress = () => {
5656
logEvent(events.ROOM_MENTION_GO_USER_INFO);
5757
const navParam = {
5858
t: 'd',
59-
rid: user && user._id,
59+
rid: atMentioned && atMentioned._id,
6060
itsMe
6161
};
6262
if (navToRoomInfo) {
6363
navToRoomInfo(navParam);
6464
}
6565
};
6666

67-
if (user) {
67+
if (atMentioned) {
68+
let text;
69+
if (atMentioned.type === 'user') {
70+
text = useRealName && atMentioned.name ? atMentioned.name : atMentioned.username;
71+
} else {
72+
text = atMentioned.name;
73+
}
74+
6875
return (
69-
<Text style={[styles.mention, mentionStyle, ...style]} onPress={handlePress}>
76+
// not enough information on mentions to navigate to team info, so we don't handle onPress
77+
<Text style={[styles.mention, mentionStyle, ...style]} onPress={atMentioned?.type === 'team' ? undefined : handlePress}>
7078
{preffix}
71-
{useRealName && user.name ? user.name : user.username}
79+
{text}
7280
</Text>
7381
);
7482
}

app/containers/message/Message.stories.tsx

Lines changed: 15 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -389,24 +389,20 @@ export const FullNameLargeFont = () => (
389389
/>
390390
);
391391

392+
const msgMentions = '@rocket.cat @diego.mello @all @here #general @team';
393+
const mentions = [
394+
{ _id: 'random', name: 'Rocket Cat', username: 'rocket.cat', type: 'user' },
395+
{ _id: 'random2', name: 'Diego Mello', username: 'diego.mello', type: 'user' },
396+
{ _id: 'here', username: 'here', type: 'user' },
397+
{ _id: 'all', username: 'all', type: 'user' },
398+
{ _id: 'team', name: 'team', type: 'team' }
399+
];
400+
392401
export const Mentions = () => (
393402
<>
394403
<Message
395-
msg='@rocket.cat @diego.mello @all @here #general'
396-
mentions={[
397-
{
398-
username: 'rocket.cat'
399-
},
400-
{
401-
username: 'diego.mello'
402-
},
403-
{
404-
username: 'all'
405-
},
406-
{
407-
username: 'here'
408-
}
409-
]}
404+
msg={msgMentions}
405+
mentions={mentions}
410406
channels={[
411407
{
412408
name: 'general'
@@ -415,20 +411,7 @@ export const Mentions = () => (
415411
/>
416412
<Message
417413
msg='@rocket.cat Lorem ipsum dolor @diego.mello sit amet, @all consectetur adipiscing @here elit, sed do eiusmod tempor #general incididunt ut labore et dolore magna aliqua.'
418-
mentions={[
419-
{
420-
username: 'rocket.cat'
421-
},
422-
{
423-
username: 'diego.mello'
424-
},
425-
{
426-
username: 'all'
427-
},
428-
{
429-
username: 'here'
430-
}
431-
]}
414+
mentions={mentions}
432415
channels={[
433416
{
434417
name: 'general'
@@ -441,21 +424,8 @@ export const Mentions = () => (
441424
export const MentionsLargeFont = () => (
442425
<>
443426
<MessageLargeFont
444-
msg='@rocket.cat @diego.mello @all @here #general'
445-
mentions={[
446-
{
447-
username: 'rocket.cat'
448-
},
449-
{
450-
username: 'diego.mello'
451-
},
452-
{
453-
username: 'all'
454-
},
455-
{
456-
username: 'here'
457-
}
458-
]}
427+
msg={msgMentions}
428+
mentions={mentions}
459429
channels={[
460430
{
461431
name: 'general'
@@ -464,20 +434,7 @@ export const MentionsLargeFont = () => (
464434
/>
465435
<MessageLargeFont
466436
msg='@rocket.cat Lorem ipsum dolor @diego.mello sit amet, @all consectetur adipiscing @here elit, sed do eiusmod tempor #general incididunt ut labore et dolore magna aliqua.'
467-
mentions={[
468-
{
469-
username: 'rocket.cat'
470-
},
471-
{
472-
username: 'diego.mello'
473-
},
474-
{
475-
username: 'all'
476-
},
477-
{
478-
username: 'here'
479-
}
480-
]}
437+
mentions={mentions}
481438
channels={[
482439
{
483440
name: 'general'

app/containers/message/__snapshots__/Message.test.tsx.snap

Lines changed: 74 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58706,7 +58706,7 @@ exports[`Story Snapshots: Mentions should match snapshot 1`] = `
5870658706
}
5870758707
>
5870858708
<View
58709-
accessibilityLabel="diego.mello 10:00:00 AM rocket.cat diego.mello all here general. "
58709+
accessibilityLabel="diego.mello 10:00:00 AM rocket.cat diego.mello all here general @team. "
5871058710
accessible={true}
5871158711
style={
5871258712
{
@@ -58948,7 +58948,7 @@ exports[`Story Snapshots: Mentions should match snapshot 1`] = `
5894858948
}
5894958949
>
5895058950
<View
58951-
testID="[email protected] @diego.mello @all @here #general"
58951+
testID="[email protected] @diego.mello @all @here #general @team"
5895258952
>
5895358953
<View
5895458954
style={
@@ -59146,6 +59146,41 @@ exports[`Story Snapshots: Mentions should match snapshot 1`] = `
5914659146
>
5914759147
general
5914859148
</Text>
59149+
<Text
59150+
accessibilityLabel=" "
59151+
style={
59152+
[
59153+
{
59154+
"flexShrink": 1,
59155+
"fontSize": 16,
59156+
"lineHeight": 22,
59157+
},
59158+
{
59159+
"color": "#2F343D",
59160+
},
59161+
]
59162+
}
59163+
>
59164+
59165+
</Text>
59166+
<Text
59167+
style={
59168+
[
59169+
{
59170+
"backgroundColor": "transparent",
59171+
"fontFamily": "Inter",
59172+
"fontSize": 16,
59173+
"fontWeight": "600",
59174+
"textAlign": "left",
59175+
},
59176+
{
59177+
"color": "#8E6300",
59178+
},
59179+
]
59180+
}
59181+
>
59182+
team
59183+
</Text>
5914959184
</Text>
5915059185
</Text>
5915159186
</View>
@@ -59708,7 +59743,7 @@ exports[`Story Snapshots: MentionsLargeFont should match snapshot 1`] = `
5970859743
}
5970959744
>
5971059745
<View
59711-
accessibilityLabel="diego.mello 10:00:00 AM rocket.cat diego.mello all here general. "
59746+
accessibilityLabel="diego.mello 10:00:00 AM rocket.cat diego.mello all here general @team. "
5971259747
accessible={true}
5971359748
style={
5971459749
{
@@ -59950,7 +59985,7 @@ exports[`Story Snapshots: MentionsLargeFont should match snapshot 1`] = `
5995059985
}
5995159986
>
5995259987
<View
59953-
testID="[email protected] @diego.mello @all @here #general"
59988+
testID="[email protected] @diego.mello @all @here #general @team"
5995459989
>
5995559990
<View
5995659991
style={
@@ -60148,6 +60183,41 @@ exports[`Story Snapshots: MentionsLargeFont should match snapshot 1`] = `
6014860183
>
6014960184
general
6015060185
</Text>
60186+
<Text
60187+
accessibilityLabel=" "
60188+
style={
60189+
[
60190+
{
60191+
"flexShrink": 1,
60192+
"fontSize": 16,
60193+
"lineHeight": 22,
60194+
},
60195+
{
60196+
"color": "#2F343D",
60197+
},
60198+
]
60199+
}
60200+
>
60201+
60202+
</Text>
60203+
<Text
60204+
style={
60205+
[
60206+
{
60207+
"backgroundColor": "transparent",
60208+
"fontFamily": "Inter",
60209+
"fontSize": 16,
60210+
"fontWeight": "600",
60211+
"textAlign": "left",
60212+
},
60213+
{
60214+
"color": "#8E6300",
60215+
},
60216+
]
60217+
}
60218+
>
60219+
team
60220+
</Text>
6015160221
</Text>
6015260222
</Text>
6015360223
</View>

app/lib/methods/search.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ export const search = async ({ text = '', filterUsers = true, filterRooms = true
137137
try {
138138
if (searchText && localSearchData.length < 7) {
139139
const { users, rooms } = (await Promise.race([
140-
spotlight(searchText, usernames, { users: filterUsers, rooms: filterRooms }, rid),
140+
spotlight(searchText, usernames, { users: filterUsers, rooms: filterRooms, mentions: true }, rid),
141141
new Promise((resolve, reject) => (debounce = reject))
142142
])) as { users: ISearch[]; rooms: ISearch[] };
143143

0 commit comments

Comments
 (0)