hashtag in top of tag feed, scroll to comment, chat blocking, muting, filtering
This commit is contained in:
mgabdev 2020-12-21 18:30:46 -05:00
parent ee91809e8d
commit 67d94858dc
39 changed files with 576 additions and 179 deletions

View File

@ -1,11 +1,11 @@
# frozen_string_literal: true # frozen_string_literal: true
class Api::V1::ChatConversationAccounts::BlockedChatAccountsController < Api::BaseController class Api::V1::ChatConversations::BlockedChatAccountsController < Api::BaseController
before_action -> { doorkeeper_authorize! :follow, :'read:blocks' } before_action -> { doorkeeper_authorize! :follow, :'read:blocks' }
before_action :require_user! before_action :require_user!
after_action :insert_pagination_headers after_action :insert_pagination_headers
def show def index
@accounts = load_accounts @accounts = load_accounts
render json: @accounts, each_serializer: REST::AccountSerializer render json: @accounts, each_serializer: REST::AccountSerializer
end end
@ -32,13 +32,13 @@ class Api::V1::ChatConversationAccounts::BlockedChatAccountsController < Api::Ba
def next_path def next_path
if records_continue? if records_continue?
api_v1_chat_conversation_accounts_chat_blocked_accounts_url pagination_params(max_id: pagination_max_id) api_v1_chat_conversations_blocked_chat_accounts_url pagination_params(max_id: pagination_max_id)
end end
end end
def prev_path def prev_path
unless paginated_blocks.empty? unless paginated_blocks.empty?
api_v1_chat_conversation_accounts_blocked_chat_accounts_url pagination_params(since_id: pagination_since_id) api_v1_chat_conversations_blocked_chat_accounts_url pagination_params(since_id: pagination_since_id)
end end
end end

View File

@ -47,7 +47,7 @@ class Api::V1::ChatConversations::MessagesController < Api::BaseController
).paginate_by_id( ).paginate_by_id(
limit_param(DEFAULT_CHAT_CONVERSATION_MESSAGE_LIMIT), limit_param(DEFAULT_CHAT_CONVERSATION_MESSAGE_LIMIT),
params_slice(:max_id, :since_id, :min_id) params_slice(:max_id, :since_id, :min_id)
) ).reject { |chat_message| FeedManager.instance.filter?(:chat_message, chat_message, current_account.id) }
end end
def insert_pagination_headers def insert_pagination_headers

View File

@ -0,0 +1,63 @@
# frozen_string_literal: true
class Api::V1::ChatConversations::MutedConversationsController < Api::BaseController
before_action -> { authorize_if_got_token! :read, :'read:chats' }
before_action :require_user!
after_action :insert_pagination_headers
def index
@chat_conversations = load_chat_conversations
render json: @chat_conversations, each_serializer: REST::ChatConversationAccountSerializer
end
private
def load_chat_conversations
paginated_chat_conversations
end
def paginated_chat_conversations
ChatConversationAccount.where(
account: current_account,
is_muted: true,
).paginate_by_max_id(
limit_param(DEFAULT_CHAT_CONVERSATION_LIMIT),
params[:max_id],
params[:since_id]
)
end
def insert_pagination_headers
set_pagination_headers(next_path, prev_path)
end
def next_path
if records_continue?
api_v1_chat_conversations_muted_conversations_url pagination_params(max_id: pagination_max_id)
end
end
def prev_path
unless paginated_chat_conversations.empty?
api_v1_chat_conversations_muted_conversations_url pagination_params(since_id: pagination_since_id)
end
end
def pagination_max_id
paginated_chat_conversations.last.id
end
def pagination_since_id
paginated_chat_conversations.first.id
end
def records_continue?
paginated_chat_conversations.size == limit_param(DEFAULT_CHAT_CONVERSATION_LIMIT)
end
def pagination_params(core_params)
params.slice(:limit).permit(:limit).merge(core_params)
end
end

View File

@ -0,0 +1,17 @@
# frozen_string_literal: true
class Api::V1::HashtagsController < Api::BaseController
before_action :require_user!
before_action :set_hashtag
def show
render json: @hashtag, serializer: REST::TagSerializer
end
private
def set_hashtag
@hashtag = Tag.where(name: params[:id]).first
end
end

View File

@ -4,8 +4,8 @@ class Api::Web::ChatSettingsController < Api::Web::BaseController
before_action :require_user! before_action :require_user!
def update def update
setting.data = params[:data] # setting.data = params[:data]
setting.save! # setting.save!
# todo validate all data objects # todo validate all data objects
@ -15,6 +15,6 @@ class Api::Web::ChatSettingsController < Api::Web::BaseController
private private
def setting def setting
@_setting ||= ::Web::Setting.where(user: current_user).first_or_initialize(user: current_user) # @_setting ||= ::Web::Setting.where(user: current_user).first_or_initialize(user: current_user)
end end
end end

View File

