fix reprööted posts not being muted properly. fix muted posts making

desktop notifications
This commit is contained in:
Henry Jameson 2020-05-25 23:38:31 +03:00
parent cf3fbdd610
commit b5c1d074f8
5 changed files with 83 additions and 17 deletions

View File

@ -12,7 +12,8 @@ import StatusPopover from '../status_popover/status_popover.vue'
import EmojiReactions from '../emoji_reactions/emoji_reactions.vue' import EmojiReactions from '../emoji_reactions/emoji_reactions.vue'
import generateProfileLink from 'src/services/user_profile_link_generator/user_profile_link_generator' import generateProfileLink from 'src/services/user_profile_link_generator/user_profile_link_generator'
import { highlightClass, highlightStyle } from '../../services/user_highlighter/user_highlighter.js' import { highlightClass, highlightStyle } from '../../services/user_highlighter/user_highlighter.js'
import { filter, unescape, uniqBy } from 'lodash' import { muteWordHits } from '../../services/status_parser/status_parser.js'
import { unescape, uniqBy } from 'lodash'
import { mapGetters, mapState } from 'vuex' import { mapGetters, mapState } from 'vuex'
const Status = { const Status = {
@ -44,6 +45,12 @@ const Status = {
muteWords () { muteWords () {
return this.mergedConfig.muteWords return this.mergedConfig.muteWords
}, },
showReasonMutedThread () {
return (
this.status.thread_muted ||
(this.status.reblog && this.status.reblog.thread_muted)
) && !this.inConversation
},
repeaterClass () { repeaterClass () {
const user = this.statusoid.user const user = this.statusoid.user
return highlightClass(user) return highlightClass(user)
@ -93,20 +100,44 @@ const Status = {
return !!this.currentUser return !!this.currentUser
}, },
muteWordHits () { muteWordHits () {
const statusText = this.status.text.toLowerCase() return muteWordHits(this.status, this.muteWords)
const statusSummary = this.status.summary.toLowerCase()
const hits = filter(this.muteWords, (muteWord) => {
return statusText.includes(muteWord.toLowerCase()) || statusSummary.includes(muteWord.toLowerCase())
})
return hits
}, },
muted () { muted () {
const relationship = this.$store.getters.relationship(this.status.user.id) const { status } = this
return !this.unmuted && ( const { reblog } = status
(!(this.inProfile && this.status.user.id === this.profileUserId) && relationship.muting) || const relationship = this.$store.getters.relationship(status.user.id)
(!this.inConversation && this.status.thread_muted) || const relationshipReblog = reblog && this.$store.getters.relationship(reblog.user.id)
this.muteWordHits.length > 0) const reasonsToMute = (
// Post is muted according to BE
status.muted ||
// Reprööt of a muted post according to BE
(reblog && reblog.muted) ||
// Muted user
relationship.muting ||
// Muted user of a reprööt
(relationshipReblog && relationshipReblog.muting) ||
// Thread is muted
status.thread_muted ||
// Wordfiltered
this.muteWordHits.length > 0
)
const excusesNotToMute = (
// Currently showing status
this.unmuted ||
(
this.inProfile && (
// Don't mute user's posts on user timeline (except reblogs)
(!reblog && status.user.id === this.profileUserId) ||
// Same as above but also allow self-reblogs
(reblog && reblog.user.id === this.profileUserId)
)
) ||
// Don't mute statuses in muted conversation when said conversation is opened
(this.inConversation && status.thread_muted)
// No excuses if post has muted words
) && !this.muteWordHits.length > 0
return !excusesNotToMute && reasonsToMute
}, },
hideFilteredStatuses () { hideFilteredStatuses () {
return this.mergedConfig.hideFilteredStatuses return this.mergedConfig.hideFilteredStatuses

View File

@ -18,10 +18,26 @@
<template v-if="muted && !isPreview"> <template v-if="muted && !isPreview">
<div class="media status container muted"> <div class="media status container muted">
<small> <small>
<i
v-if="muted && retweet"
class="button-icon icon-retweet"
/>
<router-link :to="userProfileLink"> <router-link :to="userProfileLink">
{{ status.user.screen_name }} {{ status.user.screen_name }}
</router-link> </router-link>
</small> </small>
<small
v-if="showReasonMutedThread && muteWordHits.length === 0"
class="mutedThread"
>
{{ $t('status.thread_muted') }}
</small>
<small
v-if="showReasonMutedThread && muteWordHits.length > 0"
class="mutedThread"
>
{{ $t('status.thread_muted_and_words') }}
</small>
<small class="muteWords">{{ muteWordHits.join(', ') }}</small> <small class="muteWords">{{ muteWordHits.join(', ') }}</small>
<a <a
href="#" href="#"
@ -642,7 +658,7 @@ $status-margin: 0.75em;
margin-left: auto; margin-left: auto;
} }
.muteWords { .mutedThread, .muteWords {
margin-left: 10px; margin-left: 10px;
} }
} }

View File

@ -621,7 +621,9 @@
"mute_conversation": "Mute conversation", "mute_conversation": "Mute conversation",
"unmute_conversation": "Unmute conversation", "unmute_conversation": "Unmute conversation",
"status_unavailable": "Status unavailable", "status_unavailable": "Status unavailable",
"copy_link": "Copy link to status" "copy_link": "Copy link to status",
"thread_muted": "Conversation muted",
"thread_muted_and_words": "Conversation muted, contains filtered words:"
}, },
"user_card": { "user_card": {
"approve": "Approve", "approve": "Approve",

View File

@ -15,7 +15,7 @@ import {
import { set } from 'vue' import { set } from 'vue'
import { isStatusNotification } from '../services/notification_utils/notification_utils.js' import { isStatusNotification } from '../services/notification_utils/notification_utils.js'
import apiService from '../services/api/api.service.js' import apiService from '../services/api/api.service.js'
// import parse from '../services/status_parser/status_parser.js' import { muteWordHits } from '../services/status_parser/status_parser.js'
const emptyTl = (userId = 0) => ({ const emptyTl = (userId = 0) => ({
statuses: [], statuses: [],
@ -381,7 +381,13 @@ const addNewNotifications = (state, { dispatch, notifications, older, visibleNot
notifObj.image = status.attachments[0].url notifObj.image = status.attachments[0].url
} }
if (!notification.seen && !state.notifications.desktopNotificationSilence && visibleNotificationTypes.includes(notification.type)) { if (
!notification.seen &&
!state.notifications.desktopNotificationSilence &&
visibleNotificationTypes.includes(notification.type) &&
!status.muted &&
muteWordHits(status, rootGetters.mergedConfig.muteWords).length === 0
) {
let desktopNotification = new window.Notification(title, notifObj) let desktopNotification = new window.Notification(title, notifObj)
// Chrome is known for not closing notifications automatically // Chrome is known for not closing notifications automatically
// according to MDN, anyway. // according to MDN, anyway.

View File

@ -1,3 +1,4 @@
import { filter } from 'lodash'
import sanitize from 'sanitize-html' import sanitize from 'sanitize-html'
export const removeAttachmentLinks = (html) => { export const removeAttachmentLinks = (html) => {
@ -12,4 +13,14 @@ export const parse = (html) => {
return removeAttachmentLinks(html) return removeAttachmentLinks(html)
} }
export const muteWordHits = (status, muteWords) => {
const statusText = status.text.toLowerCase()
const statusSummary = status.summary.toLowerCase()
const hits = filter(muteWords, (muteWord) => {
return statusText.includes(muteWord.toLowerCase()) || statusSummary.includes(muteWord.toLowerCase())
})
return hits
}
export default parse export default parse