static void RestoreUnreadUrlAlerts(void) { CLISTEVENT cle = { sizeof(cle) }; cle.hIcon = Skin_LoadIcon(SKINICON_EVENT_URL); cle.pszService = "SRUrl/ReadUrl"; cle.flags = CLEF_TCHAR; for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { MEVENT hDbEvent = db_event_firstUnread(hContact); while (hDbEvent) { DBEVENTINFO dbei = { sizeof(dbei) }; db_event_get(hDbEvent, &dbei); if ( !(dbei.flags&(DBEF_SENT|DBEF_READ)) && dbei.eventType == EVENTTYPE_URL) { TCHAR toolTip[256]; mir_sntprintf(toolTip, _countof(toolTip), TranslateT("URL from %s"), pcli->pfnGetContactDisplayName(hContact, 0)); cle.hContact = hContact; cle.hDbEvent = hDbEvent; cle.ptszTooltip = toolTip; CallService(MS_CLIST_ADDEVENT, 0, (LPARAM)&cle); } hDbEvent = db_event_next(hContact, hDbEvent); } } }
//************************************************************************ // updates the message count for the specified contact //************************************************************************ void CContactList::UpdateMessageCounter(CListEntry<CContactListEntry*,CContactListGroup*> *pContactEntry) { CContactListEntry *pEntry = GetContactData(pContactEntry); if(!pEntry) { return; } int iOldMessages = pEntry->iMessages; bool bSort = false; HANDLE hEvent= NULL; hEvent = db_event_firstUnread(pEntry->hHandle); if(CAppletManager::IsMessageWindowOpen(pEntry->hHandle) || (hEvent == NULL && pEntry->iMessages > 0)) { pEntry->iMessages = 0; bSort = true; } else { pEntry->iMessages = 0; HANDLE hLastEvent = db_event_last(pEntry->hHandle); while(hLastEvent != NULL && hEvent != NULL) { pEntry->iMessages++; if(hLastEvent == hEvent) break; hLastEvent = db_event_prev(hLastEvent); } } if(pEntry->iMessages >= 100) pEntry->strMessages = _T(">99"); else { char buffer[8]; buffer[0] = 0; itoa(pEntry->iMessages,buffer,10); pEntry->strMessages = toTstring(buffer); } CListContainer<CContactListEntry*,CContactListGroup*>* pContainer = ((CListContainer<CContactListEntry*,CContactListGroup*>*)pContactEntry->GetParent()); // Update the contacts group if it has one if(pContainer->GetType() != ROOT) { // Update the groups event count if(iOldMessages != 0 && pEntry->iMessages == 0) ChangeGroupObjectCounters(pContainer->GetGroupData()->strPath,0,0,-1); else if(iOldMessages == 0 && pEntry->iMessages != 0) ChangeGroupObjectCounters(pContainer->GetGroupData()->strPath,0,0,1); else return; // sort the groups parent ((CListContainer<CContactListEntry*,CContactListGroup*>*)pContainer->GetParent())->sort(CContactList::CompareEntries); } }
void RestoreUnreadMessageAlerts(void) { DBEVENTINFO dbei = { sizeof(dbei) }; for (HANDLE hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) for (HANDLE hDbEvent = db_event_firstUnread(hContact); hDbEvent; hDbEvent = db_event_next(hDbEvent)) { dbei.cbBlob = 0; if (db_event_get(hDbEvent, &dbei) == 0) if ((dbei.flags & (DBEF_SENT|DBEF_READ))==0 && ((dbei.eventType==ICQEVENTTYPE_SMS) || (dbei.eventType==ICQEVENTTYPE_SMSCONFIRMATION))) if (dbei.cbBlob>MIN_SMS_DBEVENT_LEN) handleNewMessage((WPARAM)hContact,(LPARAM)hDbEvent); } for (HANDLE hDbEvent = db_event_firstUnread(NULL); hDbEvent; hDbEvent = db_event_next(hDbEvent)) { dbei.cbBlob = 0; if (db_event_get(hDbEvent, &dbei) == 0) if ((dbei.flags & (DBEF_SENT|DBEF_READ))==0 && ((dbei.eventType==ICQEVENTTYPE_SMS) || (dbei.eventType==ICQEVENTTYPE_SMSCONFIRMATION))) if (dbei.cbBlob > MIN_SMS_DBEVENT_LEN) handleNewMessage(NULL, (LPARAM)hDbEvent); } }
static void ProcessUnreadEvents(void) { for (auto &hContact : Contacts()) { for (MEVENT hDbEvent = db_event_firstUnread(hContact); hDbEvent; hDbEvent = db_event_next(hContact, hDbEvent)) { DBEVENTINFO dbei = {}; db_event_get(hDbEvent, &dbei); if (!(dbei.flags & (DBEF_SENT | DBEF_READ)) && dbei.eventType == EVENTTYPE_CONTACTS) { //process the event HookDBEventAdded(hContact, (LPARAM)hDbEvent); } } } }
static void RestoreUnreadMessageAlerts(void) { OBJLIST<MSavedEvent> arEvents(10, NumericKeySortT); for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { for (MEVENT hDbEvent = db_event_firstUnread(hContact); hDbEvent; hDbEvent = db_event_next(hContact, hDbEvent)) { DBEVENTINFO dbei = { sizeof(dbei) }; dbei.cbBlob = 0; db_event_get(hDbEvent, &dbei); if ((dbei.flags & (DBEF_SENT | DBEF_READ)) || !DbEventIsMessageOrCustom(&dbei)) continue; int windowAlreadyExists = WindowList_Find(g_dat.hMessageWindowList, hContact) != NULL; if (windowAlreadyExists) continue; if (IsAutoPopup(hContact) && !windowAlreadyExists) { NewMessageWindowLParam newData = { 0 }; newData.hContact = hContact; newData.flags = NMWLP_INCOMING; HWND hParent = GetParentWindow(newData.hContact, FALSE); CreateDialogParam(g_hInst, MAKEINTRESOURCE(IDD_MSG), hParent, DlgProcMessage, (LPARAM)&newData); } else arEvents.insert(new MSavedEvent(hContact, hDbEvent)); } } TCHAR toolTip[256]; CLISTEVENT cle = {}; cle.hIcon = Skin_LoadIcon(SKINICON_EVENT_MESSAGE); cle.pszService = "SRMsg/ReadMessage"; cle.flags = CLEF_TCHAR; cle.ptszTooltip = toolTip; for (int i = 0; i < arEvents.getCount(); i++) { MSavedEvent &e = arEvents[i]; mir_sntprintf(toolTip, TranslateT("Message from %s"), pcli->pfnGetContactDisplayName(e.hContact, 0)); cle.hContact = e.hContact; cle.hDbEvent = e.hEvent; pcli->pfnAddEvent(&cle); } }
static void RestoreUnreadMessageAlerts(void) { TCHAR toolTip[256]; CLISTEVENT cle = { sizeof(cle) }; cle.hIcon = Skin_LoadIcon(SKINICON_EVENT_MESSAGE); cle.pszService = "SRMsg/ReadMessage"; cle.flags = CLEF_TCHAR; cle.ptszTooltip = toolTip; DBEVENTINFO dbei = { sizeof(dbei) }; for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { for (MEVENT hDbEvent = db_event_firstUnread(hContact); hDbEvent; hDbEvent = db_event_next(hContact, hDbEvent)) { bool autoPopup = false; dbei.cbBlob = 0; db_event_get(hDbEvent, &dbei); if (!(dbei.flags & (DBEF_SENT | DBEF_READ)) && (dbei.eventType == EVENTTYPE_MESSAGE || DbEventIsForMsgWindow(&dbei))) { int windowAlreadyExists = WindowList_Find(g_dat.hMessageWindowList, hContact) != NULL; if (windowAlreadyExists) continue; char *szProto = GetContactProto(hContact); if (szProto && (g_dat.openFlags & SRMMStatusToPf2(CallProtoService(szProto, PS_GETSTATUS, 0, 0)))) autoPopup = true; if (autoPopup && !windowAlreadyExists) { NewMessageWindowLParam newData = { 0 }; newData.hContact = hContact; newData.noActivate = db_get_b(NULL, SRMMMOD, SRMSGSET_DONOTSTEALFOCUS, SRMSGDEFSET_DONOTSTEALFOCUS); CreateDialogParam(g_hInst, MAKEINTRESOURCE(IDD_MSG), NULL, DlgProcMessage, (LPARAM)& newData); } else { cle.hContact = hContact; cle.hDbEvent = hDbEvent; mir_sntprintf(toolTip, TranslateT("Message from %s"), pcli->pfnGetContactDisplayName(hContact, 0)); CallService(MS_CLIST_ADDEVENT, 0, (LPARAM)&cle); } } } } }
//************************************************************************ // loads the contacts history //************************************************************************ void CChatScreen::LoadHistory() { if(!m_hContact) return; char *szProto = GetContactProto(m_hContact); if(m_bIRCProtocol && db_get_b(m_hContact, szProto, "ChatRoom", 0) != 0) { if(!CAppletManager::GetInstance()->IsIRCHookEnabled()) { time_t now; tm tm_now; time(&now); localtime_s(&tm_now,&now); AddIncomingMessage(CAppletManager::TranslateString(_T("IRC-Chatroom support is disabled!\nYou need to install the patched IRC.dll (see the readme) to use IRC-Chatrooms on the LCD")),&tm_now,true); } else { CIRCHistory *pHistory = CAppletManager::GetInstance()->GetIRCHistory(m_hContact); if(pHistory) { list<SIRCMessage>::iterator iter = pHistory->LMessages.begin(); while(iter != pHistory->LMessages.end()) { if((*iter).bIsMe) AddOutgoingMessage((*iter).strMessage,&((*iter).Time),true); else AddIncomingMessage((*iter).strMessage,&((*iter).Time),true); iter++; } } } } else { // Get last events from database CEvent Event; list<MEVENT> LHandles; MEVENT hEvent = db_event_last(m_hContact); MEVENT hUnread = db_event_firstUnread(m_hContact); if(CConfig::GetBoolSetting(SESSION_LOADDB)) { while(hEvent != NULL && hUnread != NULL) { LHandles.push_front(hEvent); if(CConfig::GetBoolSetting(SESSION_LOADDB) && *(LHandles.begin()) == hUnread) break; hEvent = db_event_prev(m_hContact, hEvent); } } else { for (int i = CConfig::GetIntSetting(SESSION_LOGSIZE); i > 0 && hEvent!=NULL; i--) { LHandles.push_front(hEvent); hEvent = db_event_prev(m_hContact, hEvent); } } bool bRead = true; while(!(LHandles.empty())) { if(CAppletManager::TranslateDBEvent(&Event,(LPARAM)m_hContact,(WPARAM)*(LHandles.begin()))) { if(Event.hValue == hUnread) bRead = false; if(Event.eType == EVENT_MSG_RECEIVED) { AddIncomingMessage(Event.strValue,&Event.Time); if(!bRead && CConfig::GetBoolSetting(SESSION_MARKREAD) && !CAppletManager::IsMessageWindowOpen(m_hContact)) CAppletManager::MarkMessageAsRead(m_hContact,Event.hValue); } else AddOutgoingMessage(Event.strValue,&Event.Time); } LHandles.pop_front(); } } }
static MEVENT findDbEvent(MCONTACT hContact, MEVENT hDbEvent, int flags) { DBEVENTINFO dbe; BOOL bEventOk; do { memset(&dbe, 0, sizeof(DBEVENTINFO)); dbe.cbSize = sizeof(DBEVENTINFO); dbe.cbBlob = 0; dbe.pBlob = NULL; if (hContact != NULL) { if ((flags & DBE_FIRST) && (flags & DBE_UNREAD)) { hDbEvent = db_event_firstUnread(hContact); if (hDbEvent == NULL && (flags & DBE_READ)) hDbEvent = db_event_first(hContact); } else if (flags & DBE_FIRST) hDbEvent = db_event_first(hContact); else if (flags & DBE_LAST) hDbEvent = db_event_last(hContact); else if (flags & DBE_NEXT) hDbEvent = db_event_next(hContact, hDbEvent); else if (flags & DBE_PREV) hDbEvent = db_event_prev(hContact, hDbEvent); } else { MEVENT hMatchEvent = NULL, hSearchEvent = NULL; DWORD matchTimestamp = 0, priorTimestamp = 0; if (flags & DBE_FIRST) { for (MCONTACT hSearchContact = db_find_first(); hSearchContact; hSearchContact = db_find_next(hSearchContact)) { hSearchEvent = findDbEvent(hSearchContact, NULL, flags); dbe.cbBlob = 0; if (!db_event_get(hSearchEvent, &dbe)) { if ((dbe.timestamp < matchTimestamp) || (matchTimestamp == 0)) { hMatchEvent = hSearchEvent; matchTimestamp = dbe.timestamp; } } } hDbEvent = hMatchEvent; } else if (flags & DBE_LAST) { for (MCONTACT hSearchContact = db_find_first(); hSearchContact; hSearchContact = db_find_next(hSearchContact)) { hSearchEvent = findDbEvent(hSearchContact, NULL, flags); dbe.cbBlob = 0; if (!db_event_get(hSearchEvent, &dbe)) { if ((dbe.timestamp > matchTimestamp) || (matchTimestamp == 0)) { hMatchEvent = hSearchEvent; matchTimestamp = dbe.timestamp; } } } hDbEvent = hMatchEvent; } else if (flags & DBE_NEXT) { dbe.cbBlob = 0; if (!db_event_get(hDbEvent, &dbe)) { priorTimestamp = dbe.timestamp; for (MCONTACT hSearchContact = db_find_first(); hSearchContact; hSearchContact = db_find_next(hSearchContact)) { hSearchEvent = findDbEvent(hSearchContact, hDbEvent, flags); dbe.cbBlob = 0; if (!db_event_get(hSearchEvent, &dbe)) { if (((dbe.timestamp < matchTimestamp) || (matchTimestamp == 0)) && (dbe.timestamp > priorTimestamp)) { hMatchEvent = hSearchEvent; matchTimestamp = dbe.timestamp; } } } hDbEvent = hMatchEvent; } } else if (flags & DBE_PREV) { if (!db_event_get(hDbEvent, &dbe)) { priorTimestamp = dbe.timestamp; for (MCONTACT hSearchContact = db_find_first(); hSearchContact; hSearchContact = db_find_next(hSearchContact)) { hSearchEvent = findDbEvent(hSearchContact, hDbEvent, flags); dbe.cbBlob = 0; if (!db_event_get(hSearchEvent, &dbe)) { if (((dbe.timestamp > matchTimestamp) || (matchTimestamp == 0)) && (dbe.timestamp < priorTimestamp)) { hMatchEvent = hSearchEvent; matchTimestamp = dbe.timestamp; } } } hDbEvent = hMatchEvent; } } } dbe.cbBlob = 0; if (db_event_get(hDbEvent, &dbe)) bEventOk = FALSE; else bEventOk = isValidDbEvent(&dbe, flags); if (!bEventOk) { if (flags&DBE_FIRST) { flags |= DBE_NEXT; flags &= ~DBE_FIRST; } else if (flags&DBE_LAST) { flags |= DBE_PREV; flags &= ~DBE_LAST; } } } while ((!bEventOk) && (hDbEvent != NULL)); return hDbEvent; }