mirror of
https://github.com/zjs81/meshcore-open.git
synced 2026-07-15 21:32:29 +10:00
try fix codex sync problem
This commit is contained in:
@@ -4338,6 +4338,12 @@ class MeshCoreConnector extends ChangeNotifier {
|
|||||||
void _handleIncomingMessage(Uint8List frame) async {
|
void _handleIncomingMessage(Uint8List frame) async {
|
||||||
if (_selfPublicKey == null) return;
|
if (_selfPublicKey == null) return;
|
||||||
|
|
||||||
|
// If we're syncing the queued messages, advance the queue immediately
|
||||||
|
// before any potentially long async work (like translation/notifications).
|
||||||
|
if (_isSyncingQueuedMessages) {
|
||||||
|
_handleQueuedMessageReceived();
|
||||||
|
}
|
||||||
|
|
||||||
var message = _parseContactMessage(frame);
|
var message = _parseContactMessage(frame);
|
||||||
|
|
||||||
// If message parsing failed due to unknown contact, refresh contacts and retry
|
// If message parsing failed due to unknown contact, refresh contacts and retry
|
||||||
@@ -4403,26 +4409,23 @@ class MeshCoreConnector extends ChangeNotifier {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
_addMessage(message.senderKeyHex, message);
|
_addMessage(message.senderKeyHex, message);
|
||||||
TranslationResult? translationResult;
|
|
||||||
if (!message.isOutgoing) {
|
|
||||||
translationResult = await _translateIncomingContactMessage(
|
|
||||||
message.senderKeyHex,
|
|
||||||
message,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
_maybeIncrementContactUnread(message);
|
_maybeIncrementContactUnread(message);
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
|
|
||||||
// Show notification for new incoming message
|
// Show notification for new incoming message (run async with translation)
|
||||||
if (!message.isOutgoing &&
|
if (!message.isOutgoing &&
|
||||||
!message.isCli &&
|
!message.isCli &&
|
||||||
_appSettingsService != null) {
|
_appSettingsService != null) {
|
||||||
final settings = _appSettingsService!.settings;
|
final settings = _appSettingsService!.settings;
|
||||||
if (settings.notificationsEnabled && settings.notifyOnNewMessage) {
|
if (settings.notificationsEnabled && settings.notifyOnNewMessage) {
|
||||||
// Capture non-null local for async closure type promotion
|
final msg = message; // capture for closure
|
||||||
final msg = message;
|
final c = contact; // capture contact reference
|
||||||
if (contact?.type == advTypeChat) {
|
unawaited(() async {
|
||||||
unawaited(() async {
|
final translationResult = await _translateIncomingContactMessage(
|
||||||
|
msg.senderKeyHex,
|
||||||
|
msg,
|
||||||
|
);
|
||||||
|
if (c?.type == advTypeChat) {
|
||||||
final resolvedText =
|
final resolvedText =
|
||||||
(translationResult != null &&
|
(translationResult != null &&
|
||||||
translationResult.status ==
|
translationResult.status ==
|
||||||
@@ -4431,18 +4434,16 @@ class MeshCoreConnector extends ChangeNotifier {
|
|||||||
? translationResult.translatedText.trim()
|
? translationResult.translatedText.trim()
|
||||||
: msg.text.trim();
|
: msg.text.trim();
|
||||||
await _notificationService.showMessageNotification(
|
await _notificationService.showMessageNotification(
|
||||||
contactName: contact?.name ?? 'Unknown',
|
contactName: c?.name ?? 'Unknown',
|
||||||
message: resolvedText,
|
message: resolvedText,
|
||||||
contactId: msg.senderKeyHex,
|
contactId: msg.senderKeyHex,
|
||||||
badgeCount: getTotalUnreadCount(),
|
badgeCount: getTotalUnreadCount(),
|
||||||
);
|
);
|
||||||
}());
|
} else if (c?.type == advTypeRoom) {
|
||||||
} else if (contact?.type == advTypeRoom) {
|
// Room server messages include a 4-char prefix; strip it for notifications
|
||||||
// Room server messages include a 4-char prefix; strip it for notifications
|
final bodyText = msg.text.length > 4
|
||||||
final bodyText = msg.text.length > 4
|
? msg.text.substring(4)
|
||||||
? msg.text.substring(4)
|
: msg.text;
|
||||||
: msg.text;
|
|
||||||
unawaited(() async {
|
|
||||||
final resolvedText =
|
final resolvedText =
|
||||||
(translationResult != null &&
|
(translationResult != null &&
|
||||||
translationResult.status ==
|
translationResult.status ==
|
||||||
@@ -4451,18 +4452,15 @@ class MeshCoreConnector extends ChangeNotifier {
|
|||||||
? translationResult.translatedText.trim()
|
? translationResult.translatedText.trim()
|
||||||
: bodyText.trim();
|
: bodyText.trim();
|
||||||
await _notificationService.showMessageNotification(
|
await _notificationService.showMessageNotification(
|
||||||
contactName: contact?.name ?? 'Unknown Room',
|
contactName: c?.name ?? 'Unknown Room',
|
||||||
message: resolvedText,
|
message: resolvedText,
|
||||||
contactId: msg.senderKeyHex,
|
contactId: msg.senderKeyHex,
|
||||||
badgeCount: getTotalUnreadCount(),
|
badgeCount: getTotalUnreadCount(),
|
||||||
);
|
);
|
||||||
}());
|
}
|
||||||
}
|
}());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_handleQueuedMessageReceived();
|
|
||||||
} else if (_isSyncingQueuedMessages) {
|
|
||||||
_handleQueuedMessageReceived();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -4758,6 +4756,11 @@ class MeshCoreConnector extends ChangeNotifier {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void _handleIncomingChannelMessage(Uint8List frame) async {
|
void _handleIncomingChannelMessage(Uint8List frame) async {
|
||||||
|
// If we're syncing the queued messages, advance the queue immediately
|
||||||
|
// before any potentially long async work (like translation/notifications).
|
||||||
|
if (_isSyncingQueuedMessages) {
|
||||||
|
_handleQueuedMessageReceived();
|
||||||
|
}
|
||||||
final parsed = ChannelMessage.fromFrame(frame);
|
final parsed = ChannelMessage.fromFrame(frame);
|
||||||
if (parsed != null && parsed.channelIndex != null) {
|
if (parsed != null && parsed.channelIndex != null) {
|
||||||
if (_shouldDropSelfChannelMessage(parsed.senderName, parsed.pathBytes)) {
|
if (_shouldDropSelfChannelMessage(parsed.senderName, parsed.pathBytes)) {
|
||||||
@@ -4776,24 +4779,18 @@ class MeshCoreConnector extends ChangeNotifier {
|
|||||||
pathBytes: message.pathBytes,
|
pathBytes: message.pathBytes,
|
||||||
);
|
);
|
||||||
final isNew = _addChannelMessage(message.channelIndex!, message);
|
final isNew = _addChannelMessage(message.channelIndex!, message);
|
||||||
TranslationResult? translationResult;
|
|
||||||
if (isNew && !message.isOutgoing) {
|
|
||||||
translationResult = await _translateIncomingChannelMessage(
|
|
||||||
message.channelIndex!,
|
|
||||||
message,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
_maybeIncrementChannelUnread(message, isNew: isNew);
|
_maybeIncrementChannelUnread(message, isNew: isNew);
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
if (isNew) {
|
if (isNew && !message.isOutgoing) {
|
||||||
_maybeNotifyChannelMessage(
|
final msg = message; // capture for closure
|
||||||
message,
|
unawaited(() async {
|
||||||
translationResult: translationResult,
|
final translationResult = await _translateIncomingChannelMessage(
|
||||||
);
|
msg.channelIndex!,
|
||||||
|
msg,
|
||||||
|
);
|
||||||
|
_maybeNotifyChannelMessage(msg, translationResult: translationResult);
|
||||||
|
}());
|
||||||
}
|
}
|
||||||
_handleQueuedMessageReceived();
|
|
||||||
} else if (_isSyncingQueuedMessages) {
|
|
||||||
_handleQueuedMessageReceived();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -4865,24 +4862,24 @@ class MeshCoreConnector extends ChangeNotifier {
|
|||||||
pathBytes: message.pathBytes,
|
pathBytes: message.pathBytes,
|
||||||
);
|
);
|
||||||
final isNew = _addChannelMessage(channel.index, message);
|
final isNew = _addChannelMessage(channel.index, message);
|
||||||
TranslationResult? translationResult;
|
|
||||||
if (isNew && !message.isOutgoing) {
|
|
||||||
translationResult = await _translateIncomingChannelMessage(
|
|
||||||
channel.index,
|
|
||||||
message,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
_maybeIncrementChannelUnread(message, isNew: isNew);
|
_maybeIncrementChannelUnread(message, isNew: isNew);
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
if (isNew) {
|
if (isNew) {
|
||||||
final label = channel.name.isEmpty
|
// Run translation + notification asynchronously to avoid blocking
|
||||||
? 'Channel ${channel.index}'
|
unawaited(() async {
|
||||||
: channel.name;
|
final translationResult = await _translateIncomingChannelMessage(
|
||||||
_maybeNotifyChannelMessage(
|
channel.index,
|
||||||
message,
|
message,
|
||||||
channelName: label,
|
);
|
||||||
translationResult: translationResult,
|
final label = channel.name.isEmpty
|
||||||
);
|
? 'Channel ${channel.index}'
|
||||||
|
: channel.name;
|
||||||
|
_maybeNotifyChannelMessage(
|
||||||
|
message,
|
||||||
|
channelName: label,
|
||||||
|
translationResult: translationResult,
|
||||||
|
);
|
||||||
|
}());
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|||||||
Reference in New Issue
Block a user