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

Commit

Permalink
Provide signed messageId when removing message by Id (#286)
Browse files Browse the repository at this point in the history
* chore: updated delete by Id request format with signature authorization

* fix: messageId existence check
  • Loading branch information
LeonFLK authored Sep 23, 2020
1 parent 18ae521 commit 95d3b66
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 29 deletions.
58 changes: 30 additions & 28 deletions src/containers/MessageView/MessageView.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-non-null-assertion */
import React from 'react'
import { connect, MapStateToProps } from 'react-redux'
import ContactPresentation from '../../components/ContactPresentation/ContactPresentation'
Expand Down Expand Up @@ -54,42 +55,43 @@ class MessageView extends React.Component<Props, State> {

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

if (!message.messageId) {
return
}
const { selectedIdentity } = this.props

if (currentMessage) {
this.onCloseMessage()
setTimeout(() => {
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 && message.messageId) {
safeDelete(
<span>
the message &apos;
<MessageSubject message={message} />
&apos; from{' '}
<ContactPresentation address={message.senderAddress} inline />
</span>,
(notification: IBlockingNotification) => {
MessageRepository.deleteByMessageId(
message.messageId!,
selectedIdentity.identity.signStr(message.messageId!)
)
.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

0 comments on commit 95d3b66

Please sign in to comment.