@ -123,7 +123,7 @@ export const fetchChatMessengerBlocks = () => (dispatch, getState) => {
dispatch(fetchChatMessengerBlocksRequest()) dispatch(fetchChatMessengerBlocksRequest())
api(getState).get('/api/v1/chat_conversation_accounts/blocked_chat_accounts').then(response => { api(getState).get('/api/v1/chat_conversations/blocked_chat_accounts').then(response => {
const next = getLinks(response).refs.find(link => link.rel === 'next') const next = getLinks(response).refs.find(link => link.rel === 'next')
dispatch(importFetchedAccounts(response.data)) dispatch(importFetchedAccounts(response.data))
dispatch(fetchChatMessengerBlocksSuccess(response.data, next ? next.uri : null)) dispatch(fetchChatMessengerBlocksSuccess(response.data, next ? next.uri : null))

View File

@ -1,4 +1,5 @@
import api, { getLinks } from '../api' import api, { getLinks } from '../api'
import debounce from 'lodash.debounce'
import { importFetchedAccounts } from './importer' import { importFetchedAccounts } from './importer'
import { me } from '../initial_state' import { me } from '../initial_state'
@ -12,7 +13,9 @@ export const CHAT_CONVERSATIONS_APPROVED_EXPAND_REQUEST = 'CHAT_CONVERSATIONS_AP
export const CHAT_CONVERSATIONS_APPROVED_EXPAND_SUCCESS = 'CHAT_CONVERSATIONS_APPROVED_EXPAND_SUCCESS' export const CHAT_CONVERSATIONS_APPROVED_EXPAND_SUCCESS = 'CHAT_CONVERSATIONS_APPROVED_EXPAND_SUCCESS'
export const CHAT_CONVERSATIONS_APPROVED_EXPAND_FAIL = 'CHAT_CONVERSATIONS_APPROVED_EXPAND_FAIL' export const CHAT_CONVERSATIONS_APPROVED_EXPAND_FAIL = 'CHAT_CONVERSATIONS_APPROVED_EXPAND_FAIL'
export const CHAT_CONVERSATION_APPROVED_UNREAD_COUNT_FETCH_SUCCESS = 'CHAT_CONVERSATIONS_APPROVED_EXPAND_FAIL' export const CHAT_CONVERSATION_APPROVED_UNREAD_COUNT_FETCH_SUCCESS = 'CHAT_CONVERSATION_APPROVED_UNREAD_COUNT_FETCH_SUCCESS'
export const CHAT_CONVERSATION_APPROVED_SEARCH_FETCH_SUCCESS = 'CHAT_CONVERSATION_APPROVED_SEARCH_FETCH_SUCCESS'
// //
@ -38,6 +41,16 @@ export const CHAT_CONVERSATIONS_REQUESTED_EXPAND_FAIL = 'CHAT_CONVERSATIONS_R
// //
export const CHAT_CONVERSATIONS_MUTED_FETCH_REQUEST = 'CHAT_CONVERSATIONS_MUTED_FETCH_REQUEST'
export const CHAT_CONVERSATIONS_MUTED_FETCH_SUCCESS = 'CHAT_CONVERSATIONS_MUTED_FETCH_SUCCESS'
export const CHAT_CONVERSATIONS_MUTED_FETCH_FAIL = 'CHAT_CONVERSATIONS_MUTED_FETCH_FAIL'
export const CHAT_CONVERSATIONS_MUTED_EXPAND_REQUEST = 'CHAT_CONVERSATIONS_MUTED_EXPAND_REQUEST'
export const CHAT_CONVERSATIONS_MUTED_EXPAND_SUCCESS = 'CHAT_CONVERSATIONS_MUTED_EXPAND_SUCCESS'
export const CHAT_CONVERSATIONS_MUTED_EXPAND_FAIL = 'CHAT_CONVERSATIONS_MUTED_EXPAND_FAIL'
//
export const CHAT_CONVERSATION_REQUEST_APPROVE_SUCCESS = 'CHAT_CONVERSATION_REQUEST_APPROVE_SUCCESS' export const CHAT_CONVERSATION_REQUEST_APPROVE_SUCCESS = 'CHAT_CONVERSATION_REQUEST_APPROVE_SUCCESS'
export const CHAT_CONVERSATION_REQUEST_APPROVE_FAIL = 'CHAT_CONVERSATION_REQUEST_APPROVE_FAIL' export const CHAT_CONVERSATION_REQUEST_APPROVE_FAIL = 'CHAT_CONVERSATION_REQUEST_APPROVE_FAIL'
@ -215,6 +228,83 @@ export const expandChatConversationRequestedFail = (error) => ({
error, error,
}) })
/**
* @description Fetch paginated muted chat conversations, import accounts and set chat converations
*/
export const fetchChatConversationMuted = () => (dispatch, getState) => {
if (!me) return
dispatch(fetchChatConversationMutedRequest())
api(getState).get('/api/v1/chat_conversations/muted_conversations').then((response) => {
const next = getLinks(response).refs.find(link => link.rel === 'next')
const conversationsAccounts = [].concat.apply([], response.data.map((c) => c.other_accounts))
// const conversationsChatMessages = response.data.map((c) => c.last_chat_message)
dispatch(importFetchedAccounts(conversationsAccounts))
// dispatch(importFetchedChatMessages(conversationsChatMessages))
dispatch(fetchChatConversationMutedSuccess(response.data, next ? next.uri : null))
}).catch((error) => {
dispatch(fetchChatConversationMutedFail(error))
})
}
export const fetchChatConversationMutedRequest = () => ({
type: CHAT_CONVERSATIONS_MUTED_FETCH_REQUEST,
})
export const fetchChatConversationMutedSuccess = (chatConversations, next) => ({
type: CHAT_CONVERSATIONS_MUTED_FETCH_SUCCESS,
chatConversations,
next,
})
export const fetchChatConversationMutedFail = (error) => ({
type: CHAT_CONVERSATIONS_MUTED_FETCH_FAIL,
showToast: true,
error,
})
/**
* @description Expand paginated muted chat conversations, import accounts and set chat converations
*/
export const expandChatConversationMuted = () => (dispatch, getState) => {
if (!me) return
const url = getState().getIn(['chat_conversations', 'muted', 'next'])
const isLoading = getState().getIn(['chat_conversations', 'muted', 'isLoading'])
if (url === null || isLoading) return
dispatch(expandChatConversationMutedRequest())
api(getState).get(url).then(response => {
const next = getLinks(response).refs.find(link => link.rel === 'next')
const conversationsAccounts = [].concat.apply([], response.data.map((c) => c.other_accounts))
// const conversationsChatMessages = response.data.map((c) => c.last_chat_message)
dispatch(importFetchedAccounts(conversationsAccounts))
// dispatch(importFetchedChatMessages(conversationsChatMessages))
dispatch(expandChatConversationMutedSuccess(response.data, next ? next.uri : null))
}).catch(error => dispatch(expandChatConversationMutedFail(error)))
}
export const expandChatConversationMutedRequest = () => ({
type: CHAT_CONVERSATIONS_MUTED_EXPAND_REQUEST,
})
export const expandChatConversationMutedSuccess = (chatConversations, next) => ({
type: CHAT_CONVERSATIONS_MUTED_EXPAND_SUCCESS,
chatConversations,
next,
})
export const expandChatConversationMutedFail = (error) => ({
type: CHAT_CONVERSATIONS_MUTED_EXPAND_FAIL,
showToast: true,
error,
})
/** /**
* @description Create a chat conversation with given accountId. May fail because of blocks. * @description Create a chat conversation with given accountId. May fail because of blocks.
* @param {String} accountId * @param {String} accountId
@ -227,6 +317,7 @@ export const createChatConversation = (accountId) => (dispatch, getState) => {
api(getState).post('/api/v1/chat_conversation', { account_id: accountId }).then((response) => { api(getState).post('/api/v1/chat_conversation', { account_id: accountId }).then((response) => {
dispatch(createChatConversationSuccess(response.data)) dispatch(createChatConversationSuccess(response.data))
}).catch((error) => { }).catch((error) => {
console.log("error:", error)
dispatch(createChatConversationFail(error)) dispatch(createChatConversationFail(error))
}) })
} }
@ -414,3 +505,40 @@ export const setChatConversationExpirationFail = (error) => ({
error, error,
}) })
/**
*
*/
export const fetchChatConversationAccountSuggestions = (query) => (dispatch, getState) => {
if (!query) return
debouncedFetchChatConversationAccountSuggestions(query, dispatch, getState)
}
export const debouncedFetchChatConversationAccountSuggestions = debounce((query, dispatch, getState) => {
if (!query) return
api(getState).get('/api/v1/accounts/search', {
params: {
q: query,
resolve: false,
limit: 4,
},
}).then((response) => {
// const next = getLinks(response).refs.find(link => link.rel === 'next')
// const conversationsAccounts = [].concat.apply([], response.data.map((c) => c.other_accounts))
dispatch(importFetchedAccounts(response.data))
// dispatch(importFetchedAccounts(conversationsAccounts))
// dispatch(importFetchedChatMessages(conversationsChatMessages))
// dispatch(fetchChatConversationsSuccess(response.data, next ? next.uri : null))
dispatch(fetchChatConversationAccountSuggestionsSuccess(response.data))
}).catch((error) => {
//
})
}, 650, { leading: true })
const fetchChatConversationAccountSuggestionsSuccess = (chatConversations) => ({
type: CHAT_CONVERSATION_APPROVED_SEARCH_FETCH_SUCCESS,
chatConversations,
})

View File

@ -5,11 +5,11 @@ import { me } from '../initial_state'
export const CHAT_SETTING_CHANGE = 'CHAT_SETTING_CHANGE' export const CHAT_SETTING_CHANGE = 'CHAT_SETTING_CHANGE'
export const CHAT_SETTING_SAVE = 'CHAT_SETTING_SAVE' export const CHAT_SETTING_SAVE = 'CHAT_SETTING_SAVE'
export const changeChatSetting = (path, value) => (dispatch) => { export const changeChatSetting = (path, checked) => (dispatch) => {
dispatch({ dispatch({
type: CHAT_SETTING_CHANGE, type: CHAT_SETTING_CHANGE,
path, path,
value, checked,
}) })
dispatch(saveChatSettings()) dispatch(saveChatSettings())

View File

@ -0,0 +1,29 @@
import api from '../api'
export const HASHTAG_FETCH_REQUEST = 'HASHTAG_FETCH_REQUEST'
export const HASHTAG_FETCH_SUCCESS = 'HASHTAG_FETCH_SUCCESS'
export const HASHTAG_FETCH_FAIL = 'HASHTAG_FETCH_FAIL'
export const fetchHashtag = (tag) => (dispatch, getState) => {
if (!tag) return
dispatch(fetchHashtagRequest())
api(getState).get(`/api/v1/hashtags/${tag.toLowerCase()}`)
.then(({ data }) => dispatch(fetchHashtagSuccess(data)))
.catch(err => dispatch(fetchHashtagFail(err)))
}
export const fetchHashtagRequest = () => ({
type: HASHTAG_FETCH_REQUEST,
})
export const fetchHashtagSuccess = (hashtag) => ({
type: HASHTAG_FETCH_SUCCESS,
hashtag,
})
export const fetchHashtagFail = error => ({
type: HASHTAG_FETCH_FAIL,
error,
})

View File

@ -84,6 +84,8 @@ export const connectChatMessagesStream = (accountId) => {
onReceive (data) { onReceive (data) {
if (!data['event'] || !data['payload']) return if (!data['event'] || !data['payload']) return
if (data.event === 'notification') { if (data.event === 'notification') {
// : todo :
//Play sound
dispatch(manageIncomingChatMessage(JSON.parse(data.payload))) dispatch(manageIncomingChatMessage(JSON.parse(data.payload)))
} }
}, },

View File

@ -51,6 +51,7 @@ class Account extends ImmutablePureComponent {
showDismiss, showDismiss,
withBio, withBio,
isCard, isCard,
noClick,
} = this.props } = this.props
if (!account) return null if (!account) return null
@ -105,6 +106,8 @@ class Account extends ImmutablePureComponent {
noUnderline: 1, noUnderline: 1,
overflowHidden: 1, overflowHidden: 1,
flexNormal: 1, flexNormal: 1,
outlineNone: 1,
bgTransparent: 1,
aiStart: !isCard, aiStart: !isCard,
aiCenter: isCard, aiCenter: isCard,
}) })
@ -133,26 +136,28 @@ class Account extends ImmutablePureComponent {
<div className={containerClasses}> <div className={containerClasses}>
<div className={innerContainerClasses}> <div className={innerContainerClasses}>
<NavLink <Button
className={[_s.d, _s.noUnderline].join(' ')} noClasses
className={[_s.d, _s.noUnderline, _s.outlineNone, _s.bgTransparent].join(' ')}
title={account.get('acct')} title={account.get('acct')}
to={`/${account.get('acct')}`} to={noClick ? undefined : `/${account.get('acct')}`}
> >
<Avatar account={account} size={avatarSize} /> <Avatar account={account} size={avatarSize} />
</NavLink> </Button>
<div className={[_s.d, _s.px10, _s.overflowHidden, _s.flexNormal].join(' ')}> <div className={[_s.d, _s.px10, _s.overflowHidden, _s.flexNormal].join(' ')}>
<div className={[_s.d, _s.flexRow, _s.aiCenter].join(' ')}> <div className={[_s.d, _s.flexRow, _s.aiCenter].join(' ')}>
<NavLink <Button
noClasses
title={account.get('acct')} title={account.get('acct')}
to={`/${account.get('acct')}`} to={noClick ? undefined : `/${account.get('acct')}`}
className={buttonClasses} className={buttonClasses}
> >
<div className={displayNameWrapperClasses}> <div className={displayNameWrapperClasses}>
<DisplayName account={account} isMultiline={compact || isCard} /> <DisplayName account={account} isMultiline={compact || isCard} />
</div> </div>
{!compact && actionButton} {!compact && actionButton}
</NavLink> </Button>
<div className={[_s.d].join(' ')}> <div className={[_s.d].join(' ')}>
{dismissBtn} {dismissBtn}
@ -232,6 +237,7 @@ Account.propTypes = {
dismissAction: PropTypes.func, dismissAction: PropTypes.func,
withBio: PropTypes.bool, withBio: PropTypes.bool,
isCard: PropTypes.bool, isCard: PropTypes.bool,
noClick: PropTypes.bool,
} }
export default injectIntl(connect(makeMapStateToProps, mapDispatchToProps)(Account)) export default injectIntl(connect(makeMapStateToProps, mapDispatchToProps)(Account))

View File

@ -88,6 +88,14 @@ class Comment extends ImmutablePureComponent {
this.moreNode = c this.moreNode = c
} }
setContainerNode = (c) => {
this.containerNode = c
if (this.props.isHighlighted && this.containerNode) {
this.containerNode.scrollIntoView({ behavior: 'smooth' });
}
}
render() { render() {
const { const {
indent, indent,
@ -101,7 +109,7 @@ class Comment extends ImmutablePureComponent {
if (isHidden) { if (isHidden) {
return ( return (
<div tabIndex='0'> <div tabIndex='0' ref={this.setContainerNode}>
{status.getIn(['account', 'display_name']) || status.getIn(['account', 'username'])} {status.getIn(['account', 'display_name']) || status.getIn(['account', 'username'])}
{status.get('content')} {status.get('content')}
</div> </div>
@ -133,7 +141,11 @@ class Comment extends ImmutablePureComponent {
}) })
return ( return (
<div className={containerClasses} data-comment={status.get('id')}> <div
className={containerClasses}
data-comment={status.get('id')}
ref={this.setContainerNode}
>
{ {
indent > 0 && indent > 0 &&
<div className={[_s.d, _s.z3, _s.flexRow, _s.posAbs, _s.topNeg20PX, _s.left0, _s.bottom20PX, _s.aiCenter, _s.jcCenter].join(' ')}> <div className={[_s.d, _s.z3, _s.flexRow, _s.posAbs, _s.topNeg20PX, _s.left0, _s.bottom20PX, _s.aiCenter, _s.jcCenter].join(' ')}>

View File

@ -1,10 +1,12 @@
import React from 'react' import React from 'react'
import PropTypes from 'prop-types' import PropTypes from 'prop-types'
import { Sparklines, SparklinesCurve } from 'react-sparklines'
import { FormattedMessage } from 'react-intl' import { FormattedMessage } from 'react-intl'
import ImmutablePropTypes from 'react-immutable-proptypes' import ImmutablePropTypes from 'react-immutable-proptypes'
import ImmutablePureComponent from 'react-immutable-pure-component' import ImmutablePureComponent from 'react-immutable-pure-component'
import { NavLink } from 'react-router-dom' import { NavLink } from 'react-router-dom'
import Button from './button' import Button from './button'
import Block from './block'
import Text from './text' import Text from './text'
class HashtagItem extends ImmutablePureComponent { class HashtagItem extends ImmutablePureComponent {
@ -12,44 +14,42 @@ class HashtagItem extends ImmutablePureComponent {
render() { render() {
const { hashtag, isCompact } = this.props const { hashtag, isCompact } = this.props
if (!hashtag) return
const count = hashtag.get('history').map((block) => { const count = hashtag.get('history').map((block) => {
return parseInt(block.get('uses')) return parseInt(block.get('uses'))
}).reduce((a, c) => a + c) }).reduce((a, c) => a + c)
return ( return (
<NavLink <Block>
to={`/tags/${hashtag.get('name')}`} <div className={[_s.d, _s.w100PC].join(' ')}>
className={[_s.d, _s.noUnderline, _s.bgSubtle_onHover, _s.px15, _s.py5].join(' ')} <div className={[_s.d, _s.noUnderline, _s.px15, _s.py5].join(' ')}>
> <div className={[_s.d, _s.flexRow, _s.aiCenter].join(' ')}>
<div className={[_s.d, _s.flexRow, _s.aiCenter].join(' ')}> <div>
<div> <Text color='brand' size='medium' weight='bold' className={[_s.py2, _s.lineHeight15].join(' ')}>
<Text color='brand' size='medium' weight='bold' className={[_s.py2, _s.lineHeight15].join(' ')}> #{hashtag.get('name')}
#{hashtag.get('name')} </Text>
</Text> </div>
</div>
{
!isCompact &&
<Text color='secondary' size='small' className={_s.py2}>
<FormattedMessage id='number_of_gabs' defaultMessage='{count} Gabs' values={{
count,
}} />
</Text>
}
</div> </div>
{
!isCompact && <Sparklines
<Button width={50}
isText height={28}
backgroundColor='none' data={hashtag.get('history').reverse().map((day) => day.get('uses')).toArray()}
color='none' >
title='Remove' <SparklinesCurve style={{ fill: 'none' }} />
icon='close' </Sparklines>
iconSize='8px'
iconClassName={_s.cSecondary}
className={_s.mlAuto}
/>
}
</div> </div>
{ </Block>
!isCompact &&
<Text color='secondary' size='small' className={_s.py2}>
<FormattedMessage id='number_of_gabs' defaultMessage='{count} Gabs' values={{
count,
}} />
</Text>
}
</NavLink>
) )
} }

View File

@ -54,6 +54,7 @@ class ChatConversationOptionsPopover extends ImmutablePureComponent {
intl, intl,
isXS, isXS,
isMuted, isMuted,
isChatConversationRequest,
} = this.props } = this.props
const items = [ const items = [
@ -62,21 +63,23 @@ class ChatConversationOptionsPopover extends ImmutablePureComponent {
title: 'Hide Conversation', title: 'Hide Conversation',
subtitle: 'Hide until next message', subtitle: 'Hide until next message',
onClick: () => this.handleOnHide(), onClick: () => this.handleOnHide(),
}, }
{ ]
if (!isChatConversationRequest) {
items.push({
hideArrow: true, hideArrow: true,
title: isMuted ? 'Unmute Conversation' : 'Mute Conversation', title: isMuted ? 'Unmute Conversation' : 'Mute Conversation',
subtitle: isMuted ? null : "Don't get notified of new messages", subtitle: isMuted ? null : "Don't get notified of new messages",
onClick: () => this.handleOnMute(), onClick: () => this.handleOnMute(),
}, })
{}, items.push({})
{ items.push({
hideArrow: true, hideArrow: true,
title: 'Purge messages', title: 'Purge messages',
subtitle: 'Remove all of your messages in this conversation', subtitle: 'Remove all of your messages in this conversation',
onClick: () => this.handleOnPurge(), onClick: () => this.handleOnPurge(),
}, })
] }
return ( return (
<PopoverLayout <PopoverLayout
@ -125,6 +128,7 @@ ChatConversationOptionsPopover.propTypes = {
isXS: PropTypes.bool, isXS: PropTypes.bool,
isPro: PropTypes.bool.isRequired, isPro: PropTypes.bool.isRequired,
chatConversation: ImmutablePropTypes.map, chatConversation: ImmutablePropTypes.map,
isChatConversationRequest: PropTypes.bool,
onClosePopover: PropTypes.func.isRequired, onClosePopover: PropTypes.func.isRequired,
} }

View File

@ -16,6 +16,10 @@ import {
unbookmark, unbookmark,
isBookmark, isBookmark,
} from '../../actions/interactions'; } from '../../actions/interactions';
import {
muteAccount,
unmuteAccount,
} from '../../actions/interactions';
import { import {
deleteStatus, deleteStatus,
editStatus, editStatus,
@ -493,7 +497,16 @@ const mapDispatchToProps = (dispatch) => ({
accountId: account.get('id'), accountId: account.get('id'),
})) }))
}, },
onMute(account) {
dispatch(closePopover())
if (account.getIn(['relationship', 'muting'])) {
dispatch(unmuteAccount(account.get('id')));
} else {
dispatch(openModal('MUTE', {
accountId: account.get('id'),
}))
}
},
onReport(status) { onReport(status) {
dispatch(closePopover()) dispatch(closePopover())
dispatch(initReport(status.get('account'), status)) dispatch(initReport(status.get('account'), status))

View File

@ -59,9 +59,9 @@ class ChatConversationBlockedAccounts extends ImmutablePureComponent {
key={`blocked-accounts-${id}`} key={`blocked-accounts-${id}`}
id={id} id={id}
compact compact
actionIcon='subtract' actionIcon=''
onActionClick={() => this.props.onRemove(id)} onActionClick={() => this.props.onRemove(id)}
actionTitle='Remove' actionTitle='Undo Chat Block'
/> />
)) ))
} }

View File

@ -56,6 +56,7 @@ class ChatConversationCreate extends React.PureComponent {
suggestionsIds.map((accountId) => ( suggestionsIds.map((accountId) => (
<Account <Account
compact compact
noClick
key={`chat-conversation-account-create-${accountId}`} key={`chat-conversation-account-create-${accountId}`}
id={accountId} id={accountId}
onActionClick={() => this.handleOnCreateChatConversation(accountId)} onActionClick={() => this.handleOnCreateChatConversation(accountId)}

View File

@ -11,7 +11,7 @@ class ChatConversationMutes extends React.PureComponent {
<div className={[_s.d, _s.h60PX, _s.w100PC, _s.px10, _s.py10, _s.borderBottom1PX, _s.borderColorSecondary].join(' ')}> <div className={[_s.d, _s.h60PX, _s.w100PC, _s.px10, _s.py10, _s.borderBottom1PX, _s.borderColorSecondary].join(' ')}>
<BlockHeading title={'Muted Chat Conversations'} /> <BlockHeading title={'Muted Chat Conversations'} />
</div> </div>
<ChatConversationsList source='mutes' /> <ChatConversationsList source='muted' />
</div> </div>
) )
} }

View File

@ -4,7 +4,9 @@ import { connect } from 'react-redux'
import { FormattedMessage } from 'react-intl' import { FormattedMessage } from 'react-intl'
import isEqual from 'lodash.isequal' import isEqual from 'lodash.isequal'
import { expandHashtagTimeline, clearTimeline } from '../actions/timelines' import { expandHashtagTimeline, clearTimeline } from '../actions/timelines'
import { fetchHashtag } from '../actions/hashtags'
import StatusList from '../components/status_list' import StatusList from '../components/status_list'
import HashtagItem from '../components/hashtag_item'
class HashtagTimeline extends React.PureComponent { class HashtagTimeline extends React.PureComponent {
@ -64,10 +66,11 @@ class HashtagTimeline extends React.PureComponent {
} }
componentDidMount () { componentDidMount () {
const { dispatch } = this.props const { dispatch, tagName } = this.props
const { id, tags } = this.props.params const { id, tags } = this.props.params
dispatch(expandHashtagTimeline(id, { tags })) dispatch(expandHashtagTimeline(id, { tags }))
dispatch(fetchHashtag(tagName))
} }
componentWillReceiveProps (nextProps) { componentWillReceiveProps (nextProps) {
@ -86,21 +89,28 @@ class HashtagTimeline extends React.PureComponent {
} }
render () { render () {
const { id } = this.props.params const { tag, tagName } = this.props
console.log("tagName:", tag)
return ( return (
<StatusList <React.Fragment>
scrollKey='hashtag_timeline' { tag && <HashtagItem hashtag={tag} /> }
timelineId={`hashtag:${id}`} <StatusList
onLoadMore={this.handleLoadMore} scrollKey='hashtag_timeline'
emptyMessage={<FormattedMessage id='empty_column.hashtag' defaultMessage='There is nothing in this hashtag yet.' />} timelineId={`hashtag:${tagName}`}
/> onLoadMore={this.handleLoadMore}
); emptyMessage={<FormattedMessage id='empty_column.hashtag' defaultMessage='There is nothing in this hashtag yet.' />}
/>
</React.Fragment>
)
} }
} }
const mapStateToProps = (state, props) => ({ const mapStateToProps = (state, props) => ({
tagName: props.params.id,
tag: state.getIn(['hashtags', `${props.params.id}`]),
hasUnread: state.getIn(['timelines', `hashtag:${props.params.id}`, 'unread']) > 0, hasUnread: state.getIn(['timelines', `hashtag:${props.params.id}`, 'unread']) > 0,
}) })

View File

@ -9,6 +9,8 @@ import {
expandChatConversations, expandChatConversations,
fetchChatConversationRequested, fetchChatConversationRequested,
expandChatConversationRequested, expandChatConversationRequested,
fetchChatConversationMuted,
expandChatConversationMuted,
} from '../../../actions/chat_conversations' } from '../../../actions/chat_conversations'
import AccountPlaceholder from '../../../components/placeholder/account_placeholder' import AccountPlaceholder from '../../../components/placeholder/account_placeholder'
import ChatConversationsListItem from './chat_conversations_list_item' import ChatConversationsListItem from './chat_conversations_list_item'
@ -72,6 +74,8 @@ const mapDispatchToProps = (dispatch) => ({
dispatch(fetchChatConversations()) dispatch(fetchChatConversations())
} else if (source ==='requested') { } else if (source ==='requested') {
dispatch(fetchChatConversationRequested()) dispatch(fetchChatConversationRequested())
} else if (source ==='muted') {
dispatch(fetchChatConversationMuted())
} }
}, },
onExpandChatConversations(source) { onExpandChatConversations(source) {
@ -79,6 +83,8 @@ const mapDispatchToProps = (dispatch) => ({
dispatch(expandChatConversations()) dispatch(expandChatConversations())
} else if (source ==='requested') { } else if (source ==='requested') {
dispatch(expandChatConversationRequested()) dispatch(expandChatConversationRequested())
} else if (source ==='muted') {
dispatch(expandChatConversationMuted())
} }
}, },
}) })

