Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

998 B
Raw Blame
import "dart:convert";

class User {
  final int id;
  String email;
  String? role;

  User({required this.id, required this.email, this.role});

  bool get isViewer => role == null || role?.toUpperCase() == 'VIEWER';

  bool get isCollaborator =>
      role != null && role?.toUpperCase() == 'COLLABORATOR';

  bool get isAdmin => role != null && role?.toUpperCase() == 'ADMIN';

  Map<String, dynamic> toMap() {
    return {'id': id, 'email': email, "role": role};
  }

  static User fromMap(Map<String, dynamic> map) {
    return User(
      id: map['id'] as int,
      email: map['email'] as String,
      role: map['role'] ?? 'VIEWER',
    );
  }

  String toJson() => json.encode(toMap());

  factory User.fromJson(String source) => User.fromMap(json.decode(source));
}

class UserSuggestion {
  const UserSuggestion(this.email, {this.userID});

  factory UserSuggestion.fromUser(User user) =>
      UserSuggestion(user.email, userID: user.id);

  final int? userID;
  final String email;
}