Change navbar color in chat view

This commit is contained in:
Nutcake 2023-09-30 14:20:08 +02:00
parent cc1bcb7a72
commit bcc03b4c9a
15 changed files with 34 additions and 41 deletions

View file

@ -1,13 +1,9 @@
import 'dart:convert'; import 'dart:convert';
import 'package:contacts_plus_plus/clients/api_client.dart'; import 'package:contacts_plus_plus/clients/api_client.dart';
import 'package:contacts_plus_plus/models/users/friend.dart';
import 'package:contacts_plus_plus/models/personal_profile.dart'; import 'package:contacts_plus_plus/models/personal_profile.dart';
import 'package:contacts_plus_plus/models/users/user.dart'; import 'package:contacts_plus_plus/models/users/user.dart';
import 'package:contacts_plus_plus/models/users/user_profile.dart';
import 'package:contacts_plus_plus/models/users/friend_status.dart';
import 'package:contacts_plus_plus/models/users/user_status.dart'; import 'package:contacts_plus_plus/models/users/user_status.dart';
import 'package:package_info_plus/package_info_plus.dart';
class UserApi { class UserApi {
static Future<Iterable<User>> searchUsers(ApiClient client, {required String needle}) async { static Future<Iterable<User>> searchUsers(ApiClient client, {required String needle}) async {
@ -37,18 +33,6 @@ class UserApi {
client.checkResponse(response); client.checkResponse(response);
} }
static Future<void> setStatus(ApiClient client, {required UserStatus status}) async {
return;
final pkginfo = await PackageInfo.fromPlatform();
status = status.copyWith(
neosVersion: "${pkginfo.version} of ${pkginfo.appName}",
isMobile: true,
);
final body = jsonEncode(status.toMap(shallow: true));
final response = await client.put("/users/${client.userId}/status", body: body);
client.checkResponse(response);
}
static Future<PersonalProfile> getPersonalProfile(ApiClient client) async { static Future<PersonalProfile> getPersonalProfile(ApiClient client) async {
final response = await client.get("/users/${client.userId}"); final response = await client.get("/users/${client.userId}");
client.checkResponse(response); client.checkResponse(response);

View file

@ -13,6 +13,7 @@ import 'package:contacts_plus_plus/clients/notification_client.dart';
import 'package:contacts_plus_plus/models/users/friend.dart'; import 'package:contacts_plus_plus/models/users/friend.dart';
import 'package:contacts_plus_plus/clients/api_client.dart'; import 'package:contacts_plus_plus/clients/api_client.dart';
import 'package:contacts_plus_plus/models/message.dart'; import 'package:contacts_plus_plus/models/message.dart';
import 'package:package_info_plus/package_info_plus.dart';
enum EventType { enum EventType {
undefined, undefined,
@ -74,7 +75,7 @@ class MessagingClient extends ChangeNotifier {
_notifyOnlineTimer = Timer.periodic(const Duration(seconds: 60), (timer) async { _notifyOnlineTimer = Timer.periodic(const Duration(seconds: 60), (timer) async {
// We should probably let the MessagingClient handle the entire state of USerStatus instead of mirroring like this // We should probably let the MessagingClient handle the entire state of USerStatus instead of mirroring like this
// but I don't feel like implementing that right now. // but I don't feel like implementing that right now.
UserApi.setStatus(apiClient, status: await UserApi.getUserStatus(apiClient, userId: apiClient.userId)); setUserStatus(await UserApi.getUserStatus(apiClient, userId: apiClient.userId));
}); });
} }
@ -142,6 +143,23 @@ class MessagingClient extends ChangeNotifier {
clearUnreadsForUser(batch.senderId); clearUnreadsForUser(batch.senderId);
} }
Future<void> setUserStatus(UserStatus status) async {
final pkginfo = await PackageInfo.fromPlatform();
status = status.copyWith(
appVersion: "${pkginfo.version} of ${pkginfo.appName}",
isMobile: true,
);
_hubManager.send("BroadcastStatus", arguments: [
status.toMap(),
{
"group": 0,
"targetIds": [],
}
]);
}
void addUnread(Message message) { void addUnread(Message message) {
var messages = _unreads[message.senderId]; var messages = _unreads[message.senderId];
if (messages == null) { if (messages == null) {

View file

@ -14,7 +14,6 @@ import 'package:contacts_plus_plus/widgets/update_notifier.dart';
import 'package:dynamic_color/dynamic_color.dart'; import 'package:dynamic_color/dynamic_color.dart';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_downloader/flutter_downloader.dart'; import 'package:flutter_downloader/flutter_downloader.dart';
import 'package:flutter_phoenix/flutter_phoenix.dart'; import 'package:flutter_phoenix/flutter_phoenix.dart';
import 'package:hive_flutter/hive_flutter.dart'; import 'package:hive_flutter/hive_flutter.dart';

View file

@ -1,6 +1,3 @@
import 'package:contacts_plus_plus/config.dart';
import 'package:uuid/uuid.dart';
class AuthenticationData { class AuthenticationData {
static const _unauthenticated = AuthenticationData( static const _unauthenticated = AuthenticationData(
userId: "", userId: "",

View file

@ -1,5 +1,4 @@
import 'package:collection/collection.dart'; import 'package:collection/collection.dart';
import 'package:contacts_plus_plus/stack.dart';
import 'package:contacts_plus_plus/models/records/record.dart'; import 'package:contacts_plus_plus/models/records/record.dart';
class ResoniteDirectory { class ResoniteDirectory {

View file

@ -4,7 +4,6 @@ import 'package:contacts_plus_plus/models/records/asset_digest.dart';
import 'package:contacts_plus_plus/models/records/resonite_db_asset.dart'; import 'package:contacts_plus_plus/models/records/resonite_db_asset.dart';
import 'package:contacts_plus_plus/string_formatter.dart'; import 'package:contacts_plus_plus/string_formatter.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:uuid/uuid.dart'; import 'package:uuid/uuid.dart';
enum RecordType { enum RecordType {

View file

@ -1,4 +1,3 @@
import 'package:contacts_plus_plus/config.dart';
import 'package:contacts_plus_plus/string_formatter.dart'; import 'package:contacts_plus_plus/string_formatter.dart';
class Session { class Session {

View file

@ -3,7 +3,6 @@ import 'package:contacts_plus_plus/models/users/user_profile.dart';
import 'package:contacts_plus_plus/models/users/friend_status.dart'; import 'package:contacts_plus_plus/models/users/friend_status.dart';
import 'package:contacts_plus_plus/models/users/online_status.dart'; import 'package:contacts_plus_plus/models/users/online_status.dart';
import 'package:contacts_plus_plus/models/users/user_status.dart'; import 'package:contacts_plus_plus/models/users/user_status.dart';
import 'package:flutter/foundation.dart';
class Friend implements Comparable { class Friend implements Comparable {
static const _emptyId = "-1"; static const _emptyId = "-1";
@ -58,14 +57,14 @@ class Friend implements Comparable {
Friend copyWith({ Friend copyWith({
String? id, String? username, String? ownerId, UserStatus? userStatus, UserProfile? userProfile, String? id, String? username, String? ownerId, UserStatus? userStatus, UserProfile? userProfile,
FriendStatus? friendStatus, DateTime? latestMessageTime}) { FriendStatus? contactStatus, DateTime? latestMessageTime}) {
return Friend( return Friend(
id: id ?? this.id, id: id ?? this.id,
username: username ?? this.username, username: username ?? this.username,
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: friendStatus ?? this.contactStatus, contactStatus: contactStatus ?? this.contactStatus,
latestMessageTime: latestMessageTime ?? this.latestMessageTime, latestMessageTime: latestMessageTime ?? this.latestMessageTime,
); );
} }

View file

@ -89,7 +89,7 @@ class UserStatus {
bool? currentHosting, bool? currentHosting,
Session? currentSession, Session? currentSession,
List<Session>? activeSessions, List<Session>? activeSessions,
String? neosVersion, String? appVersion,
String? outputDevice, String? outputDevice,
bool? isMobile, bool? isMobile,
String? compatibilityHash, String? compatibilityHash,
@ -102,7 +102,7 @@ class UserStatus {
currentHosting: currentHosting ?? this.currentHosting, currentHosting: currentHosting ?? this.currentHosting,
currentSession: currentSession ?? this.currentSession, currentSession: currentSession ?? this.currentSession,
activeSessions: activeSessions ?? this.activeSessions, activeSessions: activeSessions ?? this.activeSessions,
appVersion: neosVersion ?? this.appVersion, appVersion: appVersion ?? this.appVersion,
outputDevice: outputDevice ?? this.outputDevice, outputDevice: outputDevice ?? this.outputDevice,
isMobile: isMobile ?? this.isMobile, isMobile: isMobile ?? this.isMobile,
compatibilityHash: compatibilityHash ?? this.compatibilityHash, compatibilityHash: compatibilityHash ?? this.compatibilityHash,

View file

@ -33,12 +33,13 @@ class _FriendsListAppBarState extends State<FriendsListAppBar> with AutomaticKee
void _refreshUserStatus() { void _refreshUserStatus() {
final apiClient = _clientHolder!.apiClient; final apiClient = _clientHolder!.apiClient;
final messagingClient = Provider.of<MessagingClient>(context, listen: false);
_userStatusFuture ??= UserApi.getUserStatus(apiClient, userId: apiClient.userId).then((value) async { _userStatusFuture ??= UserApi.getUserStatus(apiClient, userId: apiClient.userId).then((value) async {
if (value.onlineStatus == OnlineStatus.offline) { if (value.onlineStatus == OnlineStatus.offline) {
final newStatus = value.copyWith( final newStatus = value.copyWith(
onlineStatus: onlineStatus:
OnlineStatus.values[_clientHolder!.settingsClient.currentSettings.lastOnlineStatus.valueOrDefault]); OnlineStatus.values[_clientHolder!.settingsClient.currentSettings.lastOnlineStatus.valueOrDefault]);
await UserApi.setStatus(apiClient, status: newStatus); await messagingClient.setUserStatus(newStatus);
return newStatus; return newStatus;
} }
return value; return value;
@ -75,18 +76,21 @@ class _FriendsListAppBarState extends State<FriendsListAppBar> with AutomaticKee
), ),
onSelected: (OnlineStatus onlineStatus) async { onSelected: (OnlineStatus onlineStatus) async {
try { try {
final messagingClient = Provider.of<MessagingClient>(context, listen: false);
final newStatus = userStatus.copyWith(onlineStatus: onlineStatus); final newStatus = userStatus.copyWith(onlineStatus: onlineStatus);
setState(() { setState(() {
_userStatusFuture = Future.value(newStatus.copyWith(lastStatusChange: DateTime.now())); _userStatusFuture = Future.value(newStatus.copyWith(lastStatusChange: DateTime.now()));
}); });
final settingsClient = _clientHolder!.settingsClient; final settingsClient = _clientHolder!.settingsClient;
await UserApi.setStatus(_clientHolder!.apiClient, status: newStatus); await messagingClient.setUserStatus(newStatus);
await settingsClient.changeSettings( await settingsClient.changeSettings(
settingsClient.currentSettings.copyWith(lastOnlineStatus: onlineStatus.index)); settingsClient.currentSettings.copyWith(lastOnlineStatus: onlineStatus.index));
} catch (e, s) { } catch (e, s) {
FlutterError.reportError(FlutterErrorDetails(exception: e, stack: s)); FlutterError.reportError(FlutterErrorDetails(exception: e, stack: s));
ScaffoldMessenger.of(context) if (context.mounted) {
ScaffoldMessenger.of(context)
.showSnackBar(const SnackBar(content: Text("Failed to set online-status."))); .showSnackBar(const SnackBar(content: Text("Failed to set online-status.")));
}
setState(() { setState(() {
_userStatusFuture = Future.value(userStatus); _userStatusFuture = Future.value(userStatus);
}); });

View file

@ -70,7 +70,8 @@ class _UserListTileState extends State<UserListTile> {
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));
ScaffoldMessenger.of(context).showSnackBar( if (context.mounted) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar( SnackBar(
duration: const Duration(seconds: 5), duration: const Duration(seconds: 5),
content: Text( content: Text(
@ -80,6 +81,7 @@ class _UserListTileState extends State<UserListTile> {
), ),
), ),
); );
}
setState(() { setState(() {
_loading = false; _loading = false;
}); });

View file

@ -216,7 +216,7 @@ class _MessageInputBarState extends State<MessageInputBar> {
color: Theme color: Theme
.of(context) .of(context)
.colorScheme .colorScheme
.background, .surfaceVariant,
), ),
padding: const EdgeInsets.symmetric(horizontal: 4), padding: const EdgeInsets.symmetric(horizontal: 4),
child: Column( child: Column(

View file

@ -58,12 +58,8 @@ class _MessagesListState extends State<MessagesList> with SingleTickerProviderSt
final friend = mClient.selectedFriend ?? Friend.empty(); final friend = mClient.selectedFriend ?? Friend.empty();
final cache = mClient.getUserMessageCache(friend.id); final cache = mClient.getUserMessageCache(friend.id);
final sessions = friend.userStatus.activeSessions; final sessions = friend.userStatus.activeSessions;
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
systemOverlayStyle: SystemUiOverlayStyle(
systemNavigationBarColor: Theme.of(context).colorScheme.background,
),
title: Row( title: Row(
crossAxisAlignment: CrossAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center,
children: [ children: [

View file

@ -2,7 +2,6 @@ import 'dart:math';
import 'package:contacts_plus_plus/client_holder.dart'; import 'package:contacts_plus_plus/client_holder.dart';
import 'package:contacts_plus_plus/clients/session_client.dart'; import 'package:contacts_plus_plus/clients/session_client.dart';
import 'package:contacts_plus_plus/clients/settings_client.dart';
import 'package:contacts_plus_plus/models/session.dart'; import 'package:contacts_plus_plus/models/session.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';

View file

@ -1,6 +1,4 @@
import 'package:contacts_plus_plus/client_holder.dart';
import 'package:contacts_plus_plus/clients/session_client.dart'; import 'package:contacts_plus_plus/clients/session_client.dart';
import 'package:contacts_plus_plus/clients/settings_client.dart';
import 'package:contacts_plus_plus/widgets/sessions/session_filter_dialog.dart'; import 'package:contacts_plus_plus/widgets/sessions/session_filter_dialog.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';