int MsgAck(WPARAM, LPARAM lParam) { ACKDATA *ack=(ACKDATA*)lParam; if (ack && ack->cbSize == sizeof(ACKDATA) && ack->type == ACKTYPE_MESSAGE) { if (ack->hProcess == (HANDLE)WindowList_Find(hWindowList,ack->hContact)) { if (db_get_b(NULL, modname, "ShowDeliveryMessages", 1)) CreateMessageAcknowlegedWindow(ack->hContact,ack->result == ACKRESULT_SUCCESS); if (ack->result == ACKRESULT_SUCCESS) { // wrtie it to the DB DBEVENTINFO dbei = { 0 }; DBVARIANT dbv; int reuse = db_get_b(ack->hContact,modname, "Reuse", 0); if (!db_get_ts(ack->hContact, modname, "PounceMsg", &dbv) && (dbv.ptszVal[0] != '\0')) { T2Utf pszUtf(dbv.ptszVal); dbei.cbSize = sizeof(dbei); dbei.eventType = EVENTTYPE_MESSAGE; dbei.flags = DBEF_UTF | DBEF_SENT; dbei.szModule = (char*)ack->szModule; dbei.timestamp = time(NULL); dbei.cbBlob = (int)mir_strlen(pszUtf) + 1; dbei.pBlob = (PBYTE)(char*)pszUtf; db_event_add(ack->hContact, &dbei); } // check to reuse if (reuse > 1) db_set_b(ack->hContact, modname, "Reuse", (BYTE)(reuse-1)); else { db_set_b(ack->hContact,modname, "Reuse", 0); db_set_ws(ack->hContact, modname, "PounceMsg", _T("")); } } WindowList_Remove(hWindowList,(HWND)ack->hProcess); } } return 0; }
INT addEvent(WPARAM hContact, LPARAM hDBEvent) { BOOL fEnabled = db_get_b(NULL, protocolname, KEY_ENABLED, 1); if (!fEnabled || !hContact || !hDBEvent) return FALSE; /// unspecifyed error char* pszProto = GetContactProto(hContact); int status = CallProtoService(pszProto, PS_GETSTATUS, 0, 0); if (status == ID_STATUS_ONLINE || status == ID_STATUS_FREECHAT || status == ID_STATUS_INVISIBLE) return FALSE; DBEVENTINFO dbei = {sizeof(dbei)}; db_event_get(hDBEvent, &dbei); /// detect size of msg if ((dbei.eventType != EVENTTYPE_MESSAGE) || (dbei.flags == DBEF_READ)) return FALSE; /// we need EVENTTYPE_MESSAGE event.. else { /// needed event has occured.. DBVARIANT dbv; if (!dbei.cbBlob) /// invalid size return FALSE; if (db_get_ts(hContact,"Protocol","p",&dbv)) // Contact with no protocol ?!! return FALSE; else db_free(&dbv); if(db_get_b(hContact, "CList", "NotOnList", 0)) return FALSE; if(db_get_b(hContact, protocolname, "TurnedOn", 0)) return FALSE; if (!( dbei.flags & DBEF_SENT)) { int timeBetween=time(NULL)-db_get_dw(hContact,protocolname,"LastReplyTS",0); if (timeBetween>interval || db_get_w(hContact,protocolname,"LastStatus",0)!=status) { char szStatus[6]={0}; int msgLen=1; int isQun=db_get_b(hContact,pszProto,"IsQun",0); if (isQun) return FALSE; mir_snprintf(szStatus,_countof(szStatus),"%d",status); if (!db_get_ts(NULL,protocolname,szStatus,&dbv)) { if (*dbv.ptszVal) { DBVARIANT dbvHead={0}, dbvNick={0}; CMString ptszTemp; TCHAR *ptszTemp2; db_get_ts(hContact,pszProto,"Nick",&dbvNick); if (mir_tstrcmp(dbvNick.ptszVal, NULL) == 0) { db_free(&dbvNick); return FALSE; } msgLen += (int)mir_tstrlen(dbv.ptszVal); if (!db_get_ts(NULL,protocolname,KEY_HEADING,&dbvHead)) { ptszTemp = dbvHead.ptszVal; ptszTemp.Replace(_T("%user%"), dbvNick.ptszVal); msgLen += (int)(mir_tstrlen(ptszTemp)); } ptszTemp2 = (TCHAR*)mir_alloc(sizeof(TCHAR) * (msgLen+5)); mir_sntprintf(ptszTemp2, msgLen+5, _T("%s\r\n\r\n%s"), ptszTemp.c_str(), dbv.ptszVal); if (ServiceExists(MS_VARS_FORMATSTRING)) { FORMATINFO fi = { 0 }; fi.cbSize = sizeof(fi); fi.flags = FIF_TCHAR; fi.tszFormat = ptszTemp2; ptszTemp = (TCHAR*)CallService(MS_VARS_FORMATSTRING, (WPARAM)&fi, 0); } else ptszTemp = Utils_ReplaceVarsT(ptszTemp2); T2Utf pszUtf(ptszTemp); CallContactService(hContact, PSS_MESSAGE, 0, pszUtf); dbei.cbSize = sizeof(dbei); dbei.eventType = EVENTTYPE_MESSAGE; dbei.flags = DBEF_UTF | DBEF_SENT; //DBEF_READ; dbei.szModule = pszProto; dbei.timestamp = time(NULL); dbei.cbBlob = (int)mir_strlen(pszUtf) + 1; dbei.pBlob = (PBYTE)pszUtf; db_event_add(hContact, &dbei); mir_free(ptszTemp2); if (dbvNick.ptszVal) db_free(&dbvNick); if (dbvHead.ptszVal) db_free(&dbvHead); } db_free(&dbv); } } } db_set_dw(hContact,protocolname,"LastReplyTS",time(NULL)); db_set_w(hContact,protocolname,"LastStatus",status); } return 0; }
int ProcessStatusMessage(DBCONTACTWRITESETTING *cws, MCONTACT hContact) { STATUSMSGINFO smi; bool bEnablePopup = true, bEnableSound = true; char *szProto = GetContactProto(hContact); smi.proto = szProto; smi.hContact = hContact; smi.compare = CompareStatusMsg(&smi, cws, "LastStatusMsg"); if (smi.compare == COMPARE_SAME) goto skip_notify; if (cws->value.type == DBVT_DELETED) db_unset(hContact, "UserOnline", "LastStatusMsg"); else db_set(hContact, "UserOnline", "LastStatusMsg", &cws->value); //don't show popup when mradio connecting and disconnecting if (_stricmp(szProto, "mRadio") == 0 && !cws->value.type == DBVT_DELETED) { wchar_t buf[MAX_PATH]; mir_snwprintf(buf, L" (%s)", TranslateT("connecting")); T2Utf pszUtf(buf); mir_snwprintf(buf, L" (%s)", TranslateT("aborting")); T2Utf pszUtf2(buf); mir_snwprintf(buf, L" (%s)", TranslateT("playing")); T2Utf pszUtf3(buf); if (_stricmp(cws->value.pszVal, pszUtf) == 0 || _stricmp(cws->value.pszVal, pszUtf2) == 0 || _stricmp(cws->value.pszVal, pszUtf3) == 0) goto skip_notify; } // check per-contact ignored events if (db_get_b(hContact, MODULE, "EnableSMsgNotify", 1) == 0) bEnableSound = bEnablePopup = false; // we're offline or just connecting int myStatus = Proto_GetStatus(szProto); if (myStatus == ID_STATUS_OFFLINE) goto skip_notify; char dbSetting[64]; mir_snprintf(dbSetting, "%s_enabled", szProto); // this proto is not set for status message notifications if (db_get_b(NULL, MODULE, dbSetting, 1) == 0) goto skip_notify; mir_snprintf(dbSetting, "%d", IDC_CHK_STATUS_MESSAGE); // status message change notifications are disabled if (db_get_b(NULL, MODULE, dbSetting, 1) == 0) goto skip_notify; if (SkipHiddenContact(hContact)) goto skip_notify; // check if our status isn't on autodisable list if (opt.AutoDisable) { char statusIDs[12], statusIDp[12]; mir_snprintf(statusIDs, "s%d", myStatus); mir_snprintf(statusIDp, "p%d", myStatus); bEnableSound = db_get_b(0, MODULE, statusIDs, 1) ? FALSE : bEnableSound; bEnablePopup = db_get_b(0, MODULE, statusIDp, 1) ? FALSE : bEnablePopup; } // check flags if ((!(templates.PopupSMsgFlags & NOTIFY_REMOVE_MESSAGE) && (smi.compare == COMPARE_DEL)) || (!(templates.PopupSMsgFlags & NOTIFY_NEW_MESSAGE) && (smi.compare == COMPARE_DIFF))) bEnablePopup = false; if (db_get_b(0, MODULE, szProto, 1) == 0 && !opt.PSMsgOnConnect) bEnablePopup = false; if (bEnablePopup && db_get_b(hContact, MODULE, "EnablePopups", 1) && !opt.TempDisabled) { // cut message if needed wchar_t *copyText = nullptr; if (opt.PSMsgTruncate && (opt.PSMsgLen > 0) && smi.newstatusmsg && (mir_wstrlen(smi.newstatusmsg) > opt.PSMsgLen)) { wchar_t buff[MAX_TEXT_LEN + 3]; copyText = mir_wstrdup(smi.newstatusmsg); wcsncpy(buff, smi.newstatusmsg, opt.PSMsgLen); buff[opt.PSMsgLen] = 0; mir_wstrcat(buff, L"..."); replaceStrW(smi.newstatusmsg, buff); } wchar_t *str; if (smi.compare == COMPARE_DEL) { char protoname[MAX_PATH]; mir_snprintf(protoname, "%s_TPopupSMsgRemoved", szProto); DBVARIANT dbVar = { 0 }; if (db_get_ws(NULL, MODULE, protoname, &dbVar)) { str = GetStr(&smi, DEFAULT_POPUP_SMSGREMOVED); } else { str = GetStr(&smi, dbVar.ptszVal); db_free(&dbVar); } } else { char protoname[MAX_PATH]; mir_snprintf(protoname, "%s_TPopupSMsgChanged", szProto); DBVARIANT dbVar = { 0 }; if (db_get_ws(NULL, MODULE, protoname, &dbVar)) { str = GetStr(&smi, DEFAULT_POPUP_SMSGCHANGED); } else { str = GetStr(&smi, dbVar.ptszVal); db_free(&dbVar); } } ShowChangePopup(hContact, Skin_LoadProtoIcon(szProto, db_get_w(hContact, szProto, "Status", ID_STATUS_ONLINE)), ID_STATUS_STATUSMSG, str); mir_free(str); if (copyText) { mir_free(smi.newstatusmsg); smi.newstatusmsg = copyText; } } if (opt.BlinkIcon && opt.BlinkIcon_ForMsgs && !opt.TempDisabled) { HICON hIcon = opt.BlinkIcon_Status ? Skin_LoadProtoIcon(szProto, db_get_w(hContact, szProto, "Status", ID_STATUS_ONLINE)) : Skin_LoadIcon(SKINICON_OTHER_USERONLINE); wchar_t str[256]; mir_snwprintf(str, TranslateT("%s changed status message to %s"), Clist_GetContactDisplayName(hContact), smi.newstatusmsg); BlinkIcon(hContact, hIcon, str); } if (bEnableSound && db_get_b(0, "Skin", "UseSound", TRUE) && db_get_b(hContact, MODULE, "EnableSounds", 1) && !opt.TempDisabled) { if (smi.compare == COMPARE_DEL) PlayChangeSound(hContact, StatusListEx[ID_STATUS_SMSGREMOVED].lpzSkinSoundName); else PlayChangeSound(hContact, StatusListEx[ID_STATUS_SMSGCHANGED].lpzSkinSoundName); } BOOL bEnableLog = opt.SMsgLogToDB && db_get_b(hContact, MODULE, "EnableSMsgLogging", 1); if (bEnableLog && (!opt.SMsgLogToDB_WinOpen || CheckMsgWnd(hContact))) LogSMsgToDB(&smi, smi.compare == COMPARE_DEL ? templates.LogSMsgRemoved : templates.LogSMsgChanged); if (opt.SMsgLogToFile && db_get_b(hContact, MODULE, "EnableSMsgLogging", 1)) { wchar_t stzDate[MAX_STATUSTEXT], stzTime[MAX_STATUSTEXT], stzText[MAX_TEXT_LEN]; GetTimeFormat(LOCALE_USER_DEFAULT, 0, nullptr, L"HH':'mm", stzTime, _countof(stzTime)); GetDateFormat(LOCALE_USER_DEFAULT, 0, nullptr, L"dd/MM/yyyy", stzDate, _countof(stzDate)); wchar_t *str; if (smi.compare == COMPARE_DEL) str = GetStr(&smi, templates.LogSMsgRemoved); else str = GetStr(&smi, templates.LogSMsgChanged); mir_snwprintf(stzText, L"%s, %s. %s %s\r\n", stzDate, stzTime, Clist_GetContactDisplayName(hContact), str); LogToFile(stzText); mir_free(str); } skip_notify: replaceStrW(smi.newstatusmsg, nullptr); replaceStrW(smi.oldstatusmsg, nullptr); return 1; }