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:convert';
|
||||||
|
import 'dart:developer';
|
||||||
|
|
||||||
import '../errorHandler.dart';
|
import '../errorHandler.dart';
|
||||||
import '../model.dart';
|
import '../model.dart';
|
||||||
|
@ -34,6 +35,7 @@ class CwtchNotifier {
|
||||||
savePeerHistory: data["saveConversationHistory"],
|
savePeerHistory: data["saveConversationHistory"],
|
||||||
numMessages: int.parse(data["numMessages"]),
|
numMessages: int.parse(data["numMessages"]),
|
||||||
numUnread: int.parse(data["unread"]),
|
numUnread: int.parse(data["unread"]),
|
||||||
|
lastMessageTime: DateTime.now(),//show at the top of the contact list even if no messages yet
|
||||||
));
|
));
|
||||||
break;
|
break;
|
||||||
case "PeerStateChange":
|
case "PeerStateChange":
|
||||||
|
@ -51,6 +53,7 @@ class CwtchNotifier {
|
||||||
case "NewMessageFromPeer":
|
case "NewMessageFromPeer":
|
||||||
profileCN.getProfile(data["ProfileOnion"]).contactList.getContact(data["RemotePeer"]).unreadMessages++;
|
profileCN.getProfile(data["ProfileOnion"]).contactList.getContact(data["RemotePeer"]).unreadMessages++;
|
||||||
profileCN.getProfile(data["ProfileOnion"]).contactList.getContact(data["RemotePeer"]).totalMessages++;
|
profileCN.getProfile(data["ProfileOnion"]).contactList.getContact(data["RemotePeer"]).totalMessages++;
|
||||||
|
profileCN.getProfile(data["ProfileOnion"]).contactList.updateLastMessageTime(data["RemotePeer"], DateTime.now());
|
||||||
break;
|
break;
|
||||||
case "AppError":
|
case "AppError":
|
||||||
print("New App Error: $data");
|
print("New App Error: $data");
|
||||||
|
@ -70,6 +73,9 @@ class CwtchNotifier {
|
||||||
var isOnline = data["Status"] == "Success";
|
var isOnline = data["Status"] == "Success";
|
||||||
profileCN.getProfile(data["ProfileOnion"]).isOnline = isOnline;
|
profileCN.getProfile(data["ProfileOnion"]).isOnline = isOnline;
|
||||||
break;
|
break;
|
||||||
|
case "ACNStatus":
|
||||||
|
print("acn status: $data");
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
print("unhandled event: $type");
|
print("unhandled event: $type");
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,7 +74,6 @@ class ProfileListState extends ChangeNotifier {
|
||||||
}
|
}
|
||||||
|
|
||||||
void add(ProfileInfoState newProfile) {
|
void add(ProfileInfoState newProfile) {
|
||||||
print("ProfileListState: adding " + newProfile.onion + " and notifying");
|
|
||||||
_profiles.add(newProfile);
|
_profiles.add(newProfile);
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
@ -101,9 +100,13 @@ class ContactListState extends ChangeNotifier {
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
void updateUnreadMessages(String forOnion, int newVal) {
|
void updateLastMessageTime(String forOnion, DateTime newVal) {
|
||||||
|
getContact(forOnion).lastMessageTime = newVal;
|
||||||
_contacts.sort((ContactInfoState a, ContactInfoState b) {
|
_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) {
|
//<todo> if(changed) {
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
|
@ -140,7 +143,6 @@ class ProfileInfoState extends ChangeNotifier {
|
||||||
this._online = online;
|
this._online = online;
|
||||||
|
|
||||||
if (contactsJson != null && contactsJson != "" && contactsJson != "null") {
|
if (contactsJson != null && contactsJson != "" && contactsJson != "null") {
|
||||||
print("decoding " + contactsJson);
|
|
||||||
List<dynamic> contacts = jsonDecode(contactsJson);
|
List<dynamic> contacts = jsonDecode(contactsJson);
|
||||||
this._contacts.addAll(contacts.map((contact) {
|
this._contacts.addAll(contacts.map((contact) {
|
||||||
return ContactInfoState(
|
return ContactInfoState(
|
||||||
|
@ -153,8 +155,14 @@ class ProfileInfoState extends ChangeNotifier {
|
||||||
isInvitation: contact["authorization"] == "unknown",
|
isInvitation: contact["authorization"] == "unknown",
|
||||||
savePeerHistory: contact["saveConversationHistory"],
|
savePeerHistory: contact["saveConversationHistory"],
|
||||||
numMessages: contact["numMessages"],
|
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;
|
String _savePeerHistory;
|
||||||
int _unreadMessages = 0;
|
int _unreadMessages = 0;
|
||||||
int _totalMessages = 0;
|
int _totalMessages = 0;
|
||||||
|
DateTime _lastMessageTime;
|
||||||
|
|
||||||
ContactInfoState({
|
ContactInfoState({
|
||||||
this.profileOnion,
|
this.profileOnion,
|
||||||
|
@ -217,6 +226,7 @@ class ContactInfoState extends ChangeNotifier {
|
||||||
savePeerHistory = "DeleteHistoryConfirmed",
|
savePeerHistory = "DeleteHistoryConfirmed",
|
||||||
numMessages = 0,
|
numMessages = 0,
|
||||||
numUnread = 0,
|
numUnread = 0,
|
||||||
|
lastMessageTime = null,
|
||||||
}) {
|
}) {
|
||||||
this._nickname = nickname;
|
this._nickname = nickname;
|
||||||
this._isGroup = isGroup;
|
this._isGroup = isGroup;
|
||||||
|
@ -227,6 +237,7 @@ class ContactInfoState extends ChangeNotifier {
|
||||||
this._totalMessages = numMessages;
|
this._totalMessages = numMessages;
|
||||||
this._unreadMessages = numUnread;
|
this._unreadMessages = numUnread;
|
||||||
this._savePeerHistory = savePeerHistory;
|
this._savePeerHistory = savePeerHistory;
|
||||||
|
this._lastMessageTime = lastMessageTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
get nickname => this._nickname;
|
get nickname => this._nickname;
|
||||||
|
@ -283,6 +294,12 @@ class ContactInfoState extends ChangeNotifier {
|
||||||
this._imagePath = newVal;
|
this._imagePath = newVal;
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get lastMessageTime => this._lastMessageTime;
|
||||||
|
set lastMessageTime(DateTime newVal) {
|
||||||
|
this._lastMessageTime = newVal;
|
||||||
|
notifyListeners();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class MessageState extends ChangeNotifier {
|
class MessageState extends ChangeNotifier {
|
||||||
|
|
|
@ -18,6 +18,14 @@ class _MessageViewState extends State<MessageView> {
|
||||||
final ctrlrCompose = TextEditingController();
|
final ctrlrCompose = TextEditingController();
|
||||||
final focusNode = FocusNode();
|
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
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
focusNode.dispose();
|
focusNode.dispose();
|
||||||
|
|
|
@ -89,7 +89,7 @@ class _ContactRowState extends State<ContactRow> {
|
||||||
return MultiProvider(
|
return MultiProvider(
|
||||||
providers: [
|
providers: [
|
||||||
ChangeNotifierProvider.value(value: Provider.of<ProfileInfoState>(context)),
|
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(),
|
child: MessageView(),
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in New Issue