vkdart

Форк
0
/
utils.dart 
55 строк · 1.3 Кб
1
import 'package:vkdart/vkontakte.dart';
2

3
/// Offset Chat ID.
4
const peerChatIdOffset = 2000000000;
5

6
/// Transforms a list of attachment objects in the format:
7
/// ```dart
8
/// [{'type': 'photo', 'photo': {...}}, {'type': 'audio', 'audio': {...}}, ...]
9
/// ```
10
/// in the attachment model.
11
List<AttachmentModel> transformAttachments(
12
        List<Map<String, dynamic>> attachments) =>
13
    attachments.map((e) {
14
      final attachType = e['type'];
15
      return AttachmentModel.fromSpecificModel(e[attachType], attachType);
16
    }).toList();
17

18
/// Message Source
19
enum MessageSource {
20
  /// User.
21
  user,
22

23
  /// Group.
24
  group,
25

26
  /// Chat.
27
  chat
28
}
29

30
/// Returns the dialog type.
31
/// Accepts the [id] parameter as input,
32
/// if [id] is less than [peerChatIdOffset], [MessageSource.chat] is returned,
33
/// if [id] is less than zero, returned [MessageSource.group],
34
/// in all other cases [MessageSource.user]
35
MessageSource getPeerType(int id) {
36
  if (peerChatIdOffset < id) {
37
    return MessageSource.chat;
38
  }
39

40
  if (id < 0) {
41
    return MessageSource.group;
42
  }
43

44
  return MessageSource.user;
45
}
46

47
/// Checks the [value] for an integer, then checks for one.
48
/// If the value is not an integer, null is returned,
49
bool? checkBoolUtil(Object? value) {
50
  if (value is! int) {
51
    return null;
52
  }
53

54
  return value == 1;
55
}
56

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.