diff --git a/src/message/__tests__/messageActionSheet-test.js b/src/message/__tests__/messageActionSheet-test.js
index 4ba396319a9..f8bd398f1ba 100644
--- a/src/message/__tests__/messageActionSheet-test.js
+++ b/src/message/__tests__/messageActionSheet-test.js
@@ -17,6 +17,11 @@ const baseBackgroundData = deepFreeze({
subscriptions: [],
theme: 'default',
twentyFourHourTime: false,
+ realmAllowMessageEditing: eg.action.realm_init.data.realm_allow_message_editing,
+ realmAllowMessageDeleting: eg.action.realm_init.data.realm_allow_message_deleting,
+ realmMessageContentEditLimit: eg.action.realm_init.data.realm_message_content_edit_limit_seconds,
+ realmMessageContentDeleteLimit:
+ eg.action.realm_init.data.realm_message_content_delete_limit_seconds,
});
const buttonTitles = buttons => buttons.map(button => button.title);
diff --git a/src/message/messageActionSheet.js b/src/message/messageActionSheet.js
index 53399ca6aef..d3f6f7dd51a 100644
--- a/src/message/messageActionSheet.js
+++ b/src/message/messageActionSheet.js
@@ -273,19 +273,32 @@ const messageNotDeleted = (message: Message | Outbox): boolean =>
message.content !== '
(deleted)
';
export const constructMessageActionButtons = ({
- backgroundData: { ownUser, flags },
+ backgroundData: {
+ ownUser,
+ flags,
+ realmAllowMessageEditing,
+ realmAllowMessageDeleting,
+ realmMessageContentEditLimit,
+ realmMessageContentDeleteLimit,
+ },
message,
narrow,
}: {
backgroundData: $ReadOnly<{
ownUser: User,
flags: FlagsState,
+ realmAllowMessageEditing: boolean,
+ realmAllowMessageDeleting: boolean,
+ realmMessageContentEditLimit: number,
+ realmMessageContentDeleteLimit: number,
...
}>,
message: Message,
narrow: Narrow,
}): Button[] => {
const buttons = [];
+ const updateMessageTimeLimit = Math.floor(Date.now() / 1000 - message.timestamp);
+
if (messageNotDeleted(message)) {
buttons.push(addReaction);
}
@@ -301,12 +314,24 @@ export const constructMessageActionButtons = ({
}
if (
message.sender_id === ownUser.user_id
+ // if realm allows users to "edit message", show edit option button
+ && realmAllowMessageEditing
// Our "edit message" UI only works in certain kinds of narrows.
- && (isStreamOrTopicNarrow(narrow) || isPmNarrow(narrow))
+ && (isStreamOrTopicNarrow(narrow)
+ || (isPmNarrow(narrow)
+ // if "edit message" time limit exceeds , don't show the edit option button
+ && updateMessageTimeLimit < realmMessageContentEditLimit))
) {
buttons.push(editMessage);
}
- if (message.sender_id === ownUser.user_id && messageNotDeleted(message)) {
+ if (
+ message.sender_id === ownUser.user_id
+ // if realm allows users to "delete message", show delete option button
+ && realmAllowMessageDeleting
+ && messageNotDeleted(message)
+ // if "delete message" time limit exceeds , don't show the delete option button
+ && updateMessageTimeLimit < realmMessageContentDeleteLimit
+ ) {
buttons.push(deleteMessage);
}
if (message.id in flags.starred) {
@@ -326,6 +351,10 @@ export const constructNonHeaderActionButtons = ({
backgroundData: $ReadOnly<{
ownUser: User,
flags: FlagsState,
+ realmAllowMessageEditing: boolean,
+ realmAllowMessageDeleting: boolean,
+ realmMessageContentEditLimit: number,
+ realmMessageContentDeleteLimit: number,
...
}>,
message: Message | Outbox,
@@ -372,6 +401,10 @@ export const showMessageActionSheet = ({
subscriptions: Subscription[],
ownUser: User,
flags: FlagsState,
+ realmAllowMessageEditing: boolean,
+ realmAllowMessageDeleting: boolean,
+ realmMessageContentEditLimit: number,
+ realmMessageContentDeleteLimit: number,
...
}>,
message: Message | Outbox,
diff --git a/src/realm/__tests__/realmReducer-test.js b/src/realm/__tests__/realmReducer-test.js
index 6301911443c..c4ee39ae4e4 100644
--- a/src/realm/__tests__/realmReducer-test.js
+++ b/src/realm/__tests__/realmReducer-test.js
@@ -29,6 +29,10 @@ describe('realmReducer', () => {
filters: [],
videoChatProvider: null,
nonActiveUsers: [],
+ realmAllowMessageEditing: true,
+ realmAllowMessageDeleting: true,
+ realmMessageContentEditLimit: 10,
+ realmMessageContentDeleteLimit: 10,
};
const actualState = realmReducer(initialState, action);
diff --git a/src/realm/realmReducer.js b/src/realm/realmReducer.js
index 52ca6f54a2b..17bbeb03f7e 100644
--- a/src/realm/realmReducer.js
+++ b/src/realm/realmReducer.js
@@ -18,6 +18,10 @@ const initialState = {
filters: [],
emoji: {},
videoChatProvider: null,
+ realmAllowMessageEditing: true,
+ realmAllowMessageDeleting: true,
+ realmMessageContentEditLimit: 10,
+ realmMessageContentDeleteLimit: 10,
email: undefined,
user_id: undefined,
@@ -66,6 +70,10 @@ export default (state: RealmState = initialState, action: Action): RealmState =>
jitsiServerUrl: action.data.jitsi_server_url,
providerId: action.data.realm_video_chat_provider,
}),
+ realmAllowMessageEditing: action.data.realm_allow_message_editing,
+ realmAllowMessageDeleting: action.data.realm_allow_message_deleting,
+ realmMessageContentEditLimit: action.data.realm_message_content_edit_limit_seconds,
+ realmMessageContentDeleteLimit: action.data.realm_message_content_delete_limit_seconds,
email: action.data.email,
user_id: action.data.user_id,
diff --git a/src/reduxTypes.js b/src/reduxTypes.js
index f44d5d7d311..fc5022f675a 100644
--- a/src/reduxTypes.js
+++ b/src/reduxTypes.js
@@ -232,6 +232,10 @@ export type VideoChatProvider = {| name: 'jitsi_meet', jitsiServerUrl: string |}
* @prop videoChatProvider - The video chat provider configured by the
* server; null if none, or if the configured provider is one we don't
* support.
+ * @prop realmAllowMessageEditing - server's permission for "edit message".
+ * @prop realmAllowMessageDeleting - server's permission for "delete message".
+ * @prop realmMessageContentEditLimit - server's timelimit for "edit message".
+ * @prop realmMessageContentDeleteLimit - server's timelimit for "delete message".
*
* About the user:
* @prop email
@@ -247,6 +251,10 @@ export type RealmState = {|
filters: RealmFilter[],
emoji: RealmEmojiById,
videoChatProvider: VideoChatProvider | null,
+ realmAllowMessageEditing: boolean,
+ realmAllowMessageDeleting: boolean,
+ realmMessageContentEditLimit: number,
+ realmMessageContentDeleteLimit: number,
email: string | void,
user_id: UserId | void,
diff --git a/src/webview/MessageList.js b/src/webview/MessageList.js
index d5257882efa..615392cbfd0 100644
--- a/src/webview/MessageList.js
+++ b/src/webview/MessageList.js
@@ -81,6 +81,10 @@ export type BackgroundData = $ReadOnly<{|
subscriptions: Subscription[],
theme: ThemeName,
twentyFourHourTime: boolean,
+ realmAllowMessageEditing: boolean,
+ realmAllowMessageDeleting: boolean,
+ realmMessageContentEditLimit: number,
+ realmMessageContentDeleteLimit: number,
|}>;
type SelectorProps = {|
@@ -357,6 +361,10 @@ export default connect((state, props: OuterProps) => {
subscriptions: getSubscriptions(state),
theme: getSettings(state).theme,
twentyFourHourTime: getRealm(state).twentyFourHourTime,
+ realmAllowMessageEditing: getRealm(state).realmAllowMessageEditing,
+ realmAllowMessageDeleting: getRealm(state).realmAllowMessageDeleting,
+ realmMessageContentEditLimit: getRealm(state).realmMessageContentEditLimit,
+ realmMessageContentDeleteLimit: getRealm(state).realmMessageContentDeleteLimit,
};
return {
diff --git a/src/webview/__tests__/generateInboundEvents-test.js b/src/webview/__tests__/generateInboundEvents-test.js
index 1db52510e0c..af8aa00f7bc 100644
--- a/src/webview/__tests__/generateInboundEvents-test.js
+++ b/src/webview/__tests__/generateInboundEvents-test.js
@@ -19,6 +19,12 @@ describe('generateInboundEvents', () => {
subscriptions: [],
theme: 'default',
twentyFourHourTime: false,
+ realmAllowMessageEditing: eg.action.realm_init.data.realm_allow_message_editing,
+ realmAllowMessageDeleting: eg.action.realm_init.data.realm_allow_message_deleting,
+ realmMessageContentEditLimit:
+ eg.action.realm_init.data.realm_message_content_edit_limit_seconds,
+ realmMessageContentDeleteLimit:
+ eg.action.realm_init.data.realm_message_content_delete_limit_seconds,
});
const baseSelectorProps = deepFreeze({