Skip to content
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

thoth000の修正 #51

Closed
wants to merge 44 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
abc5832
Merge branch 'master' of https://github.com/stamp-team/chat-flutter
thoth000 Jun 16, 2020
743a023
Merge branch 'master' of https://github.com/stamp-team/chat-flutter
thoth000 Jun 17, 2020
2bb8ad3
データ取得
thoth000 Sep 1, 2020
a5d67b3
Stream<List<Room>>として取得できない
thoth000 Sep 2, 2020
0b2d7ea
ルームリストのリアルタイム更新をとりあえず断念
thoth000 Sep 20, 2020
3c1edb2
flutter format .
thoth000 Sep 20, 2020
c300ad6
Merge pull request #2 from ProgrammableGroup/feature/46
thoth000 Sep 21, 2020
4350035
fix file name
thoth000 Sep 21, 2020
97ef520
fit package
thoth000 Sep 21, 2020
7a96252
メッセージやり取り成功!
thoth000 Sep 21, 2020
b7a8330
Merge pull request #3 from thoth000/temporary
thoth000 Sep 21, 2020
3ddb812
名前検索
thoth000 Sep 21, 2020
c5b21f6
Merge pull request #4 from thoth000/temporary
thoth000 Sep 21, 2020
f9c0ddf
エラー周りを整えた
thoth000 Sep 21, 2020
127566b
Merge pull request #5 from thoth000/temporary
thoth000 Sep 21, 2020
203cde5
画像周りと起動画面切り替え実装
thoth000 Sep 21, 2020
eaff917
起動画面の仕分けとちょっとのfix
thoth000 Sep 21, 2020
90f1281
Merge pull request #6 from thoth000/temporary
thoth000 Sep 21, 2020
062158d
room編集機能の制作
thoth000 Sep 21, 2020
2527639
Merge pull request #7 from thoth000/temporary
thoth000 Sep 21, 2020
b412265
lint解消
thoth000 Sep 21, 2020
b384571
Merge pull request #8 from thoth000/temporary
thoth000 Sep 21, 2020
623d28f
メインクラスとfile名の統一
thoth000 Sep 21, 2020
844d176
Merge pull request #9 from thoth000/temporary
thoth000 Sep 21, 2020
011dc4e
roomの更新,room画像のアップロード,commonFuncの日付casr修正
thoth000 Sep 21, 2020
5aa876c
正しい変数名付けとRoomEditController
thoth000 Sep 21, 2020
3201236
Merge pull request #10 from thoth000/temporary
thoth000 Sep 22, 2020
234f2e5
text change
thoth000 Sep 22, 2020
dfbc763
Merge pull request #11 from thoth000/temporary
thoth000 Sep 22, 2020
60add56
roomの並び変え実装
thoth000 Sep 23, 2020
67f8173
Merge pull request #12 from thoth000/temporary
thoth000 Sep 23, 2020
886cedf
既読機能の試行錯誤
thoth000 Sep 24, 2020
c287dd7
既読実装完了
thoth000 Sep 25, 2020
f4c0e86
Merge pull request #13 from thoth000/temporary
thoth000 Sep 25, 2020
16d8dce
FieldTimeStampに変更
thoth000 Sep 25, 2020
6716a26
残りも
thoth000 Sep 25, 2020
11ca4c0
セキュリティ観点からの修正
thoth000 Sep 25, 2020
b30abee
Merge pull request #14 from thoth000/temporary
thoth000 Sep 25, 2020
3b19522
メッセージ取得後に画面下までスクロール
thoth000 Sep 25, 2020
4d4e2b4
Merge pull request #15 from thoth000/temporary
thoth000 Sep 25, 2020
fc4a0a5
変数命名やいらんもの削除
thoth000 Sep 25, 2020
dd4e449
ルームのスクロールコントロール実装
thoth000 Nov 4, 2020
8f94be9
flutter format .
thoth000 Nov 4, 2020
0419f1c
Merge pull request #16 from thoth000/temporary
thoth000 Nov 4, 2020
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
2 changes: 1 addition & 1 deletion lib/interfaces/message_interface.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ import 'package:chat_flutter/model/message.dart';
abstract class MessageInterface {
Future<void> sendMessage(String text, String roomId, String senderId);

Stream<List<Message>> getMessage(String roomId);
Stream<List<Message>> getMessage(String roomId, String userId);
}
File renamed without changes.
85 changes: 51 additions & 34 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import 'package:chat_flutter/services/messgae_service.dart';
import 'package:chat_flutter/ui/pages/create_room/select_member.dart';
import 'package:chat_flutter/services/message_service.dart';
import 'package:chat_flutter/ui/pages/create_room/select_member_page.dart';
import 'package:chat_flutter/services/auth/authenticator.dart';
import 'package:chat_flutter/ui/pages/profile/profile_controller.dart';
import 'package:chat_flutter/ui/pages/sign_in/sign_in.dart';
import 'package:chat_flutter/ui/pages/sign_up/sign_up.dart';
import 'package:chat_flutter/ui/pages/room/room_edit_page.dart';
import 'package:chat_flutter/ui/pages/sign_in/sign_in_page.dart';
import 'package:chat_flutter/ui/pages/sign_up/sign_up_page.dart';
import 'package:flutter/material.dart';
import 'package:chat_flutter/ui/pages/create_room/create_room.dart';
import 'package:chat_flutter/ui/pages/home/home.dart';
import 'package:chat_flutter/ui/pages/profile/profile_edit.dart';
import 'package:chat_flutter/ui/pages/room/room.dart';
import 'package:chat_flutter/ui/pages/create_room/create_room_page.dart';
import 'package:chat_flutter/ui/pages/home/home_page.dart';
import 'package:chat_flutter/ui/pages/profile/profile_edit_page.dart';
import 'package:chat_flutter/ui/pages/room/room_page.dart';
import 'package:provider/provider.dart';

