Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
d05f909
Trying to properly place suggestions container
diegolmello Jun 27, 2023
ae3524e
Autocomplete apparently being correctly absolute placed on top of the…
diegolmello Jun 29, 2023
d43cf4a
AutocompleteType
diegolmello Jun 29, 2023
2a726bc
lastWord vs autocompleteText
diegolmello Jun 29, 2023
ae61c8f
stopAutocomplete()
diegolmello Jun 29, 2023
bb31393
Small useAutocomplete hook plan
diegolmello Jun 29, 2023
5c24413
Fix Autocomplete tap and start tracking keyboard height
diegolmello Jun 29, 2023
4aee6d5
AutocompleteItem base
diegolmello Jun 29, 2023
12f3cb7
Temp shadow
diegolmello Jun 29, 2023
f95c214
Applying values to item
diegolmello Jun 29, 2023
a966fc6
Autocomplete autocompleting
diegolmello Jun 29, 2023
06b3c35
Fix some types and use actual data
diegolmello Jun 29, 2023
9fd0a27
Lint and tests
diegolmello Jun 29, 2023
4a62217
Lint
diegolmello Jun 29, 2023
a67baf7
Add not in channel
diegolmello Jun 29, 2023
4ef7eb1
Fix input losing focus on autocomplete press
diegolmello Jun 30, 2023
618e9d1
Temp make shadow more visible
diegolmello Jun 30, 2023
afd4412
Stash Icon. Check search issues later.
diegolmello Jun 30, 2023
3497f20
Status/index fetching presence
diegolmello Jul 21, 2023
bd49874
Fix other RoomTypeIcon usage
diegolmello Jul 21, 2023
c911f3b
Fix types
diegolmello Jul 21, 2023
e0393e4
Fix reconnection
diegolmello Jul 21, 2023
9b79b63
Update RoomItem stories to match OmnichannelStatus
diegolmello Jul 21, 2023
6b8f7d9
RoomTypeIcon stories
diegolmello Jul 21, 2023
828d3e4
Status stories
diegolmello Jul 21, 2023
a933010
Fix RoomHeader types
diegolmello Jul 21, 2023
c215ffc
Minor fixes
diegolmello Jul 25, 2023
c2360df
Merge branch 'feat.new-composer' into feat.new-composer-suggestions
diegolmello Jul 25, 2023
6b7315e
Merge branch 'feat.status' into feat.new-composer-suggestions
diegolmello Jul 25, 2023
06a34fa
Autocomplete status
diegolmello Jul 25, 2023
25f3949
Fix spotlight duplicating users
diegolmello Jul 25, 2023
74cfa31
Fix room avatar and type icons
diegolmello Jul 26, 2023
6c80130
AutocompleteEmoji
diegolmello Jul 26, 2023
e1fafcd
Slash command base
diegolmello Jul 26, 2023
126d974
Slash command preview starting to work
diegolmello Jul 27, 2023
d177b51
Canned responses
diegolmello Jul 27, 2023
34856d8
@all and @here
diegolmello Jul 27, 2023
3350af5
Loading item
diegolmello Jul 27, 2023
c847e65
Cleanup
diegolmello Jul 27, 2023
191fe8b
Not in channel i18n
diegolmello Jul 27, 2023
5a43add
Prevent duplicated loading
diegolmello Jul 27, 2023
cc8a2c7
No canned responses behavior
diegolmello Jul 28, 2023
a7aeaa7
Minor refactor
diegolmello Jul 28, 2023
b9c59eb
Skeleton on slash command preview
diegolmello Jul 31, 2023
002021a
Comment some code
diegolmello Jul 31, 2023
9cb518c
mitt
diegolmello Jul 31, 2023
7fde7fe
Cleanup
diegolmello Aug 1, 2023
bacadba
i18n for core commands
diegolmello Aug 1, 2023
dd62282
Execute slash command
diegolmello Aug 1, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .storybook/storybook.requires.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ const getStories = () => {
require("../app/containers/ReactionsList/ReactionsList.stories.tsx"),
require("../app/containers/RoomHeader/RoomHeader.stories.tsx"),
require("../app/containers/RoomItem/RoomItem.stories.tsx"),
require("../app/containers/RoomTypeIcon/RoomTypeIcon.stories.tsx"),
require("../app/containers/SearchBox/SearchBox.stories.tsx"),
require("../app/containers/ServerItem/ServerItem.stories.tsx"),
require("../app/containers/Status/Status.stories.tsx"),
require("../app/containers/TextInput/TextInput.stories.tsx"),
require("../app/containers/UIKit/UiKitMessage.stories.tsx"),
require("../app/containers/UIKit/UiKitModal.stories.tsx"),
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Storyshots RoomTypeIcon All 1`] = `"[{\\"type\\":\\"Text\\",\\"props\\":{\\"selectable\\":false,\\"allowFontScaling\\":false,\\"style\\":[{\\"fontSize\\":30,\\"color\\":\\"#cbced1\\"},[{\\"width\\":30,\\"height\\":30,\\"textAlignVertical\\":\\"center\\"},[{\\"marginRight\\":4},null]],{\\"fontFamily\\":\\"custom\\",\\"fontWeight\\":\\"normal\\",\\"fontStyle\\":\\"normal\\"},{}]},\\"children\\":[\\"\\"]},{\\"type\\":\\"Text\\",\\"props\\":{\\"selectable\\":false,\\"allowFontScaling\\":false,\\"style\\":[{\\"fontSize\\":30,\\"color\\":\\"#2de0a5\\"},[{\\"width\\":30,\\"height\\":30,\\"textAlignVertical\\":\\"center\\"},[{\\"marginRight\\":4},null]],{\\"fontFamily\\":\\"custom\\",\\"fontWeight\\":\\"normal\\",\\"fontStyle\\":\\"normal\\"},{}]},\\"children\\":[\\"\\"]},{\\"type\\":\\"Text\\",\\"props\\":{\\"selectable\\":false,\\"allowFontScaling\\":false,\\"style\\":[{\\"fontSize\\":30,\\"color\\":\\"#0d0e12\\"},[{\\"marginRight\\":4},null],{\\"fontFamily\\":\\"custom\\",\\"fontWeight\\":\\"normal\\",\\"fontStyle\\":\\"normal\\"},{}]},\\"children\\":[\\"\\"]},{\\"type\\":\\"Text\\",\\"props\\":{\\"selectable\\":false,\\"allowFontScaling\\":false,\\"style\\":[{\\"fontSize\\":30,\\"color\\":\\"#0d0e12\\"},[{\\"marginRight\\":4},null],{\\"fontFamily\\":\\"custom\\",\\"fontWeight\\":\\"normal\\",\\"fontStyle\\":\\"normal\\"},{}]},\\"children\\":[\\"\\"]},{\\"type\\":\\"Text\\",\\"props\\":{\\"selectable\\":false,\\"allowFontScaling\\":false,\\"style\\":[{\\"fontSize\\":30,\\"color\\":\\"#0d0e12\\"},[{\\"marginRight\\":4},null],{\\"fontFamily\\":\\"custom\\",\\"fontWeight\\":\\"normal\\",\\"fontStyle\\":\\"normal\\"},{}]},\\"children\\":[\\"\\"]},{\\"type\\":\\"Text\\",\\"props\\":{\\"selectable\\":false,\\"allowFontScaling\\":false,\\"style\\":[{\\"fontSize\\":30,\\"color\\":\\"#0d0e12\\"},[{\\"marginRight\\":4},null],{\\"fontFamily\\":\\"custom\\",\\"fontWeight\\":\\"normal\\",\\"fontStyle\\":\\"normal\\"},{}]},\\"children\\":[\\"\\"]},{\\"type\\":\\"Text\\",\\"props\\":{\\"selectable\\":false,\\"allowFontScaling\\":false,\\"style\\":[{\\"fontSize\\":30,\\"color\\":\\"#0d0e12\\"},[{\\"marginRight\\":4},null],{\\"fontFamily\\":\\"custom\\",\\"fontWeight\\":\\"normal\\",\\"fontStyle\\":\\"normal\\"},{}]},\\"children\\":[\\"\\"]},{\\"type\\":\\"Text\\",\\"props\\":{\\"selectable\\":false,\\"allowFontScaling\\":false,\\"style\\":[{\\"fontSize\\":30,\\"color\\":\\"#0d0e12\\"},[{\\"marginRight\\":4},null],{\\"fontFamily\\":\\"custom\\",\\"fontWeight\\":\\"normal\\",\\"fontStyle\\":\\"normal\\"},{}]},\\"children\\":[\\"\\"]},{\\"type\\":\\"Text\\",\\"props\\":{\\"selectable\\":false,\\"allowFontScaling\\":false,\\"style\\":[{\\"fontSize\\":30,\\"color\\":\\"#ffd21f\\"},[{\\"marginRight\\":4},null],{\\"fontFamily\\":\\"custom\\",\\"fontWeight\\":\\"normal\\",\\"fontStyle\\":\\"normal\\"},{}]},\\"children\\":[\\"\\"]},{\\"type\\":\\"Text\\",\\"props\\":{\\"selectable\\":false,\\"allowFontScaling\\":false,\\"style\\":[{\\"fontSize\\":30,\\"color\\":\\"#0d0e12\\"},[{\\"marginRight\\":4},{\\"margin\\":10}],{\\"fontFamily\\":\\"custom\\",\\"fontWeight\\":\\"normal\\",\\"fontStyle\\":\\"normal\\"},{}]},\\"children\\":[\\"\\"]}]"`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Storyshots Status All 1`] = `"[{\\"type\\":\\"Text\\",\\"props\\":{\\"selectable\\":false,\\"allowFontScaling\\":false,\\"style\\":[{\\"fontSize\\":32,\\"color\\":\\"#2de0a5\\"},[{\\"width\\":32,\\"height\\":32,\\"textAlignVertical\\":\\"center\\"},null],{\\"fontFamily\\":\\"custom\\",\\"fontWeight\\":\\"normal\\",\\"fontStyle\\":\\"normal\\"},{}]},\\"children\\":[\\"\\"]},{\\"type\\":\\"Text\\",\\"props\\":{\\"selectable\\":false,\\"allowFontScaling\\":false,\\"style\\":[{\\"fontSize\\":32,\\"color\\":\\"#f5455c\\"},[{\\"width\\":32,\\"height\\":32,\\"textAlignVertical\\":\\"center\\"},null],{\\"fontFamily\\":\\"custom\\",\\"fontWeight\\":\\"normal\\",\\"fontStyle\\":\\"normal\\"},{}]},\\"children\\":[\\"\\"]},{\\"type\\":\\"Text\\",\\"props\\":{\\"selectable\\":false,\\"allowFontScaling\\":false,\\"style\\":[{\\"fontSize\\":32,\\"color\\":\\"#ffd21f\\"},[{\\"width\\":32,\\"height\\":32,\\"textAlignVertical\\":\\"center\\"},null],{\\"fontFamily\\":\\"custom\\",\\"fontWeight\\":\\"normal\\",\\"fontStyle\\":\\"normal\\"},{}]},\\"children\\":[\\"\\"]},{\\"type\\":\\"Text\\",\\"props\\":{\\"selectable\\":false,\\"allowFontScaling\\":false,\\"style\\":[{\\"fontSize\\":32,\\"color\\":\\"#9ea2a8\\"},[{\\"width\\":32,\\"height\\":32,\\"textAlignVertical\\":\\"center\\"},null],{\\"fontFamily\\":\\"custom\\",\\"fontWeight\\":\\"normal\\",\\"fontStyle\\":\\"normal\\"},{}]},\\"children\\":[\\"\\"]},{\\"type\\":\\"Text\\",\\"props\\":{\\"selectable\\":false,\\"allowFontScaling\\":false,\\"style\\":[{\\"fontSize\\":32,\\"color\\":\\"#F38C39\\"},[{\\"width\\":32,\\"height\\":32,\\"textAlignVertical\\":\\"center\\"},null],{\\"fontFamily\\":\\"custom\\",\\"fontWeight\\":\\"normal\\",\\"fontStyle\\":\\"normal\\"},{}]},\\"children\\":[\\"\\"]},{\\"type\\":\\"Text\\",\\"props\\":{\\"selectable\\":false,\\"allowFontScaling\\":false,\\"style\\":[{\\"fontSize\\":32,\\"color\\":\\"#cbced1\\"},[{\\"width\\":32,\\"height\\":32,\\"textAlignVertical\\":\\"center\\"},null],{\\"fontFamily\\":\\"custom\\",\\"fontWeight\\":\\"normal\\",\\"fontStyle\\":\\"normal\\"},{}]},\\"children\\":[\\"\\"]},{\\"type\\":\\"Text\\",\\"props\\":{\\"selectable\\":false,\\"allowFontScaling\\":false,\\"style\\":[{\\"fontSize\\":32,\\"color\\":\\"#cbced1\\"},[{\\"width\\":32,\\"height\\":32,\\"textAlignVertical\\":\\"center\\"},null],{\\"fontFamily\\":\\"custom\\",\\"fontWeight\\":\\"normal\\",\\"fontStyle\\":\\"normal\\"},{}]},\\"children\\":[\\"\\"]},{\\"type\\":\\"Text\\",\\"props\\":{\\"selectable\\":false,\\"allowFontScaling\\":false,\\"style\\":[{\\"fontSize\\":60,\\"color\\":\\"#2de0a5\\"},[{\\"width\\":60,\\"height\\":60,\\"textAlignVertical\\":\\"center\\"},null],{\\"fontFamily\\":\\"custom\\",\\"fontWeight\\":\\"normal\\",\\"fontStyle\\":\\"normal\\"},{}]},\\"children\\":[\\"\\"]}]"`;
5 changes: 1 addition & 4 deletions app/containers/CustomIcon/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,5 @@ export interface ICustomIcon extends TextProps {
color: string;
}

const CustomIcon = ({ name, size, color, ...props }: ICustomIcon) => (
// @ts-ignore TODO remove this after update @types/react-native to 0.65.0
<IconSet name={name} size={size} color={color} {...props} />
);
const CustomIcon = ({ name, size, color, ...props }: ICustomIcon) => <IconSet name={name} size={size} color={color} {...props} />;
export { CustomIcon };
167 changes: 153 additions & 14 deletions app/containers/MessageComposer/MessageComposer.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
import React, { useState, ReactElement, useRef, forwardRef, useImperativeHandle } from 'react';
import { View, StyleSheet, NativeModules } from 'react-native';
import React, { useState, ReactElement, useRef, forwardRef, useImperativeHandle, useEffect } from 'react';
import { View, StyleSheet, NativeModules, Keyboard } from 'react-native';
import { KeyboardAccessoryView } from 'react-native-ui-lib/keyboard';
import { useBackHandler } from '@react-native-community/hooks';
import { Q } from '@nozbe/watermelondb';

import { Toolbar, EmojiSearchbar, ComposerInput, Left, Right } from './components';
import { MIN_HEIGHT, TIMEOUT_CLOSE_EMOJI_KEYBOARD } from './constants';
import { Autocomplete, Toolbar, EmojiSearchbar, ComposerInput, Left, Right } from './components';
import { MIN_HEIGHT, NO_CANNED_RESPONSES, TIMEOUT_CLOSE_EMOJI_KEYBOARD } from './constants';
import { MessageComposerContext } from './context';
import { useCanUploadFile, useChooseMedia } from './hooks';
import { IComposerInput, IMessageComposerProps, IMessageComposerRef, ITrackingView, TMicOrSend } from './interfaces';
import { IAutocompleteItemProps, IComposerInput, IMessageComposerProps, IMessageComposerRef, ITrackingView } from './interfaces';
import { isIOS } from '../../lib/methods/helpers';
import shortnameToUnicode from '../../lib/methods/helpers/shortnameToUnicode';
import { useAppSelector } from '../../lib/hooks';
import { useTheme } from '../../theme';
import { EventTypes } from '../EmojiPicker/interfaces';
import { IEmoji } from '../../definitions';
import getMentionRegexp from '../MessageBox/getMentionRegexp';
import database from '../../lib/database';
import { sanitizeLikeString } from '../../lib/database/utils';
import { generateTriggerId } from '../../lib/methods';
import { Services } from '../../lib/services';
import log, { events, logEvent } from '../../lib/methods/helpers/log';
import { isAllOrHere } from './helpers';
import Navigation from '../../lib/navigation/appNavigation';
import { emitter } from './emitter';

const styles = StyleSheet.create({
container: {
Expand All @@ -30,20 +40,22 @@ require('../MessageBox/EmojiKeyboard');

export const MessageComposer = forwardRef<IMessageComposerRef, IMessageComposerProps>(
({ onSendMessage, rid, tmid, sharing = false, editing = false }, ref): ReactElement => {
// console.count('Message Composer');
console.count('Message Composer');
const composerInputRef = useRef(null);
const composerInputComponentRef = useRef<IComposerInput>({
sendMessage: () => '',
getTextAndClear: () => '',
getText: () => '',
getSelection: () => ({ start: 0, end: 0 }),
setInput: () => {}
setInput: () => {},
focus: () => {}
});
const trackingViewRef = useRef<ITrackingView>({ resetTracking: () => {} });
const trackingViewRef = useRef<ITrackingView>({ resetTracking: () => {}, getNativeProps: () => ({ trackingViewHeight: 0 }) });
const { colors, theme } = useTheme();
const [micOrSend, setMicOrSend] = useState<TMicOrSend>('mic');
const [showEmojiKeyboard, setShowEmojiKeyboard] = useState(false);
const [showEmojiSearchbar, setShowEmojiSearchbar] = useState(false);
const [focused, setFocused] = useState(false);
const [trackingViewHeight, setTrackingViewHeight] = useState(0);
const [keyboardHeight, setKeyboardHeight] = useState(0);
const permissionToUpload = useCanUploadFile(rid);
const { FileUpload_MediaTypeWhiteList, FileUpload_MaxFileSize } = useAppSelector(state => state.settings);
const { takePhoto, takeVideo, chooseFromLibrary, chooseFile } = useChooseMedia({
Expand All @@ -53,6 +65,7 @@ export const MessageComposer = forwardRef<IMessageComposerRef, IMessageComposerP
maxFileSize: FileUpload_MaxFileSize as number,
permissionToUpload
});
const isMasterDetail = useAppSelector(state => state.app.isMasterDetail);

useBackHandler(() => {
if (showEmojiSearchbar) {
Expand All @@ -66,8 +79,51 @@ export const MessageComposer = forwardRef<IMessageComposerRef, IMessageComposerP
closeEmojiKeyboardAndAction
}));

const sendMessage = () => {
onSendMessage(composerInputComponentRef.current.sendMessage());
useEffect(() => {
const showListener = Keyboard.addListener('keyboardWillShow', async () => {
if (trackingViewRef?.current) {
const props = await trackingViewRef.current.getNativeProps();
setKeyboardHeight(props.keyboardHeight);
}
});

const hideListener = Keyboard.addListener('keyboardWillHide', () => {
setKeyboardHeight(0);
});

return () => {
showListener.remove();
hideListener.remove();
};
}, [trackingViewRef]);

const sendMessage = async () => {
const message = composerInputComponentRef.current.getTextAndClear();

// Slash command
if (message[0] === '/') {
const db = database.active;
const commandsCollection = db.get('slash_commands');
const command = message.replace(/ .*/, '').slice(1);
const likeString = sanitizeLikeString(command);
const slashCommand = await commandsCollection.query(Q.where('id', Q.like(`${likeString}%`))).fetch();
if (slashCommand.length > 0) {
logEvent(events.COMMAND_RUN);
try {
const messageWithoutCommand = message.replace(/([^\s]+)/, '').trim();
const [{ appId }] = slashCommand;
const triggerId = generateTriggerId(appId);
await Services.runSlashCommand(command, rid, messageWithoutCommand, triggerId, tmid); // || messageTmid);
// replyCancel();
} catch (e) {
log(e);
}
return;
}
}

// Text message
onSendMessage(message);
};

const onKeyboardResigned = () => {
Expand Down Expand Up @@ -121,6 +177,87 @@ export const MessageComposer = forwardRef<IMessageComposerRef, IMessageComposerP
}
};

const onAutocompleteItemSelected: IAutocompleteItemProps['onPress'] = async item => {
if (item.type === 'loading') {
return null;
}

// If it's slash command preview, we need to execute the command
if (item.type === '/preview') {
try {
const db = database.active;
const commandsCollection = db.get('slash_commands');
const commandRecord = await commandsCollection.find(item.text);
const { appId } = commandRecord;
const triggerId = generateTriggerId(appId);
Services.executeCommandPreview(item.text, item.params, rid, item.preview, triggerId, tmid);
} catch (e) {
log(e);
}
requestAnimationFrame(() => {
stopAutocomplete();
composerInputComponentRef.current.setInput('', { start: 0, end: 0 });
});
return;
}

// If it's canned response, but there's no canned responses, we open the canned responses view
if (item.type === '!' && item.id === NO_CANNED_RESPONSES) {
const params = { rid };
if (isMasterDetail) {
Navigation.navigate('ModalStackNavigator', { screen: 'CannedResponsesListView', params });
} else {
Navigation.navigate('CannedResponsesListView', params);
}
stopAutocomplete();
return;
}

const text = composerInputComponentRef.current.getText();
const { start, end } = composerInputComponentRef.current.getSelection();
const cursor = Math.max(start, end);
const regexp = getMentionRegexp();
let result = text.substr(0, cursor).replace(regexp, '');
// Remove the ! after select the canned response
if (item.type === '!') {
const lastIndexOfExclamation = text.lastIndexOf('!', cursor);
result = text.substr(0, lastIndexOfExclamation).replace(regexp, '');
}
let mention = '';
switch (item.type) {
case '@':
mention = isAllOrHere(item) ? item.title : item.subtitle || item.title;
break;
case '#':
mention = item.subtitle ? item.subtitle : '';
break;
case ':':
mention = `${typeof item.emoji === 'string' ? item.emoji : item.emoji.name}:`;
break;
case '/':
mention = item.title;
break;
case '!':
mention = item.subtitle ? item.subtitle : '';
break;
default:
mention = '';
}
const newText = `${result}${mention} ${text.slice(cursor)}`;

const newCursor = cursor + mention.length;
composerInputComponentRef.current.setInput(newText, { start: newCursor, end: newCursor });
composerInputComponentRef.current.focus();
requestAnimationFrame(() => {
stopAutocomplete();
});
};

// TODO: duplicated
const stopAutocomplete = () => {
emitter.emit('setAutocomplete', { type: null, text: '', params: '' });
};

const openEmojiKeyboard = () => {
// logEvent(events.ROOM_OPEN_EMOJI);
setShowEmojiKeyboard(true);
Expand All @@ -146,7 +283,6 @@ export const MessageComposer = forwardRef<IMessageComposerRef, IMessageComposerP
return (
<MessageComposerContext.Provider
value={{
micOrSend,
rid,
tmid,
editing,
Expand All @@ -156,7 +292,9 @@ export const MessageComposer = forwardRef<IMessageComposerRef, IMessageComposerP
showEmojiKeyboard,
showEmojiSearchbar,
permissionToUpload,
setMicOrSend,
trackingViewHeight,
keyboardHeight,
setTrackingViewHeight,
openEmojiKeyboard,
closeEmojiKeyboard,
onEmojiSelected,
Expand Down Expand Up @@ -195,6 +333,7 @@ export const MessageComposer = forwardRef<IMessageComposerRef, IMessageComposerP
bottomViewColor={colors.surfaceLight}
iOSScrollBehavior={NativeModules.KeyboardTrackingViewTempManager?.KeyboardTrackingScrollBehaviorFixedOffset}
/>
<Autocomplete onPress={onAutocompleteItemSelected} />
</MessageComposerContext.Provider>
);
}
Expand Down
Loading