Skip to content

FStranieri/CloudySamples

Repository files navigation

CHAT APP

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.

What You Will Need

Hardware Requirements

  • A computer that can run Android Studio.
  • Android mobile device with a USB data cable for running developed apps

Software Requirements

  • 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

SETUP

  1. Follow the setup at this link ;
  2. in order to support the HUAWEI ID login, you should enable the 'Account Kit' API under the 'MANAGE API' section on AGC Console;
  3. create an 'ids.xml' file under 'res/values' folder with the ids needed for Google and Facebook login providers;
  4. import the ObjectTypes into your Cloud DB section following this guide;
  5. import the following Cloud Functions to your project -> link

Screenshots

ViewModels

  1. AuthViewModel to manage all the login flows and data;
  2. CloudDBViewModel to manage all the CloudDB flows and data

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 and input_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

Cloud Functions

Sample Cloud Function project -> link

The Cloud Functions used for the chat app -> link

Login Flow

  1. the AuthViewModel will check if the user is already logged in jump to step 7;
  2. if the user is not logged in, it clicks on a 3rd party login provider (in this project we use HUAWEI ID, Google, Facebook);
  3. the login() function from AuthViewModel will be invoked;
  4. with the login, the AUTH TRIGGER on AGConnect Console will be fired, starting a Cloud Function;
  5. the Cloud Function will set a random color for the user and then stores user data into the Cloud DB users table;
  6. a jetpack compose logic with a mutablestate loggedIn will proceed to the the final step;
  7. the app will check the data on Cloud DB with getUserDataAvailability()
  8. a jetpack compose logic with a mutablestate userDataAvailable will redirect to the chat screen

Send Message Flow

  1. user sends a input_messages object to Cloud DB using the sendMessage() function;
  2. 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 from input_messages and users, generating a random ID;
  3. 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.

Edit Message Flow

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.

Delete Message Flow

Invoke the deleteMessage() function from CloudDBViewModel passing the full_messages data we want to delete.

Technical Support

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.

About

Cloud all the things

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published