Giter Site home page Giter Site logo

rchat's Introduction

RChat app icon RChat – A Chat app built with SwiftUI and Realm

RChat is a chat application. Members of a chat room share messages, photos, location, and presence information with each other. The initial version is an iOS (Swift & SwiftUI) app, but we will use the same data model and backend Realm application to build an Android version in the future.

Read about the Realm data architecture here and how the app was built here.

Screenshot of a chatroom with messages

Building and running the app

  1. If you don't already have one, create a MongoDB Atlas Cluster, keeping the default name of Cluster0.
  2. Install the Realm CLI and create an API key pair.
  3. Download the repo and install the Realm app:
git clone https://github.com/ClusterDB/RChat.git
cd RChat/RChat-Realm/RChat
realm-cli login --api-key <your new public key> --private-api-key <your new private key>
realm-cli import # Then answer prompts, naming the app RChat
  1. From the Atlas UI, click on the Realm logo and you will see the RChat app. Open it and copy the App Id

Realm application Id

  1. (Optional) Use mongoimport to import the empty database from the dump folder to create database indexes
  2. Open the iOS project
cd ../../RChat-iOS
open RChat.xcodeproj
  1. Update RChatApp.swift with your Realm App Id and then build

The new-schema branch contains all of the iOS and backend Realm app code needed to add a new feature to tag chat message as high priority. This includes schema and code changes. You can find all of the steps to safely make such a schema change in a production app in Migrating Your iOS App's Synced Realm Schema in Production.

The V2-schema branch contains all of the iOS and backend Realm app code needed to make the ChatMessage.author field non-optional. You can find all of the steps to safely make such a schema change in a production app in Migrating Your iOS App's Synced Realm Schema in Production.

rchat's People

Contributors

am-mongodb avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rchat's Issues

Tutorial?

Hi Andrew,

Is there a companion tutorial for this? Or just a basic setup on how to config server and build?

Suggestion

A Slack channel to discuss SwitUI Realm apps would be a great way for many developers to exchange knowledge, since there are so few tutorials on the web.

Realm CLI Deprecated

The realm cli is deprecated and has been rolled into the app services cli so this no longer seems to work.

ios 14 issue for newest commit

Hi @am-MongoDB

In our application, we would like to use all the new features of the latest SDK release as used in the current commit, but support ios 14. The branch pre-ios15 seems to not have quite a lot of updates which could be useful in ios14 as well, that were made only on the main branch. Most issues with the current commit in main (which has target ios 15) are small and easy to fix, such as @FocusState and other small things. However, I am not sure how to properly make the following snippet ios 14 compatible (await is not available in ios 14 for some reason):

(Ideally, I would not want to switch to the publishers in AppState.swift if that's possible, since that code is much larger and will need many adjustments in various places. Is there a way around that, just by using an alternative to await?)

Task {
    if newUser {
        do {
            try await app.emailPasswordAuth.registerUser(email: email, password: password)
        } catch {
            DispatchQueue.main.async {
                state.error = error.localizedDescription
                state.shouldIndicateActivity = false
            }
            return
        }
    }
    do {
        let user = try await app.login(credentials: .emailPassword(email: email, password: password))
        userID = user.id
        state.shouldIndicateActivity = false
    } catch {
        DispatchQueue.main.async {
            state.error = error.localizedDescription
            state.shouldIndicateActivity = false
        }
    }
}

Persist user logged in if the app restarts

First, thanks for the sample app and its tutorial.

I am trying to understand which would be the best way to persist the logged in user in between app restarts. Right now, the user needs to log in again if the app or the phone restarts. That feels odd and it is not a standard or expected behaviour.

ClusterDB/task-tracker-swiftui suffers from the same challenge.

I haven't found any documentation, even though it should be ok as app.currentUser already maintains the identity and access token of the logged user.

Any guidance would be highly appreciated. Many thanks!

Unable to build due to LoginView.swift

Hello,

I followed the instructions on the readme and I'm running into a build issue.

let user = try await app.login(credentials: .emailPassword(email: email, password: password))
userID = user.id
state.shouldIndicateActivity = false

Is causing a an error that fails the build
Value of type 'Future<User, Error>' (aka 'Future<RLMUser, Error>') has no member 'id'

I've tried and failed to fix it. Any ideas? I'm new to swift and realm so I'm thinking it might just be a config issue on my end, but I can't find anything.

It also produces a warning:
No calls to throwing functions occur within 'try' expression
But I know this is how the Realm Documentation says to utilize the async login so I'm assuming this is fine.

slow loading times when accessing bigger chats

After playing around with the snapshot linked in the older version of the article and the newest version we noticed that the performance with "bigger" chats (already starting at about 20 messages) is a lot worse with the current version. When clicking on a chat to open the view freezes. The more messages, the longer until it then slides to the actual conversation view (already a few full seconds for more than 20 messages). There are also other things where the app laggs for some time, such as when adding people to chats or just navigating the app. Looking at the console output, that mostly occurs when there is a Disconnection and Reconnection for no apparent reason:

2022-02-27 18:23:00.413438+0100 RChat[10194:2895762] Sync: Connection[3]: Disconnected
2022-02-27 18:23:01.012754+0100 RChat[10194:2895762] Sync: Connection[4]: Session[4]: client_reset_config = false, Realm exists = true, client reset = false
2022-02-27 18:23:01.039700+0100 RChat[10194:2895762] Sync: Connected to endpoint 'xxxxx:443' (from 'xxxxx:49665')

With the linked commit the loading time was almost instant.

Could this be due to the new way of passing the .environment(...)?

.environment(\.realmConfiguration, app.currentUser!.configuration(partitionValue: "all-users=all-the-users"))

Thanks for Your help!

Chat integration with task app

Hi @am-MongoDB,

I am trying to integrate the chat app with the real task app, so that each task can have a group discussion (like in Asana or Trello).
Could you give an insight on how the overall model would look like to make both work together?

Cheers
Alex

Unable to save data after login

Hello Andrew

I enabled sync in Realm, and applied the permissions stated in the accompanying article. I am able to login and the user created, however when I attempt to save an update to the profile the data does not get stored. Would you have some suggestions what I set up incorrectly?

Thank you,
Andrew

Query: Adding a default conversation

I want to be able to add each user to a "default" conversation such that every user starts with at least one conversation (with no team members). Sounds crazy but I want to go and build out further but need to grasp the basics first!

I have literally spent HOURS trying lots of different options. Please help before I go completely crazy! My latest attempt being as follows:

// Open the default realm
let realm = try! Realm()

    try! realm.write {
        let conversation = Conversation()
        conversation.displayName = "My Conversation"
        conversation.unreadCount = 0
    
        var user = app.currentUser
        let userID = user.id
        
        let thisUser = User(_id: userID)
        realm.add(user)
    }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.