Merge pull request 'sort and update contact list' (#44) from clsort into trunk
continuous-integration/drone/push Build is failing
Details
continuous-integration/drone/push Build is failing
Details
Reviewed-on: #44
This commit is contained in:
commit
9c2da3c6ef
|
@ -1,4 +1,5 @@
|
|||
import 'dart:convert';
|
||||
import 'dart:developer';
|
||||
|
||||
import '../errorHandler.dart';
|
||||
import '../model.dart';
|
||||
|
@ -34,6 +35,7 @@ class CwtchNotifier {
|
|||
savePeerHistory: data["saveConversationHistory"],
|
||||
numMessages: int.parse(data["numMessages"]),
|
||||
numUnread: int.parse(data["unread"]),
|
||||
lastMessageTime: DateTime.now(),//show at the top of the contact list even if no messages yet
|
||||
));
|
||||
break;
|
||||
case "PeerStateChange":
|
||||
|
@ -51,6 +53,7 @@ class CwtchNotifier {
|
|||
case "NewMessageFromPeer":
|
||||
profileCN.getProfile(data["ProfileOnion"]).contactList.getContact(data["RemotePeer"]).unreadMessages++;
|
||||
profileCN.getProfile(data["ProfileOnion"]).contactList.getContact(data["RemotePeer"]).totalMessages++;
|
||||
profileCN.getProfile(data["ProfileOnion"]).contactList.updateLastMessageTime(data["RemotePeer"], DateTime.now());
|
||||
break;
|
||||
case "AppError":
|
||||
print("New App Error: $data");
|
||||
|
@ -70,6 +73,9 @@ class CwtchNotifier {
|
|||
var isOnline = data["Status"] == "Success";
|
||||
profileCN.getProfile(data["ProfileOnion"]).isOnline = isOnline;
|
||||
break;
|
||||
case "ACNStatus":
|
||||
print("acn status: $data");
|
||||
break;
|
||||
default:
|
||||
print("unhandled event: $type");
|
||||
}
|
||||
|
|
|
@ -74,7 +74,6 @@ class ProfileListState extends ChangeNotifier {
|
|||
}
|
||||
|
||||
void add(ProfileInfoState newProfile) {
|
||||
print("ProfileListState: adding " + newProfile.onion + " and notifying");
|
||||
_profiles.add(newProfile);
|
||||
notifyListeners();
|
||||
}
|
||||
|
@ -101,9 +100,13 @@ class ContactListState extends ChangeNotifier {
|
|||
notifyListeners();
|
||||
}
|
||||
|
||||
void updateUnreadMessages(String forOnion, int newVal) {
|
||||
void updateLastMessageTime(String forOnion, DateTime newVal) {
|
||||
getContact(forOnion).lastMessageTime = newVal;
|
||||
_contacts.sort((ContactInfoState a, ContactInfoState b) {
|
||||
return b.unreadMessages - a.unreadMessages;
|
||||
if (a.lastMessageTime == null && b.lastMessageTime == null) return 0;
|
||||
if (a.lastMessageTime == null) return 1;
|
||||
if (b.lastMessageTime == null) return -1;
|
||||
return b.lastMessageTime.compareTo(a.lastMessageTime);
|
||||
});
|
||||
//<todo> if(changed) {
|
||||
notifyListeners();
|
||||
|
@ -140,7 +143,6 @@ class ProfileInfoState extends ChangeNotifier {
|
|||
this._online = online;
|
||||
|
||||
if (contactsJson != null && contactsJson != "" && contactsJson != "null") {
|
||||
print("decoding " + contactsJson);
|
||||
List<dynamic> contacts = jsonDecode(contactsJson);
|
||||
this._contacts.addAll(contacts.map((contact) {
|
||||
return ContactInfoState(
|
||||
|
@ -153,8 +155,14 @@ class ProfileInfoState extends ChangeNotifier {
|
|||
isInvitation: contact["authorization"] == "unknown",
|
||||
savePeerHistory: contact["saveConversationHistory"],
|
||||
numMessages: contact["numMessages"],
|
||||
numUnread: contact["numUnread"]);
|
||||
numUnread: contact["numUnread"],
|
||||
lastMessageTime: DateTime.fromMillisecondsSinceEpoch(1000 * int.parse(contact["lastMsgTime"])));
|
||||
}));
|
||||
|
||||
// dummy set to invoke sort-on-load
|
||||
if (this._contacts.num > 0) {
|
||||
this._contacts.updateLastMessageTime(this._contacts._contacts.first.onion, this._contacts._contacts.first.lastMessageTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -204,6 +212,7 @@ class ContactInfoState extends ChangeNotifier {
|
|||
String _savePeerHistory;
|
||||
int _unreadMessages = 0;
|
||||
int _totalMessages = 0;
|
||||
DateTime _lastMessageTime;
|
||||
|
||||
ContactInfoState({
|
||||
this.profileOnion,
|
||||
|
@ -217,6 +226,7 @@ class ContactInfoState extends ChangeNotifier {
|
|||
savePeerHistory = "DeleteHistoryConfirmed",
|
||||
numMessages = 0,
|
||||
numUnread = 0,
|
||||
lastMessageTime = null,
|
||||
}) {
|
||||
this._nickname = nickname;
|
||||
this._isGroup = isGroup;
|
||||
|
@ -227,6 +237,7 @@ class ContactInfoState extends ChangeNotifier {
|
|||
this._totalMessages = numMessages;
|
||||
this._unreadMessages = numUnread;
|
||||
this._savePeerHistory = savePeerHistory;
|
||||
this._lastMessageTime = lastMessageTime;
|
||||
}
|
||||
|
||||
get nickname => this._nickname;
|
||||
|
@ -283,6 +294,12 @@ class ContactInfoState extends ChangeNotifier {
|
|||
this._imagePath = newVal;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
get lastMessageTime => this._lastMessageTime;
|
||||
set lastMessageTime(DateTime newVal) {
|
||||
this._lastMessageTime = newVal;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
class MessageState extends ChangeNotifier {
|
||||
|
|
|
@ -18,6 +18,14 @@ class _MessageViewState extends State<MessageView> {
|
|||
final ctrlrCompose = TextEditingController();
|
||||
final focusNode = FocusNode();
|
||||
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
super.didChangeDependencies();
|
||||
if (Provider.of<ContactInfoState>(context, listen: false).unreadMessages > 0) {
|
||||
Provider.of<ContactInfoState>(context, listen: false).unreadMessages = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
focusNode.dispose();
|
||||
|
|
|
@ -89,7 +89,7 @@ class _ContactRowState extends State<ContactRow> {
|
|||
return MultiProvider(
|
||||
providers: [
|
||||
ChangeNotifierProvider.value(value: Provider.of<ProfileInfoState>(context)),
|
||||
ChangeNotifierProvider.value(value: Provider.of<ContactInfoState>(context)),
|
||||
ChangeNotifierProvider.value(value: Provider.of<ProfileInfoState>(context).contactList.getContact(handle)),
|
||||
],
|
||||
child: MessageView(),
|
||||
);
|
||||
|
|
Loading…
Reference in New Issue