Simple serverless Chat App using the HUAWEI Serverless services capabilities, including a login screen and the chat screen, intended to cover a group chat scenario.
-
Login screen, using HUAWEI Auth Service it's possible to login with 3rd party providers, your own server or anonymously. The credentials are already stored into Auth Service but we are saving them on HUAWEI Cloud DB too in order to manipulate the info for the chat. The whole business logic is managed by the HUAWEI Cloud Functions
-
Chat screen using HUAWEI Cloud DB to store and read messages.
- A computer that can run Android Studio.
- Android mobile device with a USB data cable for running developed apps
- Java JDK 1.8 or later
- Android Studio 2021.3.x or later
- Android SDK package
- Android API Level 21 or higher
- For login with HUAWEI ID, you need HMS Core (APK) 5.0.0.300 or later
- For login with Google, you Google Play Services 15.0.0 or later
- Android 5.0 or later
- Follow the setup at this link ;
- in order to support the HUAWEI ID login, you should enable the 'Account Kit' API under the 'MANAGE API' section on AGC Console;
- create an 'ids.xml' file under 'res/values' folder with the ids needed for Google and Facebook login providers;
- import the ObjectTypes into your Cloud DB section following this guide;
- import the following Cloud Functions to your project -> link
- AuthViewModel to manage all the login flows and data;
- CloudDBViewModel to manage all the CloudDB flows and data
- users: the users info table;
- input_messages: the messages table that the app will use ONLY to update the data on CloudDB;
- full_messages: a join table between
users
andinput_messages
that can only be updated by the Cloud Functions and the app reads to show the message cards. - poll_lunch_choices: list of the restaurants where we want to organize the lunch
- poll_lunch: the users' choices for the lunch
Sample Cloud Function project -> link
The Cloud Functions used for the chat app -> link
- the
AuthViewModel
will check if the user is already logged in jump tostep 7
; - if the user is not logged in, it clicks on a 3rd party login provider (in this project we use
HUAWEI ID
,Google
,Facebook
); - the login() function from
AuthViewModel
will be invoked; - with the login, the AUTH TRIGGER on AGConnect Console will be fired, starting a Cloud Function;
- the Cloud Function will set a random color for the user and then stores user data into the Cloud
DB
users
table; - a jetpack compose logic with a mutablestate loggedIn will proceed to the the final step;
- the app will check the data on Cloud DB with getUserDataAvailability()
- a jetpack compose logic with a mutablestate userDataAvailable will redirect to the chat screen
- user sends a
input_messages
object to Cloud DB using the sendMessage() function; - on Cloud DB there's a configured trigger that runs a Cloud Function in order to create a new
record in the
full_messages
table using the info frominput_messages
andusers
, generating a random ID; - since we are listening for changes on the
full_messages
table through the subscribeSnapshot() function, the list will add the message card as soon as the listener notifies it.
Pretty similar to the 'Send Message flow' with the function editMessage() only taking care about the primary key which needs to be the same of the record we want to modify.
Invoke the deleteMessage() function from CloudDBViewModel
passing the full_messages
data
we want to delete.
If you are still evaluating HMS Core, obtain the latest information about HMS Core and share your insights with other developers at Reddit.
- To resolve development issues, please go to Stack Overflow. You can ask questions below the
huawei-mobile-services
tag, and Huawei R&D experts can solve your problem online on a one-to-one basis. - To join the developer discussion, please visit Huawei Developer Forum.