mirror of
https://github.com/zjs81/meshcore-open.git
synced 2026-07-20 07:41:03 +10:00
Merge pull request #453 from HDDen/mcoa-roomsrv-alfa
Room-server: fixed first message letters trim
This commit is contained in:
@@ -4462,9 +4462,7 @@ class MeshCoreConnector extends ChangeNotifier {
|
|||||||
} else if (contact?.type == advTypeRoom) {
|
} else if (contact?.type == advTypeRoom) {
|
||||||
_notificationService.showMessageNotification(
|
_notificationService.showMessageNotification(
|
||||||
contactName: contact?.name ?? 'Unknown Room',
|
contactName: contact?.name ?? 'Unknown Room',
|
||||||
message: message.text.length > 4
|
message: message.text,
|
||||||
? message.text.substring(4)
|
|
||||||
: message.text,
|
|
||||||
contactId: message.senderKeyHex,
|
contactId: message.senderKeyHex,
|
||||||
badgeCount: getTotalUnreadCount(),
|
badgeCount: getTotalUnreadCount(),
|
||||||
);
|
);
|
||||||
@@ -4511,16 +4509,24 @@ class MeshCoreConnector extends ChangeNotifier {
|
|||||||
timestampRaw * 1000,
|
timestampRaw * 1000,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (txtType == 2) {
|
final flags = txtType;
|
||||||
reader.skipBytes(4); // Skip extra 4 bytes for signed/plain variants
|
final shiftedType = flags >> 2;
|
||||||
|
final rawType = flags;
|
||||||
|
final isSigned = shiftedType == txtTypeSigned || rawType == txtTypeSigned;
|
||||||
|
final Uint8List? roomAuthorPrefix;
|
||||||
|
if (isSigned) {
|
||||||
|
// Room-server pushed posts use signed/plain contact messages where this
|
||||||
|
// 4-byte "signature" field is actually the original author's pubkey
|
||||||
|
// prefix. Keep it as metadata; the text starts after these bytes.
|
||||||
|
roomAuthorPrefix = reader.readBytes(4);
|
||||||
|
} else {
|
||||||
|
roomAuthorPrefix = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
final msgText = reader.readCString();
|
final msgText = reader.readCString();
|
||||||
|
|
||||||
final flags = txtType;
|
final isPlain =
|
||||||
final shiftedType = flags >> 2;
|
shiftedType == txtTypePlain || rawType == txtTypePlain || isSigned;
|
||||||
final rawType = flags;
|
|
||||||
final isPlain = shiftedType == txtTypePlain || rawType == txtTypePlain;
|
|
||||||
final isCli = shiftedType == txtTypeCliData || rawType == txtTypeCliData;
|
final isCli = shiftedType == txtTypeCliData || rawType == txtTypeCliData;
|
||||||
if (!isPlain && !isCli) {
|
if (!isPlain && !isCli) {
|
||||||
appLogger.warn(
|
appLogger.warn(
|
||||||
@@ -4557,9 +4563,7 @@ class MeshCoreConnector extends ChangeNotifier {
|
|||||||
status: MessageStatus.delivered,
|
status: MessageStatus.delivered,
|
||||||
pathLength: pathLength == 0xFF ? 0 : pathLength,
|
pathLength: pathLength == 0xFF ? 0 : pathLength,
|
||||||
pathBytes: Uint8List(0),
|
pathBytes: Uint8List(0),
|
||||||
fourByteRoomContactKey: msgText.length >= 4
|
fourByteRoomContactKey: roomAuthorPrefix,
|
||||||
? Uint8List.fromList(msgText.substring(0, 4).codeUnits)
|
|
||||||
: null,
|
|
||||||
);
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
appLogger.warn('Error parsing contact direct message: $e');
|
appLogger.warn('Error parsing contact direct message: $e');
|
||||||
|
|||||||
@@ -485,6 +485,8 @@ class _ChatScreenState extends State<ChatScreen> {
|
|||||||
final message = reversedMessages[messageIndex];
|
final message = reversedMessages[messageIndex];
|
||||||
String fourByteHex = '';
|
String fourByteHex = '';
|
||||||
if (contact.type == advTypeRoom) {
|
if (contact.type == advTypeRoom) {
|
||||||
|
// Room-server messages carry the original author's 4-byte prefix
|
||||||
|
// separately from message.text; use it only for resolving the name.
|
||||||
contact = _resolveContactFrom4Bytes(
|
contact = _resolveContactFrom4Bytes(
|
||||||
connector,
|
connector,
|
||||||
message.fourByteRoomContactKey.isEmpty
|
message.fourByteRoomContactKey.isEmpty
|
||||||
@@ -509,7 +511,6 @@ class _ChatScreenState extends State<ChatScreen> {
|
|||||||
? "${contact.name} [$fourByteHex]"
|
? "${contact.name} [$fourByteHex]"
|
||||||
: contact.name,
|
: contact.name,
|
||||||
sourceId: widget.contact.publicKeyHex,
|
sourceId: widget.contact.publicKeyHex,
|
||||||
isRoomServer: resolvedContact.type == advTypeRoom,
|
|
||||||
textScale: textScale,
|
textScale: textScale,
|
||||||
onTap: () => _openMessagePath(message, contact),
|
onTap: () => _openMessagePath(message, contact),
|
||||||
onLongPress: () => _showMessageActions(message, contact),
|
onLongPress: () => _showMessageActions(message, contact),
|
||||||
@@ -1721,7 +1722,6 @@ class _ChatScreenState extends State<ChatScreen> {
|
|||||||
class _MessageBubble extends StatelessWidget {
|
class _MessageBubble extends StatelessWidget {
|
||||||
final Message message;
|
final Message message;
|
||||||
final String senderName;
|
final String senderName;
|
||||||
final bool isRoomServer;
|
|
||||||
final VoidCallback? onTap;
|
final VoidCallback? onTap;
|
||||||
final VoidCallback? onLongPress;
|
final VoidCallback? onLongPress;
|
||||||
final void Function(Message message, String emoji)? onRetryReaction;
|
final void Function(Message message, String emoji)? onRetryReaction;
|
||||||
@@ -1732,7 +1732,6 @@ class _MessageBubble extends StatelessWidget {
|
|||||||
required this.message,
|
required this.message,
|
||||||
required this.senderName,
|
required this.senderName,
|
||||||
required this.sourceId,
|
required this.sourceId,
|
||||||
required this.isRoomServer,
|
|
||||||
required this.textScale,
|
required this.textScale,
|
||||||
this.onTap,
|
this.onTap,
|
||||||
this.onLongPress,
|
this.onLongPress,
|
||||||
@@ -1758,10 +1757,9 @@ class _MessageBubble extends StatelessWidget {
|
|||||||
: (isOutgoing ? colorScheme.onPrimary : colorScheme.onSurface);
|
: (isOutgoing ? colorScheme.onPrimary : colorScheme.onSurface);
|
||||||
final metaColor = textColor.withValues(alpha: 0.7);
|
final metaColor = textColor.withValues(alpha: 0.7);
|
||||||
const bodyFontSize = 14.0;
|
const bodyFontSize = 14.0;
|
||||||
String messageText = message.text;
|
// Do not strip room-server author bytes here: the parser stores them in
|
||||||
if (isRoomServer && !isOutgoing) {
|
// fourByteRoomContactKey, so message.text is safe to render as-is.
|
||||||
messageText = message.text.substring(4.clamp(0, message.text.length));
|
final messageText = message.text;
|
||||||
}
|
|
||||||
final translatedDisplayText =
|
final translatedDisplayText =
|
||||||
message.translatedText != null &&
|
message.translatedText != null &&
|
||||||
message.translatedText!.trim().isNotEmpty
|
message.translatedText!.trim().isNotEmpty
|
||||||
|
|||||||
Reference in New Issue
Block a user