2022-04-06 07:43:26 +02:00
|
|
|
// Copyright © 2022 Rangeproof Pty Ltd. All rights reserved.
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
import GRDB
|
|
|
|
import SessionUtilitiesKit
|
|
|
|
|
2023-03-31 03:09:04 +02:00
|
|
|
public struct GroupMember: Codable, Equatable, Hashable, FetchableRecord, PersistableRecord, TableRecord, ColumnExpressible {
|
2022-04-06 07:43:26 +02:00
|
|
|
public static var databaseTableName: String { "groupMember" }
|
2022-04-08 08:56:33 +02:00
|
|
|
internal static let openGroupForeignKey = ForeignKey([Columns.groupId], to: [OpenGroup.Columns.threadId])
|
|
|
|
internal static let closedGroupForeignKey = ForeignKey([Columns.groupId], to: [ClosedGroup.Columns.threadId])
|
2022-05-03 09:14:56 +02:00
|
|
|
public static let openGroup = belongsTo(OpenGroup.self, using: openGroupForeignKey)
|
|
|
|
public static let closedGroup = belongsTo(ClosedGroup.self, using: closedGroupForeignKey)
|
2022-05-06 04:44:26 +02:00
|
|
|
public static let profile = hasOne(Profile.self, using: Profile.groupMemberForeignKey)
|
2022-04-06 07:43:26 +02:00
|
|
|
|
|
|
|
public typealias Columns = CodingKeys
|
|
|
|
public enum CodingKeys: String, CodingKey, ColumnExpression {
|
|
|
|
case groupId
|
|
|
|
case profileId
|
|
|
|
case role
|
2022-08-16 05:56:40 +02:00
|
|
|
case isHidden
|
2022-04-06 07:43:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public enum Role: Int, Codable, DatabaseValueConvertible {
|
|
|
|
case standard
|
|
|
|
case zombie
|
|
|
|
case moderator
|
|
|
|
case admin
|
|
|
|
}
|
|
|
|
|
|
|
|
public let groupId: String
|
|
|
|
public let profileId: String
|
|
|
|
public let role: Role
|
2022-08-16 05:56:40 +02:00
|
|
|
public let isHidden: Bool
|
2022-04-08 08:56:33 +02:00
|
|
|
|
|
|
|
// MARK: - Relationships
|
|
|
|
|
|
|
|
public var openGroup: QueryInterfaceRequest<OpenGroup> {
|
|
|
|
request(for: GroupMember.openGroup)
|
|
|
|
}
|
|
|
|
|
|
|
|
public var closedGroup: QueryInterfaceRequest<ClosedGroup> {
|
|
|
|
request(for: GroupMember.closedGroup)
|
|
|
|
}
|
|
|
|
|
|
|
|
public var profile: QueryInterfaceRequest<Profile> {
|
|
|
|
request(for: GroupMember.profile)
|
|
|
|
}
|
2022-04-21 08:42:35 +02:00
|
|
|
|
|
|
|
// MARK: - Initialization
|
|
|
|
|
|
|
|
public init(
|
|
|
|
groupId: String,
|
|
|
|
profileId: String,
|
2022-08-16 05:56:40 +02:00
|
|
|
role: Role,
|
|
|
|
isHidden: Bool
|
2022-04-21 08:42:35 +02:00
|
|
|
) {
|
|
|
|
self.groupId = groupId
|
|
|
|
self.profileId = profileId
|
|
|
|
self.role = role
|
2022-08-16 05:56:40 +02:00
|
|
|
self.isHidden = isHidden
|
2022-04-21 08:42:35 +02:00
|
|
|
}
|
2022-04-06 07:43:26 +02:00
|
|
|
}
|