~cytrogen/masto-fe

ref: fbfc4145fd815ec2aa3e8cbc70bb064e46461973 masto-fe/app/javascript/mastodon/features/direct_timeline/containers/conversation_container.js -rw-r--r-- 2.5 KiB
fbfc4145 — Claire Merge commit '1cdcd9dc08c91321f80ffe4822f6a3da15abeb2c' into glitch-soc/merge-upstream 2 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import { defineMessages, injectIntl } from 'react-intl';

import { connect } from 'react-redux';

import { replyCompose } from 'mastodon/actions/compose';
import { markConversationRead, deleteConversation } from 'mastodon/actions/conversations';
import { openModal } from 'mastodon/actions/modal';
import { muteStatus, unmuteStatus, hideStatus, revealStatus } from 'mastodon/actions/statuses';
import { makeGetStatus } from 'mastodon/selectors';

import Conversation from '../components/conversation';

const messages = defineMessages({
  replyConfirm: { id: 'confirmations.reply.confirm', defaultMessage: 'Reply' },
  replyMessage: { id: 'confirmations.reply.message', defaultMessage: 'Replying now will overwrite the message you are currently composing. Are you sure you want to proceed?' },
});

const mapStateToProps = () => {
  const getStatus = makeGetStatus();

  return (state, { conversationId }) => {
    const conversation = state.getIn(['conversations', 'items']).find(x => x.get('id') === conversationId);
    const lastStatusId = conversation.get('last_status', null);

    return {
      accounts: conversation.get('accounts').map(accountId => state.getIn(['accounts', accountId], null)),
      unread: conversation.get('unread'),
      lastStatus: lastStatusId && getStatus(state, { id: lastStatusId }),
    };
  };
};

const mapDispatchToProps = (dispatch, { intl, conversationId }) => ({

  markRead () {
    dispatch(markConversationRead(conversationId));
  },

  reply (status, router) {
    dispatch((_, getState) => {
      let state = getState();

      if (state.getIn(['compose', 'text']).trim().length !== 0) {
        dispatch(openModal({
          modalType: 'CONFIRM',
          modalProps: {
            message: intl.formatMessage(messages.replyMessage),
            confirm: intl.formatMessage(messages.replyConfirm),
            onConfirm: () => dispatch(replyCompose(status, router)),
          },
        }));
      } else {
        dispatch(replyCompose(status, router));
      }
    });
  },

  delete () {
    dispatch(deleteConversation(conversationId));
  },

  onMute (status) {
    if (status.get('muted')) {
      dispatch(unmuteStatus(status.get('id')));
    } else {
      dispatch(muteStatus(status.get('id')));
    }
  },

  onToggleHidden (status) {
    if (status.get('hidden')) {
      dispatch(revealStatus(status.get('id')));
    } else {
      dispatch(hideStatus(status.get('id')));
    }
  },

});

export default injectIntl(connect(mapStateToProps, mapDispatchToProps)(Conversation));