Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/1amageek/muni

Chat with Cloud Firestore
https://github.com/1amageek/muni

chat cloudfirestore firebase messaging

Last synced: about 2 months ago
JSON representation

Chat with Cloud Firestore

Awesome Lists containing this project

README

        

# Muni
Chat framework

# Feature 🎊

☑️ **Serverless - Firebase Cloud Firestore**

☑️ **Realtime**

☑️ **Customizable**

☑️ **Type Safe**

☑️ **Multi Media**

#### Media
- Text
- Image
- Video
- Audio
- Location
- Sticker
- ImageMap

# Installation ⚙

`pod 'Muni'` add to your Podfile

```
pod install
```

`GoogleService-Info.plist` add to your Project

# Usage

## Prepare three documents for cloud firestore.
`UserProtocol` `RoomProtocol` `TranscriptProtocol` create document conforming to each protocol.

``` swift
@objcMembers
class User: Object, UserProtocol {
var name: String?
var thumbnailImage: File?
}
```

``` swift
@objcMembers
class Room: Object, RoomProtocol {
typealias TranscriptType = Transcript
dynamic var name: String?
dynamic var thumbnailImage: File?
dynamic var viewers: [String] = []
dynamic var members: [String] = []
dynamic var recentTranscript: [String: Any] = [:]
dynamic var transcripts: NestedCollection = []
dynamic var config: [String: Any] = [:]
dynamic var isMessagingEnabled: Bool = true
dynamic var isHidden: Bool = false
dynamic var lastViewedTimestamps: [String : Timestamp] = [:]
}
```

``` swift
@objcMembers
class Transcript: Object, TranscriptProtocol {
dynamic var to: Relation = .init()
dynamic var from: Relation = .init()
dynamic var text: String?
dynamic var image: File?
dynamic var video: File?
dynamic var audio: File?
dynamic var location: GeoPoint?
dynamic var sticker: String?
dynamic var imageMap: [File] = []
}
```

## Override two ViewControllers

```swift
class MessageViewController: Muni.MessagesViewController {

var sendBarItem: ToolbarItem!

override var senderID: String? {
return Auth.auth().currentUser!.uid
}

override func viewDidLoad() {
super.viewDidLoad()
self.sendBarItem = ToolbarItem(title: "Send", target: self, action: #selector(send))
self.toolBar.setItems([ToolbarItem(customView: self.textView), self.sendBarItem], animated: false)

// Start
self.listen()
}

override func transcript(willSend transcript: Transcript) -> Bool {
guard let text: String = self.textView.text else { return false }
if text.isEmpty { return false }
transcript.text = text
self.textView.text = nil
return true
}
}
```

```swift
class BoxViewController: Muni.InboxViewController {

override func viewDidLoad() {
super.viewDidLoad()

// Start
self.listen()
}

override func messageViewController(with room: Room) -> Muni.MessagesViewController {
return MessageViewController(roomID: room.id)
}
}
```

### Build

> Muni internally uses Firestore Query.
> An error occurs if there is no Index in Firestore. You can create an Index by accessing the URL on the console.