Skip to content

[Example] Add Message application #51

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_ASSET_PATHS = "\"BoardApplication/Preview Content\"";
DEVELOPMENT_TEAM = 2X6AD4W323;
DEVELOPMENT_TEAM = S8WBNKMKYU;
ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES;
Expand Down Expand Up @@ -319,7 +319,7 @@
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_ASSET_PATHS = "\"BoardApplication/Preview Content\"";
DEVELOPMENT_TEAM = 2X6AD4W323;
DEVELOPMENT_TEAM = S8WBNKMKYU;
ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES;
Expand Down
536 changes: 536 additions & 0 deletions Examples/Practical/MessageApp/MessageApp.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"colors" : [
{
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
{
"images" : [
{
"idiom" : "iphone",
"scale" : "2x",
"size" : "20x20"
},
{
"idiom" : "iphone",
"scale" : "3x",
"size" : "20x20"
},
{
"idiom" : "iphone",
"scale" : "2x",
"size" : "29x29"
},
{
"idiom" : "iphone",
"scale" : "3x",
"size" : "29x29"
},
{
"idiom" : "iphone",
"scale" : "2x",
"size" : "40x40"
},
{
"idiom" : "iphone",
"scale" : "3x",
"size" : "40x40"
},
{
"idiom" : "iphone",
"scale" : "2x",
"size" : "60x60"
},
{
"idiom" : "iphone",
"scale" : "3x",
"size" : "60x60"
},
{
"idiom" : "ipad",
"scale" : "1x",
"size" : "20x20"
},
{
"idiom" : "ipad",
"scale" : "2x",
"size" : "20x20"
},
{
"idiom" : "ipad",
"scale" : "1x",
"size" : "29x29"
},
{
"idiom" : "ipad",
"scale" : "2x",
"size" : "29x29"
},
{
"idiom" : "ipad",
"scale" : "1x",
"size" : "40x40"
},
{
"idiom" : "ipad",
"scale" : "2x",
"size" : "40x40"
},
{
"idiom" : "ipad",
"scale" : "2x",
"size" : "76x76"
},
{
"idiom" : "ipad",
"scale" : "2x",
"size" : "83.5x83.5"
},
{
"idiom" : "ios-marketing",
"scale" : "1x",
"size" : "1024x1024"
},
{
"idiom" : "mac",
"scale" : "1x",
"size" : "16x16"
},
{
"idiom" : "mac",
"scale" : "2x",
"size" : "16x16"
},
{
"idiom" : "mac",
"scale" : "1x",
"size" : "32x32"
},
{
"idiom" : "mac",
"scale" : "2x",
"size" : "32x32"
},
{
"idiom" : "mac",
"scale" : "1x",
"size" : "128x128"
},
{
"idiom" : "mac",
"scale" : "2x",
"size" : "128x128"
},
{
"idiom" : "mac",
"scale" : "1x",
"size" : "256x256"
},
{
"idiom" : "mac",
"scale" : "2x",
"size" : "256x256"
},
{
"idiom" : "mac",
"scale" : "1x",
"size" : "512x512"
},
{
"idiom" : "mac",
"scale" : "2x",
"size" : "512x512"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
34 changes: 34 additions & 0 deletions Examples/Practical/MessageApp/Shared/GoogleService-Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CLIENT_ID</key>
<string>515012031387-7o4ug069j815ob817upknjuoapb5tags.apps.googleusercontent.com</string>
<key>REVERSED_CLIENT_ID</key>
<string>com.googleusercontent.apps.515012031387-7o4ug069j815ob817upknjuoapb5tags</string>
<key>API_KEY</key>
<string>AIzaSyDhMV12dqdpRU_oLJRajoZKSv6XdYdqri8</string>
<key>GCM_SENDER_ID</key>
<string>515012031387</string>
<key>PLIST_VERSION</key>
<string>1</string>
<key>BUNDLE_ID</key>
<string>dev.fummicc1.EasyFirebaseSwift.Example.MessageApp</string>
<key>PROJECT_ID</key>
<string>easyfirebaseswift-message</string>
<key>STORAGE_BUCKET</key>
<string>easyfirebaseswift-message.appspot.com</string>
<key>IS_ADS_ENABLED</key>
<false></false>
<key>IS_ANALYTICS_ENABLED</key>
<false></false>
<key>IS_APPINVITE_ENABLED</key>
<true></true>
<key>IS_GCM_ENABLED</key>
<true></true>
<key>IS_SIGNIN_ENABLED</key>
<true></true>
<key>GOOGLE_APP_ID</key>
<string>1:515012031387:ios:94bfaa3a37987a9d34273e</string>
</dict>
</plist>
33 changes: 33 additions & 0 deletions Examples/Practical/MessageApp/Shared/Message.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//
// Message.swift
// MessageApp
//
// Created by Fumiya Tanaka on 2022/04/21.
//

import Foundation
import FirebaseFirestoreSwift
import FirebaseFirestore
import EasyFirebaseSwiftFirestore

struct Message: FirestoreModel {

// MARK: Protocol confirmance
static var collectionName: String = "messages"

@DocumentID
var ref: DocumentReference?

@ServerTimestamp
var createdAt: Timestamp?

@ServerTimestamp
var updatedAt: Timestamp?

// MARK: Custom Properties
var text: String

var postedAt: Timestamp?
var senderID: String
var receiverID: String? // if nil is assigned, will be broadcast.
}
27 changes: 27 additions & 0 deletions Examples/Practical/MessageApp/Shared/MessageApp.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// MessageApp.swift
// Shared
//
// Created by Fumiya Tanaka on 2022/04/21.
//

import SwiftUI
import FirebaseCore

@main
struct MessageApp: App {

init() {
FirebaseApp.configure()
}

var body: some Scene {
WindowGroup {
Group {
RootView()
.environmentObject(RepositoryImpl())
}
.environmentObject(RepositoryImpl())
}
}
}
46 changes: 46 additions & 0 deletions Examples/Practical/MessageApp/Shared/Pages/MessageListModel.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//
// MessageListModel.swift
// MessageApp
//
// Created by Fumiya Tanaka on 2022/04/21.
//

import Foundation
import Combine

class MessageListModel: ObservableObject {
@Published var messages: [Message] = []
@Published var startMessage: String?

private var uid: String?

private let repository: Repository
private var cancellables: Set<AnyCancellable> = []

init(repository: Repository) {
self.repository = repository

repository.uid.sink { uid in
self.uid = uid
}.store(in: &cancellables)

repository.messages.assign(to: &$messages)
}

func createBroadcastMessage() async {
guard let startMessage = startMessage,
let uid = uid else {
return
}
let message = Message(
text: startMessage,
senderID: uid,
receiverID: nil
)
do {
try await repository.saveMessage(message)
} catch {
print(error)
}
}
}
23 changes: 23 additions & 0 deletions Examples/Practical/MessageApp/Shared/Pages/MessageListView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// MessageListView.swift
// MessageApp
//
// Created by Fumiya Tanaka on 2022/04/21.
//

import SwiftUI

struct MessageListView: View {

@EnvironmentObject var repository: RepositoryImpl

var body: some View {
Text("Hello, World!")
}
}

struct MessageListView_Previews: PreviewProvider {
static var previews: some View {
MessageListView()
}
}
Loading