Skip to content
This repository has been archived by the owner on Nov 24, 2022. It is now read-only.

Provide signed messageId when removing message by Id #286

Merged
merged 2 commits into from
Sep 23, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 29 additions & 24 deletions src/containers/MessageView/MessageView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class MessageView extends React.Component<Props, State> {

private onDeleteMessage(message: IMessageOutput): void {
const { currentMessage } = this.state
const { selectedIdentity } = this.props

if (!message.messageId) {
return
Expand All @@ -65,31 +66,35 @@ class MessageView extends React.Component<Props, State> {
this.fetchMessages()
})
}

safeDelete(
<span>
the message &apos;
<MessageSubject message={message} />
&apos; from{' '}
<ContactPresentation address={message.senderAddress} inline />
</span>,
(notification: IBlockingNotification) => {
MessageRepository.deleteByMessageId(message.messageId as string)
.then(() => {
this.fetchMessages()
notification.remove()
})
.catch(error => {
errorService.log({
error,
message: `Could not delete message ${message.messageId}`,
origin: 'MessageView.onDeleteMessage()',
type: 'ERROR.FETCH.DELETE',
if (selectedIdentity) {
safeDelete(
<span>
the message &apos;
<MessageSubject message={message} />
&apos; from{' '}
<ContactPresentation address={message.senderAddress} inline />
</span>,
(notification: IBlockingNotification) => {
MessageRepository.deleteByMessageId(
message.messageId as string,
selectedIdentity.identity.signStr(message.messageId as string)
Copy link
Contributor

@tjwelde tjwelde Sep 23, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If messageId is a number, you can apply toString instead of using as

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

messageId is string | undefined
we previously returned on !messageId, now we check for existence and do a non-null assertion

)
.then(() => {
this.fetchMessages()
notification.remove()
})
})
},
false
)
.catch(error => {
errorService.log({
error,
message: `Could not delete message ${message.messageId}`,
origin: 'MessageView.onDeleteMessage()',
type: 'ERROR.FETCH.DELETE',
})
})
},
false
)
}
}

private onOpenMessage(message: IMessageOutput): void {
Expand Down
6 changes: 5 additions & 1 deletion src/services/MessageRepository.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,13 @@ class MessageRepository {
.then(() => undefined)
}

public static async deleteByMessageId(messageId: string): Promise<Response> {
public static async deleteByMessageId(
messageId: string,
signature: string
): Promise<Response> {
return fetch(`${MessageRepository.URL}/${messageId}`, {
...BaseDeleteParams,
headers: { ...BaseDeleteParams.headers, signature },
})
}

Expand Down