forked from cwtch.im/cwtch-ui
Merge pull request 'profile level unread notifications and in profile other profile unread notifications' (#337) from profileNotify into trunk
Reviewed-on: cwtch.im/cwtch-ui#337
This commit is contained in:
commit
dd69afc98b
|
@ -8,6 +8,7 @@ import 'package:cwtch/models/profileservers.dart';
|
|||
import 'package:cwtch/models/remoteserver.dart';
|
||||
import 'package:cwtch/models/servers.dart';
|
||||
import 'package:cwtch/notification_manager.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import 'package:cwtch/torstatus.dart';
|
||||
|
@ -145,9 +146,10 @@ class CwtchNotifier {
|
|||
var senderImage = data['Picture'];
|
||||
var isAuto = data['Auto'] == "true";
|
||||
String? contenthash = data['ContentHash'];
|
||||
var selectedConversation = appState.selectedProfile == data["ProfileOnion"] && appState.selectedConversation == identifier;
|
||||
var selectedProfile = appState.selectedProfile == data["ProfileOnion"];
|
||||
var selectedConversation = selectedProfile && appState.selectedConversation == identifier;
|
||||
|
||||
profileCN.getProfile(data["ProfileOnion"])?.contactList.newMessage(
|
||||
profileCN.getProfile(data["ProfileOnion"])?.newMessage(
|
||||
identifier,
|
||||
messageID,
|
||||
timestamp,
|
||||
|
@ -156,9 +158,10 @@ class CwtchNotifier {
|
|||
isAuto,
|
||||
data["Data"],
|
||||
contenthash,
|
||||
selectedProfile,
|
||||
selectedConversation,
|
||||
);
|
||||
|
||||
appState.notifyProfileUnread();
|
||||
break;
|
||||
case "PeerAcknowledgement":
|
||||
// We don't use these anymore, IndexedAcknowledgement is more suited to the UI front end...
|
||||
|
@ -198,7 +201,8 @@ class CwtchNotifier {
|
|||
var currentTotal = contact!.totalMessages;
|
||||
var isAuto = data['Auto'] == "true";
|
||||
String? contenthash = data['ContentHash'];
|
||||
var selectedConversation = appState.selectedProfile == data["ProfileOnion"] && appState.selectedConversation == identifier;
|
||||
var selectedProfile = appState.selectedProfile == data["ProfileOnion"];
|
||||
var selectedConversation = selectedProfile && appState.selectedConversation == identifier;
|
||||
|
||||
// Only bother to do anything if we know about the group and the provided index is greater than our current total...
|
||||
if (currentTotal != null && idx >= currentTotal) {
|
||||
|
@ -212,9 +216,10 @@ class CwtchNotifier {
|
|||
// For now we perform some minimal checks on the sent timestamp to use to provide a useful ordering for honest contacts
|
||||
// and ensure that malicious contacts in groups can only set this timestamp to a value within the range of `last seen message time`
|
||||
// and `local now`.
|
||||
profileCN.getProfile(data["ProfileOnion"])?.contactList.newMessage(identifier, idx, timestampSent, senderHandle, senderImage, isAuto, data["Data"], contenthash, selectedConversation);
|
||||
profileCN.getProfile(data["ProfileOnion"])?.newMessage(identifier, idx, timestampSent, senderHandle, senderImage, isAuto, data["Data"], contenthash, selectedProfile, selectedConversation);
|
||||
|
||||
notificationManager.notify("New Message From Group!");
|
||||
appState.notifyProfileUnread();
|
||||
}
|
||||
RemoteServerInfoState? server = profileCN.getProfile(data["ProfileOnion"])?.serverList.getServer(contact.server);
|
||||
server?.updateSyncProgressFor(timestampSent);
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
enum ModalState { none, storageMigration }
|
||||
|
@ -16,6 +18,13 @@ class AppState extends ChangeNotifier {
|
|||
bool _disableFilePicker = false;
|
||||
bool _focus = true;
|
||||
|
||||
StreamController<bool> _profilesUnreadNotifyControler = StreamController<bool>();
|
||||
late Stream<bool> profilesUnreadNotify;
|
||||
|
||||
AppState() {
|
||||
profilesUnreadNotify = _profilesUnreadNotifyControler.stream.asBroadcastStream();
|
||||
}
|
||||
|
||||
void SetCwtchInit() {
|
||||
cwtchInit = true;
|
||||
notifyListeners();
|
||||
|
@ -82,4 +91,12 @@ class AppState extends ChangeNotifier {
|
|||
}
|
||||
|
||||
bool isLandscape(BuildContext c) => MediaQuery.of(c).size.width > MediaQuery.of(c).size.height;
|
||||
|
||||
void notifyProfileUnread() {
|
||||
_profilesUnreadNotifyControler.add(true);
|
||||
}
|
||||
|
||||
Stream<bool> getUnreadProfileNotifyStream() {
|
||||
return profilesUnreadNotify;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -120,6 +120,10 @@ class ProfileInfoState extends ChangeNotifier {
|
|||
notifyListeners();
|
||||
}
|
||||
|
||||
void recountUnread() {
|
||||
this._unreadMessages = _contacts.contacts.fold(0, (i, c) => i + c.unreadMessages);
|
||||
}
|
||||
|
||||
// Remove a contact from a list. Currently only used when rejecting a group invitation.
|
||||
// Eventually will also be used for other removals.
|
||||
void removeContact(String handle) {
|
||||
|
@ -168,11 +172,30 @@ class ProfileInfoState extends ChangeNotifier {
|
|||
lastMessageTime: DateTime.fromMillisecondsSinceEpoch(1000 * int.parse(contact["lastMsgTime"])),
|
||||
));
|
||||
}
|
||||
unreadMessages += int.parse(contact["numUnread"]);
|
||||
});
|
||||
}
|
||||
this._contacts.resort();
|
||||
}
|
||||
|
||||
void newMessage(int identifier, int messageID, DateTime timestamp, String senderHandle, String senderImage, bool isAuto, String data, String? contenthash, bool selectedProfile, bool selectedConversation) {
|
||||
if (!selectedProfile) {
|
||||
unreadMessages++;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
contactList.newMessage(
|
||||
identifier,
|
||||
messageID,
|
||||
timestamp,
|
||||
senderHandle,
|
||||
senderImage,
|
||||
isAuto,
|
||||
data,
|
||||
contenthash,
|
||||
selectedConversation);
|
||||
}
|
||||
|
||||
void downloadInit(String fileKey, int numChunks) {
|
||||
this._downloads[fileKey] = FileDownloadProgress(numChunks, DateTime.now());
|
||||
notifyListeners();
|
||||
|
|
|
@ -27,4 +27,8 @@ class ProfileListState extends ChangeNotifier {
|
|||
_profiles.removeWhere((element) => element.onion == onion);
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
int generateUnreadCount(String selectedProfile) => _profiles.where( (p) => p.onion != selectedProfile ).fold(0, (i, p) => i + p.unreadMessages);
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -68,8 +68,8 @@ class CwtchDark extends OpaqueThemeType {
|
|||
get portraitBlockedTextColor => lightGrey;
|
||||
get portraitContactBadgeColor => hotPink;
|
||||
get portraitContactBadgeTextColor => whiteishPurple;
|
||||
get portraitProfileBadgeColor => mauvePurple;
|
||||
get portraitProfileBadgeTextColor => darkGreyPurple;
|
||||
get portraitProfileBadgeColor => hotPink;
|
||||
get portraitProfileBadgeTextColor => whiteishPurple;
|
||||
get dropShadowColor => mauvePurple;
|
||||
get toolbarIconColor => settings; //whiteishPurple;
|
||||
get messageFromMeBackgroundColor => userBubble; // mauvePurple;
|
||||
|
@ -112,7 +112,7 @@ class CwtchLight extends OpaqueThemeType {
|
|||
get portraitBlockedTextColor => softGrey;
|
||||
get portraitContactBadgeColor => accent;
|
||||
get portraitContactBadgeTextColor => whitePurple;
|
||||
get portraitProfileBadgeColor => brightPurple;
|
||||
get portraitProfileBadgeColor => accent;
|
||||
get portraitProfileBadgeTextColor => whitePurple;
|
||||
get dropShadowColor => purple;
|
||||
get toolbarIconColor => settings; //darkPurple;
|
||||
|
|
|
@ -76,6 +76,31 @@ class _ContactsViewState extends State<ContactsView> {
|
|||
endDrawerEnableOpenDragGesture: false,
|
||||
drawerEnableOpenDragGesture: false,
|
||||
appBar: AppBar(
|
||||
leading: Row(children: [
|
||||
IconButton(
|
||||
icon: Icon(Icons.arrow_back),
|
||||
tooltip: MaterialLocalizations.of(context).backButtonTooltip,
|
||||
onPressed: () {
|
||||
Provider.of<ProfileInfoState>(context, listen: false).recountUnread();
|
||||
Provider.of<AppState>(context, listen: false).selectedProfile = "";
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
),
|
||||
|
||||
StreamBuilder<bool>(
|
||||
stream: Provider.of<AppState>(context).getUnreadProfileNotifyStream(),
|
||||
builder: (BuildContext context, AsyncSnapshot<bool> unreadCountSnapshot) {
|
||||
int unreadCount = Provider.of<ProfileListState>(context).generateUnreadCount(Provider.of<AppState>(context).selectedProfile ?? "") ;
|
||||
|
||||
return Visibility(
|
||||
visible: unreadCount > 0,
|
||||
child: CircleAvatar(
|
||||
radius: 10.0,
|
||||
backgroundColor: Provider.of<Settings>(context).theme.portraitProfileBadgeColor,
|
||||
child: Text(unreadCount > 99 ? "99+" : unreadCount.toString(), style: TextStyle(color: Provider.of<Settings>(context).theme.portraitProfileBadgeTextColor, fontSize: 8.0)),
|
||||
));
|
||||
}),
|
||||
]),
|
||||
title: RepaintBoundary(
|
||||
child: Row(children: [
|
||||
ProfileImage(
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import 'package:cwtch/models/appstate.dart';
|
||||
import 'package:cwtch/models/contactlist.dart';
|
||||
import 'package:cwtch/models/profile.dart';
|
||||
import 'package:cwtch/models/profilelist.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:cwtch/views/addeditprofileview.dart';
|
||||
|
@ -33,7 +34,7 @@ class _ProfileRowState extends State<ProfileRow> {
|
|||
Padding(
|
||||
padding: const EdgeInsets.all(6.0), //border size
|
||||
child: ProfileImage(
|
||||
badgeCount: 0,
|
||||
badgeCount: profile.unreadMessages,
|
||||
badgeColor: Provider.of<Settings>(context).theme.portraitProfileBadgeColor,
|
||||
badgeTextColor: Provider.of<Settings>(context).theme.portraitProfileBadgeTextColor,
|
||||
diameter: 64.0,
|
||||
|
|
|
@ -7,9 +7,13 @@
|
|||
#include "generated_plugin_registrant.h"
|
||||
|
||||
#include <url_launcher_linux/url_launcher_plugin.h>
|
||||
#include <window_manager/window_manager_plugin.h>
|
||||
|
||||
void fl_register_plugins(FlPluginRegistry* registry) {
|
||||
g_autoptr(FlPluginRegistrar) url_launcher_linux_registrar =
|
||||
fl_plugin_registry_get_registrar_for_plugin(registry, "UrlLauncherPlugin");
|
||||
url_launcher_plugin_register_with_registrar(url_launcher_linux_registrar);
|
||||
g_autoptr(FlPluginRegistrar) window_manager_registrar =
|
||||
fl_plugin_registry_get_registrar_for_plugin(registry, "WindowManagerPlugin");
|
||||
window_manager_plugin_register_with_registrar(window_manager_registrar);
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
list(APPEND FLUTTER_PLUGIN_LIST
|
||||
url_launcher_linux
|
||||
window_manager
|
||||
)
|
||||
|
||||
set(PLUGIN_BUNDLED_LIBRARIES)
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 6.5 KiB After Width: | Height: | Size: 6.6 KiB |
Loading…
Reference in New Issue