Improve Emoji Reactions and add support for Chat Reactions
This commit is contained in:
73
app/soapbox/utils/__tests__/chats.test.ts
Normal file
73
app/soapbox/utils/__tests__/chats.test.ts
Normal file
@@ -0,0 +1,73 @@
|
||||
import { normalizeChatMessage } from 'soapbox/normalizers';
|
||||
import { IAccount } from 'soapbox/queries/accounts';
|
||||
import { ChatKeys, IChat } from 'soapbox/queries/chats';
|
||||
import { queryClient } from 'soapbox/queries/client';
|
||||
|
||||
import { updateChatMessage } from '../chats';
|
||||
|
||||
const chat: IChat = {
|
||||
accepted: true,
|
||||
account: {
|
||||
username: 'username',
|
||||
verified: true,
|
||||
id: '1',
|
||||
acct: 'acct',
|
||||
avatar: 'avatar',
|
||||
avatar_static: 'avatar',
|
||||
display_name: 'my name',
|
||||
} as IAccount,
|
||||
chat_type: 'direct',
|
||||
created_at: '2020-06-10T02:05:06.000Z',
|
||||
created_by_account: '1',
|
||||
discarded_at: null,
|
||||
id: '1',
|
||||
last_message: null,
|
||||
latest_read_message_by_account: [],
|
||||
latest_read_message_created_at: null,
|
||||
message_expiration: 1209600,
|
||||
unread: 0,
|
||||
};
|
||||
|
||||
const buildChatMessage = (id: string) => normalizeChatMessage({
|
||||
id,
|
||||
chat_id: '1',
|
||||
account_id: '1',
|
||||
content: `chat message #${id}`,
|
||||
created_at: '2020-06-10T02:05:06.000Z',
|
||||
emoji_reactions: null,
|
||||
expiration: 1209600,
|
||||
unread: true,
|
||||
});
|
||||
|
||||
describe('chat utils', () => {
|
||||
describe('updateChatMessage()', () => {
|
||||
const initialChatMessage = buildChatMessage('1');
|
||||
|
||||
beforeEach(() => {
|
||||
const initialQueryData = {
|
||||
pages: [
|
||||
{ result: [initialChatMessage], hasMore: false, link: undefined },
|
||||
],
|
||||
pageParams: [undefined],
|
||||
};
|
||||
|
||||
queryClient.setQueryData(ChatKeys.chatMessages(chat.id), initialQueryData);
|
||||
});
|
||||
|
||||
it('correctly updates the chat message', () => {
|
||||
expect(
|
||||
(queryClient.getQueryData(ChatKeys.chatMessages(chat.id)) as any).pages[0].result[0].content,
|
||||
).toEqual(initialChatMessage.content);
|
||||
|
||||
const nextChatMessage = normalizeChatMessage({
|
||||
...initialChatMessage.toJS(),
|
||||
content: 'new content',
|
||||
});
|
||||
|
||||
updateChatMessage(nextChatMessage);
|
||||
expect(
|
||||
(queryClient.getQueryData(ChatKeys.chatMessages(chat.id)) as any).pages[0].result[0].content,
|
||||
).toEqual(nextChatMessage.content);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -84,4 +84,11 @@ const getUnreadChatsCount = (): number => {
|
||||
return sumBy(chats, chat => chat.unread);
|
||||
};
|
||||
|
||||
export { updateChatListItem, getUnreadChatsCount, reOrderChatListItems };
|
||||
/** Update the query cache for an individual Chat Message */
|
||||
const updateChatMessage = (chatMessage: ChatMessage) => updatePageItem(
|
||||
ChatKeys.chatMessages(chatMessage.chat_id),
|
||||
normalizeChatMessage(chatMessage),
|
||||
(o, n) => o.id === n.id,
|
||||
);
|
||||
|
||||
export { updateChatListItem, updateChatMessage, getUnreadChatsCount, reOrderChatListItems };
|
||||
@@ -248,6 +248,11 @@ const getInstanceFeatures = (instance: Instance) => {
|
||||
*/
|
||||
chatAcceptance: v.software === TRUTHSOCIAL,
|
||||
|
||||
/**
|
||||
* Ability to add reactions to chat messages.
|
||||
*/
|
||||
chatEmojiReactions: v.software === TRUTHSOCIAL,
|
||||
|
||||
/**
|
||||
* Pleroma chats API.
|
||||
* @see {@link https://docs.pleroma.social/backend/development/API/chats/}
|
||||
@@ -304,6 +309,7 @@ const getInstanceFeatures = (instance: Instance) => {
|
||||
*/
|
||||
chatsWithFollowers: v.software === TRUTHSOCIAL,
|
||||
|
||||
|
||||
/**
|
||||
* Mastodon's newer solution for direct messaging.
|
||||
* @see {@link https://docs.joinmastodon.org/methods/timelines/conversations/}
|
||||
@@ -377,7 +383,7 @@ const getInstanceFeatures = (instance: Instance) => {
|
||||
* The backend allows only RGI ("Recommended for General Interchange") emoji reactions.
|
||||
* @see PUT /api/v1/pleroma/statuses/:id/reactions/:emoji
|
||||
*/
|
||||
emojiReactsRGI: v.software === PLEROMA && gte(v.version, '2.2.49'),
|
||||
emojiReactsRGI: (v.software === PLEROMA && gte(v.version, '2.2.49')) || v.software === TRUTHSOCIAL,
|
||||
|
||||
/**
|
||||
* Sign in with an Ethereum wallet.
|
||||
|
||||
Reference in New Issue
Block a user