Reactions/Edits: Mark read after database save
This commit is contained in:
parent
768ad8e928
commit
688de5a99b
5 changed files with 59 additions and 70 deletions
|
@ -2528,6 +2528,9 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
|
|||
await DataWriter.saveMessage(this.attributes, {
|
||||
ourAci: window.textsecure.storage.user.getCheckedAci(),
|
||||
});
|
||||
window.reduxActions.conversations.markOpenConversationRead(
|
||||
conversation.id
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -611,6 +611,7 @@ const PUSH_PANEL = 'conversations/PUSH_PANEL';
|
|||
const POP_PANEL = 'conversations/POP_PANEL';
|
||||
const PANEL_ANIMATION_DONE = 'conversations/PANEL_ANIMATION_DONE';
|
||||
const PANEL_ANIMATION_STARTED = 'conversations/PANEL_ANIMATION_STARTED';
|
||||
export const MARK_READ = 'conversations/MARK_READ';
|
||||
export const MESSAGE_CHANGED = 'MESSAGE_CHANGED';
|
||||
export const MESSAGE_DELETED = 'MESSAGE_DELETED';
|
||||
export const MESSAGE_EXPIRED = 'conversations/MESSAGE_EXPIRED';
|
||||
|
@ -780,6 +781,12 @@ type ConversationStoppedByMissingVerificationActionType = ReadonlyDeep<{
|
|||
untrustedServiceIds: ReadonlyArray<ServiceIdString>;
|
||||
};
|
||||
}>;
|
||||
export type MarkReadActionType = ReadonlyDeep<{
|
||||
type: typeof MARK_READ;
|
||||
payload: {
|
||||
conversationId: string;
|
||||
};
|
||||
}>;
|
||||
export type MessageChangedActionType = ReadonlyDeep<{
|
||||
type: typeof MESSAGE_CHANGED;
|
||||
payload: {
|
||||
|
@ -1027,6 +1034,7 @@ export type ConversationActionType =
|
|||
| CreateGroupRejectedActionType
|
||||
| CustomColorRemovedActionType
|
||||
| DiscardMessagesActionType
|
||||
| MarkReadActionType
|
||||
| MessageChangedActionType
|
||||
| MessageDeletedActionType
|
||||
| MessageExpandedActionType
|
||||
|
@ -1122,6 +1130,7 @@ export const actions = {
|
|||
loadRecentMediaItems,
|
||||
markAttachmentAsCorrupted,
|
||||
markMessageRead,
|
||||
markOpenConversationRead,
|
||||
messageChanged,
|
||||
messageDeleted,
|
||||
messageExpanded,
|
||||
|
@ -2888,6 +2897,26 @@ function conversationStoppedByMissingVerification(payload: {
|
|||
};
|
||||
}
|
||||
|
||||
export function markOpenConversationRead(
|
||||
conversationId: string
|
||||
): ThunkAction<void, RootStateType, unknown, MarkReadActionType> {
|
||||
return async (dispatch, getState) => {
|
||||
const state = getState();
|
||||
const { nav } = state;
|
||||
|
||||
if (nav.selectedNavTab !== NavTab.Chats) {
|
||||
return;
|
||||
}
|
||||
|
||||
dispatch({
|
||||
type: MARK_READ,
|
||||
payload: {
|
||||
conversationId,
|
||||
},
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
export function messageChanged(
|
||||
id: string,
|
||||
conversationId: string,
|
||||
|
@ -5524,6 +5553,28 @@ export function reducer(
|
|||
};
|
||||
}
|
||||
|
||||
if (action.type === MARK_READ) {
|
||||
const { conversationId } = action.payload;
|
||||
const existingConversation = state.messagesByConversation[conversationId];
|
||||
|
||||
// We don't keep track of messages unless their conversation is loaded...
|
||||
if (!existingConversation) {
|
||||
return state;
|
||||
}
|
||||
|
||||
return {
|
||||
...state,
|
||||
messagesByConversation: {
|
||||
...state.messagesByConversation,
|
||||
[conversationId]: {
|
||||
...existingConversation,
|
||||
messageChangeCounter:
|
||||
(existingConversation.messageChangeCounter || 0) + 1,
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
if (action.type === MESSAGE_CHANGED) {
|
||||
const { id, conversationId, data } = action.payload;
|
||||
const existingConversation = state.messagesByConversation[conversationId];
|
||||
|
@ -5553,8 +5604,6 @@ export function reducer(
|
|||
|
||||
const hasNewEdit =
|
||||
existingMessage.editHistory?.length !== data.editHistory?.length ? 1 : 0;
|
||||
const toIncrement = data.reactions?.length || hasNewEdit;
|
||||
|
||||
const updatedMessage = {
|
||||
...data,
|
||||
displayLimit: existingMessage.displayLimit,
|
||||
|
@ -5572,14 +5621,6 @@ export function reducer(
|
|||
state
|
||||
),
|
||||
preloadData: undefined,
|
||||
messagesByConversation: {
|
||||
...state.messagesByConversation,
|
||||
[conversationId]: {
|
||||
...existingConversation,
|
||||
messageChangeCounter:
|
||||
(existingConversation.messageChangeCounter || 0) + toIncrement,
|
||||
},
|
||||
},
|
||||
messagesLookup: {
|
||||
...state.messagesLookup,
|
||||
[id]: updatedMessage,
|
||||
|
|
|
@ -68,8 +68,7 @@ describe('backup/calling', () => {
|
|||
callLink = {
|
||||
rootKey: rootKey.toString(),
|
||||
roomId: getRoomIdFromRootKey(rootKey),
|
||||
// TODO: DESKTOP-7511
|
||||
adminKey: fromAdminKeyBytes(Buffer.concat([adminKey, adminKey])),
|
||||
adminKey: fromAdminKeyBytes(adminKey),
|
||||
name: "Let's Talk Rocks",
|
||||
restrictions: CallLinkRestrictions.AdminApproval,
|
||||
revoked: false,
|
||||
|
|
|
@ -1577,64 +1577,6 @@ describe('both/state/ducks/conversations', () => {
|
|||
0
|
||||
);
|
||||
});
|
||||
|
||||
it('increments message change counter if new message has reactions', () => {
|
||||
const changedMessageWithReaction: MessageType = {
|
||||
...changedMessage,
|
||||
reactions: [
|
||||
{
|
||||
emoji: '✨',
|
||||
fromId: 'some-other-id',
|
||||
timestamp: 2222,
|
||||
receivedAtDate: 3333,
|
||||
targetTimestamp: 1111,
|
||||
},
|
||||
],
|
||||
};
|
||||
const state = reducer(
|
||||
startState,
|
||||
messageChanged(messageId, conversationId, changedMessageWithReaction)
|
||||
);
|
||||
|
||||
assert.deepEqual(
|
||||
state.messagesLookup[messageId],
|
||||
changedMessageWithReaction
|
||||
);
|
||||
assert.strictEqual(
|
||||
state.messagesByConversation[conversationId]?.messageChangeCounter,
|
||||
1
|
||||
);
|
||||
});
|
||||
|
||||
it('does not increment message change counter if only old message had reactions', () => {
|
||||
const updatedStartState = {
|
||||
...startState,
|
||||
messagesLookup: {
|
||||
[messageId]: {
|
||||
...startState.messagesLookup[messageId],
|
||||
reactions: [
|
||||
{
|
||||
emoji: '✨',
|
||||
fromId: 'some-other-id',
|
||||
timestamp: 2222,
|
||||
receivedAtDate: 3333,
|
||||
targetTimestamp: 1111,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
};
|
||||
const state = reducer(
|
||||
updatedStartState,
|
||||
messageChanged(messageId, conversationId, changedMessage)
|
||||
);
|
||||
|
||||
assert.deepEqual(state.messagesLookup[messageId], changedMessage);
|
||||
assert.strictEqual(
|
||||
state.messagesByConversation[conversationId]?.messageChangeCounter,
|
||||
0
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('SHOW_ARCHIVED_CONVERSATIONS', () => {
|
||||
|
|
|
@ -370,6 +370,10 @@ export async function handleEditMessage(
|
|||
isFirstRun: false,
|
||||
skipEdits: true,
|
||||
});
|
||||
|
||||
window.reduxActions.conversations.markOpenConversationRead(
|
||||
mainMessageConversation.id
|
||||
);
|
||||
}
|
||||
|
||||
// Apply any other pending edits that target this message
|
||||
|
|
Loading…
Reference in a new issue