void main() {
Expand All @@ -22,44 +23,60 @@ void main() {
create: (_) => MessageService(),
),
],
child: MyApp(),
child: Wrapped(),
));
}

class MyApp extends StatelessWidget {
class Wrapped extends StatelessWidget {
@override
Widget build(BuildContext context) {
// Authenticatorをコンストラクタで渡したかったので、MultiProviderではできなかった
return ChangeNotifierProvider(
create: (_) => ProfileController(
Provider.of<Authenticator>(
context,
listen: false,
),
),
child: MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
initialRoute:
Provider.of<Authenticator>(context, listen: false).isSignIn.value
? '/homePage'
: '/signUpPage',
routes: {
'/homePage': HomePage.wrapped,
'/signUpPage': (context) => SignUpPage.wrapped(
Provider.of<Authenticator>(context, listen: false)),
'/signInPage': (context) => SignInPage.wrapped(
Provider.of<Authenticator>(context, listen: false)),
'/roomPage': RoomPage.wrapped,
'/profileEditPage': (context) => ProfileEditPage(),
'/selectMemberPage': (context) => SelectMemberPage.wrapped(),
'/createGroupPage': (context) => CreateRoomPage.wrapped(
Provider.of<Authenticator>(context, listen: false)),
},
),
child: MyApp(),
);
}
}

class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return FutureBuilder<String>(
future: Provider.of<ProfileController>(context, listen: false)
.getUserById(),
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return Container(
color: Colors.white,
);
}
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
initialRoute: snapshot.data != '' ? '/homePage' : '/signUpPage',
routes: {
'/homePage': HomePage.wrapped,
'/signUpPage': (context) => SignUpPage.wrapped(
Provider.of<Authenticator>(context, listen: false)),
'/signInPage': (context) => SignInPage.wrapped(
Provider.of<Authenticator>(context, listen: false)),
'/roomPage': (context) => RoomPage.wrapped(
context, Provider.of<Authenticator>(context, listen: false)),
'/profileEditPage': (context) => ProfileEditPage(),
'/roomEditPage': (context) => RoomEditPage(),
'/selectMemberPage': (context) => SelectMemberPage.wrapped(
Provider.of<Authenticator>(context, listen: false)),
'/createGroupPage': (context) => CreateRoomPage.wrapped(
Provider.of<Authenticator>(context, listen: false)),
},
);
});
}
}
9 changes: 0 additions & 9 deletions lib/model/group.dart

