mirror of
https://github.com/irislib/iris-messenger.git
synced 2024-09-19 17:46:33 +00:00
highlight hashtags in messages
This commit is contained in:
parent
03720cd37f
commit
3af855ad7e
@ -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"
|
||||
}
|
||||
}
|
||||
|
@ -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>');
|
||||
},
|
||||
|
@ -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>`
|
||||
|
@ -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' });
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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';
|
||||
|
Loading…
Reference in New Issue
Block a user