This repository has been archived by the owner on Oct 6, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
checkComposing.cpp
66 lines (58 loc) · 1.75 KB
/
checkComposing.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include "stdafx.h"
#pragma hdrstop
#include "ui_main.h"
#include "checkComposing.h"
using namespace Konnekt::UI::Cnt;
cCheckComposing Konnekt::UI::Cnt::checkComposing;
cCheckComposing::cCheckComposing() {
this->timer = CreateWaitableTimer(0 , 0 , 0);
timerWaiting = false;
}
cCheckComposing::~cCheckComposing() {
CloseHandle(this->timer);
}
void cCheckComposing::composing(int cntID) {
cCheckComposing::const_iterator find = this->find(cntID);
if (find == this->end()) {
IMDEBUG(DBG_MISC , "- composing cnt=%d" , cntID);
IMessage(IM_CNT_COMPOSING , NET_BC , IMT_CONTACT , cntID);
}
(*this) [cntID] = time(0);
checkTimer();
}
void cCheckComposing::stopComposing(int cntID) {
cCheckComposing::iterator find = this->find(cntID);
if (find != this->end()) {
stopComposing(find);
}
}
void cCheckComposing::stopComposing(iterator cnt) {
IMessage(IM_CNT_COMPOSING_STOP , NET_BC , IMT_CONTACT , cnt->first);
IMDEBUG(DBG_MISC , "- stopComposing cnt=%d" , cnt->first);
this->erase(cnt);
checkTimer();
}
bool cCheckComposing::isComposing(int cntID) {
return this->find(cntID) != this->end();
}
void cCheckComposing::checkTimer() {
if (this->size() == 0) {
CancelWaitableTimer(timer);
timerWaiting = false;
} else if (!timerWaiting) {
LARGE_INTEGER lDueTime;
lDueTime.QuadPart = -10000 * 10000;
SetWaitableTimer(timer , &lDueTime , 10000,(PTIMERAPCROUTINE)timerProc, this , FALSE);
timerWaiting = true;
}
}
VOID CALLBACK cCheckComposing::timerProc(cCheckComposing * ct , DWORD low , DWORD high) {
time_t current = time(0);
cCheckComposing::iterator it = ct->begin();
while (it != ct->end()) {
if ((current - it->second) > 15 /*sekund*/) {
ct->stopComposing(it++);
} else
it++;
}
}