From b07063023ffb6bac667bb865e4d30212b88ff8e2 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Thu, 20 Mar 2025 17:15:42 +0300 Subject: core helper for setting birthday & age --- src/mir_app/src/clistcontacts.cpp | 20 ++++++++++++++++++++ src/mir_app/src/mir_app.def | 1 + src/mir_app/src/mir_app64.def | 1 + 3 files changed, 22 insertions(+) (limited to 'src') diff --git a/src/mir_app/src/clistcontacts.cpp b/src/mir_app/src/clistcontacts.cpp index 759bce6f52..77fefe36af 100644 --- a/src/mir_app/src/clistcontacts.cpp +++ b/src/mir_app/src/clistcontacts.cpp @@ -296,6 +296,26 @@ MIR_APP_DLL(bool) Contact::IsGroupChat(MCONTACT hContact, const char *szProto) return db_get_b(hContact, szProto, "ChatRoom") != 0; } +MIR_APP_DLL(void) Contact::SetBirthday(MCONTACT hContact, int dd, int mm, int yy) +{ + if (auto *szProto = Proto_GetBaseAccountName(hContact)) { + db_set_w(hContact, szProto, "BirthMonth", mm); + db_set_w(hContact, szProto, "BirthDay", dd); + + if (yy) { + db_set_w(hContact, szProto, "BirthYear", yy); + + SYSTEMTIME sToday = {}; + GetLocalTime(&sToday); + int nAge = sToday.wYear - yy; + if (sToday.wMonth < mm || (sToday.wMonth == mm && sToday.wDay < dd)) + nAge--; + if (nAge) + db_set_w(hContact, szProto, "Age", nAge); + } + } +} + /////////////////////////////////////////////////////////////////////////////// MIR_APP_DLL(bool) Contact::IsHidden(MCONTACT hContact) diff --git a/src/mir_app/src/mir_app.def b/src/mir_app/src/mir_app.def index f38c665f8b..1dd24ecab3 100644 --- a/src/mir_app/src/mir_app.def +++ b/src/mir_app/src/mir_app.def @@ -997,3 +997,4 @@ Proto_CanDeleteHistory @1118 NONAME ?iHistoryMode@Srmm@@3V?$CMOption@E@@A @1128 NONAME ?getConn@MWebSocket@@QBEPAXXZ @1129 NONAME ?Chat_GetStatus@@YGPAUSTATUSINFO@@PAUSESSION_INFO@@PBUUSERINFO@@@Z @1130 NONAME +?SetBirthday@Contact@@YGXIHHH@Z @1131 NONAME diff --git a/src/mir_app/src/mir_app64.def b/src/mir_app/src/mir_app64.def index 54d6d48c19..5e7b681246 100644 --- a/src/mir_app/src/mir_app64.def +++ b/src/mir_app/src/mir_app64.def @@ -997,3 +997,4 @@ Proto_CanDeleteHistory @1118 NONAME ?iHistoryMode@Srmm@@3V?$CMOption@E@@A @1128 NONAME ?getConn@MWebSocket@@QEBAPEAXXZ @1129 NONAME ?Chat_GetStatus@@YAPEAUSTATUSINFO@@PEAUSESSION_INFO@@PEBUUSERINFO@@@Z @1130 NONAME +?SetBirthday@Contact@@YAXIHHH@Z @1131 NONAME -- cgit v1.2.3