fix: Fix the wrong call on byShortName
feat: Add hashCode and equals override to Emoji class.
This commit is contained in:
@@ -26,7 +26,8 @@
|
|||||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
import 'package:collection/collection.dart' show IterableExtension;
|
import 'package:collection/collection.dart'
|
||||||
|
show IterableExtension, ListEquality;
|
||||||
|
|
||||||
/// All Groups
|
/// All Groups
|
||||||
enum EmojiGroup {
|
enum EmojiGroup {
|
||||||
@@ -114240,7 +114241,6 @@ final emojiRegex = RegExp(
|
|||||||
class Emoji {
|
class Emoji {
|
||||||
static const variationSelector16 = 65039;
|
static const variationSelector16 = 65039;
|
||||||
static const ZWJ = 8205;
|
static const ZWJ = 8205;
|
||||||
|
|
||||||
final String? name;
|
final String? name;
|
||||||
final String? char;
|
final String? char;
|
||||||
final String? shortName;
|
final String? shortName;
|
||||||
@@ -114252,14 +114252,39 @@ class Emoji {
|
|||||||
|
|
||||||
/// Emoji class.
|
/// Emoji class.
|
||||||
/// [name] of emoji. [char] and character of emoji. [shortName] and a digest name of emoji, [emojiGroup] is emoji's group and [emojiSubgroup] is emoji's subgroup. [keywords] list of keywords for emoji. [modifiable] `true` if emoji has skin.
|
/// [name] of emoji. [char] and character of emoji. [shortName] and a digest name of emoji, [emojiGroup] is emoji's group and [emojiSubgroup] is emoji's subgroup. [keywords] list of keywords for emoji. [modifiable] `true` if emoji has skin.
|
||||||
Emoji(
|
Emoji({
|
||||||
{this.name,
|
this.name,
|
||||||
this.char,
|
this.char,
|
||||||
this.shortName,
|
this.shortName,
|
||||||
this.emojiGroup,
|
this.emojiGroup,
|
||||||
this.emojiSubgroup,
|
this.emojiSubgroup,
|
||||||
this.keywords = const [],
|
this.keywords = const [],
|
||||||
this.modifiable = false});
|
this.modifiable = false,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool operator ==(Object other) =>
|
||||||
|
identical(this, other) ||
|
||||||
|
other is Emoji &&
|
||||||
|
runtimeType == other.runtimeType &&
|
||||||
|
name == other.name &&
|
||||||
|
char == other.char &&
|
||||||
|
shortName == other.shortName &&
|
||||||
|
emojiGroup == other.emojiGroup &&
|
||||||
|
emojiSubgroup == other.emojiSubgroup &&
|
||||||
|
const ListEquality().equals(keywords, other.keywords) &&
|
||||||
|
modifiable == other.modifiable;
|
||||||
|
|
||||||
|
@override
|
||||||
|
int get hashCode => Object.hash(
|
||||||
|
name.hashCode,
|
||||||
|
char.hashCode,
|
||||||
|
shortName.hashCode,
|
||||||
|
emojiGroup.hashCode,
|
||||||
|
emojiSubgroup.hashCode,
|
||||||
|
keywords.hashCode,
|
||||||
|
modifiable.hashCode,
|
||||||
|
);
|
||||||
|
|
||||||
/// Runes of Emoji Character
|
/// Runes of Emoji Character
|
||||||
List<int> get charRunes {
|
List<int> get charRunes {
|
||||||
@@ -114339,9 +114364,11 @@ class Emoji {
|
|||||||
return _emojis.firstWhereOrNull((Emoji emoji) => emoji.name == name);
|
return _emojis.firstWhereOrNull((Emoji emoji) => emoji.name == name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns Emoji by [name] as short name.
|
/// Returns Emoji by [shortName] as short name.
|
||||||
static Emoji? byShortName(String name) {
|
static Emoji? byShortName(String shortName) {
|
||||||
return _emojis.firstWhereOrNull((Emoji emoji) => emoji.char == name);
|
return _emojis.firstWhereOrNull(
|
||||||
|
(Emoji emoji) => emoji.shortName == shortName,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns list of Emojis in a same [group]
|
/// Returns list of Emojis in a same [group]
|
||||||
|
|||||||
@@ -0,0 +1,79 @@
|
|||||||
|
import 'package:stream_chat_flutter/src/emoji/emoji.dart';
|
||||||
|
import 'package:test/test.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
group('src/emoji', () {
|
||||||
|
test('${Emoji.byShortName} should bring the correct emoji', () {
|
||||||
|
final resultEmoji = Emoji.byShortName('smiley');
|
||||||
|
expect(resultEmoji, _mockEmoji);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
final _mockEmoji = Emoji(
|
||||||
|
name: 'grinning face with big eyes',
|
||||||
|
char: '\u{1F603}',
|
||||||
|
shortName: 'smiley',
|
||||||
|
emojiGroup: EmojiGroup.smileysEmotion,
|
||||||
|
emojiSubgroup: EmojiSubgroup.faceSmiling,
|
||||||
|
keywords: [
|
||||||
|
'face',
|
||||||
|
'mouth',
|
||||||
|
'open',
|
||||||
|
'smile',
|
||||||
|
'uc6',
|
||||||
|
'smiley',
|
||||||
|
'happy',
|
||||||
|
'silly',
|
||||||
|
'laugh',
|
||||||
|
'good',
|
||||||
|
'smile',
|
||||||
|
'teeth',
|
||||||
|
'fun',
|
||||||
|
'smileys',
|
||||||
|
'mood',
|
||||||
|
'emotion',
|
||||||
|
'emotions',
|
||||||
|
'emotional',
|
||||||
|
'hooray',
|
||||||
|
'cheek',
|
||||||
|
'cheeky',
|
||||||
|
'excited',
|
||||||
|
'feliz',
|
||||||
|
'heureux',
|
||||||
|
'cheerful',
|
||||||
|
'delighted',
|
||||||
|
'ecstatic',
|
||||||
|
'elated',
|
||||||
|
'glad',
|
||||||
|
'joy',
|
||||||
|
'merry',
|
||||||
|
'funny',
|
||||||
|
'laughing',
|
||||||
|
'lol',
|
||||||
|
'rofl',
|
||||||
|
'lmao',
|
||||||
|
'lmfao',
|
||||||
|
'hilarious',
|
||||||
|
'ha',
|
||||||
|
'haha',
|
||||||
|
'chuckle',
|
||||||
|
'comedy',
|
||||||
|
'giggle',
|
||||||
|
'hehe',
|
||||||
|
'joyful',
|
||||||
|
'laugh out loud',
|
||||||
|
'rire',
|
||||||
|
'tee hee',
|
||||||
|
'jaja',
|
||||||
|
'good job',
|
||||||
|
'nice',
|
||||||
|
'well done',
|
||||||
|
'bravo',
|
||||||
|
'congratulations',
|
||||||
|
'congrats',
|
||||||
|
'smiles',
|
||||||
|
'dentist',
|
||||||
|
':-D',
|
||||||
|
'=D'
|
||||||
|
]);
|
||||||
Reference in New Issue
Block a user