chore: cleanup call notification message selectors

pull/3281/head
Audric Ackermann 4 months ago
parent a70fda8472
commit 35c77accac
No known key found for this signature in database

@ -21,7 +21,7 @@ import { SessionLastSeenIndicator } from './SessionLastSeenIndicator';
import { TimerNotification } from './TimerNotification';
import { DataExtractionNotification } from './message/message-item/DataExtractionNotification';
import { InteractionNotification } from './message/message-item/InteractionNotification';
import { PropsForCallNotification, PropsForInteractionNotification } from '../../state/ducks/types';
import { PropsForInteractionNotification } from '../../state/ducks/types';
function isNotTextboxEvent(e: KeyboardEvent) {
return (e?.target as any)?.type === undefined;
@ -144,9 +144,7 @@ export const SessionMessagesList = (props: {
}
if (messageProps.message?.messageType === 'call-notification') {
const msgProps = messageProps.message.props as PropsForCallNotification;
return [<CallNotification key={messageId} {...msgProps} />, ...componentToMerge];
return [<CallNotification key={messageId} messageId={messageId} />, ...componentToMerge];
}
if (messageProps.message?.messageType === 'interaction-notification') {

@ -1,4 +1,4 @@
import { CallNotificationType, PropsForCallNotification } from '../../../../../state/ducks/types';
import { CallNotificationType } from '../../../../../state/ducks/types';
import { useSelectedNicknameOrProfileNameOrShortenedPubkey } from '../../../../../state/selectors/selectedConversation';
import { SessionIconType } from '../../../../icon';
@ -6,6 +6,8 @@ import { ExpirableReadableMessage } from '../ExpirableReadableMessage';
import { NotificationBubble } from './NotificationBubble';
import { Localizer } from '../../../../basic/Localizer';
import { MergedLocalizerTokens } from '../../../../../localization/localeTools';
import type { WithMessageId } from '../../../../../session/types/with';
import { useMessageCallNotificationType } from '../../../../../state/selectors';
type StyleType = Record<
CallNotificationType,
@ -30,11 +32,17 @@ const style = {
},
} satisfies StyleType;
export const CallNotification = (props: PropsForCallNotification) => {
const { messageId, notificationType } = props;
export const CallNotification = (props: WithMessageId) => {
const { messageId } = props;
const notificationType = useMessageCallNotificationType(messageId);
const name = useSelectedNicknameOrProfileNameOrShortenedPubkey() ?? window.i18n('unknown');
if (!notificationType) {
return null;
}
const { iconColor, iconType, notificationTextKey } = style[notificationType];
return (

@ -753,9 +753,7 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
public async addOutgoingApprovalMessage(timestamp: number) {
await this.addSingleOutgoingMessage({
sent_at: timestamp,
messageRequestResponse: {
isApproved: 1,
},
messageRequestResponse: {},
expireTimer: 0,
});
@ -771,9 +769,7 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
await this.addSingleIncomingMessage({
sent_at: timestamp,
source,
messageRequestResponse: {
isApproved: 1,
},
messageRequestResponse: {},
unread: READ_MESSAGE_STATE.unread, // 1 means unread
expireTimer: 0,
});

@ -227,7 +227,7 @@ export class MessageModel extends Backbone.Model<MessageAttributes> {
return this.get('groupInvitation');
}
public isMessageRequestResponse() {
private isMessageRequestResponse() {
return !!this.get('messageRequestResponse');
}

@ -194,8 +194,8 @@ export interface MessageAttributesOptionals {
hasVisualMediaAttachments?: boolean;
dataExtractionNotification?: DataExtractionNotificationMsg;
messageRequestResponse?: {
/** 1 means approved, 0 means unapproved. */
isApproved?: number;
// keeping it as a object in case we ever add a field here.
// Note: we had isApproved field, but it was unused so I got rid of it
};
unread?: number;
group?: any;

@ -793,6 +793,7 @@ async function handleMessageRequestResponse(
envelope: EnvelopePlus,
messageRequestResponse: SignalService.MessageRequestResponse
) {
// no one cares about the is `messageRequestResponse.isApproved` field currently.
if (!messageRequestResponse || !messageRequestResponse.isApproved) {
window?.log?.error('handleMessageRequestResponse: Invalid parameters -- dropping message.');
await IncomingMessageCache.removeFromCache(envelope);

@ -204,3 +204,15 @@ export function useMessageCommunityInvitationCommunityName(messageId: string) {
return useMessagePropsByMessageId(messageId)?.propsForGroupInvitation?.serverName;
}
/**
* =========================================
* Below are selectors for call notification
* =========================================
*/
/**
* Return the call notification type linked to the specified message
*/
export function useMessageCallNotificationType(messageId: string) {
return useMessagePropsByMessageId(messageId)?.propsForCallNotification?.notificationType;
}

Loading…
Cancel
Save