highlight hashtags in messages

This commit is contained in:
Martti Malmi 2021-08-18 12:59:13 +03:00
parent 03720cd37f
commit 3af855ad7e
6 changed files with 16 additions and 4 deletions

View File

@ -25,6 +25,7 @@
"rules": {
"react/no-did-mount-set-state": "off",
"react/no-did-update-set-state": "off",
"no-useless-escape": "off",
"radix": "off"
}
}

View File

@ -1852,6 +1852,10 @@ export default {
return s.match(emojiRegex);
},
highlightHashtags(s) {
return s.replace(/\B\#\w\w+\b/g, match => `<a href="/hashtag/${match.replace('#', '')}">${match}</a>`);
},
highlightEmoji(s) {
return s.replace(emojiRegex, '<span class="emoji">$&</span>');
},

View File

@ -41,7 +41,6 @@ class ChatList extends Component {
));
State.public.user().get('hashtagSubscriptions').map().on(this.sub(
(isSubscribed, hashtag) => {
console.log(hashtag, isSubscribed ? 'subscribed' : 'unsubscribed');
if (isSubscribed) {
hashtags[hashtag] = true;
} else {
@ -78,7 +77,7 @@ class ChatList extends Component {
html`<div class="chat-item" onClick=${() => route(`/hashtag/${hashtag}`)}>
<div class="text">
<div>
<span class="name">#${hashtag}</span>
<b class="name">#${hashtag}</b>
</div>
</div>
</div>`

View File

@ -217,7 +217,11 @@ msg => {
}
const title = `${name || 'User'} on Iris`;
p.innerText = text;
const h = emojiOnly ? p.innerHTML : Helpers.highlightEmoji(p.innerHTML);
let h = p.innerHTML;
if (!emojiOnly) {
h = Helpers.highlightEmoji(h);
h = Helpers.highlightHashtags(h);
}
const innerHTML = autolinker.link(h);
const time = typeof this.state.msg.time === 'object' ? this.state.msg.time : new Date(this.state.msg.time);
const dateStr = time.toLocaleString(window.navigator.language, { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' });

View File

@ -51,6 +51,10 @@ class PublicMessageForm extends Component {
});
node.get(msg.time).put(hash);
}
const hashtags = msg.text && msg.text.match(/\B\#\w\w+\b/g);
if (hashtags) {
hashtags.forEach(hashtag => State.public.user().get('hashtags').get(hashtag.replace('#', '')).get(msg.time).put(hash));
}
msg.torrentId && State.public.user().get('media').get(msg.time).put(hash);
}

View File

@ -4,7 +4,7 @@ export default class SubscribeHashtagButton extends FollowButton {
constructor() {
super();
this.cls = 'follow';
this.action = 'Subscribe hashtag';
this.action = 'Subscribe';
this.actionDone = 'Subscribed';
this.key = 'hashtagSubscriptions';
this.activeClass = 'following';