mirror of
https://gitlab.com/comunic/comunicmobile
synced 2024-11-26 06:49:22 +00:00
Get custom emojies from server
This commit is contained in:
parent
c42fe7f806
commit
032b247080
@ -22,6 +22,7 @@ abstract class UserTableContract {
|
|||||||
static const C_VISIBILITY = "visibility";
|
static const C_VISIBILITY = "visibility";
|
||||||
static const C_VIRTUAL_DIRECTORY = "virtual_directory";
|
static const C_VIRTUAL_DIRECTORY = "virtual_directory";
|
||||||
static const C_ACCOUNT_IMAGE_URL = "account_image_url";
|
static const C_ACCOUNT_IMAGE_URL = "account_image_url";
|
||||||
|
static const C_CUSTOM_EMOJIES = "custom_emojies";
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Conversations table contract
|
/// Conversations table contract
|
||||||
|
@ -70,7 +70,8 @@ abstract class DatabaseHelper {
|
|||||||
"${UserTableContract.C_LAST_NAME} TEXT, "
|
"${UserTableContract.C_LAST_NAME} TEXT, "
|
||||||
"${UserTableContract.C_VISIBILITY} TEXT, "
|
"${UserTableContract.C_VISIBILITY} TEXT, "
|
||||||
"${UserTableContract.C_VIRTUAL_DIRECTORY} TEXT, "
|
"${UserTableContract.C_VIRTUAL_DIRECTORY} TEXT, "
|
||||||
"${UserTableContract.C_ACCOUNT_IMAGE_URL} TEXT"
|
"${UserTableContract.C_ACCOUNT_IMAGE_URL} TEXT, "
|
||||||
|
"${UserTableContract.C_CUSTOM_EMOJIES} TEXT"
|
||||||
")");
|
")");
|
||||||
|
|
||||||
// Create conversations table
|
// Create conversations table
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
import 'package:comunic/enums/user_page_visibility.dart';
|
import 'package:comunic/enums/user_page_visibility.dart';
|
||||||
import 'package:comunic/helpers/database/users_database_helper.dart';
|
import 'package:comunic/helpers/database/users_database_helper.dart';
|
||||||
|
import 'package:comunic/lists/custom_emojies_list.dart';
|
||||||
import 'package:comunic/lists/users_list.dart';
|
import 'package:comunic/lists/users_list.dart';
|
||||||
import 'package:comunic/models/advanced_user_info.dart';
|
import 'package:comunic/models/advanced_user_info.dart';
|
||||||
import 'package:comunic/models/api_request.dart';
|
import 'package:comunic/models/api_request.dart';
|
||||||
|
import 'package:comunic/models/custom_emoji.dart';
|
||||||
import 'package:comunic/models/user.dart';
|
import 'package:comunic/models/user.dart';
|
||||||
|
|
||||||
/// User helper
|
/// User helper
|
||||||
@ -53,10 +55,10 @@ class UsersHelper {
|
|||||||
: (v["openPage"] == "false"
|
: (v["openPage"] == "false"
|
||||||
? UserPageVisibility.PRIVATE
|
? UserPageVisibility.PRIVATE
|
||||||
: UserPageVisibility.OPEN),
|
: UserPageVisibility.OPEN),
|
||||||
virtualDirectory: v["virtualDirectory"] == ""
|
virtualDirectory:
|
||||||
? null
|
v["virtualDirectory"] == "" ? null : v["virtualDirectory"],
|
||||||
: v["virtualDirectory"],
|
|
||||||
accountImageURL: v["accountImage"],
|
accountImageURL: v["accountImage"],
|
||||||
|
customEmojies: _parseCustomEmojies(v["customEmojis"]),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@ -154,8 +156,24 @@ class UsersHelper {
|
|||||||
virtualDirectory:
|
virtualDirectory:
|
||||||
data["virtualDirectory"] == "" ? null : data["virtualDirectory"],
|
data["virtualDirectory"] == "" ? null : data["virtualDirectory"],
|
||||||
accountImageURL: data["accountImage"],
|
accountImageURL: data["accountImage"],
|
||||||
|
customEmojies: _parseCustomEmojies(data["customEmojis"]),
|
||||||
publicNote: data["publicNote"],
|
publicNote: data["publicNote"],
|
||||||
canPostTexts: data["can_post_texts"],
|
canPostTexts: data["can_post_texts"],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Parse the list of custom emojies
|
||||||
|
CustomEmojiesList _parseCustomEmojies(List<dynamic> list) {
|
||||||
|
final l = list.cast<Map<String, dynamic>>();
|
||||||
|
|
||||||
|
return CustomEmojiesList()
|
||||||
|
..addAll(l
|
||||||
|
.map((f) => CustomEmoji(
|
||||||
|
id: f["id"],
|
||||||
|
userID: f["userID"],
|
||||||
|
shortcut: f["shorcut"],
|
||||||
|
url: f["url"],
|
||||||
|
))
|
||||||
|
.toList());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
17
lib/lists/custom_emojies_list.dart
Normal file
17
lib/lists/custom_emojies_list.dart
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
import 'package:comunic/lists/abstract_list.dart';
|
||||||
|
import 'package:comunic/models/custom_emoji.dart';
|
||||||
|
|
||||||
|
/// Custom emojies list
|
||||||
|
///
|
||||||
|
/// @author Pierre HUBERT
|
||||||
|
|
||||||
|
class CustomEmojiesList extends AbstractList<CustomEmoji> {
|
||||||
|
/// Serialize this list
|
||||||
|
List<Map<String, dynamic>> toSerializableList() =>
|
||||||
|
map((f) => f.toMap()).toList();
|
||||||
|
|
||||||
|
/// Un-serialize this list
|
||||||
|
static CustomEmojiesList fromSerializedList(List<dynamic> list) =>
|
||||||
|
CustomEmojiesList()
|
||||||
|
..addAll(list.map((f) => CustomEmoji.fromMap(f)).toList());
|
||||||
|
}
|
@ -1,4 +1,5 @@
|
|||||||
import 'package:comunic/enums/user_page_visibility.dart';
|
import 'package:comunic/enums/user_page_visibility.dart';
|
||||||
|
import 'package:comunic/lists/custom_emojies_list.dart';
|
||||||
import 'package:comunic/models/user.dart';
|
import 'package:comunic/models/user.dart';
|
||||||
import 'package:meta/meta.dart';
|
import 'package:meta/meta.dart';
|
||||||
|
|
||||||
@ -17,6 +18,7 @@ class AdvancedUserInfo extends User {
|
|||||||
@required UserPageVisibility pageVisibility,
|
@required UserPageVisibility pageVisibility,
|
||||||
@required String virtualDirectory,
|
@required String virtualDirectory,
|
||||||
@required String accountImageURL,
|
@required String accountImageURL,
|
||||||
|
@required CustomEmojiesList customEmojies,
|
||||||
@required this.publicNote,
|
@required this.publicNote,
|
||||||
@required this.canPostTexts,
|
@required this.canPostTexts,
|
||||||
}) : assert(publicNote != null),
|
}) : assert(publicNote != null),
|
||||||
@ -27,5 +29,6 @@ class AdvancedUserInfo extends User {
|
|||||||
lastName: lastName,
|
lastName: lastName,
|
||||||
pageVisibility: pageVisibility,
|
pageVisibility: pageVisibility,
|
||||||
virtualDirectory: virtualDirectory,
|
virtualDirectory: virtualDirectory,
|
||||||
accountImageURL: accountImageURL);
|
accountImageURL: accountImageURL,
|
||||||
|
customEmojies: customEmojies);
|
||||||
}
|
}
|
||||||
|
35
lib/models/custom_emoji.dart
Normal file
35
lib/models/custom_emoji.dart
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
/// Single custom emoji information
|
||||||
|
///
|
||||||
|
/// @author Pierre Hubert
|
||||||
|
|
||||||
|
class CustomEmoji {
|
||||||
|
final int id;
|
||||||
|
final int userID;
|
||||||
|
final String shortcut;
|
||||||
|
final String url;
|
||||||
|
|
||||||
|
const CustomEmoji({
|
||||||
|
@required this.id,
|
||||||
|
@required this.userID,
|
||||||
|
@required this.shortcut,
|
||||||
|
@required this.url,
|
||||||
|
}) : assert(id != null),
|
||||||
|
assert(userID != null),
|
||||||
|
assert(shortcut != null),
|
||||||
|
assert(url != null);
|
||||||
|
|
||||||
|
Map<String, dynamic> toMap() => {
|
||||||
|
"id": id,
|
||||||
|
"userID": userID,
|
||||||
|
"shortcut": shortcut,
|
||||||
|
"url": url,
|
||||||
|
};
|
||||||
|
|
||||||
|
CustomEmoji.fromMap(Map<String, dynamic> map)
|
||||||
|
: id = map["id"],
|
||||||
|
userID = map["userID"],
|
||||||
|
shortcut = map["shortcut"],
|
||||||
|
url = map["url"];
|
||||||
|
}
|
@ -1,5 +1,8 @@
|
|||||||
|
import 'dart:convert';
|
||||||
|
|
||||||
import 'package:comunic/enums/user_page_visibility.dart';
|
import 'package:comunic/enums/user_page_visibility.dart';
|
||||||
import 'package:comunic/helpers/database/database_contract.dart';
|
import 'package:comunic/helpers/database/database_contract.dart';
|
||||||
|
import 'package:comunic/lists/custom_emojies_list.dart';
|
||||||
import 'package:comunic/models/cache_model.dart';
|
import 'package:comunic/models/cache_model.dart';
|
||||||
import 'package:comunic/utils/ui_utils.dart';
|
import 'package:comunic/utils/ui_utils.dart';
|
||||||
import 'package:meta/meta.dart';
|
import 'package:meta/meta.dart';
|
||||||
@ -14,6 +17,7 @@ class User extends CacheModel {
|
|||||||
final UserPageVisibility pageVisibility;
|
final UserPageVisibility pageVisibility;
|
||||||
final String virtualDirectory;
|
final String virtualDirectory;
|
||||||
final String accountImageURL;
|
final String accountImageURL;
|
||||||
|
final CustomEmojiesList customEmojies;
|
||||||
|
|
||||||
const User({
|
const User({
|
||||||
@required int id,
|
@required int id,
|
||||||
@ -22,11 +26,13 @@ class User extends CacheModel {
|
|||||||
@required this.pageVisibility,
|
@required this.pageVisibility,
|
||||||
@required this.virtualDirectory,
|
@required this.virtualDirectory,
|
||||||
@required this.accountImageURL,
|
@required this.accountImageURL,
|
||||||
|
@required this.customEmojies,
|
||||||
}) : assert(id != null),
|
}) : assert(id != null),
|
||||||
assert(firstName != null),
|
assert(firstName != null),
|
||||||
assert(lastName != null),
|
assert(lastName != null),
|
||||||
assert(pageVisibility != null),
|
assert(pageVisibility != null),
|
||||||
assert(accountImageURL != null),
|
assert(accountImageURL != null),
|
||||||
|
assert(customEmojies != null),
|
||||||
super(id: id);
|
super(id: id);
|
||||||
|
|
||||||
/// Get user full name
|
/// Get user full name
|
||||||
@ -43,6 +49,8 @@ class User extends CacheModel {
|
|||||||
UserTableContract.C_VISIBILITY: pageVisibility.toString(),
|
UserTableContract.C_VISIBILITY: pageVisibility.toString(),
|
||||||
UserTableContract.C_VIRTUAL_DIRECTORY: virtualDirectory,
|
UserTableContract.C_VIRTUAL_DIRECTORY: virtualDirectory,
|
||||||
UserTableContract.C_ACCOUNT_IMAGE_URL: accountImageURL,
|
UserTableContract.C_ACCOUNT_IMAGE_URL: accountImageURL,
|
||||||
|
UserTableContract.C_CUSTOM_EMOJIES:
|
||||||
|
jsonEncode(customEmojies.toSerializableList()),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,5 +61,7 @@ class User extends CacheModel {
|
|||||||
userPageVisibilityFromString(map[UserTableContract.C_VISIBILITY]),
|
userPageVisibilityFromString(map[UserTableContract.C_VISIBILITY]),
|
||||||
this.virtualDirectory = map[UserTableContract.C_VIRTUAL_DIRECTORY],
|
this.virtualDirectory = map[UserTableContract.C_VIRTUAL_DIRECTORY],
|
||||||
this.accountImageURL = map[UserTableContract.C_ACCOUNT_IMAGE_URL],
|
this.accountImageURL = map[UserTableContract.C_ACCOUNT_IMAGE_URL],
|
||||||
|
this.customEmojies = CustomEmojiesList.fromSerializedList(
|
||||||
|
jsonDecode(map[UserTableContract.C_CUSTOM_EMOJIES])),
|
||||||
super.fromMap(map);
|
super.fromMap(map);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user