This file was deleted.

7 changes: 2 additions & 5 deletions lib/model/message.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,26 @@ class Message {
String text;
DateTime sendTime;
bool isMe;
bool isRead;
String senderId;
String roomId;
Message({
this.text,
this.sendTime,
this.isMe,
this.isRead,
this.senderId,
this.roomId,
});

factory Message.fromJson(Map<String, dynamic> json) {
factory Message.fromJson(Map<String, dynamic> json, String userId) {
bool judgeIsMe(String senderId) {
// 自分のIDと比較
return senderId == 'userId';
return senderId == userId;
}

return Message(
text: json['text'].toString(),
sendTime: (json['createdAt'] as Timestamp).toDate(),
isMe: judgeIsMe(json['from'].toString()),
isRead: true,
senderId: json['from'].toString(),
roomId: json['to'].toString(),
);
Expand Down
14 changes: 11 additions & 3 deletions lib/model/room.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,22 @@ class Room {
String name;
String imgUrl;
List<String> members;
String lastMessage;
String sendTime;
Map<String, dynamic> lastMessage;
Room({
this.id,
this.name,
this.imgUrl,
this.members,
this.lastMessage,
this.sendTime,
});

factory Room.fromJson(Map<String, dynamic> json, String roomId) {
return Room(
id: roomId,
name: json['name'].toString(),
imgUrl: json['imgUrl'].toString(),
members: json['members'].cast<String>() as List<String>,
lastMessage: json['lastMessage'] as Map<String, dynamic>,
);
}
}
20 changes: 0 additions & 20 deletions lib/providers/user.dart

This file was deleted.

7 changes: 5 additions & 2 deletions lib/services/auth/authenticator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import 'package:rxdart/rxdart.dart';

class Authenticator {
Authenticator() {
_isSignIn.value = firebaseUser.value != null;
_isSignIn.value = _firebaseUser.value != null;
_firebaseAuth.onAuthStateChanged.pipe(_firebaseUser);
_firebaseAuth.onAuthStateChanged
.map((firebaseUser) => firebaseUser != null)
.map((firebaseUser) => _firebaseUser != null)
.pipe(_isSignIn);
}

Expand Down Expand Up @@ -50,6 +50,9 @@ class Authenticator {

Future<String> getUid() async {
final current = await fetchFirebaseUser();
if (current == null) {
return '';
}
return current.uid;
}

Expand Down
11 changes: 8 additions & 3 deletions lib/services/firebase_message_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,27 @@ class FirebaseMessageService {
'from': message.senderId,
'to': message.roomId,
'text': message.text,
'createdAt': message.sendTime,
'createdAt': FieldValue.serverTimestamp(),
};
final updateData = {'lastMessage': messageData};
await _db
.collection('message/v1/rooms/${message.roomId}/transcripts')
.document()
.setData(messageData);
await _db
.collection('message/v1/rooms')
.document('${message.roomId}')
.updateData(updateData);
}

Stream<List<Message>> getMessageData(String roomId) {
Stream<List<Message>> getMessageData(String roomId, String userId) {
final Stream<QuerySnapshot> querySnapshot = _db
.collection('message/v1/rooms/$roomId/transcripts')
.orderBy('createdAt', descending: false)
.snapshots();
return querySnapshot.map((snapshot) {
return snapshot.documents.map((doc) {
return Message.fromJson(doc.data);
return Message.fromJson(doc.data, userId);
}).toList();
});
}
Expand Down
61 changes: 60 additions & 1 deletion lib/services/firebase_room_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class FirebaseRoomService {
return docRef.documentID;
}

Future<void> setRoomSetting(String userId, String roomId) async {
Future<void> setMyRoomSetting(String userId, String roomId) async {
final settingData = {
'allowNotification': false,
};
Expand All @@ -26,4 +26,63 @@ class FirebaseRoomService {
.document(roomId)
.setData(settingData);
}

Future<void> updateRoomData(Room room) async {
final Map<String, String> roomData = {
'name': room.name,
'imgUrl': room.imgUrl,
};
await _db
.collection('message/v1/rooms')
.document(room.id)
.updateData(roomData);
}

Future<void> setMyLastReadTime(String roomId, String userId) async {
final timeData = {
'lastReadTime': FieldValue.serverTimestamp(),
};
await _db
.collection('message/v1/rooms/$roomId/members')
.document('$userId')
.setData(timeData);
}

Stream<List<DateTime>> getLastReadTimeList(String roomId) {
final Stream<QuerySnapshot> querySnapshot = _db
.collection('message/v1/rooms/$roomId/members')
.orderBy('lastReadTime', descending: false)
.snapshots();
return querySnapshot.map((snapshot) {
return snapshot.documents.map((doc) {
return (doc.data['lastReadTime'] as Timestamp).toDate();
}).toList();
});
}

Future<List<Room>> getMyRoomList(String uid) async {
final QuerySnapshot querySnapshot = await _db
.collection('message/v1/users/$uid/room_setting')
.getDocuments();
final List<DocumentSnapshot> docList = querySnapshot.documents;
final List<String> roomIdList =
docList.map((doc) => doc.documentID).toList();
final List<Room> roomList = [];
for (final String roomId in roomIdList) {
final DocumentSnapshot roomData =
await _db.collection('message/v1/rooms').document('$roomId').get();
roomList.add(Room.fromJson(roomData.data, roomId));
}
//時間順に並び替え
roomList.sort((a, b) {
final aTime = a.lastMessage['createdAt'] as Timestamp;
final bTime = b.lastMessage['createdAt'] as Timestamp;
if (aTime.compareTo(bTime) > 0) {
return -1;
} else {
return 1;
}
});
return roomList;
}
}
4 changes: 2 additions & 2 deletions lib/services/firebase_storage_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ class FirebaseStorageService {
final _storage = FirebaseStorage.instance;

Future<String> uploadImage(
File file, String uid, StorageType storageType) async {
File file, String id, StorageType storageType) async {
final StorageReference ref =
_storage.ref().child('${storageTypeToString(storageType)}/$uid');
_storage.ref().child('${storageTypeToString(storageType)}/$id');
final StorageUploadTask uploadTask = ref.putFile(file);

await uploadTask.onComplete;
Expand Down
23 changes: 22 additions & 1 deletion lib/services/firebase_user_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,34 @@ class FirebaseUserService {
return User.fromJson(user, uid);
}

Future<List<User>> getAllUser() async {
Future<String> getUserImgUrl(String uid) async {
final DocumentSnapshot result =
await _db.collection('message/v1/users').document('$uid').get();
return result.data['profileImageURL'].toString();
}

/*Future<List<User>> getAllUser() async {
final QuerySnapshot result =
await _db.collection('message/v1/users').getDocuments();

return result.documents.map((doc) {
final Map<String, dynamic> user = doc.data;
return User.fromJson(user, doc.documentID);
}).toList();
}*/

Future<List<User>> getSearchedUser(String name) async {
final startAt = [name];
final endAt = ['$name\uf8ff'];
final QuerySnapshot result = await _db
.collection('message/v1/users')
.orderBy('name')
.startAt(startAt)
.endAt(endAt)
.getDocuments();
return result.documents.map((doc) {
final Map<String, dynamic> user = doc.data;
return User.fromJson(user, doc.documentID);
}).toList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@ class MessageService implements MessageInterface {
text: text,
senderId: senderId,
roomId: roomId,
sendTime: DateTime.now(),
);
await FirebaseMessageService().setMessageData(message);
}

@override
Stream<List<Message>> getMessage(String roomId) {
return FirebaseMessageService().getMessageData(roomId);
Stream<List<Message>> getMessage(String roomId, String userId) {
return FirebaseMessageService().getMessageData(roomId, userId);
}
}
Loading