Initial adjustments to datamodels and hub interface
This commit is contained in:
parent
8b285203aa
commit
70ec225a7d
16 changed files with 201 additions and 163 deletions
|
|
@ -1,28 +1,28 @@
|
||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
|
|
||||||
import 'package:recon/clients/api_client.dart';
|
import 'package:recon/clients/api_client.dart';
|
||||||
import 'package:recon/models/users/friend.dart';
|
import 'package:recon/models/users/contact.dart';
|
||||||
import 'package:recon/models/users/friend_status.dart';
|
import 'package:recon/models/users/contact_status.dart';
|
||||||
import 'package:recon/models/users/user.dart';
|
import 'package:recon/models/users/user.dart';
|
||||||
import 'package:recon/models/users/user_profile.dart';
|
import 'package:recon/models/users/user_profile.dart';
|
||||||
import 'package:recon/models/users/user_status.dart';
|
import 'package:recon/models/users/user_status.dart';
|
||||||
|
|
||||||
class ContactApi {
|
class ContactApi {
|
||||||
static Future<List<Friend>> getFriendsList(ApiClient client, {DateTime? lastStatusUpdate}) async {
|
static Future<List<Contact>> getFriendsList(ApiClient client, {DateTime? lastStatusUpdate}) async {
|
||||||
final response = await client.get("/users/${client.userId}/contacts${lastStatusUpdate != null ? "?lastStatusUpdate=${lastStatusUpdate.toUtc().toIso8601String()}" : ""}");
|
final response = await client.get("/users/${client.userId}/contacts${lastStatusUpdate != null ? "?lastStatusUpdate=${lastStatusUpdate.toUtc().toIso8601String()}" : ""}");
|
||||||
client.checkResponse(response);
|
client.checkResponse(response);
|
||||||
final data = jsonDecode(response.body) as List;
|
final data = jsonDecode(response.body) as List;
|
||||||
return data.map((e) => Friend.fromMap(e)).toList();
|
return data.map((e) => Contact.fromMap(e)).toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<void> addUserAsFriend(ApiClient client, {required User user}) async {
|
static Future<void> addUserAsFriend(ApiClient client, {required User user}) async {
|
||||||
final friend = Friend(
|
final friend = Contact(
|
||||||
id: user.id,
|
id: user.id,
|
||||||
username: user.username,
|
contactUsername: user.username,
|
||||||
ownerId: client.userId,
|
ownerId: client.userId,
|
||||||
userStatus: UserStatus.empty(),
|
userStatus: UserStatus.empty(),
|
||||||
userProfile: UserProfile.empty(),
|
userProfile: UserProfile.empty(),
|
||||||
contactStatus: FriendStatus.accepted,
|
friendStatus: ContactStatus.accepted,
|
||||||
latestMessageTime: DateTime.now(),
|
latestMessageTime: DateTime.now(),
|
||||||
);
|
);
|
||||||
final body = jsonEncode(friend.toMap(shallow: true));
|
final body = jsonEncode(friend.toMap(shallow: true));
|
||||||
|
|
|
||||||
|
|
@ -12,8 +12,9 @@ import 'package:recon/hub_manager.dart';
|
||||||
import 'package:recon/models/hub_events.dart';
|
import 'package:recon/models/hub_events.dart';
|
||||||
import 'package:recon/models/message.dart';
|
import 'package:recon/models/message.dart';
|
||||||
import 'package:recon/models/session.dart';
|
import 'package:recon/models/session.dart';
|
||||||
import 'package:recon/models/users/friend.dart';
|
import 'package:recon/models/users/contact.dart';
|
||||||
import 'package:recon/models/users/online_status.dart';
|
import 'package:recon/models/users/online_status.dart';
|
||||||
|
import 'package:recon/models/users/user.dart';
|
||||||
import 'package:recon/models/users/user_status.dart';
|
import 'package:recon/models/users/user_status.dart';
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:flutter/widgets.dart';
|
import 'package:flutter/widgets.dart';
|
||||||
|
|
@ -21,7 +22,6 @@ import 'package:hive_flutter/hive_flutter.dart';
|
||||||
import 'package:logging/logging.dart';
|
import 'package:logging/logging.dart';
|
||||||
import 'package:package_info_plus/package_info_plus.dart';
|
import 'package:package_info_plus/package_info_plus.dart';
|
||||||
|
|
||||||
|
|
||||||
class MessagingClient extends ChangeNotifier {
|
class MessagingClient extends ChangeNotifier {
|
||||||
static const Duration _autoRefreshDuration = Duration(seconds: 10);
|
static const Duration _autoRefreshDuration = Duration(seconds: 10);
|
||||||
static const Duration _unreadSafeguardDuration = Duration(seconds: 120);
|
static const Duration _unreadSafeguardDuration = Duration(seconds: 120);
|
||||||
|
|
@ -30,7 +30,7 @@ class MessagingClient extends ChangeNotifier {
|
||||||
static const String _lastUpdateKey = "__last-update-time";
|
static const String _lastUpdateKey = "__last-update-time";
|
||||||
|
|
||||||
final ApiClient _apiClient;
|
final ApiClient _apiClient;
|
||||||
final List<Friend> _sortedFriendsCache = []; // Keep a sorted copy so as to not have to sort during build()
|
final List<Contact> _sortedFriendsCache = []; // Keep a sorted copy so as to not have to sort during build()
|
||||||
final Map<String, MessageCache> _messageCache = {};
|
final Map<String, MessageCache> _messageCache = {};
|
||||||
final Map<String, List<Message>> _unreads = {};
|
final Map<String, List<Message>> _unreads = {};
|
||||||
final Logger _logger = Logger("Messaging");
|
final Logger _logger = Logger("Messaging");
|
||||||
|
|
@ -39,7 +39,7 @@ class MessagingClient extends ChangeNotifier {
|
||||||
final Map<String, Session> _sessionMap = {};
|
final Map<String, Session> _sessionMap = {};
|
||||||
final Set<String> _knownSessionKeys = {};
|
final Set<String> _knownSessionKeys = {};
|
||||||
final SettingsClient _settingsClient;
|
final SettingsClient _settingsClient;
|
||||||
Friend? selectedFriend;
|
Contact? selectedFriend;
|
||||||
|
|
||||||
Timer? _statusHeartbeat;
|
Timer? _statusHeartbeat;
|
||||||
Timer? _autoRefresh;
|
Timer? _autoRefresh;
|
||||||
|
|
@ -49,11 +49,13 @@ class MessagingClient extends ChangeNotifier {
|
||||||
|
|
||||||
UserStatus get userStatus => _userStatus;
|
UserStatus get userStatus => _userStatus;
|
||||||
|
|
||||||
MessagingClient({required ApiClient apiClient, required NotificationClient notificationClient, required SettingsClient settingsClient})
|
MessagingClient(
|
||||||
|
{required ApiClient apiClient,
|
||||||
|
required NotificationClient notificationClient,
|
||||||
|
required SettingsClient settingsClient})
|
||||||
: _apiClient = apiClient,
|
: _apiClient = apiClient,
|
||||||
_notificationClient = notificationClient,
|
_notificationClient = notificationClient,
|
||||||
_settingsClient = settingsClient
|
_settingsClient = settingsClient {
|
||||||
{
|
|
||||||
debugPrint("mClient created: $hashCode");
|
debugPrint("mClient created: $hashCode");
|
||||||
Hive.openBox(_messageBoxKey).then((box) async {
|
Hive.openBox(_messageBoxKey).then((box) async {
|
||||||
await box.delete(_lastUpdateKey);
|
await box.delete(_lastUpdateKey);
|
||||||
|
|
@ -75,16 +77,16 @@ class MessagingClient extends ChangeNotifier {
|
||||||
|
|
||||||
String? get initStatus => _initStatus;
|
String? get initStatus => _initStatus;
|
||||||
|
|
||||||
List<Friend> get cachedFriends => _sortedFriendsCache;
|
List<Contact> get cachedFriends => _sortedFriendsCache;
|
||||||
|
|
||||||
List<Message> getUnreadsForFriend(Friend friend) => _unreads[friend.id] ?? [];
|
List<Message> getUnreadsForFriend(Contact friend) => _unreads[friend.id] ?? [];
|
||||||
|
|
||||||
bool friendHasUnreads(Friend friend) => _unreads.containsKey(friend.id);
|
bool friendHasUnreads(Contact friend) => _unreads.containsKey(friend.id);
|
||||||
|
|
||||||
bool messageIsUnread(Message message) =>
|
bool messageIsUnread(Message message) =>
|
||||||
_unreads[message.senderId]?.any((element) => element.id == message.id) ?? false;
|
_unreads[message.senderId]?.any((element) => element.id == message.id) ?? false;
|
||||||
|
|
||||||
Friend? getAsFriend(String userId) => Friend.fromMapOrNull(Hive.box(_messageBoxKey).get(userId));
|
Contact? getAsFriend(String userId) => Contact.fromMapOrNull(Hive.box(_messageBoxKey).get(userId));
|
||||||
|
|
||||||
MessageCache? getUserMessageCache(String userId) => _messageCache[userId];
|
MessageCache? getUserMessageCache(String userId) => _messageCache[userId];
|
||||||
|
|
||||||
|
|
@ -106,7 +108,7 @@ class MessagingClient extends ChangeNotifier {
|
||||||
|
|
||||||
final friends = await ContactApi.getFriendsList(_apiClient, lastStatusUpdate: lastUpdateUtc);
|
final friends = await ContactApi.getFriendsList(_apiClient, lastStatusUpdate: lastUpdateUtc);
|
||||||
for (final friend in friends) {
|
for (final friend in friends) {
|
||||||
await _updateContact(friend);
|
await _updateContactLocal(friend);
|
||||||
}
|
}
|
||||||
|
|
||||||
_initStatus = "";
|
_initStatus = "";
|
||||||
|
|
@ -153,7 +155,7 @@ class MessagingClient extends ChangeNotifier {
|
||||||
|
|
||||||
final self = getAsFriend(_apiClient.userId);
|
final self = getAsFriend(_apiClient.userId);
|
||||||
if (self != null) {
|
if (self != null) {
|
||||||
await _updateContact(self.copyWith(userStatus: _userStatus));
|
await _updateContactLocal(self.copyWith(userStatus: _userStatus));
|
||||||
}
|
}
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
@ -206,7 +208,7 @@ class MessagingClient extends ChangeNotifier {
|
||||||
final friend = getAsFriend(userId);
|
final friend = getAsFriend(userId);
|
||||||
if (friend == null) return;
|
if (friend == null) return;
|
||||||
final newStatus = await UserApi.getUserStatus(_apiClient, userId: userId);
|
final newStatus = await UserApi.getUserStatus(_apiClient, userId: userId);
|
||||||
await _updateContact(friend.copyWith(userStatus: newStatus));
|
await _updateContactLocal(friend.copyWith(userStatus: newStatus));
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -215,6 +217,10 @@ class MessagingClient extends ChangeNotifier {
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void addUserAsFriend(User user) {
|
||||||
|
_hubManager.send("UpdateContact", arguments: [user.asContactRequest(_apiClient.userId)]);
|
||||||
|
}
|
||||||
|
|
||||||
Future<void> _refreshUnreads() async {
|
Future<void> _refreshUnreads() async {
|
||||||
try {
|
try {
|
||||||
final unreadMessages = await MessageApi.getUserMessages(_apiClient, unreadOnly: true);
|
final unreadMessages = await MessageApi.getUserMessages(_apiClient, unreadOnly: true);
|
||||||
|
|
@ -233,7 +239,7 @@ class MessagingClient extends ChangeNotifier {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _updateContact(Friend friend) async {
|
Future<void> _updateContactLocal(Contact friend) async {
|
||||||
final box = Hive.box(_messageBoxKey);
|
final box = Hive.box(_messageBoxKey);
|
||||||
box.put(friend.id, friend.toMap());
|
box.put(friend.id, friend.toMap());
|
||||||
final lastStatusUpdate = box.get(_lastUpdateKey);
|
final lastStatusUpdate = box.get(_lastUpdateKey);
|
||||||
|
|
@ -271,16 +277,17 @@ class MessagingClient extends ChangeNotifier {
|
||||||
"InitializeStatus",
|
"InitializeStatus",
|
||||||
responseHandler: (Map data) async {
|
responseHandler: (Map data) async {
|
||||||
final rawContacts = data["contacts"] as List;
|
final rawContacts = data["contacts"] as List;
|
||||||
final contacts = rawContacts.map((e) => Friend.fromMap(e)).toList();
|
final contacts = rawContacts.map((e) => Contact.fromMap(e)).toList();
|
||||||
for (final contact in contacts) {
|
for (final contact in contacts) {
|
||||||
await _updateContact(contact);
|
await _updateContactLocal(contact);
|
||||||
}
|
}
|
||||||
_initStatus = "";
|
_initStatus = "";
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
await _refreshUnreads();
|
await _refreshUnreads();
|
||||||
_unreadSafeguard = Timer.periodic(_unreadSafeguardDuration, (timer) => _refreshUnreads());
|
_unreadSafeguard = Timer.periodic(_unreadSafeguardDuration, (timer) => _refreshUnreads());
|
||||||
_hubManager.send("RequestStatus", arguments: [null, false]);
|
_hubManager.send("RequestStatus", arguments: [null, false]);
|
||||||
final lastOnline = OnlineStatus.values.elementAtOrNull(_settingsClient.currentSettings.lastOnlineStatus.valueOrDefault);
|
final lastOnline =
|
||||||
|
OnlineStatus.values.elementAtOrNull(_settingsClient.currentSettings.lastOnlineStatus.valueOrDefault);
|
||||||
await setOnlineStatus(lastOnline ?? OnlineStatus.online);
|
await setOnlineStatus(lastOnline ?? OnlineStatus.online);
|
||||||
_statusHeartbeat = Timer.periodic(_statusHeartbeatDuration, (timer) {
|
_statusHeartbeat = Timer.periodic(_statusHeartbeatDuration, (timer) {
|
||||||
setOnlineStatus(_userStatus.onlineStatus);
|
setOnlineStatus(_userStatus.onlineStatus);
|
||||||
|
|
@ -332,10 +339,12 @@ class MessagingClient extends ChangeNotifier {
|
||||||
var status = UserStatus.fromMap(statusUpdate);
|
var status = UserStatus.fromMap(statusUpdate);
|
||||||
final sessionMap = createSessionMap(status.hashSalt);
|
final sessionMap = createSessionMap(status.hashSalt);
|
||||||
status = status.copyWith(
|
status = status.copyWith(
|
||||||
decodedSessions: status.sessions.map((e) => sessionMap[e.sessionHash] ?? Session.none().copyWith(accessLevel: e.accessLevel)).toList());
|
decodedSessions: status.sessions
|
||||||
|
.map((e) => sessionMap[e.sessionHash] ?? Session.none().copyWith(accessLevel: e.accessLevel))
|
||||||
|
.toList());
|
||||||
final friend = getAsFriend(statusUpdate["userId"])?.copyWith(userStatus: status);
|
final friend = getAsFriend(statusUpdate["userId"])?.copyWith(userStatus: status);
|
||||||
if (friend != null) {
|
if (friend != null) {
|
||||||
_updateContact(friend);
|
_updateContactLocal(friend);
|
||||||
}
|
}
|
||||||
for (var session in status.sessions) {
|
for (var session in status.sessions) {
|
||||||
if (session.broadcastKey != null && _knownSessionKeys.add(session.broadcastKey ?? "")) {
|
if (session.broadcastKey != null && _knownSessionKeys.add(session.broadcastKey ?? "")) {
|
||||||
|
|
|
||||||
|
|
@ -1,70 +1,70 @@
|
||||||
import 'package:recon/auxiliary.dart';
|
import 'package:recon/auxiliary.dart';
|
||||||
import 'package:recon/models/users/user_profile.dart';
|
import 'package:recon/models/users/user_profile.dart';
|
||||||
import 'package:recon/models/users/friend_status.dart';
|
import 'package:recon/models/users/contact_status.dart';
|
||||||
import 'package:recon/models/users/online_status.dart';
|
import 'package:recon/models/users/online_status.dart';
|
||||||
import 'package:recon/models/users/user_status.dart';
|
import 'package:recon/models/users/user_status.dart';
|
||||||
|
|
||||||
class Friend implements Comparable {
|
class Contact implements Comparable {
|
||||||
static const _emptyId = "-1";
|
static const _emptyId = "-1";
|
||||||
static const _resoniteBotId = "U-Resonite";
|
static const _resoniteBotId = "U-Resonite";
|
||||||
final String id;
|
final String id;
|
||||||
final String username;
|
final String contactUsername;
|
||||||
final String ownerId;
|
final String ownerId;
|
||||||
final UserStatus userStatus;
|
final UserStatus userStatus;
|
||||||
final UserProfile userProfile;
|
final UserProfile userProfile;
|
||||||
final FriendStatus contactStatus;
|
final ContactStatus friendStatus;
|
||||||
final DateTime latestMessageTime;
|
final DateTime latestMessageTime;
|
||||||
|
|
||||||
const Friend({required this.id, required this.username, required this.ownerId, required this.userStatus, required this.userProfile,
|
const Contact({required this.id, required this.contactUsername, required this.ownerId, required this.userStatus, required this.userProfile,
|
||||||
required this.contactStatus, required this.latestMessageTime,
|
required this.friendStatus, required this.latestMessageTime,
|
||||||
});
|
});
|
||||||
|
|
||||||
bool get isHeadless => userStatus.outputDevice == "Headless";
|
bool get isHeadless => userStatus.outputDevice == "Headless";
|
||||||
|
|
||||||
factory Friend.fromMap(Map map) {
|
factory Contact.fromMap(Map map) {
|
||||||
var userStatus = map["userStatus"] == null ? UserStatus.empty() : UserStatus.fromMap(map["userStatus"]);
|
var userStatus = map["userStatus"] == null ? UserStatus.empty() : UserStatus.fromMap(map["userStatus"]);
|
||||||
return Friend(
|
return Contact(
|
||||||
id: map["id"],
|
id: map["id"],
|
||||||
username: map["contactUsername"],
|
contactUsername: map["contactUsername"],
|
||||||
ownerId: map["ownerId"] ?? map["id"],
|
ownerId: map["ownerId"] ?? map["id"],
|
||||||
// Neos bot status is always offline but should be displayed as online
|
// Neos bot status is always offline but should be displayed as online
|
||||||
userStatus: map["id"] == _resoniteBotId ? userStatus.copyWith(onlineStatus: OnlineStatus.online) : userStatus,
|
userStatus: map["id"] == _resoniteBotId ? userStatus.copyWith(onlineStatus: OnlineStatus.online) : userStatus,
|
||||||
userProfile: UserProfile.fromMap(map["profile"] ?? {}),
|
userProfile: UserProfile.fromMap(map["profile"] ?? {}),
|
||||||
contactStatus: FriendStatus.fromString(map["contactStatus"]),
|
friendStatus: ContactStatus.fromString(map["contactStatus"]),
|
||||||
latestMessageTime: map["latestMessageTime"] == null
|
latestMessageTime: map["latestMessageTime"] == null
|
||||||
? DateTime.fromMillisecondsSinceEpoch(0) : DateTime.parse(map["latestMessageTime"]),
|
? DateTime.fromMillisecondsSinceEpoch(0) : DateTime.parse(map["latestMessageTime"]),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Friend? fromMapOrNull(Map? map) {
|
static Contact? fromMapOrNull(Map? map) {
|
||||||
if (map == null) return null;
|
if (map == null) return null;
|
||||||
return Friend.fromMap(map);
|
return Contact.fromMap(map);
|
||||||
}
|
}
|
||||||
|
|
||||||
factory Friend.empty() {
|
factory Contact.empty() {
|
||||||
return Friend(
|
return Contact(
|
||||||
id: _emptyId,
|
id: _emptyId,
|
||||||
username: "",
|
contactUsername: "",
|
||||||
ownerId: "",
|
ownerId: "",
|
||||||
userStatus: UserStatus.empty(),
|
userStatus: UserStatus.empty(),
|
||||||
userProfile: UserProfile.empty(),
|
userProfile: UserProfile.empty(),
|
||||||
contactStatus: FriendStatus.none,
|
friendStatus: ContactStatus.none,
|
||||||
latestMessageTime: DateTimeX.epoch
|
latestMessageTime: DateTimeX.epoch
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool get isEmpty => id == _emptyId;
|
bool get isEmpty => id == _emptyId;
|
||||||
|
|
||||||
Friend copyWith({
|
Contact copyWith({
|
||||||
String? id, String? username, String? ownerId, UserStatus? userStatus, UserProfile? userProfile,
|
String? id, String? contactUsername, String? ownerId, UserStatus? userStatus, UserProfile? userProfile,
|
||||||
FriendStatus? contactStatus, DateTime? latestMessageTime}) {
|
ContactStatus? friendStatus, DateTime? latestMessageTime}) {
|
||||||
return Friend(
|
return Contact(
|
||||||
id: id ?? this.id,
|
id: id ?? this.id,
|
||||||
username: username ?? this.username,
|
contactUsername: contactUsername ?? this.contactUsername,
|
||||||
ownerId: ownerId ?? this.ownerId,
|
ownerId: ownerId ?? this.ownerId,
|
||||||
userStatus: userStatus ?? this.userStatus,
|
userStatus: userStatus ?? this.userStatus,
|
||||||
userProfile: userProfile ?? this.userProfile,
|
userProfile: userProfile ?? this.userProfile,
|
||||||
contactStatus: contactStatus ?? this.contactStatus,
|
friendStatus: friendStatus ?? this.friendStatus,
|
||||||
latestMessageTime: latestMessageTime ?? this.latestMessageTime,
|
latestMessageTime: latestMessageTime ?? this.latestMessageTime,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -72,17 +72,17 @@ class Friend implements Comparable {
|
||||||
Map toMap({bool shallow=false}) {
|
Map toMap({bool shallow=false}) {
|
||||||
return {
|
return {
|
||||||
"id": id,
|
"id": id,
|
||||||
"contactUsername": username,
|
"contactUsername": contactUsername,
|
||||||
"ownerId": ownerId,
|
"ownerId": ownerId,
|
||||||
"userStatus": userStatus.toMap(shallow: shallow),
|
"userStatus": userStatus.toMap(shallow: shallow),
|
||||||
"profile": userProfile.toMap(),
|
"profile": userProfile.toMap(),
|
||||||
"contactStatus": contactStatus.name,
|
"contactStatus": friendStatus.name,
|
||||||
"latestMessageTime": latestMessageTime.toIso8601String(),
|
"latestMessageTime": latestMessageTime.toIso8601String(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
int compareTo(covariant Friend other) {
|
int compareTo(covariant Contact other) {
|
||||||
return username.compareTo(other.username);
|
return contactUsername.compareTo(other.contactUsername);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
14
lib/models/users/contact_status.dart
Normal file
14
lib/models/users/contact_status.dart
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
enum ContactStatus {
|
||||||
|
none,
|
||||||
|
searchResult,
|
||||||
|
requested,
|
||||||
|
ignored,
|
||||||
|
blocked,
|
||||||
|
accepted;
|
||||||
|
|
||||||
|
factory ContactStatus.fromString(String text) {
|
||||||
|
return ContactStatus.values.firstWhere((element) => element.name.toLowerCase() == text.toLowerCase(),
|
||||||
|
orElse: () => ContactStatus.none,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,14 +0,0 @@
|
||||||
enum FriendStatus {
|
|
||||||
none,
|
|
||||||
searchResult,
|
|
||||||
requested,
|
|
||||||
ignored,
|
|
||||||
blocked,
|
|
||||||
accepted;
|
|
||||||
|
|
||||||
factory FriendStatus.fromString(String text) {
|
|
||||||
return FriendStatus.values.firstWhere((element) => element.name.toLowerCase() == text.toLowerCase(),
|
|
||||||
orElse: () => FriendStatus.none,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
import 'package:recon/models/users/contact_status.dart';
|
||||||
import 'package:recon/models/users/user_profile.dart';
|
import 'package:recon/models/users/user_profile.dart';
|
||||||
|
|
||||||
class User {
|
class User {
|
||||||
|
|
@ -31,4 +32,13 @@ class User {
|
||||||
"profile": userProfile?.toMap(),
|
"profile": userProfile?.toMap(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Map asContactRequest(String ownerId) {
|
||||||
|
return {
|
||||||
|
"ownerId": ownerId,
|
||||||
|
"id": id,
|
||||||
|
"contactUsername": username,
|
||||||
|
"contactStatus": ContactStatus.accepted.name,
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -4,7 +4,7 @@ import 'package:provider/provider.dart';
|
||||||
import 'package:recon/auxiliary.dart';
|
import 'package:recon/auxiliary.dart';
|
||||||
import 'package:recon/clients/messaging_client.dart';
|
import 'package:recon/clients/messaging_client.dart';
|
||||||
import 'package:recon/models/message.dart';
|
import 'package:recon/models/message.dart';
|
||||||
import 'package:recon/models/users/friend.dart';
|
import 'package:recon/models/users/contact.dart';
|
||||||
import 'package:recon/models/users/online_status.dart';
|
import 'package:recon/models/users/online_status.dart';
|
||||||
import 'package:recon/widgets/formatted_text.dart';
|
import 'package:recon/widgets/formatted_text.dart';
|
||||||
import 'package:recon/widgets/friends/friend_online_status_indicator.dart';
|
import 'package:recon/widgets/friends/friend_online_status_indicator.dart';
|
||||||
|
|
@ -14,7 +14,7 @@ import 'package:recon/widgets/messages/messages_list.dart';
|
||||||
class FriendListTile extends StatelessWidget {
|
class FriendListTile extends StatelessWidget {
|
||||||
const FriendListTile({required this.friend, required this.unreads, this.onTap, super.key});
|
const FriendListTile({required this.friend, required this.unreads, this.onTap, super.key});
|
||||||
|
|
||||||
final Friend friend;
|
final Contact friend;
|
||||||
final int unreads;
|
final int unreads;
|
||||||
final Function? onTap;
|
final Function? onTap;
|
||||||
|
|
||||||
|
|
@ -38,7 +38,7 @@ class FriendListTile extends StatelessWidget {
|
||||||
: null,
|
: null,
|
||||||
title: Row(
|
title: Row(
|
||||||
children: [
|
children: [
|
||||||
Text(friend.username),
|
Text(friend.contactUsername),
|
||||||
if (friend.isHeadless)
|
if (friend.isHeadless)
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.only(left: 8),
|
padding: const EdgeInsets.only(left: 8),
|
||||||
|
|
|
||||||
|
|
@ -45,9 +45,9 @@ class _FriendsListState extends State<FriendsList> with AutomaticKeepAliveClient
|
||||||
var friends = List.from(mClient.cachedFriends); // Explicit copy.
|
var friends = List.from(mClient.cachedFriends); // Explicit copy.
|
||||||
if (_searchFilter.isNotEmpty) {
|
if (_searchFilter.isNotEmpty) {
|
||||||
friends = friends
|
friends = friends
|
||||||
.where((element) => element.username.toLowerCase().contains(_searchFilter.toLowerCase()))
|
.where((element) => element.contactUsername.toLowerCase().contains(_searchFilter.toLowerCase()))
|
||||||
.toList();
|
.toList();
|
||||||
friends.sort((a, b) => a.username.length.compareTo(b.username.length));
|
friends.sort((a, b) => a.contactUsername.length.compareTo(b.contactUsername.length));
|
||||||
}
|
}
|
||||||
return ListView.builder(
|
return ListView.builder(
|
||||||
physics: const BouncingScrollPhysics(decelerationRate: ScrollDecelerationRate.fast),
|
physics: const BouncingScrollPhysics(decelerationRate: ScrollDecelerationRate.fast),
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,20 @@
|
||||||
|
import 'package:provider/provider.dart';
|
||||||
import 'package:recon/apis/contact_api.dart';
|
import 'package:recon/apis/contact_api.dart';
|
||||||
import 'package:recon/auxiliary.dart';
|
import 'package:recon/auxiliary.dart';
|
||||||
import 'package:recon/client_holder.dart';
|
import 'package:recon/client_holder.dart';
|
||||||
|
import 'package:recon/clients/messaging_client.dart';
|
||||||
import 'package:recon/models/users/user.dart';
|
import 'package:recon/models/users/user.dart';
|
||||||
import 'package:recon/widgets/generic_avatar.dart';
|
import 'package:recon/widgets/generic_avatar.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:intl/intl.dart';
|
import 'package:intl/intl.dart';
|
||||||
|
|
||||||
class UserListTile extends StatefulWidget {
|
class UserListTile extends StatefulWidget {
|
||||||
const UserListTile({required this.user, required this.isFriend, required this.onChanged, super.key});
|
const UserListTile({
|
||||||
|
required this.user,
|
||||||
|
required this.isFriend,
|
||||||
|
required this.onChanged,
|
||||||
|
super.key,
|
||||||
|
});
|
||||||
|
|
||||||
final User user;
|
final User user;
|
||||||
final bool isFriend;
|
final bool isFriend;
|
||||||
|
|
@ -24,24 +31,20 @@ class _UserListTileState extends State<UserListTile> {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final colorScheme = Theme
|
final colorScheme = Theme.of(context).colorScheme;
|
||||||
.of(context)
|
final style = _localAdded
|
||||||
.colorScheme;
|
? IconButton.styleFrom(
|
||||||
final style = _localAdded ? IconButton.styleFrom(
|
foregroundColor: colorScheme.onBackground,
|
||||||
foregroundColor: colorScheme.onBackground,
|
side: BorderSide(color: colorScheme.error, width: 2),
|
||||||
side: BorderSide(
|
)
|
||||||
color: colorScheme.error,
|
: IconButton.styleFrom(
|
||||||
width: 2
|
foregroundColor: colorScheme.onBackground,
|
||||||
),
|
side: BorderSide(color: colorScheme.primary, width: 2),
|
||||||
) : IconButton.styleFrom(
|
);
|
||||||
foregroundColor: colorScheme.onBackground,
|
|
||||||
side: BorderSide(
|
|
||||||
color: colorScheme.primary,
|
|
||||||
width: 2
|
|
||||||
),
|
|
||||||
);
|
|
||||||
return ListTile(
|
return ListTile(
|
||||||
leading: GenericAvatar(imageUri: Aux.resdbToHttp(widget.user.userProfile?.iconUrl),),
|
leading: GenericAvatar(
|
||||||
|
imageUri: Aux.resdbToHttp(widget.user.userProfile?.iconUrl),
|
||||||
|
),
|
||||||
title: Text(widget.user.username),
|
title: Text(widget.user.username),
|
||||||
subtitle: Text(_regDateFormat.format(widget.user.registrationDate)),
|
subtitle: Text(_regDateFormat.format(widget.user.registrationDate)),
|
||||||
trailing: IconButton(
|
trailing: IconButton(
|
||||||
|
|
@ -49,48 +52,48 @@ class _UserListTileState extends State<UserListTile> {
|
||||||
iconSize: 20,
|
iconSize: 20,
|
||||||
icon: _localAdded ? const Icon(Icons.person_remove) : const Icon(Icons.person_add),
|
icon: _localAdded ? const Icon(Icons.person_remove) : const Icon(Icons.person_add),
|
||||||
style: style,
|
style: style,
|
||||||
onPressed: _loading ? null : () async {
|
onPressed: _loading
|
||||||
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text("Sorry, this feature is not yet available")));
|
? null
|
||||||
return;
|
: () async {
|
||||||
setState(() {
|
final mClient = Provider.of<MessagingClient>(context, listen: false);
|
||||||
_loading = true;
|
setState(() {
|
||||||
});
|
_loading = true;
|
||||||
try {
|
});
|
||||||
if (_localAdded) {
|
try {
|
||||||
await ContactApi.removeUserAsFriend(ClientHolder
|
if (_localAdded) {
|
||||||
.of(context)
|
await ContactApi.removeUserAsFriend(
|
||||||
.apiClient, user: widget.user);
|
ClientHolder.of(context).apiClient,
|
||||||
} else {
|
user: widget.user,
|
||||||
await ContactApi.addUserAsFriend(ClientHolder
|
);
|
||||||
.of(context)
|
} else {
|
||||||
.apiClient, user: widget.user);
|
mClient.addUserAsFriend(widget.user);
|
||||||
}
|
}
|
||||||
setState(() {
|
setState(() {
|
||||||
_loading = false;
|
_loading = false;
|
||||||
_localAdded = !_localAdded;
|
_localAdded = !_localAdded;
|
||||||
});
|
});
|
||||||
widget.onChanged?.call();
|
widget.onChanged?.call();
|
||||||
} catch (e, s) {
|
} catch (e, s) {
|
||||||
FlutterError.reportError(FlutterErrorDetails(exception: e, stack: s));
|
FlutterError.reportError(FlutterErrorDetails(exception: e, stack: s));
|
||||||
if (context.mounted) {
|
if (context.mounted) {
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
SnackBar(
|
SnackBar(
|
||||||
duration: const Duration(seconds: 5),
|
duration: const Duration(seconds: 5),
|
||||||
content: Text(
|
content: Text(
|
||||||
"Something went wrong: $e",
|
"Something went wrong: $e",
|
||||||
softWrap: true,
|
softWrap: true,
|
||||||
maxLines: null,
|
maxLines: null,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
setState(() {
|
setState(() {
|
||||||
_loading = false;
|
_loading = false;
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -29,24 +29,19 @@ class _UserSearchState extends State<UserSearch> {
|
||||||
late Future<List<User>?>? _usersFuture = _emptySearch;
|
late Future<List<User>?>? _usersFuture = _emptySearch;
|
||||||
|
|
||||||
Future<List<User>> get _emptySearch =>
|
Future<List<User>> get _emptySearch =>
|
||||||
Future(() =>
|
Future(() => throw const SearchError(message: "Start typing to search for users", icon: Icons.search));
|
||||||
throw const SearchError(
|
|
||||||
message: "Start typing to search for users", icon: Icons.search)
|
|
||||||
);
|
|
||||||
|
|
||||||
void _querySearch(BuildContext context, String needle) {
|
void _querySearch(BuildContext context, String needle) {
|
||||||
if (needle.isEmpty) {
|
if (needle.isEmpty) {
|
||||||
_usersFuture = _emptySearch;
|
_usersFuture = _emptySearch;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_usersFuture = UserApi.searchUsers(ClientHolder
|
_usersFuture = UserApi.searchUsers(ClientHolder.of(context).apiClient, needle: needle).then((value) {
|
||||||
.of(context)
|
|
||||||
.apiClient, needle: needle).then((value) {
|
|
||||||
final res = value.toList();
|
final res = value.toList();
|
||||||
if (res.isEmpty) throw SearchError(message: "No user found with username '$needle'", icon: Icons.search_off);
|
if (res.isEmpty) {
|
||||||
res.sort(
|
throw SearchError(message: "No user found with username '$needle'", icon: Icons.search_off);
|
||||||
(a, b) => a.username.length.compareTo(b.username.length)
|
}
|
||||||
);
|
res.sort((a, b) => a.username.length.compareTo(b.username.length));
|
||||||
return res;
|
return res;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -72,9 +67,13 @@ class _UserSearchState extends State<UserSearch> {
|
||||||
itemCount: users.length,
|
itemCount: users.length,
|
||||||
itemBuilder: (context, index) {
|
itemBuilder: (context, index) {
|
||||||
final user = users[index];
|
final user = users[index];
|
||||||
return UserListTile(user: user, onChanged: () {
|
return UserListTile(
|
||||||
mClient.refreshFriendsList();
|
user: user,
|
||||||
}, isFriend: mClient.getAsFriend(user.id) != null,);
|
onChanged: () {
|
||||||
|
mClient.refreshFriendsList();
|
||||||
|
},
|
||||||
|
isFriend: mClient.getAsFriend(user.id) != null,
|
||||||
|
);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
} else if (snapshot.hasError) {
|
} else if (snapshot.hasError) {
|
||||||
|
|
@ -85,9 +84,13 @@ class _UserSearchState extends State<UserSearch> {
|
||||||
iconOverride: err.icon,
|
iconOverride: err.icon,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
FlutterError.reportError(
|
FlutterError.reportError(FlutterErrorDetails(
|
||||||
FlutterErrorDetails(exception: snapshot.error!, stack: snapshot.stackTrace));
|
exception: snapshot.error!,
|
||||||
return DefaultErrorWidget(title: "${snapshot.error}",);
|
stack: snapshot.stackTrace,
|
||||||
|
));
|
||||||
|
return DefaultErrorWidget(
|
||||||
|
title: "${snapshot.error}",
|
||||||
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return const Column(
|
return const Column(
|
||||||
|
|
@ -106,10 +109,7 @@ class _UserSearchState extends State<UserSearch> {
|
||||||
isDense: true,
|
isDense: true,
|
||||||
hintText: "Search for users...",
|
hintText: "Search for users...",
|
||||||
contentPadding: const EdgeInsets.all(16),
|
contentPadding: const EdgeInsets.all(16),
|
||||||
border: OutlineInputBorder(
|
border: OutlineInputBorder(borderRadius: BorderRadius.circular(24))),
|
||||||
borderRadius: BorderRadius.circular(24)
|
|
||||||
)
|
|
||||||
),
|
|
||||||
autocorrect: false,
|
autocorrect: false,
|
||||||
controller: _searchInputController,
|
controller: _searchInputController,
|
||||||
onChanged: (String value) {
|
onChanged: (String value) {
|
||||||
|
|
@ -136,4 +136,4 @@ class _UserSearchState extends State<UserSearch> {
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ import 'package:recon/client_holder.dart';
|
||||||
import 'package:recon/clients/api_client.dart';
|
import 'package:recon/clients/api_client.dart';
|
||||||
import 'package:recon/clients/messaging_client.dart';
|
import 'package:recon/clients/messaging_client.dart';
|
||||||
import 'package:recon/models/message.dart';
|
import 'package:recon/models/message.dart';
|
||||||
import 'package:recon/models/users/friend.dart';
|
import 'package:recon/models/users/contact.dart';
|
||||||
import 'package:recon/widgets/messages/message_attachment_list.dart';
|
import 'package:recon/widgets/messages/message_attachment_list.dart';
|
||||||
import 'package:record/record.dart';
|
import 'package:record/record.dart';
|
||||||
|
|
||||||
|
|
@ -21,7 +21,7 @@ class MessageInputBar extends StatefulWidget {
|
||||||
const MessageInputBar({this.disabled = false, required this.recipient, this.onMessageSent, super.key});
|
const MessageInputBar({this.disabled = false, required this.recipient, this.onMessageSent, super.key});
|
||||||
|
|
||||||
final bool disabled;
|
final bool disabled;
|
||||||
final Friend recipient;
|
final Contact recipient;
|
||||||
final Function()? onMessageSent;
|
final Function()? onMessageSent;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|
@ -403,7 +403,7 @@ class _MessageInputBarState extends State<MessageInputBar> {
|
||||||
style: Theme.of(context).textTheme.bodyLarge,
|
style: Theme.of(context).textTheme.bodyLarge,
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
isDense: true,
|
isDense: true,
|
||||||
hintText: _isRecording ? "" : "Message ${widget.recipient.username}...",
|
hintText: _isRecording ? "" : "Message ${widget.recipient.contactUsername}...",
|
||||||
hintMaxLines: 1,
|
hintMaxLines: 1,
|
||||||
contentPadding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
|
contentPadding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
|
||||||
fillColor: Colors.black26,
|
fillColor: Colors.black26,
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ import 'package:flutter/material.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
import 'package:recon/clients/audio_cache_client.dart';
|
import 'package:recon/clients/audio_cache_client.dart';
|
||||||
import 'package:recon/clients/messaging_client.dart';
|
import 'package:recon/clients/messaging_client.dart';
|
||||||
import 'package:recon/models/users/friend.dart';
|
import 'package:recon/models/users/contact.dart';
|
||||||
import 'package:recon/widgets/default_error_widget.dart';
|
import 'package:recon/widgets/default_error_widget.dart';
|
||||||
import 'package:recon/widgets/friends/friend_online_status_indicator.dart';
|
import 'package:recon/widgets/friends/friend_online_status_indicator.dart';
|
||||||
import 'package:recon/widgets/messages/message_input_bar.dart';
|
import 'package:recon/widgets/messages/message_input_bar.dart';
|
||||||
|
|
@ -54,7 +54,7 @@ class _MessagesListState extends State<MessagesList> with SingleTickerProviderSt
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final appBarColor = Theme.of(context).colorScheme.surface;
|
final appBarColor = Theme.of(context).colorScheme.surface;
|
||||||
return Consumer<MessagingClient>(builder: (context, mClient, _) {
|
return Consumer<MessagingClient>(builder: (context, mClient, _) {
|
||||||
final friend = mClient.selectedFriend ?? Friend.empty();
|
final friend = mClient.selectedFriend ?? Contact.empty();
|
||||||
final cache = mClient.getUserMessageCache(friend.id);
|
final cache = mClient.getUserMessageCache(friend.id);
|
||||||
final sessions = friend.userStatus.decodedSessions.where((element) => element.isVisible).toList();
|
final sessions = friend.userStatus.decodedSessions.where((element) => element.isVisible).toList();
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
|
|
@ -66,7 +66,7 @@ class _MessagesListState extends State<MessagesList> with SingleTickerProviderSt
|
||||||
const SizedBox(
|
const SizedBox(
|
||||||
width: 8,
|
width: 8,
|
||||||
),
|
),
|
||||||
Text(friend.username),
|
Text(friend.contactUsername),
|
||||||
if (friend.isHeadless)
|
if (friend.isHeadless)
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.only(left: 12),
|
padding: const EdgeInsets.only(left: 12),
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ publish_to: "none" # Remove this line if you wish to publish to pub.dev
|
||||||
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
|
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
|
||||||
# In Windows, build-name is used as the major, minor, and patch parts
|
# In Windows, build-name is used as the major, minor, and patch parts
|
||||||
# of the product and file versions while build-number is used as the build suffix.
|
# of the product and file versions while build-number is used as the build suffix.
|
||||||
version: 0.11.0-beta+1
|
version: 0.11.1-beta+1
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
sdk: ">=3.0.1"
|
sdk: ">=3.0.1"
|
||||||
|
|
|
||||||
16
windows/installer-script.nsi
Normal file
16
windows/installer-script.nsi
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
OutFile "ReCon-Installer.exe"
|
||||||
|
|
||||||
|
# define the directory to install to, the desktop in this case as specified
|
||||||
|
# by the predefined $DESKTOP variable
|
||||||
|
InstallDir $DESKTOP
|
||||||
|
|
||||||
|
# default section
|
||||||
|
Section
|
||||||
|
|
||||||
|
# define the output path for this file
|
||||||
|
SetOutPath $INSTDIR
|
||||||
|
|
||||||
|
# define what to install and place it in the output path
|
||||||
|
File test.txt
|
||||||
|
|
||||||
|
SectionEnd
|
||||||
|
|
@ -26,8 +26,8 @@ int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev,
|
||||||
|
|
||||||
FlutterWindow window(project);
|
FlutterWindow window(project);
|
||||||
Win32Window::Point origin(10, 10);
|
Win32Window::Point origin(10, 10);
|
||||||
Win32Window::Size size(1280, 720);
|
Win32Window::Size size(480, 900);
|
||||||
if (!window.Create(L"recon", origin, size)) {
|
if (!window.Create(L"ReCon", origin, size)) {
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
window.SetQuitOnClose(true);
|
window.SetQuitOnClose(true);
|
||||||
|
|
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 33 KiB After Width: | Height: | Size: 264 KiB |
Reference in a new issue