View File

@ -1,29 +1,31 @@
import React from 'react' import React from 'react'
import PropTypes from 'prop-types' import PropTypes from 'prop-types'
import { connect } from 'react-redux'
import Input from '../../../components/input' import Input from '../../../components/input'
class ChatConversationsSearch extends React.PureComponent { class ChatConversationsSearch extends React.PureComponent {
static contextTypes = { state = {
router: PropTypes.object, value: '',
} }
state = { handleOnChange = (value) => {
composeFocused: false, this.setState({ value })
this.props.onChange(value)
} }
render() { render() {
const { const { value } = this.state
children
} = this.props
return ( return (
<div className={[_s.d, _s.h60PX, _s.w100PC, _s.px10, _s.py10, _s.borderBottom1PX, _s.borderColorSecondary].join(' ')}> <div className={[_s.d, _s.h60PX, _s.w100PC, _s.px10, _s.py10, _s.borderBottom1PX, _s.borderColorSecondary].join(' ')}>
<Input <Input
type='search' type='search'
placeholder='Search for messages' placeholder='Search for conversations'
id='messages-search' id='messages-search'
prependIcon='search' prependIcon='search'
value={value}
onChange={this.handleOnChange}
/> />
</div> </div>
) )
@ -31,8 +33,10 @@ class ChatConversationsSearch extends React.PureComponent {
} }
ChatConversationsSearch.propTypes = { const mapDispatchToProps = (dispatch) => ({
// onChange(value) {
} // dispatch()
}
})
export default ChatConversationsSearch export default connect(null, mapDispatchToProps)(ChatConversationsSearch)

View File

@ -21,7 +21,12 @@ class ChatMessageHeader extends React.PureComponent {
} }
handleOnOpenChatConversationOptionsPopover = () => { handleOnOpenChatConversationOptionsPopover = () => {
this.props.onOpenChatConversationOptionsPopover(this.props.chatConversationId, this.optionsBtnRef) const isChatConversationRequest = !!this.props.chatConversation ? !this.props.chatConversation.get('is_approved') : false
this.props.onOpenChatConversationOptionsPopover({
isChatConversationRequest,
chatConversationId: this.props.chatConversationId,
targetRef: this.optionsBtnRef,
})
} }
setOptionsBtnRef = (c) => { setOptionsBtnRef = (c) => {
@ -63,7 +68,7 @@ class ChatMessageHeader extends React.PureComponent {
onClick={this.handleOnApproveMessageRequest} onClick={this.handleOnApproveMessageRequest}
className={_s.ml10} className={_s.ml10}
> >
<Text> <Text color='inherit'>
Approve Message Request Approve Message Request
</Text> </Text>
</Button> </Button>
@ -82,10 +87,9 @@ const mapDispatchToProps = (dispatch) => ({
onApproveChatConversationRequest(chatConversationId) { onApproveChatConversationRequest(chatConversationId) {
dispatch(approveChatConversationRequest(chatConversationId)) dispatch(approveChatConversationRequest(chatConversationId))
}, },
onOpenChatConversationOptionsPopover(chatConversationId, targetRef) { onOpenChatConversationOptionsPopover(options) {
dispatch(openPopover(POPOVER_CHAT_CONVERSATION_OPTIONS, { dispatch(openPopover(POPOVER_CHAT_CONVERSATION_OPTIONS, {
chatConversationId, ...options,
targetRef,
position: 'left-end', position: 'left-end',
})) }))
}, },

View File

@ -22,6 +22,7 @@ import ChatMessagePlaceholder from '../../../components/placeholder/chat_message
import ChatMessageItem from './chat_message_item' import ChatMessageItem from './chat_message_item'
import ColumnIndicator from '../../../components/column_indicator' import ColumnIndicator from '../../../components/column_indicator'
import LoadMore from '../../../components/load_more' import LoadMore from '../../../components/load_more'
import Text from '../../../components/text'
class ChatMessageScrollingList extends ImmutablePureComponent { class ChatMessageScrollingList extends ImmutablePureComponent {
@ -238,6 +239,7 @@ class ChatMessageScrollingList extends ImmutablePureComponent {
isLoading, isLoading,
isPartial, isPartial,
hasMore, hasMore,
amITalkingToMyself,
onScrollToBottom, onScrollToBottom,
onScroll, onScroll,
isXS, isXS,
@ -299,6 +301,15 @@ class ChatMessageScrollingList extends ImmutablePureComponent {
className={[_s.d, _s.h100PC, _s.w100PC, _s.px15, _s.py15, _s.overflowYScroll].join(' ')} className={[_s.d, _s.h100PC, _s.w100PC, _s.px15, _s.py15, _s.overflowYScroll].join(' ')}
ref={this.setScrollContainerRef} ref={this.setScrollContainerRef}
> >
{
amITalkingToMyself &&
<div className={[_s.d, _s.bgTertiary, _s.radiusSmall, _s.mt5, _s.ml10, _s.mr15, _s.px15, _s.py15, _s.mb15].join(' ')}>
<Text size='medium' color='secondary'>
This is a chat conversation with yourself. Use this space to keep messages, links and texts. Please remember that these messages are not encrypted.
</Text>
</div>
}
{ {
(hasMore && !isLoading) && (hasMore && !isLoading) &&
<LoadMore onClick={this.handleLoadOlder} /> <LoadMore onClick={this.handleLoadOlder} />
@ -349,7 +360,11 @@ class ChatMessageScrollingList extends ImmutablePureComponent {
const mapStateToProps = (state, { chatConversationId }) => { const mapStateToProps = (state, { chatConversationId }) => {
if (!chatConversationId) return {} if (!chatConversationId) return {}
const otherAccountIds = state.getIn(['chat_conversations', chatConversationId, 'other_account_ids'], null)
const amITalkingToMyself = !!otherAccountIds ? otherAccountIds.size == 1 && otherAccountIds.get(0) === me : false
return { return {
amITalkingToMyself,
chatMessageIds: state.getIn(['chat_conversation_messages', chatConversationId, 'items'], ImmutableList()), chatMessageIds: state.getIn(['chat_conversation_messages', chatConversationId, 'items'], ImmutableList()),
isLoading: state.getIn(['chat_conversation_messages', chatConversationId, 'isLoading'], true), isLoading: state.getIn(['chat_conversation_messages', chatConversationId, 'isLoading'], true),
isPartial: state.getIn(['chat_conversation_messages', chatConversationId, 'isPartial'], false), isPartial: state.getIn(['chat_conversation_messages', chatConversationId, 'isPartial'], false),

View File

@ -1,36 +1,25 @@
import React from 'react' import React from 'react'
import PropTypes from 'prop-types' import PropTypes from 'prop-types'
import { connect } from 'react-redux' import { connect } from 'react-redux'
import { injectIntl, FormattedMessage } from 'react-intl'
import ImmutablePureComponent from 'react-immutable-pure-component' import ImmutablePureComponent from 'react-immutable-pure-component'
import ImmutablePropTypes from 'react-immutable-proptypes' import ImmutablePropTypes from 'react-immutable-proptypes'
import debounce from 'lodash.debounce'
import { me } from '../initial_state' import { me } from '../initial_state'
import { fetchMutes, expandMutes } from '../actions/mutes' import { changeChatSetting } from '../actions/chat_settings'
import Account from '../components/account'
import BlockHeading from '../components/block_heading' import BlockHeading from '../components/block_heading'
import Button from '../components/button'
import Form from '../components/form' import Form from '../components/form'
import Switch from '../components/switch' import SettingSwitch from '../components/setting_switch'
import Text from '../components/text'
import Divider from '../components/divider' import Divider from '../components/divider'
class MessagesSettings extends ImmutablePureComponent { class MessagesSettings extends ImmutablePureComponent {
componentWillMount() { handleOnChange = (key, checked) => {
this.props.onFetchMutes() this.props.onSave(key, checked)
} }
handleLoadMore = debounce(() => {
this.props.onExpandMutes()
}, 300, { leading: true })
render() { render() {
const { const { chatSettings } = this.props
accountIds,
hasMore, if (!chatSettings) return null
isLoading,
} = this.props
return ( return (
<div className={[_s.d, _s.w100PC, _s.boxShadowNone].join(' ')}> <div className={[_s.d, _s.w100PC, _s.boxShadowNone].join(' ')}>
@ -40,23 +29,34 @@ class MessagesSettings extends ImmutablePureComponent {
<div className={[_s.d, _s.px15, _s.py15, _s.overflowHidden].join(' ')}> <div className={[_s.d, _s.px15, _s.py15, _s.overflowHidden].join(' ')}>
<Form> <Form>
<Switch <SettingSwitch
label='Restrict messages from people you dont follow' label='Restrict messages from people you dont follow'
checked={true} settings={chatSettings}
onChange={this.handleLockedChange} settingPath='restrict_non_followers'
onChange={this.handleOnChange}
/> />
{ /* : todo :
<div className={[_s.d, _s.w100PC, _s.my10, _s.borderColorSecondary, _s.borderBottom1PX].join(' ')} /> <div className={[_s.d, _s.w100PC, _s.my10, _s.borderColorSecondary, _s.borderBottom1PX].join(' ')} />
<Switch <SettingSwitch
label='Show when you are active' label='Show when you are active'
checked={false} settings={chatSettings}
onChange={this.handleLockedChange} settingPath='show_active'
onChange={this.handleOnChange}
/> />
<div className={[_s.d, _s.w100PC, _s.my10, _s.borderColorSecondary, _s.borderBottom1PX].join(' ')} /> <div className={[_s.d, _s.w100PC, _s.my10, _s.borderColorSecondary, _s.borderBottom1PX].join(' ')} />
<Switch <SettingSwitch
label='Notification sound enabled' label='Show read receipts'
checked={false} settings={chatSettings}
onChange={this.handleLockedChange} settingPath='read_receipts'
onChange={this.handleOnChange}
/> />
<div className={[_s.d, _s.w100PC, _s.my10, _s.borderColorSecondary, _s.borderBottom1PX].join(' ')} />
<SettingSwitch
label='Notification sound enabled'
settings={chatSettings}
settingPath='sounds'
onChange={this.handleOnChange}
/> */ }
</Form> </Form>
</div> </div>
</div> </div>
@ -66,22 +66,18 @@ class MessagesSettings extends ImmutablePureComponent {
} }
const mapStateToProps = (state) => ({ const mapStateToProps = (state) => ({
accountIds: state.getIn(['user_lists', 'mutes', me, 'items']), chatSettings: state.getIn(['chat_settings']),
hasMore: !!state.getIn(['user_lists', 'mutes', me, 'next']),
isLoading: state.getIn(['user_lists', 'mutes', me, 'isLoading']),
}) })
const mapDispatchToProps = (dispatch) => ({ const mapDispatchToProps = (dispatch) => ({
onFetchMutes: () => dispatch(fetchMutes()), onSave(key, checked) {
onExpandMutes: () => dispatch(expandMutes()), // dispatch(changeChatSetting(key, checked))
},
}) })
MessagesSettings.propTypes = { MessagesSettings.propTypes = {
accountIds: ImmutablePropTypes.list, chatSettings: ImmutablePropTypes.map,
hasMore: PropTypes.bool, onSave: PropTypes.func.isRequired,
isLoading: PropTypes.bool,
onExpandMutes: PropTypes.func.isRequired,
onFetchMutes: PropTypes.func.isRequired,
} }
export default injectIntl(connect(mapStateToProps, mapDispatchToProps)(MessagesSettings)) export default connect(mapStateToProps, mapDispatchToProps)(MessagesSettings)

View File

@ -76,7 +76,7 @@ class MessagesLayout extends React.PureComponent {
actions={[ actions={[
{ {
icon: 'add', icon: 'add',
to: `'/messages/new'`, to: '/messages/new',
}, },
{ {
icon: 'cog', icon: 'cog',

View File

@ -79,10 +79,6 @@ class SearchLayout extends React.PureComponent {
title: intl.formatMessage(messages.links), title: intl.formatMessage(messages.links),
to: '/search/links', to: '/search/links',
}, },
{
title: intl.formatMessage(messages.hashtags),
to: '/search/hashtags',
},
] ]
} }

View File

@ -15,6 +15,13 @@ import {
CHAT_CONVERSATIONS_REQUESTED_EXPAND_FAIL, CHAT_CONVERSATIONS_REQUESTED_EXPAND_FAIL,
CHAT_CONVERSATION_REQUEST_APPROVE_SUCCESS, CHAT_CONVERSATION_REQUEST_APPROVE_SUCCESS,
CHAT_CONVERSATIONS_MUTED_FETCH_REQUEST,
CHAT_CONVERSATIONS_MUTED_FETCH_SUCCESS,
CHAT_CONVERSATIONS_MUTED_FETCH_FAIL,
CHAT_CONVERSATIONS_MUTED_EXPAND_REQUEST,
CHAT_CONVERSATIONS_MUTED_EXPAND_SUCCESS,
CHAT_CONVERSATIONS_MUTED_EXPAND_FAIL,
} from '../actions/chat_conversations' } from '../actions/chat_conversations'
const initialState = ImmutableMap({ const initialState = ImmutableMap({
@ -28,6 +35,11 @@ const initialState = ImmutableMap({
isLoading: false, isLoading: false,
items: ImmutableList(), items: ImmutableList(),
}), }),
muted: ImmutableMap({
next: null,
isLoading: false,
items: ImmutableList(),
}),
}) })
const normalizeList = (state, source, chatConversations, next) => { const normalizeList = (state, source, chatConversations, next) => {
@ -79,6 +91,18 @@ export default function chat_conversation_lists(state = initialState, action) {
case CHAT_CONVERSATION_REQUEST_APPROVE_SUCCESS: case CHAT_CONVERSATION_REQUEST_APPROVE_SUCCESS:
return removeOneFromList(state, 'requested', action.chatConversation.chat_conversation_id) return removeOneFromList(state, 'requested', action.chatConversation.chat_conversation_id)
case CHAT_CONVERSATIONS_MUTED_FETCH_REQUEST:
case CHAT_CONVERSATIONS_MUTED_EXPAND_REQUEST:
return state.setIn(['muted', 'isLoading'], true)
case CHAT_CONVERSATIONS_MUTED_FETCH_FAIL:
case CHAT_CONVERSATIONS_MUTED_EXPAND_FAIL:
return state.setIn(['muted', 'isLoading'], false)
case CHAT_CONVERSATIONS_MUTED_FETCH_SUCCESS:
return normalizeList(state, 'muted', action.chatConversations, action.next)
case CHAT_CONVERSATIONS_MUTED_EXPAND_SUCCESS:
return appendToList(state, 'muted', action.chatConversations, action.next)
default: default:
return state return state
} }

View File

@ -17,9 +17,7 @@ const initialState = ImmutableMap({
export default function chat_settings(state = initialState, action) { export default function chat_settings(state = initialState, action) {
switch(action.type) { switch(action.type) {
case CHAT_SETTING_CHANGE: case CHAT_SETTING_CHANGE:
return state return state.set(action.path, action.checked).set('saved', false)
.setIn(action.path, action.value)
.set('saved', false)
default: default:
return state return state
} }

View File

@ -0,0 +1,20 @@
import {
HASHTAG_FETCH_REQUEST,
HASHTAG_FETCH_SUCCESS,
HASHTAG_FETCH_FAIL,
} from '../actions/hashtags'
import { Map as ImmutableMap, fromJS } from 'immutable'
const importHashtag = (state, hashtag) => state.set(`${hashtag.name}`.toLowerCase(), fromJS(hashtag))
const initialState = ImmutableMap()
export default function hashtags(state = initialState, action) {
switch (action.type) {
case HASHTAG_FETCH_SUCCESS:
console.log("HASHTAG_FETCH_SUCCESS:", action)
return importHashtag(state, action.hashtag)
default:
return state
}
}

View File

@ -21,6 +21,7 @@ import group_categories from './group_categories'
import group_editor from './group_editor' import group_editor from './group_editor'
import group_lists from './group_lists' import group_lists from './group_lists'
import group_relationships from './group_relationships' import group_relationships from './group_relationships'
import hashtags from './hashtags'
import height_cache from './height_cache' import height_cache from './height_cache'
import links from './links.js' import links from './links.js'
import lists from './lists' import lists from './lists'
@ -75,6 +76,7 @@ const reducers = {
group_editor, group_editor,
group_lists, group_lists,
group_relationships, group_relationships,
hashtags,
height_cache, height_cache,
links, links,
lists, lists,

View File

@ -17,9 +17,12 @@ class FeedManager
"feed:#{type}:#{id}:#{subtype}" "feed:#{type}:#{id}:#{subtype}"
end end
# status or chatMessage
def filter?(timeline_type, status, receiver_id) def filter?(timeline_type, status, receiver_id)
if timeline_type == :home if timeline_type == :home
filter_from_home?(status, receiver_id) filter_from_home?(status, receiver_id)
elsif timeline_type == :chat_message
filter_from_chat_messages?(status, receiver_id)
elsif timeline_type == :mentions elsif timeline_type == :mentions
filter_from_mentions?(status, receiver_id) filter_from_mentions?(status, receiver_id)
else else
@ -140,6 +143,10 @@ class FeedManager
(context == :home ? Mute.where(account_id: receiver_id, target_account_id: account_ids).any? : Mute.where(account_id: receiver_id, target_account_id: account_ids, hide_notifications: true).any?) (context == :home ? Mute.where(account_id: receiver_id, target_account_id: account_ids).any? : Mute.where(account_id: receiver_id, target_account_id: account_ids, hide_notifications: true).any?)
end end
def chat_blocks?(receiver_id, account_ids)
ChatBlock.where(account_id: receiver_id, target_account_id: account_ids).any?
end
def filter_from_home?(status, receiver_id) def filter_from_home?(status, receiver_id)
return false if receiver_id == status.account_id return false if receiver_id == status.account_id
return true if status.reply? && (status.in_reply_to_id.nil? || status.in_reply_to_account_id.nil?) return true if status.reply? && (status.in_reply_to_id.nil? || status.in_reply_to_account_id.nil?)
@ -170,6 +177,18 @@ class FeedManager
false false
end end
def filter_from_chat_messages?(chat_message, receiver_id)
return false if receiver_id == chat_message.from_account_id
return true if phrase_filtered_from_chat_message?(chat_message, receiver_id, :thread)
check_for_blocks = [chat_message.from_account_id]
return true if blocks_or_mutes?(receiver_id, check_for_blocks, :home)
return true if chat_blocks?(receiver_id, check_for_blocks)
false
end
def filter_from_mentions?(status, receiver_id) def filter_from_mentions?(status, receiver_id)
return true if receiver_id == status.account_id return true if receiver_id == status.account_id
return true if phrase_filtered?(status, receiver_id, :notifications) return true if phrase_filtered?(status, receiver_id, :notifications)
@ -211,6 +230,29 @@ class FeedManager
(status.spoiler_text.present? && !combined_regex.match(status.spoiler_text).nil?) (status.spoiler_text.present? && !combined_regex.match(status.spoiler_text).nil?)
end end
def phrase_filtered_from_chat_message?(chat_message, receiver_id, context)
active_filters = Rails.cache.fetch("filters:#{receiver_id}") { CustomFilter.where(account_id: receiver_id).active_irreversible.to_a }.to_a
active_filters.select! { |filter| filter.context.include?(context.to_s) && !filter.expired? }
active_filters.map! do |filter|
if filter.whole_word
sb = filter.phrase =~ /\A[[:word:]]/ ? '\b' : ''
eb = filter.phrase =~ /[[:word:]]\z/ ? '\b' : ''
/(?mix:#{sb}#{Regexp.escape(filter.phrase)}#{eb})/
else
/#{Regexp.escape(filter.phrase)}/i
end
end
return false if active_filters.empty?
combined_regex = active_filters.reduce { |memo, obj| Regexp.union(memo, obj) }
!combined_regex.match(chat_message.text).nil?
end
# Adds a status to an account's feed, returning true if a status was # Adds a status to an account's feed, returning true if a status was
# added, and false if it was not added to the feed. Note that this is # added, and false if it was not added to the feed. Note that this is
# an internal helper: callers must call trim or push updates if # an internal helper: callers must call trim or push updates if

View File

@ -39,6 +39,7 @@ class SortingQueryBuilder < BaseService
query = query.where('statuses.id > ? AND statuses.id <> ?', max_id, max_id) unless max_id.nil? || max_id.empty? query = query.where('statuses.id > ? AND statuses.id <> ?', max_id, max_id) unless max_id.nil? || max_id.empty?
query = query.limit(20) query = query.limit(20)
# : todo : reject blocks, etc. in feedmanager
# SELECT "statuses".* # SELECT "statuses".*
# FROM "statuses" # FROM "statuses"
# INNER JOIN "status_stats" ON "status_stats"."status_id" = "statuses"."id" # INNER JOIN "status_stats" ON "status_stats"."status_id" = "statuses"."id"

View File

@ -37,8 +37,6 @@ class ChatConversationAccount < ApplicationRecord
belongs_to :chat_conversation belongs_to :chat_conversation
belongs_to :last_chat_message, class_name: 'ChatMessage', optional: true belongs_to :last_chat_message, class_name: 'ChatMessage', optional: true
validate :validate_total_limit
def participant_accounts def participant_accounts
if participant_account_ids.empty? if participant_account_ids.empty?
[account] [account]
@ -50,8 +48,4 @@ class ChatConversationAccount < ApplicationRecord
private private
def validate_total_limit
# errors.add(:base, I18n.t('scheduled_statuses.over_total_limit', limit: PER_ACCOUNT_APPROVED_LIMIT)) if account.scheduled_statuses.count >= PER_ACCOUNT_APPROVED_LIMIT
end
end end

View File

@ -84,8 +84,8 @@ class MediaAttachment < ApplicationRecord
}, },
}.freeze }.freeze
IMAGE_LIMIT = Proc.new { |account| account.is_pro ? 50.megabytes : 8.megabytes } IMAGE_LIMIT = Proc.new { |account| account.is_pro ? 100.megabytes : 20.megabytes }
VIDEO_LIMIT = Proc.new { |account| account.is_pro ? 1.gigabytes : 40.megabytes} VIDEO_LIMIT = Proc.new { |account| account.is_pro ? 2.gigabytes : 250.megabytes}
belongs_to :account, inverse_of: :media_attachments, optional: true belongs_to :account, inverse_of: :media_attachments, optional: true
belongs_to :status, inverse_of: :media_attachments, optional: true belongs_to :status, inverse_of: :media_attachments, optional: true

View File

@ -15,26 +15,36 @@ class CreateChatConversationService < BaseService
# : todo : # : todo :
# check if allow anyone to message then create with approved:true # check if allow anyone to message then create with approved:true
# unique account id, participants
chat_conversation = ChatConversation.create @chat_conversation = ChatConversation.create
my_chat = ChatConversationAccount.create!( my_chat = ChatConversationAccount.create!(
account: current_account, account: @current_account,
participant_account_ids: [@account.id.to_s], participant_account_ids: account_ids_as_array,
chat_conversation: chat_conversation, chat_conversation: @chat_conversation,
is_approved: true is_approved: true
) )
# : todo : if multiple ids if @other_accounts.length == 1 && @other_accounts[0].id == @current_account.id
if @account.id != current_account.id # dont create two conversations if you are chatting with yourself
their_chat = ChatConversationAccount.create!( else
account: @account, for other_account in @other_accounts
participant_account_ids: [current_account.id.to_s], this_conversation_participants = @other_accounts.map { |account|
chat_conversation: chat_conversation, account.id.to_s
is_approved: false # : todo : check if allow all else default as request }.reject { |id| id == other_account.id.to_s } << @current_account.id.to_s
)
# is_approved = other_account&.user&.setting_chat_messages_restrict_non_followers == true
ChatConversationAccount.create!(
account: other_account,
participant_account_ids: this_conversation_participants,
chat_conversation: @chat_conversation,
is_approved: false
)
end
end end
my_chat
end end
def account_ids_as_array def account_ids_as_array

View File

@ -54,13 +54,16 @@ class PostChatMessageService < BaseService
# Get not mine # Get not mine
if @account_conversation.id != recipient.id if @account_conversation.id != recipient.id
recipient.unread_count = recipient.unread_count + 1 # check if recipient is blocking me
recipient.is_hidden = false unless recipient.account.chat_blocking?(@account)
recipient.unread_count = recipient.unread_count + 1
recipient.is_hidden = false
# check if muting # check if muting
unless recipient.is_muted unless recipient.is_muted
payload = InlineRenderer.render(@chat, recipient.account, :chat_message) payload = InlineRenderer.render(@chat, recipient.account, :chat_message)
Redis.current.publish("chat_messages:#{recipient.account.id}", Oj.dump(event: :notification, payload: payload)) Redis.current.publish("chat_messages:#{recipient.account.id}", Oj.dump(event: :notification, payload: payload))
end
end end
else else
recipient.unread_count = 0 recipient.unread_count = 0
@ -73,20 +76,6 @@ class PostChatMessageService < BaseService
def set_chat_conversation_recipients! def set_chat_conversation_recipients!
@account_conversation = ChatConversationAccount.where(account: @account, chat_conversation: @chat_conversation).first @account_conversation = ChatConversationAccount.where(account: @account, chat_conversation: @chat_conversation).first
@chat_conversation_recipients_accounts = ChatConversationAccount.where(chat_conversation: @chat_conversation) @chat_conversation_recipients_accounts = ChatConversationAccount.where(chat_conversation: @chat_conversation)
# if 1-to-1 chat, check for blocking and dont allow message to send if blocking
# if 1-to-many let chat go through but keep is_hidden
@chat_conversation_recipients_accounts.each do |recipient|
# : todo :
# check if chat blocked
# check if normal blocked
if recipient.account.blocking?(@account) || recipient.account.chat_blocking?(@account)
raise GabSocial::NotPermittedError
end
end
rescue ArgumentError rescue ArgumentError
raise ActiveRecord::RecordInvalid raise ActiveRecord::RecordInvalid
end end

View File

@ -227,7 +227,7 @@ Rails.application.routes.draw do
end end
namespace :chat_conversation_accounts do namespace :chat_conversation_accounts do
resource :blocked_chat_accounts, only: :show, controller: 'chat_conversation_accounts/blocked_chat_accounts' #
end end
resources :chat_conversation_accounts, only: :show do resources :chat_conversation_accounts, only: :show do
@ -256,6 +256,8 @@ Rails.application.routes.draw do
get :count get :count
end end
end end
resources :blocked_chat_accounts, only: :index
resources :muted_conversations, only: :index
end end
resources :chat_conversation, only: [:show, :create] do resources :chat_conversation, only: [:show, :create] do
@ -268,6 +270,7 @@ Rails.application.routes.draw do
end end
resources :links, only: :show resources :links, only: :show
resources :hashtags, only: :show
resource :popular_links, only: :show resource :popular_links, only: :show
resources :streaming, only: [:index] resources :streaming, only: [:index]
resources :custom_emojis, only: [:index] resources :custom_emojis, only: [:index]

View File

@ -114,6 +114,7 @@
"react-router-dom": "^4.1.1", "react-router-dom": "^4.1.1",
"react-router-scroll-4": "^1.0.0-beta.2", "react-router-scroll-4": "^1.0.0-beta.2",
"react-sortable-hoc": "^1.11.0", "react-sortable-hoc": "^1.11.0",
"react-sparklines": "^1.7.0",
"react-stickynode": "^3.0.4", "react-stickynode": "^3.0.4",
"react-swipeable-views": "^0.13.9", "react-swipeable-views": "^0.13.9",
"react-textarea-autosize": "^7.1.0", "react-textarea-autosize": "^7.1.0",

View File

@ -6618,6 +6618,13 @@ react-sortable-hoc@^1.11.0:
invariant "^2.2.4" invariant "^2.2.4"
prop-types "^15.5.7" prop-types "^15.5.7"
react-sparklines@^1.7.0:
version "1.7.0"
resolved "https://registry.yarnpkg.com/react-sparklines/-/react-sparklines-1.7.0.tgz#9b1d97e8c8610095eeb2ad658d2e1fcf91f91a60"
integrity sha512-bJFt9K4c5Z0k44G8KtxIhbG+iyxrKjBZhdW6afP+R7EnIq+iKjbWbEFISrf3WKNFsda+C46XAfnX0StS5fbDcg==
dependencies:
prop-types "^15.5.10"
react-stickynode@^3.0.4: react-stickynode@^3.0.4:
version "3.0.4" version "3.0.4"
resolved "https://registry.yarnpkg.com/react-stickynode/-/react-stickynode-3.0.4.tgz#1e9c096cec3613cc8294807eba319ced074c8b21" resolved "https://registry.yarnpkg.com/react-stickynode/-/react-stickynode-3.0.4.tgz#1e9c096cec3613cc8294807eba319ced074c8b21"