[Feature Enhancement]: UserSessionRegistry as a Protocol
まだ誰も着手していません。
評価
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 初心者へのやさしさ
- 25/100
- issue の種類
- 機能追加
- 明瞭さ
- おおむね明確
- 活発さ
- 停滞
- 技術スタック
- swift
調査の方向性
Read Sources/ATProtoKit/APIReference/SessionManager/UserSessionRegistry.swift and the linked working branch to understand the existing registry and proposed protocol. Check how session persistence and token storage are handled, then determine what documentation and tests are needed for a supported custom implementation; done means the protocol, persistence guidance, and behavior are validated in a real app.
索引モデルが issue の本文から書いたものです。
説明
Summary
As a developer building an ios app, it would be nice to have UserSessionRegistry as a protocol, so that users can pass in their own implmentation to persist the sessions
Pain points
I've been building out an app using this package and found that the UserSessionRegistry seems to be only in memory. I propose changing this to be a protocol so each system can provide a way to save these, for me that was with SwiftData. and also saving the accessToken in the keychain, like the refreshToken is
Considered Alternatives
There is a chance that I may have misunderstood how to use UserSessionRegistry, but I could not find a solution that would allow that to persist besides reloading it manually every reboot of the app
Is this a breaking change?
No
Additional Context
I acutally already have a working branch found here fatfingers23/ATProtoKit/tree/feature/UserSessionRegistryProtocol. So far it seems to be working, but I would like to clean it up, add proper formating, add documentation, and test more in a real life scenario before making a PR. But feel free to use it or propose a different approach, and I don't mind putting in the time to make it a proper PR to give back to the project
I have a SwiftData implementation of the UserSessionRegistry protocol here that is working in my app
import ATProtoKit
import Foundation
import SwiftData
@MainActor
public struct PersistentUserSessionRegistry: UserSessionRegistry {
private var modelContext: ModelContext
init(modelContext: ModelContext) {
self.modelContext = modelContext
}
public func register(_ id: UUID, session: UserSession) async {
let model = UserSessionToModel(id, session: session)
self.modelContext.insert(model)
do {
try self.modelContext.save()
} catch {
print("Error saving user session: \(error)")
}
}
public func getSession(for id: UUID) async -> UserSession? {
let descriptor = FetchDescriptor<UserSessionModel>(
predicate: #Predicate { $0.id == id }
)
do {
let models = try self.modelContext.fetch(descriptor)
guard let model = models.first else { return nil }
return ModelToUserSession(model)
} catch {
return nil
}
}
public func containsSession(for id: UUID) async -> Bool {
let descriptor = FetchDescriptor<UserSessionModel>(
predicate: #Predicate { $0.id == id }
)
do {
let count = try self.modelContext.fetchCount(descriptor)
return count > 0
} catch {
return false
}
}
public func removeSession(for id: UUID) async {
let descriptor = FetchDescriptor<UserSessionModel>(
predicate: #Predicate { $0.id == id }
)
do {
let models = try self.modelContext.fetch(descriptor)
for model in models {
self.modelContext.delete(model)
}
try self.modelContext.save()
} catch {
// Handle error silently or log as needed
}
}
public func removeAllSessions() async {
let descriptor = FetchDescriptor<UserSessionModel>()
do {
let models = try self.modelContext.fetch(descriptor)
for model in models {
self.modelContext.delete(model)
}
try self.modelContext.save()
} catch {
// Handle error silently or log as needed
}
}
public func getAllSessions() async -> [UUID: UserSession] {
let descriptor = FetchDescriptor<UserSessionModel>()
do {
let models = try self.modelContext.fetch(descriptor)
var sessions: [UUID: UserSession] = [:]
for model in models {
let session = ModelToUserSession(model)
sessions[model.id] = session
}
return sessions
} catch {
return [:]
}
}
}
private func ModelToUserSession(_ model: UserSessionModel) -> UserSession {
return UserSession(
handle: model.handle,
sessionDID: model.sessionDID,
email: model.email,
isEmailConfirmed: model.isEmailConfirmed,
isEmailAuthenticationFactorEnabled: model.isEmailAuthenticationFactorEnabled,
didDocument: model.didDocument,
isActive: model.isActive,
status: model.status,
serviceEndpoint: model.serviceEndpoint,
pdsURL: model.pdsURL
)
}
private func UserSessionToModel(_ id: UUID, session: UserSession) -> UserSessionModel {
return UserSessionModel(
sessionId: id,
handle: session.handle,
sessionDID: session.sessionDID,
email: session.email,
isEmailConfirmed: session.isEmailConfirmed,
isEmailAuthenticationFactorEnabled: session.isEmailAuthenticationFactorEnabled,
didDocument: session.didDocument,
isActive: session.isActive,
status: session.status,
serviceEndpoint: session.serviceEndpoint,
pdsURL: session.pdsURL)
}
- 主要言語
- Swift
- スター
- 226
- フォーク
- 40
- 平均マージ
- 5時間 8分
- マージ済み PR(30日)
- 3
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
MasterJ93/ATProtoKit のほかの issue
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 86/100
MasterJ93/ATProtoKit#344 ·
-
enhancement
難易度 4/5 1〜2日 初心者へのやさしさ 52/100
MasterJ93/ATProtoKit#337 · コメント 3 件 ·
-
new feature
難易度 4/5 3〜5日 初心者へのやさしさ 52/100
MasterJ93/ATProtoKit#321 · コメント 1 件 ·
-
new feature
難易度 4/5 3〜5日 初心者へのやさしさ 43/100
MasterJ93/ATProtoKit#320 · コメント 1 件 ·
-
new feature
難易度 4/5 1〜2日 初心者へのやさしさ 55/100
MasterJ93/ATProtoKit#316 · コメント 1 件 ·
MasterJ93/ATProtoKit の issue をすべて見る
似ている issue
-
area: build-and-ci possible-duplicate S3: minor
難易度 2/5 1〜3時間 初心者へのやさしさ 67/100
manaflow-ai/cmux#38889 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
LibChecker/LibChecker-Rules#1453 ·
-
documentation good first issue
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
-
triage me type: bug
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 73/100
modelcontextprotocol/swift-sdk#327 ·
メンテナーはふだん 2 日以内に返信