Skip to content

Commit

Permalink
Merge pull request #3005 from serge-web/3004_store_previous_collab_me…
Browse files Browse the repository at this point in the history
…ssage

Store previous version of message, if edited.
  • Loading branch information
IanMayo authored Oct 18, 2024
2 parents bc876c5 + d7012f0 commit 1acf347
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react'
import { ForceRole, FeedbackItem, MessageCustom, ChannelCollab } from 'src/custom-types'
import { ForceRole, FeedbackItem, MessageCustom, ChannelCollab, MessageStructure } from 'src/custom-types'

/* Import Icons */
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
Expand All @@ -9,6 +9,7 @@ import { expiredStorage } from 'src/config'
import { formatFullDate } from 'src/Helpers'
/* Import Stylesheet */
import styles from '../styles.module.scss'
import * as jsonpatch from 'fast-json-patch'

export type ModalHandlerFn = (message: MessageCustom) => void

Expand Down Expand Up @@ -96,17 +97,20 @@ export const CollapsedFeedbackList = ({ onExpand, collapsed, feedback }: {onExpa
)
}

export const injectFeedback = (message: MessageCustom, verb: string, feedback: string, role: ForceRole): MessageCustom => {
export const injectFeedback = (message: MessageCustom, verb: string, feedback: string, role: ForceRole, previous?: MessageStructure): MessageCustom => {
const verbStr = '[' + verb + '] '
const withFeedback = verbStr + (feedback || '')
// put message into feedback item
// is the new message different to the previous one?
const messageChanged = previous && JSON.stringify(message.message) !== JSON.stringify(previous)
const feedbackItem: FeedbackItem =
{
fromId: role.roleId,
fromName: role.roleName,
fromForce: role.forceName,
date: new Date().toISOString(),
feedback: withFeedback
feedback: withFeedback,
...(messageChanged && { revert: jsonpatch.compare(message.message, previous) })
}
if (message.details.collaboration) {
if (!message.details.collaboration.feedback) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ export const CollabMessageDetail: React.FC<Props> = ({
// different handling depending upon if it's a response that's being sent
const updatedPart = isResponse ? answer : newMsg
const changed = handler(role, verb, message, updatedPart, privateMessage)
const withFeedback = injectFeedback(changed, verb, '', role)
const withFeedback = injectFeedback(changed, verb, '', role, message.message)
handleChange(withFeedback, true)
}

Expand Down
2 changes: 2 additions & 0 deletions client/src/custom-types/message.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ export interface FeedbackItem {
readonly date: string
/** the feedback */
readonly feedback: string
/** deltas to get to the previous version */
readonly revert?: jsonpath.Operation[]
}

/** data for a message that is being
Expand Down

0 comments on commit 1acf347

Please sign in to comment.