Skip to content

Commit b0f11db

Browse files
committed
update DB structure for demo projects: issue# 135
1 parent 0f6dbb3 commit b0f11db

File tree

4 files changed

+14
-10
lines changed

4 files changed

+14
-10
lines changed

samples/objc/FirebaseUIChat/Samples/Chat/FIRChatMessage.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@
1818

1919
@interface FIRChatMessage : NSObject
2020

21-
@property(strong, nonatomic) NSString *name;
22-
@property(strong, nonatomic) NSString *text;
21+
@property(copy, nonatomic) NSString *name;
22+
@property(copy, nonatomic) NSString *text;
23+
@property(copy, nonatomic) NSString *uid;
2324

24-
- (instancetype)initWithName:(NSString *)name andText:(NSString *)text;
25+
- (instancetype)initWithName:(NSString *)name andText:(NSString *)text userId:(NSString *)uid;
2526

2627
@end

samples/objc/FirebaseUIChat/Samples/Chat/FIRChatMessage.m

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,15 @@
1919
@implementation FIRChatMessage
2020

2121
- (instancetype)init {
22-
return [self initWithName:@"" andText:@""];
22+
return [self initWithName:@"" andText:@"" userId:@""];
2323
}
2424

25-
- (instancetype)initWithName:(NSString *)name andText:(NSString *)text {
25+
- (instancetype)initWithName:(NSString *)name andText:(NSString *)text userId:(NSString *)uid {
2626
self = [super init];
2727
if (self) {
2828
self.name = name;
2929
self.text = text;
30+
self.uid = uid;
3031
}
3132
return self;
3233
}

samples/objc/FirebaseUIChat/Samples/Chat/FIRChatViewController.m

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
//
1616

1717
#import <FirebaseAuthUI/FirebaseAuthUI.h>
18+
#import <FirebaseAuth/FirebaseAuth.h>
1819

1920
#import "FIRChatViewController.h"
2021
#import "FIRChatMessage.h"
@@ -26,7 +27,7 @@ @implementation FIRChatViewController
2627
- (void)viewDidLoad {
2728
[super viewDidLoad];
2829

29-
self.ref = [FIRDatabase database].reference;
30+
self.ref = [[FIRDatabase database].reference child:@"objc_demo-chat"];
3031

3132
self.dataSource =
3233
[[FIRChatMessageDataSource alloc] initWithRef:self.ref
@@ -39,7 +40,7 @@ - (void)viewDidLoad {
3940
populateCellWithBlock:^void(FIRChatMessageTableViewCell *__nonnull cell,
4041
FIRChatMessage *__nonnull message) {
4142

42-
if ([message.name isEqualToString:[FIRAuth auth].currentUser.displayName]) {
43+
if ([message.uid isEqualToString:[FIRAuth auth].currentUser.uid]) {
4344
cell.myMessageLabel.text = message.text;
4445
cell.myNameLabel.text = message.name;
4546
cell.myNameLabel.textColor = [UIColor colorWithRed:164.0 / 255.0
@@ -82,10 +83,11 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
8283

8384
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
8485

85-
NSString *currentUser = [FIRAuth auth].currentUser.displayName ?: @"iOS User";
86+
FIRUser *cuurentUser = [FIRAuth auth].currentUser;
87+
NSString *currentUser = cuurentUser.displayName ?: @"iOS User";
8688

8789
[[self.ref childByAutoId]
88-
setValue:@{@"name" : currentUser, @"text" : textField.text}];
90+
setValue:@{@"name" : currentUser, @"text" : textField.text, @"uid" : cuurentUser.uid}];
8991
[textField resignFirstResponder];
9092
textField.text = @"";
9193
return YES;

samples/swift/uidemo/ChatViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class ChatViewController: UIViewController, UICollectionViewDelegateFlowLayout {
4343
@IBOutlet private var bottomConstraint: NSLayoutConstraint!
4444

4545
private let auth = FIRAuth.auth()
46-
private let chatReference = FIRDatabase.database().reference().child("chats")
46+
private let chatReference = FIRDatabase.database().reference().child("swift_demo-chat")
4747

4848
private var collectionViewDataSource: FirebaseCollectionViewDataSource!
4949

0 commit comments

Comments
 (0)