OSDN Git Service

0177243bb14a1595a39d39938d9cc1ea771cf1ac
[nlite/nlite.git] / nlite / nlite_chatData.cpp
1 #include "stdafx.h"
2 #include "nlite_include.h"
3
4 namespace nlite{
5 CListenerList nlite::listenerList;
6
7
8
9
10 //\83\8a\83X\83i\81[\8c\9f\8dõ\83I\83u\83W\83F\83N\83g
11 struct ListenerPre{
12
13         ListenerData &user;
14
15         ListenerPre(ListenerData &in_user):
16                 user(in_user)
17         {}
18
19         bool operator()(CListenerList::reference listenerData){
20
21                 
22                 return (user.user_id == listenerData.user_id) && (user.community == listenerData.community);
23         }
24
25 };
26
27
28 //
29 //\83\8a\83X\83i\81[\83f\81[\83^
30 /////////////////////////////////////////////////////////////////////////////////////////////////
31
32
33 ListenerData::ListenerData():
34 user_id(TEXT("")),
35 name(TEXT("")),
36 community(TEXT("")),
37 bgcolor(INIT_COLOR),
38 //originBkFlag(FALSE),
39 time(0)
40 {}
41
42 VOID ListenerData::SetBkColor(COLORREF bkColor_in){
43         bgcolor = bkColor_in;
44         return;
45 }
46
47
48 CChatData::ViewData::ViewData():
49                         sellLineColor(INIT_COLOR),
50                         stringColor(INIT_COLOR),
51                         backColor(INIT_COLOR),
52                   selectFlag(FALSE),
53                   height(0)
54                 {}
55
56 VOID CChatData::SetChat(NicoLiveChat &chat_in,ListenerData &listener){
57         
58         
59         this->anonymity = _ttol(chat_in.anonymity);
60         this->premium = _ttol(chat_in.premium);
61         this->chatBuf = chat_in.chatBuf;
62         this->no = _ttol(chat_in.no);
63
64         if(_tcscmp(chat_in.locale,TEXT("jp")) == 0){
65                 this->locale = cuntry::jp;
66         } else {
67                 this->locale = cuntry::unknown;
68         }
69         this->mail.reserve(chat_in.mailCount);
70         for(UINT_PTR index = 0;index < chat_in.mailCount ;index++){
71
72                 this->mail.push_back(chat_in.mail[index]);
73         }
74
75         this->name = chat_in.name;
76
77
78         
79         this->listenerData = &listenerList.Register(listener,FALSE);
80
81         
82         this->vpos = _ttol(chat_in.vpos);
83         this->thread = _ttol(chat_in.thread);
84         this->date = _ttol(chat_in.date);
85         
86
87
88         return;
89 }
90
91
92 //
93 //
94 //\83R\83\81\83\93\83g\83\8a\83X\83g\83N\83\89\83X
95 //////////////////////////////////////////////////////////////////////////
96
97 //\91I\91ð\8ds\8eæ\93¾\97p\83t\83@\83\93\83N\83V\83\87\83i\83\8b
98 struct GetCurSelFunc_t{
99
100         INT_PTR count;
101         BOOL findFlag;
102         GetCurSelFunc_t():
103                 count(0)
104                 {}
105
106         BOOL operator() (const CChatData &target){
107                 count++;
108                 return  target.viewData.selectFlag;
109         }
110
111 };
112
113 //\91}\93ü\88Ê\92u\8c\9f\8dõ\83t\83@\83\93\83N\83V\83\87\83i\83\8b
114 struct SeartchSetPos_t{
115         time_t time;
116
117         SeartchSetPos_t(time_t in_time):time(in_time){}
118
119         bool operator()(const CChatData &target){
120
121                 return time > target.date;
122         }
123 };
124
125 CCommentList::CCommentList(){}
126
127 CCommentList::~CCommentList(){}
128
129 CCommentList::iterator CCommentList::GetCurSel(){
130         auto end = this->end();
131         auto ite = this->begin();
132
133         for(;ite != end && ite->viewData.selectFlag == FALSE;++ite);
134
135         return ite ;
136 }
137
138
139 INT_PTR CCommentList::GetCurSelNo(){
140
141         auto end = this->end();
142         auto ite = this->begin();
143         INT_PTR no = 0;
144         for(;ite != end && ite->viewData.selectFlag == FALSE;++ite,++no);
145
146         return ite != end ? no : -1;
147
148 }
149
150
151 CCommentList::iterator CCommentList::OnChatReceve(NicoLiveChat_P chatData_in,LPCTSTR communityID, UINT_PTR commnetCountSum,CCommentListWindow &listWindow){
152
153         CChatData chatData;
154         ListenerData listenerData;
155         listenerData.user_id = chatData_in->user_id;
156         listenerData.time = time(NULL);
157         listenerData.community = communityID;
158         chatData.SetChat(*chatData_in,listenerData);
159         iterator rslt;
160         if(empty() == TRUE || back().date <= chatData.date){
161                 chatList.push_back(chatData);
162                 rslt = (--chatList.end());
163         }else {
164
165                 rslt = chatList.insert(std::find_if(chatList.begin(),chatList.end(),SeartchSetPos_t(chatData.date)),chatData);
166         }
167         
168         if(shortcut ==chatList.end())shortcut = chatList.begin();
169
170         return rslt;
171 }
172
173 CCommentList::iterator CCommentList::GetCurSelItem(){
174         auto rslt = std::find_if(chatList.begin(),chatList.end(),GetCurSelFunc_t());
175
176         return rslt;
177 }
178
179
180 VOID CCommentList::SetCurSel(CCommentList::iterator cursel){
181         
182         auto end = this->end();
183         if(cursel == end)goto end;
184         {
185                 auto curselItem = this->GetCurSelItem();
186         
187                 if(curselItem != end){
188                         curselItem->viewData.selectFlag = FALSE;
189                 }
190         
191                 
192                 cursel->viewData.selectFlag = TRUE;
193         }
194 end:
195
196         return;
197 }
198
199
200 CCommentList::reference CCommentList::GetChatAt(UINT_PTR no){
201
202         iterator data = chatList.begin();
203         std::advance(data,no);
204         return *data;
205 }
206
207
208 UINT_PTR CCommentList::Size(){
209
210         return chatList.size();
211 }
212
213 BOOL CCommentList::empty(){
214
215         return chatList.empty();
216 }
217
218
219
220 CCommentList::iterator CCommentList::begin(){
221
222         return chatList.begin();
223 }
224
225 CCommentList::iterator CCommentList::end(){
226         
227         return chatList.end();
228 }
229
230
231 CCommentList::reverse_iterator CCommentList::rbegein(){
232
233         
234         return chatList.rbegin();
235 }
236
237
238
239                 
240 CCommentList::reverse_iterator CCommentList::rend(){
241
242         return chatList.rend();
243 }
244
245 VOID CCommentList::OnDestroy(){
246         
247         chatList.clear();
248         
249 }
250
251 VOID CCommentList::OnConnect(){
252         OnDestroy();
253         shortcut = chatList.begin();
254 }
255
256 CCommentList::reference CCommentList::back(){
257
258         return chatList.back();
259 }
260
261 ///
262 ///\83V\83\87\81[\83g\83J\83b\83g\83C\83e\83\8c\81[\83^\82ð\8eæ\93¾
263 ///
264 CCommentList::iterator CCommentList::GetShortCut(){
265
266         return shortcut;
267 }
268                 
269 ///
270 ///\83V\83\87\81[\83g\83J\83b\83g\82ð\90Ý\92è
271 ///
272 BOOL CCommentList::SetShortCut(UINT_PTR no){
273
274
275         if(static_cast<INT_PTR>(chatList.size()) <= no)return FALSE;
276
277         shortcut = chatList.begin();
278         std::advance(shortcut,no);
279
280         return TRUE;
281
282 }
283
284
285
286 VOID CListenerList::BkColorCollect(CListenerColorCollector &target){
287
288         iterator end = m_listenerList.end();
289         std::for_each(m_listenerList.begin(), end,target);
290 }
291
292 CListenerList::reference CListenerList::Register(ListenerData &listener,BOOL bUpdate){
293
294         ListenerPre listenerPre(listener);
295
296         iterator begin = m_listenerList.begin();
297         iterator end = m_listenerList.end();
298
299         iterator rslt = std::find_if(begin,end,listenerPre);
300
301         
302
303         if(rslt == end){
304
305                 
306                 m_listenerList.push_back(listener);
307
308                 return m_listenerList.back();
309
310         } else if(bUpdate == TRUE){
311
312                 *rslt = listener;
313
314         }
315         
316         return *rslt;
317
318 }
319
320
321 }