mirror of
https://github.com/ergochat/ergo.git
synced 2025-12-20 02:00:11 -08:00
implement draft/resume-0.4
This commit is contained in:
parent
eaf0328608
commit
3d445573cf
15 changed files with 442 additions and 343 deletions
|
|
@ -65,6 +65,18 @@ func (client *Client) Sessions() (sessions []*Session) {
|
|||
return
|
||||
}
|
||||
|
||||
func (client *Client) GetSessionByResumeID(resumeID string) (result *Session) {
|
||||
client.stateMutex.RLock()
|
||||
defer client.stateMutex.RUnlock()
|
||||
|
||||
for _, session := range client.sessions {
|
||||
if session.resumeID == resumeID {
|
||||
return session
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
type SessionData struct {
|
||||
ctime time.Time
|
||||
atime time.Time
|
||||
|
|
@ -100,9 +112,17 @@ func (client *Client) AddSession(session *Session) (success bool) {
|
|||
client.stateMutex.Lock()
|
||||
defer client.stateMutex.Unlock()
|
||||
|
||||
if len(client.sessions) == 0 {
|
||||
// client may be dying and ineligible to receive another session
|
||||
switch client.brbTimer.state {
|
||||
case BrbDisabled:
|
||||
if len(client.sessions) == 0 {
|
||||
return false
|
||||
}
|
||||
case BrbDead:
|
||||
return false
|
||||
// default: BrbEnabled or BrbSticky, proceed
|
||||
}
|
||||
// success, attach the new session to the client
|
||||
session.client = client
|
||||
client.sessions = append(client.sessions, session)
|
||||
return true
|
||||
|
|
@ -125,6 +145,12 @@ func (client *Client) removeSession(session *Session) (success bool, length int)
|
|||
return
|
||||
}
|
||||
|
||||
func (session *Session) SetResumeID(resumeID string) {
|
||||
session.client.stateMutex.Lock()
|
||||
session.resumeID = resumeID
|
||||
session.client.stateMutex.Unlock()
|
||||
}
|
||||
|
||||
func (client *Client) Nick() string {
|
||||
client.stateMutex.RLock()
|
||||
defer client.stateMutex.RUnlock()
|
||||
|
|
@ -233,6 +259,14 @@ func (client *Client) RawHostname() (result string) {
|
|||
return
|
||||
}
|
||||
|
||||
func (client *Client) SetRawHostname(rawHostname string) {
|
||||
client.stateMutex.Lock()
|
||||
defer client.stateMutex.Unlock()
|
||||
|
||||
client.rawHostname = rawHostname
|
||||
client.updateNickMaskNoMutex()
|
||||
}
|
||||
|
||||
func (client *Client) AwayMessage() (result string) {
|
||||
client.stateMutex.RLock()
|
||||
result = client.awayMessage
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue