mirror of
https://github.com/rustdesk/rustdesk.git
synced 2026-03-17 02:01:01 +03:00
improve display name handling
- Append (@username) when multiple users share the same display name - Trim whitespace from display_name before comparison and display - Add missing translate() for Logout button on desktop Signed-off-by: 21pages <sunboeasy@gmail.com>
This commit is contained in:
@@ -164,6 +164,12 @@ class _MyGroupState extends State<MyGroup> {
|
||||
}
|
||||
return true;
|
||||
}).toList();
|
||||
// Count occurrences of each displayNameOrName to detect duplicates
|
||||
final displayNameCount = <String, int>{};
|
||||
for (final u in userItems) {
|
||||
final dn = u.displayNameOrName;
|
||||
displayNameCount[dn] = (displayNameCount[dn] ?? 0) + 1;
|
||||
}
|
||||
final deviceGroupItems = gFFI.groupModel.deviceGroups.where((p0) {
|
||||
if (searchAccessibleItemNameText.isNotEmpty) {
|
||||
return p0.name
|
||||
@@ -177,7 +183,8 @@ class _MyGroupState extends State<MyGroup> {
|
||||
itemCount: deviceGroupItems.length + userItems.length,
|
||||
itemBuilder: (context, index) => index < deviceGroupItems.length
|
||||
? _buildDeviceGroupItem(deviceGroupItems[index])
|
||||
: _buildUserItem(userItems[index - deviceGroupItems.length]));
|
||||
: _buildUserItem(userItems[index - deviceGroupItems.length],
|
||||
displayNameCount));
|
||||
var maxHeight = max(MediaQuery.of(context).size.height / 6, 100.0);
|
||||
return Obx(() => stateGlobal.isPortrait.isFalse
|
||||
? listView(false)
|
||||
@@ -185,9 +192,14 @@ class _MyGroupState extends State<MyGroup> {
|
||||
});
|
||||
}
|
||||
|
||||
Widget _buildUserItem(UserPayload user) {
|
||||
Widget _buildUserItem(UserPayload user, Map<String, int> displayNameCount) {
|
||||
final username = user.name;
|
||||
final displayName = user.displayNameOrName;
|
||||
final dn = user.displayNameOrName;
|
||||
final isDuplicate = (displayNameCount[dn] ?? 0) > 1;
|
||||
final displayName =
|
||||
isDuplicate && user.displayName.trim().isNotEmpty
|
||||
? '${user.displayName} (@$username)'
|
||||
: dn;
|
||||
return InkWell(onTap: () {
|
||||
isSelectedDeviceGroup.value = false;
|
||||
if (selectedAccessibleItemName.value != username) {
|
||||
@@ -223,7 +235,7 @@ class _MyGroupState extends State<MyGroup> {
|
||||
alignment: Alignment.center,
|
||||
child: Center(
|
||||
child: Text(
|
||||
username.characters.first.toUpperCase(),
|
||||
displayName.characters.first.toUpperCase(),
|
||||
style: TextStyle(color: Colors.white),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
|
||||
@@ -2018,7 +2018,7 @@ class _AccountState extends State<_Account> {
|
||||
return Obx(() => _Button(
|
||||
gFFI.userModel.userName.value.isEmpty
|
||||
? 'Login'
|
||||
: 'Logout (${gFFI.userModel.accountLabelWithHandle})',
|
||||
: '${translate('Logout')} (${gFFI.userModel.accountLabelWithHandle})',
|
||||
() => {
|
||||
gFFI.userModel.userName.value.isEmpty
|
||||
? loginDialog()
|
||||
@@ -2040,8 +2040,9 @@ class _AccountState extends State<_Account> {
|
||||
child: Column(
|
||||
children: [
|
||||
if (gFFI.userModel.displayName.value.trim().isNotEmpty &&
|
||||
gFFI.userModel.displayName.value != gFFI.userModel.userName.value)
|
||||
text('Display Name', gFFI.userModel.displayName.value),
|
||||
gFFI.userModel.displayName.value.trim() !=
|
||||
gFFI.userModel.userName.value.trim())
|
||||
text('Display Name', gFFI.userModel.displayName.value.trim()),
|
||||
text('Username', gFFI.userModel.userName.value),
|
||||
// text('Group', gFFI.groupModel.groupName.value),
|
||||
],
|
||||
@@ -2137,7 +2138,7 @@ class _PluginState extends State<_Plugin> {
|
||||
return Obx(() => _Button(
|
||||
gFFI.userModel.userName.value.isEmpty
|
||||
? 'Login'
|
||||
: 'Logout (${gFFI.userModel.accountLabelWithHandle})',
|
||||
: '${translate('Logout')} (${gFFI.userModel.accountLabelWithHandle})',
|
||||
() => {
|
||||
gFFI.userModel.userName.value.isEmpty
|
||||
? loginDialog()
|
||||
|
||||
Reference in New Issue
Block a user