Update CallLogEvent to latest spec

This commit is contained in:
Jamie Kyle 2024-06-25 17:58:38 -07:00 committed by GitHub
parent 815fd77849
commit fc08e70c0f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 366 additions and 142 deletions

View file

@ -18,6 +18,10 @@ import type { CallHistoryDetails } from '../../types/CallDisposition';
import * as log from '../../logging/log';
import * as Errors from '../../types/errors';
import { drop } from '../../util/drop';
import {
getCallHistoryLatestCall,
getCallHistorySelector,
} from '../selectors/callHistory';
export type CallHistoryState = ReadonlyDeep<{
// This informs the app that underlying call history data has changed.
@ -103,15 +107,35 @@ function markCallHistoryRead(
};
}
export function markCallHistoryReadInConversation(
callId: string
): ThunkAction<void, RootStateType, unknown, CallHistoryUpdateUnread> {
return async (dispatch, getState) => {
const callHistorySelector = getCallHistorySelector(getState());
const callHistory = callHistorySelector(callId);
if (callHistory == null) {
return;
}
try {
await markAllCallHistoryReadAndSync(callHistory, true);
} finally {
dispatch(updateCallHistoryUnreadCount());
}
};
}
function markCallsTabViewed(): ThunkAction<
void,
RootStateType,
unknown,
CallHistoryUpdateUnread
> {
return async dispatch => {
await markAllCallHistoryReadAndSync();
dispatch(updateCallHistoryUnreadCount());
return async (dispatch, getState) => {
const latestCall = getCallHistoryLatestCall(getState());
if (latestCall != null) {
await markAllCallHistoryReadAndSync(latestCall, false);
dispatch(updateCallHistoryUnreadCount());
}
};
}
@ -143,10 +167,13 @@ function clearAllCallHistory(): ThunkAction<
unknown,
CallHistoryReset | ToastActionType
> {
return async dispatch => {
return async (dispatch, getState) => {
try {
await clearCallHistoryDataAndSync();
dispatch(showToast({ toastType: ToastType.CallHistoryCleared }));
const latestCall = getCallHistoryLatestCall(getState());
if (latestCall != null) {
await clearCallHistoryDataAndSync(latestCall);
dispatch(showToast({ toastType: ToastType.CallHistoryCleared }));
}
} catch (error) {
log.error('Error clearing call history', Errors.toLogFormat(error));
} finally {

View file

@ -195,6 +195,7 @@ import {
} from '../../util/deleteForMe';
import { MAX_MESSAGE_COUNT } from '../../util/deleteForMe.types';
import { isEnabled } from '../../RemoteConfig';
import { markCallHistoryReadInConversation } from './callHistory';
import type { CapabilitiesType } from '../../textsecure/WebAPI';
// State
@ -1358,7 +1359,7 @@ function markMessageRead(
conversationId: string,
messageId: string
): ThunkAction<void, RootStateType, unknown, NoopActionType> {
return async (_dispatch, getState) => {
return async (dispatch, getState) => {
const conversation = window.ConversationController.get(conversationId);
if (!conversation) {
throw new Error('markMessageRead: Conversation not found!');
@ -1382,6 +1383,12 @@ function markMessageRead(
newestSentAt: message.get('sent_at'),
sendReadReceipts: true,
});
if (message.get('type') === 'call-history') {
const callId = message.get('callId');
strictAssert(callId, 'callId not found');
dispatch(markCallHistoryReadInConversation(callId));
}
};
}

View file

@ -4,7 +4,11 @@
import { createSelector } from 'reselect';
import type { CallHistoryState } from '../ducks/callHistory';
import type { StateType } from '../reducer';
import type { CallHistoryDetails } from '../../types/CallDisposition';
import {
AdhocCallStatus,
CallType,
type CallHistoryDetails,
} from '../../types/CallDisposition';
import { getOwn } from '../../util/getOwn';
const getCallHistory = (state: StateType): CallHistoryState =>
@ -36,3 +40,28 @@ export const getCallHistoryUnreadCount = createSelector(
return callHistory.unreadCount;
}
);
export const getCallHistoryLatestCall = createSelector(
getCallHistory,
callHistory => {
let latestCall = null;
for (const callId of Object.keys(callHistory.callHistoryByCallId)) {
const call = callHistory.callHistoryByCallId[callId];
// Skip unused call links
if (
call.type === CallType.Adhoc &&
call.status === AdhocCallStatus.Pending
) {
continue;
}
if (latestCall == null || call.timestamp > latestCall.timestamp) {
latestCall = call;
}
}
return latestCall;
}
);