forked from cwtch.im/cwtch-ui
Don't attempt to load messages on group syncing (Fixes: #56)
Also should help with #32
This commit is contained in:
parent
1dd3593c97
commit
7648916f6a
|
@ -60,10 +60,11 @@ class FlwtchWorker(context: Context, parameters: WorkerParameters) :
|
||||||
val evt = MainActivity.AppbusEvent(Cwtch.getAppBusEvent())
|
val evt = MainActivity.AppbusEvent(Cwtch.getAppBusEvent())
|
||||||
if (evt.EventType == "NewMessageFromPeer" || evt.EventType == "NewMessageFromGroup") {
|
if (evt.EventType == "NewMessageFromPeer" || evt.EventType == "NewMessageFromGroup") {
|
||||||
val data = JSONObject(evt.Data)
|
val data = JSONObject(evt.Data)
|
||||||
|
val handle = if (evt.EventType == "NewMessageFromPeer") data.getString("RemotePeer") else data.getString("GroupID");
|
||||||
if (data["RemotePeer"] != data["ProfileOnion"]) {
|
if (data["RemotePeer"] != data["ProfileOnion"]) {
|
||||||
val channelId =
|
val channelId =
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
createMessageNotificationChannel(data.getString("RemotePeer"), data.getString("RemotePeer"))
|
createMessageNotificationChannel(handle, handle)
|
||||||
} else {
|
} else {
|
||||||
// If earlier version channel ID is not used
|
// If earlier version channel ID is not used
|
||||||
// https://developer.android.com/reference/android/support/v4/app/NotificationCompat.Builder.html#NotificationCompat.Builder(android.content.Context)
|
// https://developer.android.com/reference/android/support/v4/app/NotificationCompat.Builder.html#NotificationCompat.Builder(android.content.Context)
|
||||||
|
@ -74,11 +75,12 @@ class FlwtchWorker(context: Context, parameters: WorkerParameters) :
|
||||||
val key = loader.getLookupKeyForAsset("assets/" + data.getString("Picture"))//"assets/profiles/001-centaur.png")
|
val key = loader.getLookupKeyForAsset("assets/" + data.getString("Picture"))//"assets/profiles/001-centaur.png")
|
||||||
val fh = applicationContext.assets.open(key)
|
val fh = applicationContext.assets.open(key)
|
||||||
|
|
||||||
|
|
||||||
val clickIntent = Intent(applicationContext, MainActivity::class.java).also { intent ->
|
val clickIntent = Intent(applicationContext, MainActivity::class.java).also { intent ->
|
||||||
intent.action = Intent.ACTION_RUN
|
intent.action = Intent.ACTION_RUN
|
||||||
intent.putExtra("EventType", "NotificationClicked")
|
intent.putExtra("EventType", "NotificationClicked")
|
||||||
intent.putExtra("ProfileOnion", data.getString("ProfileOnion"))
|
intent.putExtra("ProfileOnion", data.getString("ProfileOnion"))
|
||||||
intent.putExtra("RemotePeer", if (evt.EventType == "NewMessageFromPeer") data.getString("RemotePeer") else data.getString("GroupID"))
|
intent.putExtra("Handle", handle)
|
||||||
}
|
}
|
||||||
|
|
||||||
val newNotification = NotificationCompat.Builder(applicationContext, channelId)
|
val newNotification = NotificationCompat.Builder(applicationContext, channelId)
|
||||||
|
@ -89,7 +91,7 @@ class FlwtchWorker(context: Context, parameters: WorkerParameters) :
|
||||||
.setContentIntent(PendingIntent.getActivity(applicationContext, 1, clickIntent, PendingIntent.FLAG_UPDATE_CURRENT))
|
.setContentIntent(PendingIntent.getActivity(applicationContext, 1, clickIntent, PendingIntent.FLAG_UPDATE_CURRENT))
|
||||||
.setAutoCancel(true)
|
.setAutoCancel(true)
|
||||||
.build()
|
.build()
|
||||||
notificationManager.notify(getNotificationID(data.getString("ProfileOnion"), data.getString("RemotePeer")), newNotification)
|
notificationManager.notify(getNotificationID(data.getString("ProfileOnion"), handle), newNotification)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -52,13 +52,13 @@ class MainActivity: FlutterActivity() {
|
||||||
if (notificationClickChannel == null || intent.extras == null) return
|
if (notificationClickChannel == null || intent.extras == null) return
|
||||||
|
|
||||||
if (intent.extras!!.getString("EventType") == "NotificationClicked") {
|
if (intent.extras!!.getString("EventType") == "NotificationClicked") {
|
||||||
if (!intent.extras!!.containsKey("ProfileOnion") || !intent.extras!!.containsKey("RemotePeer")) {
|
if (!intent.extras!!.containsKey("ProfileOnion") || !intent.extras!!.containsKey("Handle")) {
|
||||||
Log.i("onNewIntent", "got notification clicked intent with no onions")
|
Log.i("onNewIntent", "got notification clicked intent with no onions")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
val profile = intent.extras!!.getString("ProfileOnion")
|
val profile = intent.extras!!.getString("ProfileOnion")
|
||||||
val handle = intent.extras!!.getString("RemotePeer")
|
val handle = intent.extras!!.getString("Handle")
|
||||||
val mappo = mapOf("ProfileOnion" to profile, "RemotePeer" to handle)
|
val mappo = mapOf("ProfileOnion" to profile, "Handle" to handle)
|
||||||
val j = JSONObject(mappo)
|
val j = JSONObject(mappo)
|
||||||
notificationClickChannel!!.invokeMethod("NotificationClicked", j.toString())
|
notificationClickChannel!!.invokeMethod("NotificationClicked", j.toString())
|
||||||
} else if (intent.extras!!.getString("EventType") == "ShutdownClicked") {
|
} else if (intent.extras!!.getString("EventType") == "ShutdownClicked") {
|
||||||
|
|
|
@ -167,8 +167,8 @@ class FlwtchState extends State<Flwtch> {
|
||||||
Future<void> _externalNotificationClicked(MethodCall call) async {
|
Future<void> _externalNotificationClicked(MethodCall call) async {
|
||||||
var args = jsonDecode(call.arguments);
|
var args = jsonDecode(call.arguments);
|
||||||
var profile = profs.getProfile(args["ProfileOnion"])!;
|
var profile = profs.getProfile(args["ProfileOnion"])!;
|
||||||
var contact = profile.contactList.getContact(args["RemotePeer"])!;
|
var convo = profile.contactList.getContact(args["Handle"])!;
|
||||||
contact.unreadMessages = 0;
|
convo.unreadMessages = 0;
|
||||||
|
|
||||||
// single pane mode pushes; double pane mode reads AppState.selectedProfile/Conversation
|
// single pane mode pushes; double pane mode reads AppState.selectedProfile/Conversation
|
||||||
var isLandscape = Provider.of<AppState>(navKey.currentContext!, listen: false).isLandscape(navKey.currentContext!);
|
var isLandscape = Provider.of<AppState>(navKey.currentContext!, listen: false).isLandscape(navKey.currentContext!);
|
||||||
|
@ -183,7 +183,7 @@ class FlwtchState extends State<Flwtch> {
|
||||||
return MultiProvider(
|
return MultiProvider(
|
||||||
providers: [
|
providers: [
|
||||||
ChangeNotifierProvider.value(value: profile),
|
ChangeNotifierProvider.value(value: profile),
|
||||||
ChangeNotifierProvider.value(value: contact),
|
ChangeNotifierProvider.value(value: convo),
|
||||||
],
|
],
|
||||||
builder: (context, child) => MessageView(),
|
builder: (context, child) => MessageView(),
|
||||||
);
|
);
|
||||||
|
@ -192,7 +192,7 @@ class FlwtchState extends State<Flwtch> {
|
||||||
);
|
);
|
||||||
} else { //dual pane
|
} else { //dual pane
|
||||||
Provider.of<AppState>(navKey.currentContext!, listen: false).selectedProfile = args["ProfileOnion"];
|
Provider.of<AppState>(navKey.currentContext!, listen: false).selectedProfile = args["ProfileOnion"];
|
||||||
Provider.of<AppState>(navKey.currentContext!, listen: false).selectedConversation = args["RemotePeer"];
|
Provider.of<AppState>(navKey.currentContext!, listen: false).selectedConversation = args["Handle"];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,10 +16,18 @@ class _MessageListState extends State<MessageList> {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext outerContext) {
|
Widget build(BuildContext outerContext) {
|
||||||
bool showEphemeralWarning = (Provider.of<ContactInfoState>(context).isGroup == false && Provider.of<ContactInfoState>(context).savePeerHistory != "SaveHistory");
|
|
||||||
|
bool isP2P = !Provider.of<ContactInfoState>(context).isGroup;
|
||||||
|
bool isGroupAndSyncing = Provider.of<ContactInfoState>(context).isGroup == true && Provider.of<ContactInfoState>(context).status == "Authenticated";
|
||||||
|
bool isGroupAndSynced = Provider.of<ContactInfoState>(context).isGroup && Provider.of<ContactInfoState>(context).status == "Synced";
|
||||||
|
bool isGroupAndNotAuthenticated= Provider.of<ContactInfoState>(context).isGroup && Provider.of<ContactInfoState>(context).status != "Authenticated";
|
||||||
|
|
||||||
|
bool showEphemeralWarning = (isP2P && Provider.of<ContactInfoState>(context).savePeerHistory != "SaveHistory");
|
||||||
bool showOfflineWarning = Provider.of<ContactInfoState>(context).isOnline() == false;
|
bool showOfflineWarning = Provider.of<ContactInfoState>(context).isOnline() == false;
|
||||||
bool showMessageWarning = showEphemeralWarning || showOfflineWarning;
|
bool showMessageWarning = showEphemeralWarning || showOfflineWarning;
|
||||||
bool showSyncing = Provider.of<ContactInfoState>(context).isGroup == true && Provider.of<ContactInfoState>(context).status != "Synced";
|
bool showSyncing = isGroupAndSyncing;
|
||||||
|
// Only load historical messages when the conversation is with a p2p contact OR the conversation is a server and *not* syncing.
|
||||||
|
bool loadMessages = isP2P || (isGroupAndSynced || isGroupAndNotAuthenticated);
|
||||||
|
|
||||||
return RepaintBoundary(
|
return RepaintBoundary(
|
||||||
child: Container(
|
child: Container(
|
||||||
|
@ -56,7 +64,7 @@ class _MessageListState extends State<MessageList> {
|
||||||
image: AssetImage("assets/core/negative_heart_512px.png"),
|
image: AssetImage("assets/core/negative_heart_512px.png"),
|
||||||
colorFilter: ColorFilter.mode(Provider.of<Settings>(context).theme.hilightElementTextColor(), BlendMode.srcIn))),
|
colorFilter: ColorFilter.mode(Provider.of<Settings>(context).theme.hilightElementTextColor(), BlendMode.srcIn))),
|
||||||
// Don't load messages for syncing server...
|
// Don't load messages for syncing server...
|
||||||
child: ListView.builder(
|
child: loadMessages ? ListView.builder(
|
||||||
controller: ctrlr1,
|
controller: ctrlr1,
|
||||||
itemCount: Provider.of<ContactInfoState>(outerContext).totalMessages,
|
itemCount: Provider.of<ContactInfoState>(outerContext).totalMessages,
|
||||||
reverse: true, // NOTE: There seems to be a bug in flutter that corrects the mouse wheel scroll, but not the drag direction...
|
reverse: true, // NOTE: There seems to be a bug in flutter that corrects the mouse wheel scroll, but not the drag direction...
|
||||||
|
@ -78,7 +86,7 @@ class _MessageListState extends State<MessageList> {
|
||||||
return RepaintBoundary(child: MessageRow(key: Provider.of<ContactInfoState>(bcontext).getMessageKey(idx)));
|
return RepaintBoundary(child: MessageRow(key: Provider.of<ContactInfoState>(bcontext).getMessageKey(idx)));
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
))))
|
) : null )))
|
||||||
])));
|
])));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue