unarchive session

This commit is contained in:
sawka
2022-12-26 18:42:55 -08:00
parent af16ab1aed
commit 5933287e0d
2 changed files with 44 additions and 5 deletions
+8 -1
View File
@@ -1428,12 +1428,19 @@ func SessionArchiveCommand(ctx context.Context, pk *scpacket.FeCommandPacketType
if err != nil {
return nil, fmt.Errorf("cannot archive session: %v", err)
}
update.Info = &sstore.InfoMsgType{
InfoMsg: "session archived",
}
return update, nil
} else {
update, err := sstore.UnArchiveSession(ctx, sessionId)
activate := resolveBool(pk.Kwargs["activate"], false)
update, err := sstore.UnArchiveSession(ctx, sessionId, activate)
if err != nil {
return nil, fmt.Errorf("cannot un-archive session: %v", err)
}
update.Info = &sstore.InfoMsgType{
InfoMsg: "session un-archived",
}
return update, nil
}
}
+36 -4
View File
@@ -1344,7 +1344,7 @@ func fixActiveSessionId(ctx context.Context) (string, error) {
return newActiveSessionId, nil
}
func ArchiveSession(ctx context.Context, sessionId string) (UpdatePacket, error) {
func ArchiveSession(ctx context.Context, sessionId string) (*ModelUpdate, error) {
if sessionId == "" {
return nil, fmt.Errorf("invalid blank sessionid")
}
@@ -1368,7 +1368,7 @@ func ArchiveSession(ctx context.Context, sessionId string) (UpdatePacket, error)
return nil, txErr
}
bareSession, _ := GetBareSessionById(ctx, sessionId)
update := ModelUpdate{}
update := &ModelUpdate{}
if bareSession != nil {
update.Sessions = append(update.Sessions, bareSession)
}
@@ -1378,8 +1378,40 @@ func ArchiveSession(ctx context.Context, sessionId string) (UpdatePacket, error)
return update, nil
}
func UnArchiveSession(ctx context.Context, sessionId string) (UpdatePacket, error) {
return nil, nil
func UnArchiveSession(ctx context.Context, sessionId string, activate bool) (*ModelUpdate, error) {
if sessionId == "" {
return nil, fmt.Errorf("invalid blank sessionid")
}
txErr := WithTx(ctx, func(tx *TxWrap) error {
query := `SELECT sessionid FROM session WHERE sessionid = ?`
if !tx.Exists(query, sessionId) {
return fmt.Errorf("session does not exist")
}
query = `SELECT archived FROM session WHERE sessionid = ?`
isArchived := tx.GetBool(query, sessionId)
if !isArchived {
return nil
}
query = `UPDATE session SET archived = 0, archivedts = 0 WHERE sessionid = ?`
tx.ExecWrap(query, sessionId)
if activate {
query = `UPDATE client SET activesessionid = ?`
tx.ExecWrap(query, sessionId)
}
return nil
})
if txErr != nil {
return nil, txErr
}
bareSession, _ := GetBareSessionById(ctx, sessionId)
update := &ModelUpdate{}
if bareSession != nil {
update.Sessions = append(update.Sessions, bareSession)
}
if activate {
update.ActiveSessionId = sessionId
}
return update, nil
}
func GetSessionStats(ctx context.Context, sessionId string) (*SessionStatsType, error) {