Create new stream event type: emoji_reaction

This commit is contained in:
KMY 2023-02-26 09:45:22 +09:00
parent 14fddebbd0
commit 1c028a20ac
15 changed files with 171 additions and 15 deletions

View file

@ -207,8 +207,7 @@ export function emojiReact(status, emoji) {
return function (dispatch, getState) {
dispatch(emojiReactRequest(status, emoji));
api(getState).post(`/api/v1/statuses/${status.get('id')}/emoji_reactions`, { emoji: emoji.custom ? (emoji.name + (emoji.domain || '')) : emoji.native }).then(function (response) {
dispatch(importFetchedStatus(response.data));
api(getState).post(`/api/v1/statuses/${status.get('id')}/emoji_reactions`, { emoji: emoji.custom ? (emoji.name + (emoji.domain || '')) : emoji.native }).then(function () {
dispatch(emojiReactSuccess(status, emoji));
}).catch(function (error) {
dispatch(emojiReactFail(status, emoji, error));
@ -220,8 +219,7 @@ export function unEmojiReact(status, emoji) {
return (dispatch, getState) => {
dispatch(unEmojiReactRequest(status, emoji));
api(getState).post(`/api/v1/statuses/${status.get('id')}/emoji_unreaction`, { emoji }).then(response => {
dispatch(importFetchedStatus(response.data));
api(getState).post(`/api/v1/statuses/${status.get('id')}/emoji_unreaction`, { emoji }).then(() => {
dispatch(unEmojiReactSuccess(status, emoji));
}).catch(error => {
dispatch(unEmojiReactFail(status, emoji, error));

View file

@ -15,6 +15,7 @@ import { unescapeHTML } from '../utils/html';
import { usePendingItems as preferPendingItems } from 'mastodon/initial_state';
import compareId from 'mastodon/compare_id';
import { requestNotificationPermission } from '../utils/notifications';
import { STATUS_EMOJI_REACTION_UPDATE } from './statuses';
export const NOTIFICATIONS_UPDATE = 'NOTIFICATIONS_UPDATE';
export const NOTIFICATIONS_UPDATE_NOOP = 'NOTIFICATIONS_UPDATE_NOOP';
@ -54,6 +55,15 @@ export const loadPending = () => ({
type: NOTIFICATIONS_LOAD_PENDING,
});
export function updateEmojiReactions(emoji_reaction, accountId) {
return (dispatch) =>
dispatch({
type: STATUS_EMOJI_REACTION_UPDATE,
emoji_reaction,
accountId,
});
}
export function updateNotifications(notification, intlMessages, intlLocale) {
return (dispatch, getState) => {
const activeFilter = getState().getIn(['settings', 'notifications', 'quickFilter', 'active']);

View file

@ -39,6 +39,8 @@ export const STATUS_TRANSLATE_SUCCESS = 'STATUS_TRANSLATE_SUCCESS';
export const STATUS_TRANSLATE_FAIL = 'STATUS_TRANSLATE_FAIL';
export const STATUS_TRANSLATE_UNDO = 'STATUS_TRANSLATE_UNDO';
export const STATUS_EMOJI_REACTION_UPDATE = 'STATUS_EMOJI_REACTION_UPDATE';
export function fetchStatusRequest(id, skipLoading) {
return {
type: STATUS_FETCH_REQUEST,
@ -347,3 +349,8 @@ export const undoStatusTranslation = id => ({
type: STATUS_TRANSLATE_UNDO,
id,
});
export const updateEmojiReaction = (emoji_reaction) => ({
type: STATUS_EMOJI_REACTION_UPDATE,
emoji_reaction,
});

View file

@ -12,7 +12,7 @@ import {
fillCommunityTimelineGaps,
fillListTimelineGaps,
} from './timelines';
import { updateNotifications, expandNotifications } from './notifications';
import { updateNotifications, expandNotifications, updateEmojiReactions } from './notifications';
import { updateConversations } from './conversations';
import { updateStatus } from './statuses';
import {
@ -93,6 +93,9 @@ export const connectTimelineStream = (timelineId, channelName, params = {}, opti
case 'notification':
dispatch(updateNotifications(JSON.parse(data.payload), messages, locale));
break;
case 'emoji_reaction':
dispatch(updateEmojiReactions(JSON.parse(data.payload), getState().getIn(['meta', 'me'])));
break;
case 'conversation':
dispatch(updateConversations(JSON.parse(data.payload)));
break;

View file

@ -14,7 +14,6 @@ class EmojiReactionButton extends React.PureComponent {
staticUrl: PropTypes.string,
count: PropTypes.number.isRequired,
me: PropTypes.bool,
status: PropTypes.map,
onEmojiReact: PropTypes.func,
onUnEmojiReact: PropTypes.func,
};

View file

@ -396,6 +396,7 @@
"not_signed_in_indicator.not_signed_in": "You need to sign in to access this resource.",
"notification.admin.report": "{name} reported {target}",
"notification.admin.sign_up": "{name} signed up",
"notification.emoji_reaction": "{name} reacted your post with emoji",
"notification.favourite": "{name} favourited your post",
"notification.follow": "{name} followed you",
"notification.follow_request": "{name} has requested to follow you",

View file

@ -396,6 +396,7 @@
"not_signed_in_indicator.not_signed_in": "この機能を使うにはログインする必要があります。",
"notification.admin.report": "{name}さんが{target}さんを通報しました",
"notification.admin.sign_up": "{name}さんがサインアップしました",
"notification.emoji_reaction": "{name}さんがあなたの投稿に絵文字をつけました",
"notification.favourite": "{name}さんがあなたの投稿をお気に入りに登録しました",
"notification.follow": "{name}さんにフォローされました",
"notification.follow_request": "{name}さんがあなたにフォローリクエストしました",

View file

@ -17,10 +17,11 @@ import {
STATUS_TRANSLATE_UNDO,
STATUS_FETCH_REQUEST,
STATUS_FETCH_FAIL,
STATUS_EMOJI_REACTION_UPDATE,
} from '../actions/statuses';
import { TIMELINE_DELETE } from '../actions/timelines';
import { STATUS_IMPORT, STATUSES_IMPORT } from '../actions/importer';
import { Map as ImmutableMap, fromJS } from 'immutable';
import { Map as ImmutableMap, List as ImmutableList, fromJS } from 'immutable';
const importStatus = (state, status) => state.set(status.id, fromJS(status));
@ -35,6 +36,30 @@ const deleteStatus = (state, id, references) => {
return state.delete(id);
};
const updateStatusEmojiReaction = (state, emoji_reaction, myId) => {
emoji_reaction.me = emoji_reaction.account_ids ? emoji_reaction.account_ids.indexOf(myId) >= 0 : false;
const status = state.get(emoji_reaction.status_id);
if (!status) return state;
let emoji_reactions = Array.from(status.get('emoji_reactions') || []);
if (emoji_reaction.count > 0) {
const old_emoji = emoji_reactions.find((er) => er.name === emoji_reaction.name && er.url === emoji_reaction.url);
if (old_emoji) {
old_emoji.account_ids = emoji_reaction.account_ids;
old_emoji.count = emoji_reaction.count;
old_emoji.me = emoji_reaction.me;
} else {
emoji_reactions.push(ImmutableMap(emoji_reaction));
}
} else {
emoji_reactions = emoji_reactions.filter((er) => er.get('name') !== emoji_reaction.name || er.get('domain') !== emoji_reaction.domain);
}
return state.setIn([emoji_reaction.status_id, 'emoji_reactions'], ImmutableList(emoji_reactions));
};
const initialState = ImmutableMap();
export default function statuses(state = initialState, action) {
@ -89,6 +114,8 @@ export default function statuses(state = initialState, action) {
return state.setIn([action.id, 'translation'], fromJS(action.translation));
case STATUS_TRANSLATE_UNDO:
return state.deleteIn([action.id, 'translation']);
case STATUS_EMOJI_REACTION_UPDATE:
return updateStatusEmojiReaction(state, action.emoji_reaction, action.accountId);
default:
return state;
}

View file

@ -1264,7 +1264,8 @@ body > [data-popper-placement] {
.status__emoji-reactions-bar {
display: flex;
gap: 8px;
flex-wrap: wrap;
gap: 4px 8px;
margin: 8px 0 2px 4px;
.emoji-reactions-bar__button {