Skip to content

Commit

Permalink
background data: Handle edit,delete message realm data
Browse files Browse the repository at this point in the history
Handle the actual edit,delete message realm data as
follows:

* Import realm permission,timelimit data for edit,delete
  message into `realmReducer` from `initalDatatypes`.Handle
  types for them in `reduxTypes`.

* Add all new realm data in `BackgroundData` in `MessageList`.

* Handle the `backgroundData` params in `messageActionsheet`.

* Add all the new realm data in `baseBackgroundData` in test
  files : `messageActionSheet-test`,`generateInboundEvents-test`
  and to `expectedState` in `realmReducer-test` file.

Fixes: zulip#2792
Fixes: zulip#2793
Signed-off-by: rajprakash00 <rajprakash1999@gmail.com>
  • Loading branch information
rajprakash00 committed May 2, 2021
1 parent 126c56f commit 37b402f
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/message/__tests__/messageActionSheet-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
39 changes: 36 additions & 3 deletions src/message/messageActionSheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,19 +273,32 @@ const messageNotDeleted = (message: Message | Outbox): boolean =>
message.content !== '<p>(deleted)</p>';

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<MessageArgs>[] => {
const buttons = [];
const updateMessageTimeLimit = Math.floor(Date.now() / 1000 - message.timestamp);

if (messageNotDeleted(message)) {
buttons.push(addReaction);
}
Expand All @@ -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) {
Expand All @@ -326,6 +351,10 @@ export const constructNonHeaderActionButtons = ({
backgroundData: $ReadOnly<{
ownUser: User,
flags: FlagsState,
realmAllowMessageEditing: boolean,
realmAllowMessageDeleting: boolean,
realmMessageContentEditLimit: number,
realmMessageContentDeleteLimit: number,
...
}>,
message: Message | Outbox,
Expand Down Expand Up @@ -372,6 +401,10 @@ export const showMessageActionSheet = ({
subscriptions: Subscription[],
ownUser: User,
flags: FlagsState,
realmAllowMessageEditing: boolean,
realmAllowMessageDeleting: boolean,
realmMessageContentEditLimit: number,
realmMessageContentDeleteLimit: number,
...
}>,
message: Message | Outbox,
Expand Down
4 changes: 4 additions & 0 deletions src/realm/__tests__/realmReducer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ describe('realmReducer', () => {
filters: [],
videoChatProvider: null,
nonActiveUsers: [],
realmAllowMessageEditing: true,
realmAllowMessageDeleting: true,
realmMessageContentEditLimit: 10,
realmMessageContentDeleteLimit: 10,
};

const actualState = realmReducer(initialState, action);
Expand Down
8 changes: 8 additions & 0 deletions src/realm/realmReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ const initialState = {
filters: [],
emoji: {},
videoChatProvider: null,
realmAllowMessageEditing: true,
realmAllowMessageDeleting: true,
realmMessageContentEditLimit: 10,
realmMessageContentDeleteLimit: 10,

email: undefined,
user_id: undefined,
Expand Down Expand Up @@ -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,
Expand Down
8 changes: 8 additions & 0 deletions src/reduxTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,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
Expand All @@ -250,6 +254,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,
Expand Down
8 changes: 8 additions & 0 deletions src/webview/MessageList.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ export type BackgroundData = $ReadOnly<{|
subscriptions: Subscription[],
theme: ThemeName,
twentyFourHourTime: boolean,
realmAllowMessageEditing: boolean,
realmAllowMessageDeleting: boolean,
realmMessageContentEditLimit: number,
realmMessageContentDeleteLimit: number,
|}>;

type SelectorProps = {|
Expand Down Expand Up @@ -363,6 +367,10 @@ export default connect<SelectorProps, _, _>((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 {
Expand Down
6 changes: 6 additions & 0 deletions src/webview/__tests__/generateInboundEvents-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,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({
Expand Down

0 comments on commit 37b402f

Please sign in to comment.