session-ios/SessionMessagingKit/Database/Models/GroupMember.swift
Morgan Pretty 11231599db Further work on migrations and message pipeline refactoring
Refactored the AppDelegate from Objective C to Swift
Updated the HomeVC to use GRDB
Refactored a number of the Job types to be driven via GRDB and the new JobRunner
Fixed a bug where the LinkPreviewView wouldn't render correctly in dark mode
2022-04-21 16:42:35 +10:00

60 lines
1.9 KiB
Swift

// Copyright © 2022 Rangeproof Pty Ltd. All rights reserved.
import Foundation
import GRDB
import SessionUtilitiesKit
public struct GroupMember: Codable, FetchableRecord, PersistableRecord, TableRecord, ColumnExpressible {
public static var databaseTableName: String { "groupMember" }
internal static let openGroupForeignKey = ForeignKey([Columns.groupId], to: [OpenGroup.Columns.threadId])
internal static let closedGroupForeignKey = ForeignKey([Columns.groupId], to: [ClosedGroup.Columns.threadId])
internal static let profileForeignKey = ForeignKey([Columns.profileId], to: [Profile.Columns.id])
private static let openGroup = belongsTo(OpenGroup.self, using: openGroupForeignKey)
private static let closedGroup = belongsTo(ClosedGroup.self, using: closedGroupForeignKey)
private static let profile = hasOne(Profile.self, using: profileForeignKey)
public typealias Columns = CodingKeys
public enum CodingKeys: String, CodingKey, ColumnExpression {
case groupId
case profileId
case role
}
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
// 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)
}
// MARK: - Initialization
public init(
groupId: String,
profileId: String,
role: Role
) {
self.groupId = groupId
self.profileId = profileId
self.role = role
}
}