Skip to content

Commit 4d72839

Browse files
committed
message: Add feature to view edit history.
Creates a component 'EditHistory' that renders a webview to show the edit history of a message. This webview is non-interactive - the user can select/copy message contents, but can not interact with them - like open links/navigate to narrows etc. Fixes: #4134
1 parent 169ec59 commit 4d72839

File tree

5 files changed

+100
-1
lines changed

5 files changed

+100
-1
lines changed

src/message/EditHistory.js

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/* @flow strict-local */
2+
3+
import React from 'react';
4+
import { View } from 'react-native';
5+
import type { NavigationScreenProp } from 'react-navigation';
6+
import type { Dispatch, Auth, ThemeName, UserOrBot } from '../types';
7+
import SpinningProgress from '../common/SpinningProgress';
8+
import type { MessageSnapshot } from '../api/modelTypes';
9+
import { connect } from '../react-redux';
10+
import { getAuth, getAllUsersById } from '../selectors';
11+
import { Screen, WebView } from '../common';
12+
import * as api from '../api';
13+
import editHistoryHtml from '../webview/html/editHistoryHtml';
14+
15+
type SelectorProps = {|
16+
auth: Auth,
17+
usersById: Map<number, UserOrBot>,
18+
|};
19+
20+
type Props = $ReadOnly<{|
21+
navigation: NavigationScreenProp<{ params: {| messageId: number, theme: ThemeName |} }>,
22+
23+
dispatch: Dispatch,
24+
...SelectorProps,
25+
|}>;
26+
27+
type State = $ReadOnly<{|
28+
messageHistory: MessageSnapshot[] | null,
29+
|}>;
30+
31+
class EditHistory extends React.Component<Props, State> {
32+
state = {
33+
messageHistory: null,
34+
};
35+
36+
async componentDidMount() {
37+
const { auth, navigation } = this.props;
38+
39+
this.setState({
40+
messageHistory: (await api.getMessageHistory(auth, navigation.state.params.messageId))
41+
.message_history,
42+
});
43+
}
44+
45+
render() {
46+
const { messageHistory } = this.state;
47+
48+
if (messageHistory === null) {
49+
return (
50+
<Screen title="Edit History">
51+
<View style={{ justifyContent: 'center', alignItems: 'center', flex: 1 }}>
52+
<SpinningProgress color="white" size={48} />
53+
</View>
54+
</Screen>
55+
);
56+
}
57+
const { usersById, auth } = this.props;
58+
const theme = this.props.navigation.state.params.theme;
59+
60+
return (
61+
<Screen title="Edit History">
62+
<WebView
63+
html={editHistoryHtml(messageHistory, theme, usersById, auth)}
64+
onError={(msg: mixed) => {
65+
// eslint-disable-next-line no-console
66+
console.error(msg);
67+
}}
68+
/>
69+
</Screen>
70+
);
71+
}
72+
}
73+
74+
export default connect<SelectorProps, _, _>((state, props) => ({
75+
auth: getAuth(state),
76+
usersById: getAllUsersById(state),
77+
}))(EditHistory);

src/message/messageActionSheet.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import { isTopicMuted } from '../utils/message';
2222
import * as api from '../api';
2323
import { showToast } from '../utils/info';
2424
import { doNarrow, deleteOutboxMessage, navigateToEmojiPicker } from '../actions';
25-
import { navigateToMessageReactionScreen } from '../nav/navActions';
25+
import { navigateToMessageReactionScreen, navigateToEditHistory } from '../nav/navActions';
2626
import { pmUiRecipientsFromMessage } from '../utils/recipient';
2727
import { deleteMessagesForTopic } from '../topics/topicActions';
2828
import * as logging from '../utils/logging';
@@ -41,6 +41,7 @@ type ButtonDescription = {
4141
ownEmail: string,
4242
message: Message | Outbox,
4343
subscriptions: Subscription[],
44+
backgroundData: BackgroundData,
4445
dispatch: Dispatch,
4546
_: GetText,
4647
startEditMessage: (editMessage: EditMessage) => void,
@@ -200,6 +201,12 @@ const showReactions = ({ message, dispatch }) => {
200201
showReactions.title = 'See who reacted';
201202
showReactions.errorMessage = 'Failed to show reactions';
202203

204+
const editHistory = ({ message, dispatch, backgroundData }) => {
205+
dispatch(navigateToEditHistory(message.id, backgroundData.theme));
206+
};
207+
editHistory.title = 'Show edit history';
208+
editHistory.errorMessage = 'Failed to show edit history';
209+
203210
const cancel = params => {};
204211
cancel.title = 'Cancel';
205212
cancel.errorMessage = 'Failed to hide menu';
@@ -215,6 +222,7 @@ const allButtonsRaw = {
215222
starMessage,
216223
unstarMessage,
217224
showReactions,
225+
editHistory,
218226

219227
// For headers
220228
unmuteTopic,
@@ -316,6 +324,11 @@ export const constructMessageActionButtons = ({
316324
} else {
317325
buttons.push('starMessage');
318326
}
327+
328+
if (message.last_edit_timestamp !== undefined) {
329+
buttons.push('editHistory');
330+
}
331+
319332
buttons.push('cancel');
320333
return buttons;
321334
};

src/nav/AppNavigator.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import TopicListScreen from '../topics/TopicListScreen';
3131
import EmojiPickerScreen from '../emoji/EmojiPickerScreen';
3232
import LegalScreen from '../settings/LegalScreen';
3333
import UserStatusScreen from '../user-status/UserStatusScreen';
34+
import EditHistory from '../message/EditHistory';
3435

3536
export default createStackNavigator(
3637
// $FlowFixMe react-navigation types :-/ -- see a36814e80
@@ -45,6 +46,7 @@ export default createStackNavigator(
4546
loading: { screen: LoadingScreen },
4647
main: { screen: MainScreenWithTabs },
4748
'message-reactions': { screen: MessageReactionList },
49+
'edit-history': { screen: EditHistory },
4850
password: { screen: PasswordAuthScreen },
4951
realm: { screen: RealmScreen },
5052
search: { screen: SearchMessagesScreen },

src/nav/navActions.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import type {
99
Narrow,
1010
UserOrBot,
1111
ApiResponseServerSettings,
12+
ThemeName,
1213
} from '../types';
1314
import { getSameRoutesCount } from '../selectors';
1415

@@ -99,6 +100,9 @@ export const navigateToMessageReactionScreen = (
99100
): NavigationAction =>
100101
StackActions.push({ routeName: 'message-reactions', params: { messageId, reactionName } });
101102

103+
export const navigateToEditHistory = (messageId: number, theme: ThemeName): NavigationAction =>
104+
StackActions.push({ routeName: 'edit-history', params: { messageId, theme } });
105+
102106
export const navigateToLegal = (): NavigationAction => StackActions.push({ routeName: 'legal' });
103107

104108
export const navigateToUserStatus = (): NavigationAction =>

static/translations/messages_en.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,8 @@
135135
"Share": "Share",
136136
"Star message": "Star message",
137137
"Unstar message": "Unstar message",
138+
"Show edit history": "Show edit history",
139+
"Failed to show edit history": "Failed to show edit history",
138140
"Cancel": "Cancel",
139141
"Message copied": "Message copied",
140142
"Edit message": "Edit message",
@@ -183,6 +185,7 @@
183185
"Please download the image from your browser": "Please download the image from your browser",
184186
"Can not download": "Can not download",
185187
"Download file": "Download file",
188+
"Edit History": "Edit History",
186189
"Update": "Update",
187190
"Save": "Save",
188191
"Pinned": "Pinned",

0 commit comments

Comments
 (0)