Skip to content

Commit 09e7131

Browse files
committed
fix: в превью сообщений не выделялись ссылки и хештеги
1 parent 76a9498 commit 09e7131

File tree

7 files changed

+32
-41
lines changed

7 files changed

+32
-41
lines changed

Diff for: src/components/SnackbarsWrapper.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
/>
1313

1414
<div>
15-
<VKText mention="attachment">{{ snackbar.text }}</VKText>
15+
<VKText preview>{{ snackbar.text }}</VKText>
1616
</div>
1717

1818
<Icon

Diff for: src/components/UI/VKText.vue

+26-35
Original file line numberDiff line numberDiff line change
@@ -8,39 +8,32 @@ import domains from 'js/json/domains.json';
88
99
export default {
1010
props: {
11-
// Заменять ли <br> на пробел, чтобы получить однострочный текст
12-
inline: {
13-
type: Boolean,
14-
default: true
15-
},
16-
// Парсить ли ссылки и хештеги
11+
// true - оставляет переносы строк, false (по умолчанию) - удаляет переносы строк
12+
multiline: Boolean,
13+
// Парсит ссылки и хештеги
1714
link: Boolean,
18-
// text - преобразовать упоминание в нормальный вид ([id|text] -> text)
19-
// attachment - выделить упоминание синим цветом
20-
// link - выделить синим цветом и сделать кликабельным
21-
mention: String
15+
// Парсит упоминания
16+
mention: Boolean,
17+
// Выделяет ссылки, хештеги и упоминания синим цветом, но не делает их кликабельными
18+
preview: Boolean
2219
},
2320
2421
setup(props, { slots }) {
2522
const text = computed(() => slots.default()[0].children);
2623
2724
function parseBlock(block) {
2825
if (block.type === 'mention') {
29-
if (!props.mention) {
26+
if (!props.mention && !props.preview) {
3027
return [block.raw];
3128
}
3229
3330
const mentionContent = block.value.reduce((blocks, mentionTextBlock) => (
3431
[...blocks, ...parseBlock(mentionTextBlock)]
3532
), []);
3633
37-
if (props.mention === 'text') {
38-
return mentionContent;
39-
}
40-
4134
let attrs;
4235
43-
if (props.mention === 'link') {
36+
if (props.mention) {
4437
attrs = {
4538
class: 'link',
4639
onClick() {
@@ -49,7 +42,7 @@ export default {
4942
}
5043
};
5144
} else {
52-
attrs = { class: 'mention_attachment' };
45+
attrs = { class: 'message_preview' };
5346
}
5447
5548
return [h('div', attrs, mentionContent)];
@@ -60,29 +53,27 @@ export default {
6053
}
6154
6255
if (block.type === 'br') {
63-
return [props.inline ? ' ' : h('br')];
56+
return [props.multiline ? h('br') : ' '];
6457
}
6558
66-
if (block.type === 'link' && props.link) {
67-
return [
68-
h('div', {
69-
class: 'link',
70-
onClick: () => internalLinkResolver(block.link)
71-
}, [block.value])
72-
];
59+
if (block.type === 'link' && (props.link || props.preview)) {
60+
const params = props.link
61+
? { class: 'link', onClick: () => internalLinkResolver(block.link) }
62+
: { class: 'message_preview' };
63+
64+
return [h('div', params, [block.value])];
7365
}
7466
75-
if (block.type === 'hashtag' && props.link) {
76-
return [
77-
h('div', {
78-
class: 'link'
79-
// onClick() {}
80-
}, [block.value])
81-
];
67+
if (block.type === 'hashtag' && (props.link || props.preview)) {
68+
const params = props.link
69+
? { class: 'link' }
70+
: { class: 'message_preview' };
71+
72+
return [h('div', params, [block.value])];
8273
}
8374
84-
if (block.type === 'massMention' && props.mention && props.mention !== 'text') {
85-
return [h('div', { class: 'mention_attachment' }, block.value)];
75+
if (block.type === 'massMention' && (props.mention || props.preview)) {
76+
return [h('div', { class: 'message_preview' }, block.value)];
8677
}
8778
8879
return [block.value];
@@ -194,7 +185,7 @@ const mentionParser = createParser({
194185
</script>
195186

196187
<style>
197-
.mention_attachment {
188+
.message_preview {
198189
display: inline;
199190
color: var(--text-blue);
200191
}

Diff for: src/components/messages/MessagesPeer.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
:author="author"
5555
:peer_id="peer.id"
5656
/>
57-
<VKText v-else mention="attachment">{{ message }}</VKText>
57+
<VKText v-else preview>{{ message }}</VKText>
5858
</div>
5959
</div>
6060

Diff for: src/components/messages/chat/Message.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
{{ l(msg.isExpired ? 'is_message_expired' : 'im_attachment_deleted') }}
4545
</div>
4646
<div v-else class="message_text">
47-
<VKText :inline="false" link mention="link">{{ msg.text }}</VKText>
47+
<VKText multiline mention link>{{ msg.text }}</VKText>
4848
</div>
4949

5050
<Attachments :attachments="msg.attachments" />

Diff for: src/components/messages/chat/PinnedMessage.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<div class="im_pinned_msg_time">{{ time }}</div>
99
</div>
1010
<div :class="['im_pinned_msg_text text-overflow', { hasAttachment }]">
11-
<VKText mention="attachment">{{ text }}</VKText>
11+
<VKText preview>{{ text }}</VKText>
1212
</div>
1313
</div>
1414

Diff for: src/components/messages/chat/attachments/ForwardedMessage.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
</div>
2121
<div v-else class="attach_fwd_msg_text">
2222
<ShortText>
23-
<VKText :inline="false" mention="link" link>{{ msg.text }}</VKText>
23+
<VKText multiline mention link>{{ msg.text }}</VKText>
2424
</ShortText>
2525
</div>
2626

Diff for: src/components/messages/chat/attachments/Reply.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
{{ l(msg.isExpired ? 'is_message_expired' : 'im_attachment_deleted') }}
1717
</div>
1818
<div v-else :class="['attach_reply_text', { hasAttachment: msg.hasAttachment && !msg.text }]">
19-
<VKText mention="attachment">{{ text }}</VKText>
19+
<VKText preview>{{ text }}</VKText>
2020
</div>
2121
</div>
2222
</div>

0 commit comments

Comments
 (0)