fix: avoid duplicate manufacturer in camera name (#32657)

* fix(web,mobile): avoid duplicate manufacturer in camera name

Some cameras (e.g. Canon) already include the manufacturer in the EXIF
model, which made the details view show "Canon Canon EOS R6m2". Only
prepend the make when the model does not already start with it.

* refactor(web,mobile): address review feedback on camera name helper

- Use toLowerCase instead of toLocaleLowerCase for the comparison
- Hoist the whitespace regex to a static in the Dart helper
- Match any word of the make, so "EASTMAN KODAK COMPANY" with
  "KODAK EASYSHARE C875" is deduplicated too
- Compute the camera name once in DetailPanel

---------

Co-authored-by: Daniel Dietzler <mail@ddietzler.dev>
(cherry picked from commit cb2ea1e308d8a85f2f340f50b646f161d3528670)
This commit is contained in:
Brent Saltzman
2026-10-29 20:41:02 +03:00
committed by Codex
parent 477fcc2338
commit 3c383e46d1
6 changed files with 169 additions and 9 deletions
@@ -8,6 +8,7 @@ import 'package:immich_mobile/generated/translations.g.dart';
import 'package:immich_mobile/presentation/widgets/asset_viewer/sheet_tile.widget.dart';
import 'package:immich_mobile/repositories/asset_media.repository.dart';
import 'package:immich_mobile/utils/bytes_units.dart';
import 'package:immich_mobile/utils/camera.utils.dart';
const _kSeparator = ' • ';
@@ -114,12 +115,7 @@ class TechnicalDetails extends ConsumerWidget {
if (exifInfo == null) {
return null;
}
return switch ((exifInfo.make, exifInfo.model)) {
(null, null) => null,
(final String make, null) => make,
(null, final String model) => model,
(final String make, final String model) => '$make $model',
};
return getCameraName(exifInfo.make, exifInfo.model);
}
static String? _getCameraInfoSubtitle(ExifInfo? exifInfo) {
+38
View File
@@ -0,0 +1,38 @@
final _whitespace = RegExp(r'\s+');
final _wordChar = RegExp(r'\w');
/// Builds the display name of a camera from its EXIF make and model.
///
/// Many cameras (e.g. Canon) already include the manufacturer in the model
/// (`Canon EOS R6m2`), so prefixing the make again would produce
/// "Canon Canon EOS R6m2". The make is only prepended when the model does not
/// already start with it. Makes made up of several words are matched word by
/// word, since the model usually repeats only part of them:
/// `NIKON CORPORATION` / `NIKON D850` and
/// `EASTMAN KODAK COMPANY` / `KODAK EASYSHARE C875`.
///
/// Returns `null` when neither a make nor a model is available.
String? getCameraName(String? make, String? model) {
final trimmedMake = make?.trim() ?? '';
final trimmedModel = model?.trim() ?? '';
if (trimmedMake.isEmpty && trimmedModel.isEmpty) {
return null;
}
if (trimmedMake.isEmpty) {
return trimmedModel;
}
if (trimmedModel.isEmpty) {
return trimmedMake;
}
final lowerModel = trimmedModel.toLowerCase();
final modelIncludesMake = trimmedMake.toLowerCase().split(_whitespace).any((word) {
final charAfterWord = lowerModel.length > word.length ? lowerModel[word.length] : '';
return lowerModel.startsWith(word) && !_wordChar.hasMatch(charAfterWord);
});
return modelIncludesMake ? trimmedModel : '$trimmedMake $trimmedModel';
}
+47
View File
@@ -0,0 +1,47 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:immich_mobile/utils/camera.utils.dart';
void main() {
group('getCameraName', () {
test('does not repeat the make when the model already starts with it', () {
expect(getCameraName('Canon', 'Canon EOS R6m2'), 'Canon EOS R6m2');
expect(getCameraName('Canon', 'Canon EOS 5D Mark IV'), 'Canon EOS 5D Mark IV');
});
test('compares the make and model case-insensitively', () {
expect(getCameraName('NIKON', 'Nikon Z 6'), 'Nikon Z 6');
expect(getCameraName('canon', 'CANON EOS R5'), 'CANON EOS R5');
});
test('compares against the first word of a multi-word make', () {
expect(getCameraName('NIKON CORPORATION', 'NIKON D850'), 'NIKON D850');
expect(getCameraName('OLYMPUS IMAGING CORP.', 'OLYMPUS E-M1'), 'OLYMPUS E-M1');
});
test('matches any word of a multi-word make', () {
expect(getCameraName('EASTMAN KODAK COMPANY', 'KODAK EASYSHARE C875'), 'KODAK EASYSHARE C875');
expect(getCameraName('EASTMAN KODAK COMPANY', 'EASTMAN KODAK 1'), 'EASTMAN KODAK 1');
});
test('prepends the make when the model does not include it', () {
expect(getCameraName('SONY', 'ILCE-7M4'), 'SONY ILCE-7M4');
expect(getCameraName('FUJIFILM', 'X-T5'), 'FUJIFILM X-T5');
expect(getCameraName('Apple', 'iPhone 15 Pro'), 'Apple iPhone 15 Pro');
});
test('only treats the make as a prefix on a word boundary', () {
expect(getCameraName('Canon', 'Canonical X1'), 'Canon Canonical X1');
});
test('handles a missing make or model', () {
expect(getCameraName('Canon', null), 'Canon');
expect(getCameraName(null, 'EOS R6m2'), 'EOS R6m2');
expect(getCameraName(null, null), isNull);
expect(getCameraName('', ''), isNull);
});
test('ignores surrounding whitespace', () {
expect(getCameraName(' Canon ', ' Canon EOS R6m2 '), 'Canon EOS R6m2');
});
});
}