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 '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/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:package_info_plus/package_info_plus.dart';
class UserApi {
static Future<Iterable<User>> searchUsers(ApiClient client, {required String needle}) async {
@ -37,18 +33,6 @@ class UserApi {
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 {
final response = await client.get("/users/${client.userId}");
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/clients/api_client.dart';
import 'package:contacts_plus_plus/models/message.dart';
import 'package:package_info_plus/package_info_plus.dart';
enum EventType {
undefined,
@ -74,7 +75,7 @@ class MessagingClient extends ChangeNotifier {
_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
// 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);
}
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) {
var messages = _unreads[message.senderId];
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:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_downloader/flutter_downloader.dart';
import 'package:flutter_phoenix/flutter_phoenix.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 {
static const _unauthenticated = AuthenticationData(
userId: "",

View file

@ -1,5 +1,4 @@
import 'package:collection/collection.dart';
import 'package:contacts_plus_plus/stack.dart';
import 'package:contacts_plus_plus/models/records/record.dart';
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/string_formatter.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:uuid/uuid.dart';
enum RecordType {

View file

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

View file

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

View file

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

View file

@ -70,6 +70,7 @@ class _UserListTileState extends State<UserListTile> {
widget.onChanged?.call();
} catch (e, s) {
FlutterError.reportError(FlutterErrorDetails(exception: e, stack: s));
if (context.mounted) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
duration: const Duration(seconds: 5),
@ -80,6 +81,7 @@ class _UserListTileState extends State<UserListTile> {
),
),
);
}
setState(() {
_loading = false;
});

View file

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

View file

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

View file

@ -2,7 +2,6 @@ import 'dart:math';
import 'package:contacts_plus_plus/client_holder.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:flutter/material.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/settings_client.dart';
import 'package:contacts_plus_plus/widgets/sessions/session_filter_dialog.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';