diff --git a/.github/workflows/create_tag_and_release.yml b/.github/workflows/create_tag_and_release.yml new file mode 100644 index 0000000..7eb634a --- /dev/null +++ b/.github/workflows/create_tag_and_release.yml @@ -0,0 +1,67 @@ +name: Publish Create Tag and Git Release + +on: + push: + branches: + - "master" + +permissions: write-all + +defaults: + run: + working-directory: ./likeminds-chat-reactnative-integration + +jobs: + create_tag: + name: Create Git Tag + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v3 + with: + fetch-depth: 0 + - name: Check for version changes + run: | + # Fetch all tags from the remote repository + git fetch --tags + + # Get the previous version from the last release tag + export previous_version=$(git describe --tags --abbrev=0) + + # Get the current version from package.json + export current_version=$(cat package.json | grep '"version":' | awk -F'"' '{print $4}') + + if [[ "$previous_version" != "v$current_version" ]]; then + echo "Version has changed from $previous_version to v$current_version." + else + echo "Version has not changed." + exit 1 + fi + - name: Push Git Tag + run: | + # Git login + git config --global user.name "$(git log -n 1 --pretty=format:%an)" + git config --global user.email "$(git log -n 1 --pretty=format:%ae)" + + # Push a Git tag with the new version + export current_version=$(cat package.json | grep '"version":' | awk -F'"' '{print $4}') + git tag -a "v$current_version" -m "Version $current_version" + git push origin "v$current_version" + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + create-github-release: + name: Create GitHub Release + runs-on: ubuntu-latest + needs: create_tag + permissions: + contents: write + steps: + - name: Checkout code + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Create Release + run: gh release create "$(git describe --tags --abbrev=0)" --generate-notes + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/example/.gitignore b/example/.gitignore index 16f8c30..67b4307 100644 --- a/example/.gitignore +++ b/example/.gitignore @@ -61,3 +61,6 @@ yarn-error.log # Temporary files created by Metro to check the health of the file watcher .metro-health-check* + +google-services.json +GoogleService-Info.plist diff --git a/example/App.tsx b/example/App.tsx index a6e277b..4cde494 100644 --- a/example/App.tsx +++ b/example/App.tsx @@ -5,7 +5,7 @@ * @format */ -import React, {useEffect} from 'react'; +import React, {useEffect, useState} from 'react'; import {KeyboardAvoidingView, Platform} from 'react-native'; import {NavigationContainer} from '@react-navigation/native'; import {createNativeStackNavigator} from '@react-navigation/native-stack'; @@ -31,8 +31,8 @@ import { ViewParticipants, AddParticipants, DmAllMembers, + initMyClient, } from '@likeminds.community/chat-rn-core'; -import {myClient} from '.'; import ChatroomScreenWrapper from './screens/Chatroom/ChatroomScreenWrapper'; import {setStyles} from './styles'; import { @@ -45,6 +45,11 @@ import { } from '@likeminds.community/chat-rn-core/ChatSX/constants/Screens'; import FileUploadScreen from './screens/FileUpload'; import FileUploadScreenWrapper from './screens/FileUpload/FileUploadWrapper'; +import {useQuery} from '@realm/react'; +import {Credentials} from './login/credentials'; +import {LoginSchemaRO} from './login/loginSchemaRO'; +import FetchKeyInputScreen from './login'; +import {ConversationState} from '@likeminds.community/chat-rn'; const Stack = createNativeStackNavigator(); @@ -70,180 +75,257 @@ class CustomCallbacks implements LMChatCallbacks, LMChatroomCallbacks { const lmChatInterface = new CustomCallbacks(); function App(): React.JSX.Element { - const userName = ''; - const userUniqueId = ''; const chatroomId = ''; const profileImageUrl = ''; + const [users, setUsers] = useState(); + const [apiKey, setApiKey] = useState( + Credentials?.apiKey?.length > 0 ? Credentials?.apiKey : users?.apiKey, + ); + const [userUniqueID, setUserUniqueID] = useState( + Credentials?.userUniqueId?.length > 0 + ? Credentials.userUniqueId + : users?.userUniqueID, + ); + const [userName, setUserName] = useState( + Credentials?.username?.length > 0 ? Credentials?.username : users?.userName, + ); + const [myClient, setMyClient] = useState(); + const [isTrue, setIsTrue] = useState(true); + const loginSchemaArray: any = useQuery(LoginSchemaRO); + + useEffect(() => { + const userSchema = async () => { + const loginSchema = loginSchemaArray[0]; + if (loginSchema) { + Credentials.setCredentials( + loginSchema?.userName, + loginSchema?.userUniqueID, + loginSchema?.apiKey, + ); + setUsers(loginSchema); + } + }; + userSchema(); + }, [isTrue]); + + useEffect(() => { + setUserName( + Credentials?.username?.length > 0 + ? Credentials?.username + : users?.userName, + ); + setUserUniqueID( + Credentials?.userUniqueId?.length > 0 + ? Credentials.userUniqueId + : users?.userUniqueID, + ); + setApiKey( + Credentials?.apiKey?.length > 0 ? Credentials?.apiKey : users?.apiKey, + ); + }, [users, isTrue]); + + useEffect(() => { + if (apiKey) { + const filterStateMessage = [ + ConversationState.MEMBER_LEFT_SECRET_CHATROOM, + ]; // give type of conversation to be filtered using ConversationState enum + + // proivde apiKey below to initMyClient + const res: any = initMyClient(apiKey, filterStateMessage); // pass api key as first param and filterStateMessage array as second + setMyClient(res); + } + }, [isTrue, apiKey]); + + const themeStyles = { + fontTypes: { + LIGHT: 'SofiaPro-Light', + MEDIUM: 'SofiaPro-Medium', + SEMI_BOLD: 'SofiaPro-SemiBold', + BOLD: 'SofiaPro-Bold', + BLACK: 'SofiaPro-Black', + }, + }; useEffect(() => { - setStyles(); + STYLES.setTheme(themeStyles); }, []); return ( <> - {Platform.OS === 'ios' ? ( - - - - - - - - - - - - - - - - - - - - - - - ) : ( - - - - - - - - - - - - - - - - - - - - - )} + {userName && userUniqueID && apiKey && myClient ? ( + <> + {Platform.OS === 'ios' ? ( + + + + + + + + + + + + + + + + + + + + + + + ) : ( + + + + + + + + + + + + + + + + + + + + + )} + + ) : !userName && !userUniqueID && !apiKey ? ( + + ) : null} ); } diff --git a/example/index.js b/example/index.js index efc5cc3..4b78a2f 100644 --- a/example/index.js +++ b/example/index.js @@ -4,14 +4,13 @@ import {AppRegistry} from 'react-native'; import App from './App'; import {name as appName} from './app.json'; -import {initMyClient} from '@likeminds.community/chat-rn-core'; -import { ConversationState } from "@likeminds.community/chat-rn"; +import {RealmProvider} from '@realm/react'; +import {LoginSchemaRO} from './login/loginSchemaRO'; -const filterStateMessage = []; // give type of conversation to be filtered using ConversationState enum +const WrappedApp = () => ( + + + +); -// proivde apiKey below to initMyClient -const myClient = initMyClient("", filterStateMessage); // pass api key as first param and filterStateMessage array as second - -AppRegistry.registerComponent(appName, () => App); - -export { myClient }; +AppRegistry.registerComponent(appName, () => WrappedApp); diff --git a/example/login/credentials.ts b/example/login/credentials.ts new file mode 100644 index 0000000..7ce9970 --- /dev/null +++ b/example/login/credentials.ts @@ -0,0 +1,27 @@ +export class Credentials { + private static _apiKey: string = ''; + private static _username: string = ''; + private static _userUniqueId: string = ''; + + static setCredentials( + username: string, + userUniqueId: string, + apiKey: string, + ): void { + Credentials._apiKey = apiKey; + Credentials._username = username; + Credentials._userUniqueId = userUniqueId; + } + + static get apiKey(): string { + return Credentials._apiKey; + } + + static get username(): string { + return Credentials._username; + } + + static get userUniqueId(): string { + return Credentials._userUniqueId; + } +} diff --git a/example/login/index.tsx b/example/login/index.tsx new file mode 100644 index 0000000..d45cb84 --- /dev/null +++ b/example/login/index.tsx @@ -0,0 +1,142 @@ +import React, {useEffect, useState} from 'react'; +import { + View, + TextInput, + Button, + StyleSheet, + TouchableOpacity, + Text, + ActivityIndicator, + Keyboard, +} from 'react-native'; +import {Credentials} from './credentials'; +import {useRealm} from '@realm/react'; +import {LoginSchemaRO} from './loginSchemaRO'; +import {UpdateMode} from 'realm'; +import {STYLES} from '@likeminds.community/chat-rn-core'; + +interface ChildProps { + isTrue: boolean; + setIsTrue: (isTrue: boolean) => void; +} + +const FetchKeyInputScreen: React.FC = ({isTrue, setIsTrue}) => { + const [userUniqueID, setUserUniqueID] = useState(''); + const [userName, setUserName] = useState(''); + const [apiKey, setApiKey] = useState(''); + const [isButtonClicked, setIsButtonClicked] = useState(false); + const realm = useRealm(); + + const handleAddNotes = ( + userUniqueID: string, + userName: string, + apiKey: string, + ) => { + Credentials.setCredentials(userName, userUniqueID, apiKey); + }; + + useEffect(() => { + if (userUniqueID && userName && apiKey && isButtonClicked) { + return setIsTrue(!isTrue); + } + }, [isButtonClicked]); + + const saveLoginData = () => { + realm.write(() => { + realm.create( + LoginSchemaRO, + { + id: 'LoginSchema', + userUniqueID: userUniqueID, + userName: userName, + apiKey: apiKey, + }, + UpdateMode.All, + ); + }); + }; + + const handleButtonPress = () => { + // Perform some action when the button is pressed + // You can access the input values from input1 and input2 variables + handleAddNotes(userUniqueID, userName, apiKey); + + saveLoginData(); + + userUniqueID && userName && apiKey + ? setIsButtonClicked(true) + : setIsButtonClicked(false); + + if (userUniqueID && userName && apiKey) { + Keyboard.dismiss(); + } + }; + + return ( + + setApiKey(text)} + /> + setUserUniqueID(text)} + /> + setUserName(text)} + placeholderTextColor={'grey'} + /> + {} + }> + + Submit + + + + ); +}; + +const styles = StyleSheet.create({ + container: { + flex: 1, + justifyContent: 'center', + alignItems: 'center', + padding: 20, + backgroundColor: 'white', + }, + input: { + width: '100%', + height: 40, + borderColor: 'gray', + borderWidth: 1, + marginBottom: 20, + paddingHorizontal: 10, + color: 'black', + }, +}); + +export default FetchKeyInputScreen; diff --git a/example/login/loginSchemaRO.ts b/example/login/loginSchemaRO.ts new file mode 100644 index 0000000..0e7727a --- /dev/null +++ b/example/login/loginSchemaRO.ts @@ -0,0 +1,19 @@ +import Realm from 'realm'; + +export class LoginSchemaRO extends Realm.Object { + id!: string; + userUniqueID!: string; + userName!: string; + apiKey!: string; + + static schema = { + name: 'LoginSchemaRO', + properties: { + id: 'string', + userUniqueID: 'string', + userName: 'string', + apiKey: 'string', + }, + primaryKey: 'id', + }; +} diff --git a/example/package.json b/example/package.json index a016723..5fe585f 100644 --- a/example/package.json +++ b/example/package.json @@ -1,6 +1,6 @@ { "name": "example", - "version": "1.0.2", + "version": "1.0.3", "private": true, "scripts": { "android": "react-native run-android", @@ -11,8 +11,8 @@ }, "dependencies": { "@giphy/react-native-sdk": "2.1.3", - "@likeminds.community/chat-rn": "1.5.6", - "@likeminds.community/chat-rn-core": "1.0.2", + "@likeminds.community/chat-rn": "1.5.7", + "@likeminds.community/chat-rn-core": "1.0.3", "@notifee/react-native": "7.6.1", "@react-native-clipboard/clipboard": "1.11.2", "@react-native-community/datetimepicker": "7.4.1", @@ -24,6 +24,7 @@ "@react-navigation/native": "6.1.2", "@react-navigation/native-stack": "6.9.8", "@react-navigation/stack": "6.3.29", + "@realm/react": "0.6.2", "@shopify/flash-list": "1.4.3", "@types/react-native-video": "5.0.19", "aws-sdk": "2.1380.0", diff --git a/likeminds-chat-reactnative-integration/ChatSX/components/InputBox/index.tsx b/likeminds-chat-reactnative-integration/ChatSX/components/InputBox/index.tsx index 9146282..20f1254 100644 --- a/likeminds-chat-reactnative-integration/ChatSX/components/InputBox/index.tsx +++ b/likeminds-chat-reactnative-integration/ChatSX/components/InputBox/index.tsx @@ -102,6 +102,7 @@ import { VoiceNotesProps, } from "./models"; import Animated, { + AnimatedStyleProp, Easing, useAnimatedStyle, useSharedValue, @@ -438,7 +439,9 @@ const MessageInputBox = ({ const composedGesture = Gesture.Simultaneous(longPressGesture, panGesture); // draggle mic panGesture styles - const panStyle = useAnimatedStyle((): ViewStyle | ImageStyle | TextStyle => { + const panStyle = useAnimatedStyle((): AnimatedStyleProp< + ViewStyle | ImageStyle | TextStyle + > => { return { transform: [ { diff --git a/likeminds-chat-reactnative-integration/ChatSX/context/ChatroomContext.tsx b/likeminds-chat-reactnative-integration/ChatSX/context/ChatroomContext.tsx index cdebf30..55c4080 100644 --- a/likeminds-chat-reactnative-integration/ChatSX/context/ChatroomContext.tsx +++ b/likeminds-chat-reactnative-integration/ChatSX/context/ChatroomContext.tsx @@ -104,7 +104,6 @@ import { import { getChatroom } from "../store/actions/chatroom"; import { fetchResourceFromURI, formatTime } from "../commonFuctions"; import { Image as CompressedImage } from "react-native-compressor"; -import { Conversation } from "@likeminds.community/chat-rn/dist/shared/responseModels/Conversation"; import { Client } from "../client"; import AudioPlayer from "../optionalDependecies/AudioPlayer"; diff --git a/likeminds-chat-reactnative-integration/ChatSX/context/MessageContext.tsx b/likeminds-chat-reactnative-integration/ChatSX/context/MessageContext.tsx index 1b556cf..a86a9a0 100644 --- a/likeminds-chat-reactnative-integration/ChatSX/context/MessageContext.tsx +++ b/likeminds-chat-reactnative-integration/ChatSX/context/MessageContext.tsx @@ -9,9 +9,7 @@ import React, { useState, } from "react"; import { useAppDispatch, useAppSelector } from "../store"; -import { ActivityIndicator, GestureResponderEvent, View } from "react-native"; -import STYLES from "../constants/Styles"; -import { Conversation } from "@likeminds.community/chat-rn/dist/shared/responseModels/Conversation"; +import { GestureResponderEvent, View } from "react-native"; import { SET_POSITION } from "../store/types/types"; import { Credentials } from "../credentials"; import { ChatroomContextValues, useChatroomContext } from "./ChatroomContext"; diff --git a/likeminds-chat-reactnative-integration/ChatSX/setup.ts b/likeminds-chat-reactnative-integration/ChatSX/setup.ts index 9fcec31..a3dc784 100644 --- a/likeminds-chat-reactnative-integration/ChatSX/setup.ts +++ b/likeminds-chat-reactnative-integration/ChatSX/setup.ts @@ -14,6 +14,7 @@ export const initMyClient = ( ) => { const myClient = LMChatClient.setApiKey(apiKey) .setfilterStateConversation(filterStateMessage) + .setVersionCode(32) .build(); Client.setMyClient(myClient); diff --git a/likeminds-chat-reactnative-integration/package.json b/likeminds-chat-reactnative-integration/package.json index 837950c..932fc97 100644 --- a/likeminds-chat-reactnative-integration/package.json +++ b/likeminds-chat-reactnative-integration/package.json @@ -1,8 +1,8 @@ { "name": "@likeminds.community/chat-rn-core", - "version": "1.0.2", - "versionCode": "14", - "versionName": "1.0.2", + "version": "1.0.3", + "versionCode": "15", + "versionName": "1.0.3", "description": "LikeMinds ReactNative Core SDK for chat", "scripts": { "android": "react-native run-android", @@ -20,7 +20,7 @@ "homepage": "https://likeminds.community/", "license": "ISC", "dependencies": { - "@likeminds.community/chat-rn": "1.5.6", + "@likeminds.community/chat-rn": "1.5.7", "@react-native/babel-preset": "0.74.0", "diff": "5.1.0", "realm": "11.10.2"