VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "Alert"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit
Public UserName As String
Public OldName As String
Public NewName As String
Public OldStatus As MISTATUS
Public NewStatus As MISTATUS
Public TimeStamp As String 'HH:ss

Public Code As EventCode
Public Blocked As Boolean

Private LocalPi As PersonInfo

Public Enum EventCode
    evtMyStatusChange = 1 'NewStatus
    evtMyNameChange 'PrevName, NewName
    evtMySignIn '
    evtMySignOut '
    evtMyEmail 'Count is stored under NewStatus (a bit dubiously)
    evtNameChange 'Signin, PrevName, NewName
    evtSignIn 'Signin
    evtSignOut 'Signin
    evtStatusChange 'Signin, PrevStatus, NewStatus
End Enum

Public Function CodeName() As String
CodeName = MsgAlert.EventName(Code)
End Function

Public Sub SetTimeStamp()
TimeStamp = Format$(Now(), "HH:mm")
End Sub

Public Property Get NiceOldStatus() As String
NiceOldStatus = StatusName(OldStatus)
End Property

Public Property Get NiceNewStatus() As String
NiceNewStatus = StatusName(NewStatus)
End Property

Private Function StatusName(Status As MISTATUS) As String
Select Case Status
Case 0: Debug.Assert False
Case MISTATUS_AWAY, MISTATUS_IDLE: StatusName = "Away"
Case MISTATUS_BE_RIGHT_BACK: StatusName = "Be Right Back"
Case MISTATUS_BUSY: StatusName = "Busy"
Case MISTATUS_ON_THE_PHONE: StatusName = "On The Phone"
Case MISTATUS_OUT_TO_LUNCH: StatusName = "Out To Lunch"
Case MISTATUS_INVISIBLE: StatusName = "Hiding"
Case MISTATUS_OFFLINE: Debug.Assert False
Case Else: StatusName = "Normal"
End Select
End Function

Public Property Get pi() As PersonInfo
If UserName = "" Then Exit Property

If LocalPi Is Nothing Then
    Set LocalPi = GetPersonInfo(UserName)
End If
Set pi = LocalPi
End Property

Public Sub Action()
Debug.Assert IsAction = True

Select Case Code
Case evtMyNameChange
    MainForm.ChangeUserName

Case evtMySignIn
    If Online Then
        Msg.SignOut
    Else
        MsgBox "You are already signed out"
    End If

Case evtMySignOut
    If Online Then
        MsgBox "You are already signed in"
    Else
        MainForm.DoSignIn
    End If
    
Case evtMyEmail
    CheckEmail

Case evtNameChange, evtSignIn, evtSignOut, evtStatusChange
    If MainForm.Visible Or Not Online Then
        TrayCode.Restore
        BuddyList.Locate UserName
    Else
        StartIM UserName
    End If

Case Else: Debug.Assert False
End Select
End Sub

Public Property Get IsAction() As Boolean
Select Case Code
Case evtMyNameChange, evtMySignIn, evtMySignOut, evtMyEmail, evtNameChange, evtSignIn, evtSignOut, evtStatusChange
    IsAction = True
End Select
End Property
