open-insight/LSL2/STPROC/NOTES_SERVICES.txt
Infineon\StieberD 7762b129af pre cutover push
2024-09-04 20:33:41 -07:00

242 lines
8.0 KiB
Plaintext

Compile function Notes_Services(@Service, @Params)
Declare function Database_Services,obj_Notes_Sent, Get_Status, Error_Services, Obj_Tables, Datetime, SRP_Datetime
Declare subroutine Obj_Tables, Obj_Notes_Sent, Update_Index, Errmsg, Database_Services, Btree.Extract, Error_Services
Declare subroutine Notes_Services
#pragma precomp SRP_PreCompiler
$insert LOGICAL
$insert NOTE_PTRS_EQU
$insert MSG_EQUATES
$Insert NOTES_EQU
*$Insert NOTES_EQUATES
GoToService
Return Response or ""
//-----------------------------------------------------------------------------
// SERVICES
//-----------------------------------------------------------------------------
Service SnoozeNewMessageNotifications(UserID)
Open 'NOTE_PTRS' to hTable then
SnoozeTime = Datetime()
WriteV SnoozeTime to hTable, UserID, NOTE_PTRS_SNOOZE$ else
Errmsg('Error setting snooze.')
end
end else
Errmsg('Error setting snooze.')
end
end service
Service AllowNewMessageNotifications(UserID)
Open 'NOTE_PTRS' to hTable then
SnoozeTime = ''
WriteV SnoozeTime to hTable, UserID, NOTE_PTRS_SNOOZE$ else
Errmsg('Error setting snooze.')
end
end else
Errmsg('Error setting snooze.')
end
end service
Service CheckForNotificationSnooze(UserID)
SnoozeRow = ''
Snoozed = FALSE$
UserRec = Database_Services('ReadDataRow','NOTE_PTRS', @USER4, '', '', '')
CurrentTime = Datetime()
SnoozeRow = UserRec<NOTE_PTRS_SNOOZE$>
If SnoozeRow NE '' then
CutoffTime = SRP_DateTime("AddMinutes", SnoozeRow, 30)
If CurrentTime LE CutoffTime then
Snoozed = TRUE$
end else
Notes_Services('AllowNewMessageNotifications', @USER4)
end
end
Response = Snoozed
end service
Service GetInboxMessages(UserID)
//debug
InboxList = ''
UserRec = Database_Services('ReadDataRow','NOTE_PTRS', @USER4, '', '', '')
MessageCount = Dcount(UserRec<1>, @VM)
For index = 1 to MessageCount
ArchiveFlag = UserRec<NOTE_PTRS_ARCHIVED$, Index>
If ArchiveFlag = '' or ArchiveFlag = False$ then
InboxList<NOTE_PTRS_SUBJECT$,-1> = UserRec<NOTE_PTRS_SUBJECT$, index>
InboxList<NOTE_PTRS_FROM$,-1> = UserRec<NOTE_PTRS_FROM$, index>
InboxList<NOTE_PTRS_DATE$,-1> = UserRec<NOTE_PTRS_DATE$, index>
InboxList<NOTE_PTRS_TIME$,-1> = UserRec<NOTE_PTRS_TIME$, index>
InboxList<NOTE_PTRS_NEW$,-1> = UserRec<NOTE_PTRS_NEW$, index>
InboxList<NOTE_PTRS_ATTACHMENT$,-1> = UserRec<NOTE_PTRS_ATTACHMENT$, index>
InboxList<NOTE_PTRS_NOTE_IDS$,-1> = UserRec<NOTE_PTRS_NOTE_IDS$, index>
end
Next index
Response = InboxList
end service
Service GetArchivedMessages(UserID)
//debug
ArchiveList = ''
UserRec = Database_Services('ReadDataRow','NOTE_PTRS', @USER4, '', '', '')
MessageCount = Dcount(UserRec<1>, @VM)
For index = 1 to MessageCount
ArchiveFlag = UserRec<NOTE_PTRS_ARCHIVED$, Index>
If ArchiveFlag = True$ then
ArchiveList<NOTE_PTRS_SUBJECT$,-1> = UserRec<NOTE_PTRS_SUBJECT$, index>
ArchiveList<NOTE_PTRS_FROM$,-1> = UserRec<NOTE_PTRS_FROM$, index>
ArchiveList<NOTE_PTRS_DATE$,-1> = UserRec<NOTE_PTRS_DATE$, index>
ArchiveList<NOTE_PTRS_TIME$,-1> = UserRec<NOTE_PTRS_TIME$, index>
ArchiveList<NOTE_PTRS_NEW$,-1> = UserRec<NOTE_PTRS_NEW$, index>
ArchiveList<NOTE_PTRS_ATTACHMENT$,-1> = UserRec<NOTE_PTRS_ATTACHMENT$, index>
ArchiveList<NOTE_PTRS_NOTE_IDS$,-1> = UserRec<NOTE_PTRS_NOTE_IDS$, index>
end
Next index
Response = ArchiveList
end service
Service UpdateNotes(UserID)
ErrorMsg = ''
IF UserID = '' THEN ErrorMsg = 'Unassigned Parameter "UserID" passed to object. (':Method:')'
IF ErrorMsg NE '' THEN RETURN
//OtParms = 'NOTE_PTRS':@RM:UserID
//NPRec = obj_Tables('ReadRec',OtParms) ;* If not found then returns null, otherwise reads and sets the lock
NPRec = Database_Services('ReadDataRow', 'NOTE_PTRS', UserID)
IF LEN(NPRec) > 60000 THEN
* Dump the oldest note pointers
PtrCnt = COUNT(NPRec<note_ptrs_from$>, @vm) + (NPRec<note_ptrs_from$> NE '')
FOR N = PtrCnt TO (PtrCnt - 100) STEP -1
NPRec = Delete(NPRec, note_ptrs_subject$, N, 0)
NPRec = Delete(NPRec, note_ptrs_from$, N, 0)
NPRec = Delete(NPRec, note_ptrs_date$, N, 0)
NPRec = Delete(NPRec, note_ptrs_time$, N, 0)
NPRec = Delete(NPRec, note_ptrs_new$, N, 0)
NPRec = Delete(NPRec, note_ptrs_note_ids$, N, 0)
NPRec = Delete(NPRec, note_ptrs_attachment$, N, 0)
NPRec = Delete(NPRec, note_ptrs_archived$, N, 0)
NEXT N
TLen = LEN(NPRec)
END
NotesSentKeys = obj_Notes_Sent('GetUserKeys',UserID)
IF NotesSentKeys NE '' THEN
FOR I = 1 TO COUNT(NotesSentKeys,@VM) + (NotesSentKeys NE '')
NotesSentKey = NotesSentKeys<1,I>
NoteID = FIELD(NotesSentKey,'*',2)
LOCATE NoteID IN NPRec<NOTE_PTRS_NOTE_IDS$> USING @VM SETTING POS ELSE
NoteRec = XLATE('NOTES',NoteID,'','X')
SentFrom = NoteRec<NOTES_FROM$>
SentDate = NoteRec<NOTES_ENTRY_DATE$>
SentTime = NoteRec<NOTES_ENTRY_TIME$>
AttachWindow = NoteRec<NOTES_ATTACH_WINDOW$>
AttachKeys = NoteRec<NOTES_ATTACH_KEYS$>
Subject = NoteRec<NOTES_SUBJECT$>
IF AttachWindow NE '' AND AttachKeys NE '' THEN
Attachment = 'Yes'
END ELSE
Attachment = 'No'
END
NPRec = INSERT( NPRec, note_ptrs_subject$, 1, 0, Subject ) ;* Add the subject
ConvSentFrom = OCONV(SentFrom,'[XLATE_CONV,LSL_USERS*FIRST_LAST]')
IF ConvSentFrom NE '' THEN SentFrom = ConvSentFrom
NPRec = INSERT( NPRec, note_ptrs_from$, 1, 0, SentFrom )
NPRec = INSERT( NPRec, note_ptrs_date$, 1, 0, OCONV(SentDate,'D2/') )
NPRec = INSERT( NPRec, note_ptrs_time$, 1, 0, OCONV(SentTime,'MTH') )
NPRec = INSERT( NPRec, note_ptrs_new$, 1, 0, 'Yes' )
NPRec = INSERT( NPRec, note_ptrs_note_ids$, 1, 0, NoteID )
NPRec = INSERT( NPRec, note_ptrs_attachment$, 1, 0, Attachment )
NPRec = INSERT( NPRec, note_ptrs_archived$, 1, 0, '0' )
END
Database_Services('WriteDataRow', 'NOTE_PTRS', UserID, NPRec, True$, False$, True$)
NEXT I
IF Get_Status(errCode) THEN
ErrMsg(errCode)
END ELSE
obj_Notes_Sent('Delete',NotesSentKeys)
Update_Index('NOTES_SENT','USER_ID','')
END
END ELSE
//obj_Tables('UnlockRec',OtParms)
END
end service
Service GetUnreadMessageCount(UserID)
unreadMessageCount = 0
IF UserID NE '' then
if xlate( 'NOTE_PTRS', @user4, 'NEW_MESSAGES', 'X' ) then
NotePtrRec = xlate( 'NOTE_PTRS', @user4, '', 'X' )
LOCATE 'Yes' in NotePtrRec<note_ptrs_new$> using @VM setting mPos then
*If any are marked as yes, that means there are unread messages
for each messageRead in NotePtrRec<note_ptrs_new$> using @VM
if messageRead EQ 'Yes' then unreadMessageCount += 1
Next message
end
end
end
Response = unreadMessageCount
end service
Service GetNewMessages(UserId)
NotesSentKeys = ''
IF UserId NE '' THEN
OPEN 'DICT.NOTES_SENT' TO DictVar THEN
SearchString = 'USER_ID':@VM:UserId:@FM
Flag = ''
Btree.Extract(SearchString,'NOTES_SENT',DictVar,NotesSentKeys,'',Flag)
IF Get_Status(errCode) THEN
ErrMsg(errCode)
RETURN
END
END
end
Response = NotesSentKeys
end service
Service MarkAllAsRead(UserId)
if UserID NE '' then
NotePtrsRec = Database_Services('ReadDataRow', 'NOTE_PTRS', UserId)
NotePtrsStatus = NotePtrsRec<NOTE_PTRS_NEW$>
for each NotePtrsRead in NotePtrsStatus using @VM setting nPos
NotePtrsRec<NOTE_PTRS_NEW$, nPos> = 'No'
Next NotePtrsRead
isNPRecCurrent = NotePtrsRec<NOTE_PTRS_TIME$> EQ Database_Services('ReadDataRow', 'NOTE_PTRS', UserId)<NOTE_PTRS_TIME$>
if isNPRecCurrent then
Database_Services('WriteDataRow','NOTE_PTRS', UserId, NotePtrsRec, '','', true$)
end
end else
Error_Services('Set', 'Error in Notes Service, MarkAllAsRead. UserId parameter not supplied')
end
end service