Skip to content

Commit

Permalink
move eventType logic from advance_create_ to global_actions and chang…
Browse files Browse the repository at this point in the history
…e some parameters name
  • Loading branch information
Ovgodd committed Aug 7, 2024
1 parent 68a02f3 commit b6a5826
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 81 deletions.
17 changes: 13 additions & 4 deletions webapp/channels/src/actions/global_actions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,8 @@ export function sendAddToChannelEphemeralPost(user: UserProfile, addedUsername:
}

let lastTimeTypingSent = 0;
export function emitLocalUserTypingEvent(type = 'typing', channelId: string, parentPostId: string) {
let recordingInterval: ReturnType<typeof setInterval> | null = null;
export function emitLocalUserTypingEvent(eventType = 'typing', channelId: string, parentPostId: string) {
const userTyping: ActionFuncAsync = async (actionDispatch, actionGetState) => {
const state = actionGetState();
const config = getConfig(state);
Expand All @@ -237,15 +238,23 @@ export function emitLocalUserTypingEvent(type = 'typing', channelId: string, par
const timeBetweenUserTypingUpdatesMilliseconds = Utils.stringToNumber(config.TimeBetweenUserTypingUpdatesMilliseconds);
const maxNotificationsPerChannel = Utils.stringToNumber(config.MaxNotificationsPerChannel);

if (type === 'typing') {
if (eventType === 'typing') {
if (((t - lastTimeTypingSent) > timeBetweenUserTypingUpdatesMilliseconds) &&
(membersInChannel < maxNotificationsPerChannel) && (config.EnableUserTypingMessages === 'true')) {
WebSocketClient.userTyping(channelId, userId, parentPostId);
lastTimeTypingSent = t;
}
} else if (type === 'recording') {
WebSocketClient.userRecording(channelId, userId, parentPostId);
} else if (eventType === 'recording') {
const TIMER = 1000;
recordingInterval = setInterval(() => {
WebSocketClient.userRecording(channelId, userId, parentPostId);
}, TIMER);
} else if (eventType === 'stop') {
if (recordingInterval !== null) {
clearInterval(recordingInterval);
}
}

return {data: true};
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,6 @@ class AdvancedCreateComment extends React.PureComponent<Props, State> {
private isDraftEdited = false;
private isNonFormattedPaste = false;
private timeoutId: number | null = null;
private recordingInterval: ReturnType<typeof setInterval> | null = null;

private readonly textboxRef: React.RefObject<TextboxClass>;
private readonly fileUploadRef: React.RefObject<FileUploadClass>;
Expand Down Expand Up @@ -315,7 +314,6 @@ class AdvancedCreateComment extends React.PureComponent<Props, State> {
if (this.timeoutId !== null) {
clearTimeout(this.timeoutId);
}
this.stopRecordingEvent();
}

componentDidUpdate(prevProps: Props, prevState: State) {
Expand Down Expand Up @@ -768,36 +766,9 @@ class AdvancedCreateComment extends React.PureComponent<Props, State> {
emitShortcutReactToLastPostFrom(Locations.RHS_ROOT);
};

// infomaniak
emitTypingEvent = (type = 'typing') => {
emitTypingEvent = (eventType = 'typing') => {
const {channelId, rootId} = this.props;
switch (type) {
case 'typing':
GlobalActions.emitLocalUserTypingEvent('typing', channelId, rootId);
break;
case 'recording':
this.emitRecordingEvent();
break;
case 'stop':
this.stopRecordingEvent();
break;
default:
break;
}
};

emitRecordingEvent = () => {
const TIMER = 1000;
this.recordingInterval = setInterval(() => {
const {channelId, rootId} = this.props;
GlobalActions.emitLocalUserTypingEvent('recording', channelId, rootId);
}, TIMER);
};

stopRecordingEvent = () => {
if (this.recordingInterval !== null) {
clearInterval(this.recordingInterval);
}
GlobalActions.emitLocalUserTypingEvent(eventType, channelId, rootId);
};

handleChange = (e: React.ChangeEvent<TextboxElement>) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,6 @@ class AdvancedCreatePost extends React.PureComponent<Props, State> {
private isDraftSubmitting = false;
private isNonFormattedPaste = false;
private timeoutId: number | null = null;
private recordingInterval: ReturnType<typeof setInterval> | null = null;

private topDiv: React.RefObject<HTMLFormElement>;
private textboxRef: React.RefObject<TextboxClass>;
Expand Down Expand Up @@ -366,7 +365,6 @@ class AdvancedCreatePost extends React.PureComponent<Props, State> {
if (this.timeoutId !== null) {
clearTimeout(this.timeoutId);
}
this.stopRecordingEvent();
}

getChannelMemberCountsByGroup = () => {
Expand Down Expand Up @@ -903,36 +901,9 @@ class AdvancedCreatePost extends React.PureComponent<Props, State> {
this.emitTypingEvent();
};

// infomaniak
emitTypingEvent = (type = 'typing') => {
emitTypingEvent = (eventType = 'typing') => {
const channelId = this.props.currentChannel.id;
switch (type) {
case 'typing':
GlobalActions.emitLocalUserTypingEvent('typing', channelId, '');
break;
case 'recording':
this.emitRecordingEvent();
break;
case 'stop':
this.stopRecordingEvent();
break;
default:
break;
}
};

emitRecordingEvent = () => {
const TIMER = 1000;
this.recordingInterval = setInterval(() => {
const channelId = this.props.currentChannel.id;
GlobalActions.emitLocalUserTypingEvent('recording', channelId, '');
}, TIMER);
};

stopRecordingEvent = () => {
if (this.recordingInterval !== null) {
clearInterval(this.recordingInterval);
}
GlobalActions.emitLocalUserTypingEvent(eventType, channelId, '');
};

setDraftAsPostType = (channelId: Channel['id'], draft: PostDraft, postType?: PostDraft['postType']) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ type Props = {
enableGifPicker: boolean;
handleBlur: () => void;
handlePostError: (postError: React.ReactNode) => void;
emitTypingEvent: (type: string) => void;
emitTypingEvent: (eventType: string) => void;
handleMouseUpKeyUp: (e: React.MouseEvent<TextboxElement> | React.KeyboardEvent<TextboxElement>) => void;
postMsgKeyPress: (e: React.KeyboardEvent<TextboxElement>) => void;
handleChange: (e: React.ChangeEvent<TextboxElement>) => void;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ import {convertSecondsToMSS} from 'utils/datetime';

interface Props {
theme: Theme;
onCancel: (type: string) => void;
onComplete: (audioFile: File, type: string) => Promise<void>;
onStarted: (type: string) => void;
onCancel: (eventType: string) => void;
onComplete: (audioFile: File, eventType: string) => Promise<void>;
onStarted: (eventType: string) => void;
}

function VoiceMessageRecordingStarted(props: Props) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ interface Props {
onUploadError: (err: string | ServerError, clientId?: string, channelId?: Channel['id'], rootId?: Post['id']) => void;
onRemoveDraft: (fileInfoIdOrClientId: FileInfo['id'] | string) => void;
onSubmit: (e: FormEvent<Element>) => void;
onComplete: (type: string) => void;
onCancel: (type: string) => void;
onStarted: (type: string) => void;
onComplete: (eventType: string) => void;
onCancel: (eventType: string) => void;
onStarted: (eventType: string) => void;
}

const VoiceMessageAttachment = (props: Props) => {
Expand Down
9 changes: 4 additions & 5 deletions webapp/channels/src/components/msg_typing/msg_typing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ export default function MsgTyping(props: Props) {
userStartedRecording(userId, channelId, rootId, Date.now());
break;
default:
throw new Error('no SocketEvents found');
break;
}
} else if (msg.event === SocketEvents.POSTED) {
Expand All @@ -56,12 +55,12 @@ export default function MsgTyping(props: Props) {
userStoppedRecording]),
});

const getInputText = (users: string[], type = 'typing') => {
const getInputText = (users: string[], eventType = 'typing') => {
const numUsers = users.length;
if (numUsers === 0) {
return '';
}
const {simpleMessage, multipleMessage, defaultSimpleMessage, defaultMultipleMessage} = getMessages(type);
const {simpleMessage, multipleMessage, defaultSimpleMessage, defaultMultipleMessage} = getMessages(eventType);

if (numUsers === 1) {
return (
Expand All @@ -87,8 +86,8 @@ export default function MsgTyping(props: Props) {
);
};

const getMessages = (type = 'typing') => {
switch (type) {
const getMessages = (eventType = 'typing') => {
switch (eventType) {
case 'typing':
return {
simpleMessage: 'msg_typing.isTyping',
Expand Down
2 changes: 1 addition & 1 deletion webapp/channels/src/components/textbox/textbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export type Props = {
value: string;
onChange: (e: ChangeEvent<TextboxElement>) => void;
onKeyPress: (e: KeyboardEvent<any>) => void;
onComposition?: (type: 'typing' | 'recording' | 'stop') => void; // infomaniak
onComposition?: (eventType: 'typing' | 'recording' | 'stop') => void; // infomaniak
onHeightChange?: (height: number, maxHeight: number) => void;
onWidthChange?: (width: number) => void;
createMessage: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ const getUsersTypingImpl = (profiles: IDMappedObjects<UserProfile>, teammateName
return [];
};

export function makeGetUsersTypingByChannelAndPost(type: 'typing' | 'recording' = 'typing'): (state: GlobalState, props: {channelId: string; postId: string}) => string[] {
export function makeGetUsersTypingByChannelAndPost(eventType: 'typing' | 'recording' = 'typing'): (state: GlobalState, props: {channelId: string; postId: string}) => string[] {
return createSelector(
'makeGetUsersTypingByChannelAndPost',
getUsers,
getTeammateNameDisplaySetting,
(state: GlobalState, options: {channelId: string; postId: string}) => options.channelId,
(state: GlobalState, options: {channelId: string; postId: string}) => options.postId,
(state: GlobalState) => state.entities[type],
(state: GlobalState) => state.entities[eventType],
getUsersTypingImpl,
);
}

0 comments on commit b6a5826

Please sign in to comment.