-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathllimview.cpp
More file actions
4492 lines (3905 loc) · 159 KB
/
Copy pathllimview.cpp
File metadata and controls
4492 lines (3905 loc) · 159 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* @file LLIMMgr.cpp
* @brief Container for Instant Messaging
*
* $LicenseInfo:firstyear=2001&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2010, Linden Research, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*/
#include "llviewerprecompiledheaders.h"
#include "llimview.h"
#include "llavatarnamecache.h" // IDEVO
#include "llavataractions.h"
#include "llfloaterconversationlog.h"
#include "llfloaterreg.h"
#include "llfontgl.h"
#include "llgl.h"
#include "llrect.h"
#include "llerror.h"
#include "llbutton.h"
#include "llsdutil_math.h"
#include "llstring.h"
#include "lltextutil.h"
#include "lltrans.h"
#include "lltranslate.h"
#include "lluictrlfactory.h"
#include "llfloaterimsessiontab.h"
#include "llagent.h"
#include "llagentui.h"
#include "llappviewer.h"
#include "llavatariconctrl.h"
#include "llcallingcard.h"
#include "llchat.h"
#include "llfloaterimsession.h"
#include "llfloaterimcontainer.h"
#include "llgroupiconctrl.h"
#include "llmd5.h"
#include "llmutelist.h"
#include "llrecentpeople.h"
#include "llslurl.h"
#include "llviewermessage.h"
#include "llviewerwindow.h"
#include "llnotifications.h"
#include "llnotificationsutil.h"
#include "llfloaterimnearbychat.h"
#include "llspeakers.h" //for LLIMSpeakerMgr
#include "lltextbox.h"
#include "lltoolbarview.h"
#include "llviewercontrol.h"
#include "llviewerparcelmgr.h"
#include "llconversationlog.h"
#include "message.h"
#include "llviewerregion.h"
#include "llcorehttputil.h"
#include "llurlregistry.h"
#include <array>
// [RLVa:KB] - Checked: 2013-05-10 (RLVa-1.4.9)
#include "rlvactions.h"
#include "rlvcommon.h"
// [/RLVa:KB]
const static std::string ADHOC_NAME_SUFFIX(" Conference");
const static std::string NEARBY_P2P_BY_OTHER("nearby_P2P_by_other");
const static std::string NEARBY_P2P_BY_AGENT("nearby_P2P_by_agent");
// Markers inserted around translated part of chat text
const static std::string XL8_START_TAG(" (");
const static std::string XL8_END_TAG(")");
const S32 XL8_PADDING = 3; // XL8_START_TAG.size() + XL8_END_TAG.size()
/** Timeout of outgoing session initialization (in seconds) */
const static U32 SESSION_INITIALIZATION_TIMEOUT = 30;
// This enum corresponds to the sim's and adds P2P_CHAT_SESSION,
// as webrtc uses the multiagent chat mechanism for p2p calls.
// Don't change this without consulting a server developer.
enum EMultiAgentChatSessionType
{
GROUP_CHAT_SESSION = 0,
CONFERENCE_SESSION = 1,
P2P_CHAT_SESSION = 2,
SESSION_TYPE_COUNT
};
void startConferenceCoro(std::string url, LLUUID tempSessionId, LLUUID creatorId, LLUUID otherParticipantId, LLSD agents);
void startP2PVoiceCoro(std::string url, LLUUID tempSessionId, LLUUID creatorId, LLUUID otherParticipantId);
void chatterBoxInvitationCoro(std::string url, LLUUID sessionId, LLIMMgr::EInvitationType invitationType, const LLSD& voiceChannelInfo);
void chatterBoxHistoryCoro(std::string url, LLUUID sessionId, std::string from, std::string message, U32 timestamp);
void start_deprecated_conference_chat(const LLUUID& temp_session_id, const LLUUID& creator_id, const LLUUID& other_participant_id, const LLSD& agents_to_invite);
const LLUUID LLOutgoingCallDialog::OCD_KEY = LLUUID("7CF78E11-0CFE-498D-ADB9-1417BF03DDB4");
//
// Globals
//
LLIMMgr* gIMMgr = NULL;
bool LLSessionTimeoutTimer::tick()
{
if (mSessionId.isNull()) return true;
LLIMModel::LLIMSession* session = LLIMModel::getInstance()->findIMSession(mSessionId);
if (session && !session->mSessionInitialized)
{
gIMMgr->showSessionStartError("session_initialization_timed_out_error", mSessionId);
}
return true;
}
void notify_of_message(const LLSD& msg, bool is_dnd_msg);
void process_dnd_im(const LLSD& notification)
{
LLSD data = notification["substitutions"];
LLUUID sessionID = data["SESSION_ID"].asUUID();
LLUUID fromID = data["FROM_ID"].asUUID();
//re-create the IM session if needed
//(when coming out of DND mode upon app restart)
if(!gIMMgr->hasSession(sessionID))
{
//reconstruct session using data from the notification
std::string name = data["FROM"];
LLAvatarName av_name;
if (LLAvatarNameCache::get(data["FROM_ID"], &av_name))
{
name = av_name.getDisplayName();
}
LLIMModel::getInstance()->newSession(sessionID,
name,
IM_NOTHING_SPECIAL,
fromID,
LLSD(),
false); //will need slight refactor to retrieve whether offline message or not (assume online for now)
}
notify_of_message(data, true);
}
static void on_avatar_name_cache_toast(const LLUUID& agent_id,
const LLAvatarName& av_name,
LLSD msg)
{
LLSD args;
args["MESSAGE"] = msg["message"];
args["TIME"] = msg["time"];
// *TODO: Can this ever be an object name or group name?
args["FROM"] = av_name.getCompleteName();
args["FROM_ID"] = msg["from_id"];
args["SESSION_ID"] = msg["session_id"];
args["SESSION_TYPE"] = msg["session_type"];
LLNotificationsUtil::add("IMToast", args, args, boost::bind(&LLFloaterIMContainer::showConversation, LLFloaterIMContainer::getInstance(), msg["session_id"].asUUID()));
}
void notify_of_message(const LLSD& msg, bool is_dnd_msg)
{
std::string user_preferences;
LLUUID participant_id = msg[is_dnd_msg ? "FROM_ID" : "from_id"].asUUID();
LLUUID session_id = msg[is_dnd_msg ? "SESSION_ID" : "session_id"].asUUID();
LLIMModel::LLIMSession* session = LLIMModel::instance().findIMSession(session_id);
// do not show notification which goes from agent
if (gAgent.getID() == participant_id)
{
return;
}
// determine state of conversations floater
enum {CLOSED, NOT_ON_TOP, ON_TOP, ON_TOP_AND_ITEM_IS_SELECTED} conversations_floater_status;
LLFloaterIMContainer* im_box = LLFloaterReg::getTypedInstance<LLFloaterIMContainer>("im_container");
LLFloaterIMSessionTab* session_floater = LLFloaterIMSessionTab::getConversation(session_id);
bool store_dnd_message = false; // flag storage of a dnd message
bool is_session_focused = session_floater->isTornOff() && session_floater->hasFocus();
bool contains_mention = LLUrlRegistry::getInstance()->containsAgentMention(msg["message"].asString());
static LLCachedControl<bool> play_snd_mention_pref(gSavedSettings, "PlaySoundChatMention", false);
bool play_snd_mention = contains_mention && play_snd_mention_pref && (msg["source_type"].asInteger() != CHAT_SOURCE_OBJECT);
if (!LLFloater::isVisible(im_box) || im_box->isMinimized())
{
conversations_floater_status = CLOSED;
}
else if (!im_box->hasFocus() &&
!(session_floater && LLFloater::isVisible(session_floater)
&& !session_floater->isMinimized() && session_floater->hasFocus()))
{
conversations_floater_status = NOT_ON_TOP;
}
else if (im_box->getSelectedSession() != session_id)
{
conversations_floater_status = ON_TOP;
}
else
{
conversations_floater_status = ON_TOP_AND_ITEM_IS_SELECTED;
}
// determine user prefs for this session
if (session_id.isNull())
{
if (msg["source_type"].asInteger() == CHAT_SOURCE_OBJECT)
{
user_preferences = gSavedSettings.getString("NotificationObjectIMOptions");
if (!gAgent.isDoNotDisturb() && (gSavedSettings.getBOOL("PlaySoundObjectIM")))
{
make_ui_sound("UISndNewIncomingIMSession");
}
}
else
{
user_preferences = gSavedSettings.getString("NotificationNearbyChatOptions");
if (!gAgent.isDoNotDisturb() && (gSavedSettings.getBOOL("PlaySoundNearbyChatIM")) && !play_snd_mention)
{
make_ui_sound("UISndNewIncomingIMSession");
}
}
}
else if (session->isP2PSessionType())
{
if (LLAvatarTracker::instance().isBuddy(participant_id))
{
user_preferences = gSavedSettings.getString("NotificationFriendIMOptions");
if (!gAgent.isDoNotDisturb() && (gSavedSettings.getBOOL("PlaySoundFriendIM")) && !play_snd_mention)
{
make_ui_sound("UISndNewIncomingIMSession");
}
}
else
{
user_preferences = gSavedSettings.getString("NotificationNonFriendIMOptions");
if (!gAgent.isDoNotDisturb() && (gSavedSettings.getBOOL("PlaySoundNonFriendIM")) && !play_snd_mention)
{
make_ui_sound("UISndNewIncomingIMSession");
}
}
}
else if (session->isAdHocSessionType())
{
user_preferences = gSavedSettings.getString("NotificationConferenceIMOptions");
if (!gAgent.isDoNotDisturb() && (gSavedSettings.getBOOL("PlaySoundConferenceIM")) && !play_snd_mention)
{
make_ui_sound("UISndNewIncomingIMSession");
}
}
else if(session->isGroupSessionType())
{
user_preferences = gSavedSettings.getString("NotificationGroupChatOptions");
if (!gAgent.isDoNotDisturb() && (gSavedSettings.getBOOL("PlaySoundGroupChatIM")) && !play_snd_mention)
{
make_ui_sound("UISndNewIncomingIMSession");
}
}
if (play_snd_mention)
{
if (!gAgent.isDoNotDisturb())
{
make_ui_sound("UISndChatMention");
}
}
// actions:
// 0. nothing - exit
if (("noaction" == user_preferences ||
ON_TOP_AND_ITEM_IS_SELECTED == conversations_floater_status)
&& session_floater->isMessagePaneExpanded())
{
return;
}
// 1. open floater and [optional] surface it
if ("openconversations" == user_preferences &&
(CLOSED == conversations_floater_status
|| NOT_ON_TOP == conversations_floater_status))
{
if(!gAgent.isDoNotDisturb())
{
if(!LLAppViewer::instance()->quitRequested() && !LLFloater::isVisible(im_box))
{
// Open conversations floater
LLFloaterReg::showInstance("im_container");
}
im_box->collapseMessagesPane(false);
if (session_floater)
{
if (session_floater->getHost())
{
if (NULL != im_box && im_box->isMinimized())
{
LLFloater::onClickMinimize(im_box);
}
}
else
{
if (session_floater->isMinimized())
{
LLFloater::onClickMinimize(session_floater);
}
}
}
}
else
{
store_dnd_message = true;
}
}
// 2. Flash line item
if ("openconversations" == user_preferences
|| ON_TOP == conversations_floater_status
|| ("toast" == user_preferences && ON_TOP != conversations_floater_status)
|| (("flash" == user_preferences || contains_mention) && (CLOSED == conversations_floater_status
|| NOT_ON_TOP == conversations_floater_status))
|| is_dnd_msg)
{
if(!LLMuteList::getInstance()->isMuted(participant_id))
{
if(gAgent.isDoNotDisturb())
{
store_dnd_message = true;
}
else
{
if (is_dnd_msg && (ON_TOP == conversations_floater_status ||
NOT_ON_TOP == conversations_floater_status ||
CLOSED == conversations_floater_status))
{
im_box->highlightConversationItemWidget(session_id, true);
}
else
{
im_box->flashConversationItemWidget(session_id, true, contains_mention);
}
}
}
}
// 3. Flash FUI button
if (("toast" == user_preferences || "flash" == user_preferences) &&
(CLOSED == conversations_floater_status
|| NOT_ON_TOP == conversations_floater_status)
&& !is_session_focused
&& !is_dnd_msg) //prevent flashing FUI button because the conversation floater will have already opened
{
// Prevent flashing for nearby chat when chat bar is active
static LLCachedControl<bool> sChatInWindow(gSavedSettings, "AlchemyNearbyChatInput", true);
if (!sChatInWindow
|| (participant_id.notNull() && session_id.notNull()))
{
if (!LLMuteList::getInstance()->isMuted(participant_id))
{
if (!gAgent.isDoNotDisturb())
{
gToolBarView->flashCommand(LLCommandId("chat"), true, im_box->isMinimized());
}
else
{
store_dnd_message = true;
}
}
}
}
// 4. Toast
if ((("toast" == user_preferences) &&
(ON_TOP_AND_ITEM_IS_SELECTED != conversations_floater_status) &&
(!session_floater->isTornOff()
|| session_floater->isMinimized()
|| !LLFloater::isVisible(session_floater)))
|| !session_floater->isMessagePaneExpanded())
{
//Show IM toasts (upper right toasts)
// Skip toasting for system messages and for nearby chat
if(session_id.notNull() && participant_id.notNull())
{
if(!is_dnd_msg)
{
if(gAgent.isDoNotDisturb())
{
store_dnd_message = true;
}
else
{
LLAvatarNameCache::get(participant_id, boost::bind(&on_avatar_name_cache_toast, _1, _2, msg));
}
}
}
}
if (store_dnd_message)
{
// If in DND mode, allow notification to be stored so upon DND exit
// the user will be notified with some limitations (see 'is_dnd_msg' flag checks)
if(session_id.notNull()
&& participant_id.notNull()
&& !session_floater->isShown())
{
LLAvatarNameCache::get(participant_id, boost::bind(&on_avatar_name_cache_toast, _1, _2, msg));
}
}
}
void on_new_message(const LLSD& msg)
{
notify_of_message(msg, false);
}
void startConferenceCoro(std::string url,
LLUUID tempSessionId, LLUUID creatorId, LLUUID otherParticipantId, LLSD agents)
{
LLCore::HttpRequest::policy_t httpPolicy(LLCore::HttpRequest::DEFAULT_POLICY_ID);
LLCoreHttpUtil::HttpCoroutineAdapter::ptr_t
httpAdapter = std::make_shared<LLCoreHttpUtil::HttpCoroutineAdapter>("ConferenceChatStart", httpPolicy);
LLCore::HttpRequest::ptr_t httpRequest = std::make_shared<LLCore::HttpRequest>();
LLSD postData;
postData["method"] = "start conference";
postData["session-id"] = tempSessionId;
postData["params"] = agents;
LLSD altParams;
std::string voice_server_type = gSavedSettings.getString("VoiceServerType");
if (voice_server_type.empty())
{
// default to the server type associated with the region we're on.
LLVoiceVersionInfo versionInfo = LLVoiceClient::getInstance()->getVersion();
voice_server_type = versionInfo.internalVoiceServerType;
}
altParams["voice_server_type"] = voice_server_type;
postData["alt_params"] = altParams;
LLSD result = httpAdapter->postAndSuspend(httpRequest, url, postData);
LLSD httpResults = result[LLCoreHttpUtil::HttpCoroutineAdapter::HTTP_RESULTS];
LLCore::HttpStatus status = LLCoreHttpUtil::HttpCoroutineAdapter::getStatusFromLLSD(httpResults);
if (!status)
{
LL_WARNS("LLIMModel") << "Failed to start conference" << LL_ENDL;
//try an "old school" way.
// *TODO: What about other error status codes? 4xx 5xx?
if (status == LLCore::HttpStatus(HTTP_BAD_REQUEST))
{
start_deprecated_conference_chat(
tempSessionId,
creatorId,
otherParticipantId,
agents);
}
//else throw an error back to the client?
//in theory we should have just have these error strings
//etc. set up in this file as opposed to the IMMgr,
//but the error string were unneeded here previously
//and it is not worth the effort switching over all
//the possible different language translations
}
}
void startP2PVoiceCoro(std::string url, LLUUID sessionID, LLUUID creatorId, LLUUID otherParticipantId)
{
LLCore::HttpRequest::policy_t httpPolicy(LLCore::HttpRequest::DEFAULT_POLICY_ID);
LLCoreHttpUtil::HttpCoroutineAdapter::ptr_t httpAdapter = std::make_shared<LLCoreHttpUtil::HttpCoroutineAdapter>("StartP2PVoiceCoro", httpPolicy);
LLCore::HttpRequest::ptr_t httpRequest = std::make_shared<LLCore::HttpRequest>();
LLSD postData;
postData["method"] = "start p2p voice";
postData["session-id"] = sessionID;
postData["params"] = otherParticipantId;
LLSD altParams;
std::string voice_server_type = gSavedSettings.getString("VoiceServerType");
if (voice_server_type.empty())
{
// default to the server type associated with the region we're on.
LLVoiceVersionInfo versionInfo = LLVoiceClient::getInstance()->getVersion();
voice_server_type = versionInfo.internalVoiceServerType;
}
altParams["voice_server_type"] = voice_server_type;
postData["alt_params"] = altParams;
LLSD result = httpAdapter->postAndSuspend(httpRequest, url, postData);
LLSD httpResults = result[LLCoreHttpUtil::HttpCoroutineAdapter::HTTP_RESULTS];
LLCore::HttpStatus status = LLCoreHttpUtil::HttpCoroutineAdapter::getStatusFromLLSD(httpResults);
if (!status)
{
LL_WARNS("LLIMModel") << "Failed to start p2p session:" << postData << "->" << result << LL_ENDL;
// try an "old school" way.
// *TODO: What about other error status codes? 4xx 5xx?
if (status == LLCore::HttpStatus(HTTP_BAD_REQUEST))
{
static const std::string error_string("session_does_not_exist_error");
gIMMgr->showSessionStartError(error_string, sessionID);
}
}
}
void chatterBoxInvitationCoro(std::string url, LLUUID sessionId, LLIMMgr::EInvitationType invitationType, const LLSD& voiceChannelInfo)
{
LLCore::HttpRequest::policy_t httpPolicy(LLCore::HttpRequest::DEFAULT_POLICY_ID);
LLCoreHttpUtil::HttpCoroutineAdapter::ptr_t
httpAdapter = std::make_shared<LLCoreHttpUtil::HttpCoroutineAdapter>("ConferenceInviteStart", httpPolicy);
LLCore::HttpRequest::ptr_t httpRequest = std::make_shared<LLCore::HttpRequest>();
LLSD postData;
postData["method"] = "accept invitation";
postData["session-id"] = sessionId;
LLSD result = httpAdapter->postAndSuspend(httpRequest, url, postData);
LLSD httpResults = result[LLCoreHttpUtil::HttpCoroutineAdapter::HTTP_RESULTS];
LLCore::HttpStatus status = LLCoreHttpUtil::HttpCoroutineAdapter::getStatusFromLLSD(httpResults);
if (!gIMMgr)
{
LL_WARNS("") << "Global IM Manager is NULL" << LL_ENDL;
return;
}
if (!status)
{
LL_WARNS("LLIMModel") << "Bad HTTP response in chatterBoxInvitationCoro" << LL_ENDL;
//throw something back to the viewer here?
gIMMgr->clearPendingAgentListUpdates(sessionId);
gIMMgr->clearPendingInvitation(sessionId);
if (status == LLCore::HttpStatus(HTTP_NOT_FOUND))
{
static const std::string error_string("session_does_not_exist_error");
gIMMgr->showSessionStartError(error_string, sessionId);
}
return;
}
result.erase(LLCoreHttpUtil::HttpCoroutineAdapter::HTTP_RESULTS);
LLIMSpeakerMgr* speakerMgr = LLIMModel::getInstance()->getSpeakerManager(sessionId);
if (speakerMgr)
{
//we've accepted our invitation
//and received a list of agents that were
//currently in the session when the reply was sent
//to us. Now, it is possible that there were some agents
//to slip in/out between when that message was sent to us
//and now.
//the agent list updates we've received have been
//accurate from the time we were added to the session
//but unfortunately, our base that we are receiving here
//may not be the most up to date. It was accurate at
//some point in time though.
speakerMgr->setSpeakers(result);
//we now have our base of users in the session
//that was accurate at some point, but maybe not now
//so now we apply all of the updates we've received
//in case of race conditions
speakerMgr->updateSpeakers(gIMMgr->getPendingAgentListUpdates(sessionId));
}
if (LLIMMgr::INVITATION_TYPE_VOICE == invitationType)
{
gIMMgr->startCall(sessionId, LLVoiceChannel::INCOMING_CALL, voiceChannelInfo);
}
if ((invitationType == LLIMMgr::INVITATION_TYPE_VOICE
|| invitationType == LLIMMgr::INVITATION_TYPE_IMMEDIATE)
&& LLIMModel::getInstance()->findIMSession(sessionId))
{
// TODO remove in 2010, for voice calls we do not open an IM window
//LLFloaterIMSession::show(mSessionID);
}
gIMMgr->clearPendingAgentListUpdates(sessionId);
gIMMgr->clearPendingInvitation(sessionId);
}
void translateSuccess(const LLUUID& session_id, const std::string& from, const LLUUID& from_id, const std::string& utf8_text,
U64 time_n_flags, std::string originalMsg, std::string expectLang, std::string translation, const std::string detected_language)
{
std::string message_txt(utf8_text);
// filter out non-interesting responses
if (!translation.empty()
&& ((detected_language.empty()) || (expectLang != detected_language))
&& (LLStringUtil::compareInsensitive(translation, originalMsg) != 0))
{ // Note - if this format changes, also fix code in addMessagesFromServerHistory()
message_txt += XL8_START_TAG + LLTranslate::removeNoTranslateTags(translation) + XL8_END_TAG;
}
// Extract info packed in time_n_flags
bool log2file = (bool)(time_n_flags & (1LL << 32));
bool is_region_msg = (bool)(time_n_flags & (1LL << 33));
U32 time_stamp = (U32)(time_n_flags & 0x00000000ffffffff);
LLIMModel::getInstance()->processAddingMessage(session_id, from, from_id, message_txt, log2file, is_region_msg, time_stamp);
}
void translateFailure(const LLUUID& session_id, const std::string& from, const LLUUID& from_id, const std::string& utf8_text,
U64 time_n_flags, int status, const std::string err_msg)
{
std::string message_txt(utf8_text);
std::string msg = LLTrans::getString("TranslationFailed", LLSD().with("[REASON]", err_msg));
LLStringUtil::replaceString(msg, "\n", " "); // we want one-line error messages
message_txt += XL8_START_TAG + msg + XL8_END_TAG;
// Extract info packed in time_n_flags
bool log2file = (bool)(time_n_flags & (1LL << 32));
bool is_region_msg = (bool)(time_n_flags & (1LL << 33));
U32 time_stamp = (U32)(time_n_flags & 0x00000000ffffffff);
LLIMModel::getInstance()->processAddingMessage(session_id, from, from_id, message_txt, log2file, is_region_msg, time_stamp);
}
void chatterBoxHistoryCoro(std::string url, LLUUID sessionId, std::string from, std::string message, U32 timestamp)
{ // if parameters from, message and timestamp have values, they are a message that opened chat
LLCore::HttpRequest::policy_t httpPolicy(LLCore::HttpRequest::DEFAULT_POLICY_ID);
LLCoreHttpUtil::HttpCoroutineAdapter::ptr_t
httpAdapter = std::make_shared<LLCoreHttpUtil::HttpCoroutineAdapter>("ChatHistory", httpPolicy);
LLCore::HttpRequest::ptr_t httpRequest = std::make_shared<LLCore::HttpRequest>();
LLSD postData;
postData["method"] = "fetch history";
postData["session-id"] = sessionId;
LL_DEBUGS("ChatHistory") << sessionId << ": Chat history posting " << postData << " to " << url
<< ", from " << from << ", message " << message << ", timestamp " << (S32)timestamp << LL_ENDL;
LLSD result = httpAdapter->postAndSuspend(httpRequest, url, postData);
LLSD httpResults = result[LLCoreHttpUtil::HttpCoroutineAdapter::HTTP_RESULTS];
LLCore::HttpStatus status = LLCoreHttpUtil::HttpCoroutineAdapter::getStatusFromLLSD(httpResults);
if (!status)
{
LL_WARNS("ChatHistory") << sessionId << ": Bad HTTP response in chatterBoxHistoryCoro"
<< ", results: " << httpResults << LL_ENDL;
return;
}
if (LLApp::isExiting() || gDisconnected)
{
LL_DEBUGS("ChatHistory") << "Ignoring chat history response, shutting down" << LL_ENDL;
return;
}
// Add history to IM session
LLSD history = result[LLCoreHttpUtil::HttpCoroutineAdapter::HTTP_RESULTS_CONTENT];
LL_DEBUGS("ChatHistory") << sessionId << ": Chat server history fetch returned " << history << LL_ENDL;
try
{
LLIMModel::LLIMSession* session = LLIMModel::getInstance()->findIMSession(sessionId);
if (session && history.isArray())
{ // Result array is sorted oldest to newest
if (history.size() > 0)
{ // History from the chat server has an integer 'time' value timestamp. Create 'datetime' string which will match
// what we have from the local history cache
for (LLSD::array_iterator cur_server_hist = history.beginArray(), endLists = history.endArray();
cur_server_hist != endLists;
cur_server_hist++)
{
if ((*cur_server_hist).isMap())
{ // Take the 'time' value from the server and make the date-time string that will be in local cache log files
// {'from_id':u7aa8c222-8a81-450e-b3d1-9c28491ef717,'message':'Can you hear me now?','from':'Chat Tester','num':i86,'time':r1.66501e+09}
U32 timestamp = (U32)((*cur_server_hist)[LL_IM_TIME].asInteger());
(*cur_server_hist)[LL_IM_DATE_TIME] = LLLogChat::timestamp2LogString(timestamp, true);
}
}
session->addMessagesFromServerHistory(history, from, message, timestamp);
// Display the newly added messages
LLFloaterIMSession* floater = LLFloaterReg::findTypedInstance<LLFloaterIMSession>("impanel", sessionId);
if (floater && floater->isInVisibleChain())
{
floater->updateMessages();
}
}
else
{
LL_DEBUGS("ChatHistory") << sessionId << ": Empty history from chat server, nothing to add" << LL_ENDL;
}
}
else if (session && !history.isArray())
{
LL_WARNS("ChatHistory") << sessionId << ": Bad array data fetching chat history" << LL_ENDL;
}
else
{
LL_WARNS("ChatHistory") << sessionId << ": Unable to find session fetching chat history" << LL_ENDL;
}
}
catch (...)
{
LOG_UNHANDLED_EXCEPTION("chatterBoxHistoryCoro");
LL_WARNS("ChatHistory") << "chatterBoxHistoryCoro unhandled exception while processing data for session " << sessionId << LL_ENDL;
}
}
LLIMModel::LLIMModel()
{
addNewMsgCallback(boost::bind(&LLFloaterIMSession::newIMCallback, _1));
addNewMsgCallback(boost::bind(&on_new_message, _1));
LLCallDialogManager::instance();
}
LLIMModel::LLIMSession::LLIMSession(const LLUUID& session_id,
const std::string& name,
const EInstantMessage& type,
const LLUUID& other_participant_id,
const LLSD& voice_channel_info,
const uuid_vec_t& ids,
bool has_offline_msg)
: mSessionID(session_id),
mName(name),
mType(type),
mHasOfflineMessage(has_offline_msg),
mParticipantUnreadMessageCount(0),
mNumUnread(0),
mOtherParticipantID(other_participant_id),
mInitialTargetIDs(ids),
mVoiceChannel(NULL),
mP2PAsAdhocCall(false),
mSpeakers(NULL),
mSessionInitialized(false),
mCallBackEnabled(true),
mTextIMPossible(true),
mStartCallOnInitialize(false),
mStartedAsIMCall(!voice_channel_info.isUndefined()),
mIsDNDsend(false),
mAvatarNameCacheConnection()
{
// set P2P type by default
mSessionType = P2P_SESSION;
if (IM_NOTHING_SPECIAL == mType || IM_SESSION_P2P_INVITE == mType)
{
mP2PAsAdhocCall = (LLVoiceClient::getInstance()->getOutgoingCallInterface(voice_channel_info) == NULL);
}
else
{
// determine whether it is group or conference session
mSessionType = gAgent.isInGroup(mSessionID) ? GROUP_SESSION : ADHOC_SESSION;
}
initVoiceChannel(voice_channel_info);
// All participants will be added to the list of people we've recently interacted with.
// we need to add only _active_ speakers...so comment this.
// may delete this later on cleanup
//mSpeakers->addListener(&LLRecentPeople::instance(), "add");
//we need to wait for session initialization for outgoing ad-hoc and group chat session
//correct session id for initiated ad-hoc chat will be received from the server
if (!LLIMModel::getInstance()->sendStartSession(mSessionID, mOtherParticipantID, mInitialTargetIDs, mType, mP2PAsAdhocCall))
{
//we don't need to wait for any responses
//so we're already initialized
mSessionInitialized = true;
}
else
{
//tick returns true - timer will be deleted after the tick
new LLSessionTimeoutTimer(mSessionID, SESSION_INITIALIZATION_TIMEOUT);
}
if (IM_NOTHING_SPECIAL == mType)
{
mCallBackEnabled = LLVoiceClient::getInstance()->isSessionCallBackPossible(mSessionID);
mTextIMPossible = LLVoiceClient::getInstance()->isSessionTextIMPossible(mSessionID);
}
buildHistoryFileName();
loadHistory();
// Localizing name of ad-hoc session. STORM-153
// Changing name should happen here- after the history file was created, so that
// history files have consistent (English) names in different locales.
if (isAdHocSessionType() && IM_SESSION_INVITE == mType)
{
mAvatarNameCacheConnection = LLAvatarNameCache::get(mOtherParticipantID,boost::bind(&LLIMModel::LLIMSession::onAdHocNameCache,this, _2));
}
}
void LLIMModel::LLIMSession::initVoiceChannel(const LLSD& voiceChannelInfo)
{
if (mVoiceChannel)
{
if (!voiceChannelInfo.isMap())
{
LL_WARNS() << "initVoiceChannel called without voiceChannelInfo" << LL_ENDL;
}
if (mVoiceChannel->isThisVoiceChannel(voiceChannelInfo))
{
return;
}
mVoiceChannelStateChangeConnection.disconnect();
mVoiceChannel->deactivate();
delete mVoiceChannel;
mVoiceChannel = NULL;
}
mP2PAsAdhocCall = false;
if (IM_NOTHING_SPECIAL == mType || IM_SESSION_P2P_INVITE == mType)
{
LLVoiceP2POutgoingCallInterface *outgoingInterface = LLVoiceClient::getInstance()->getOutgoingCallInterface(voiceChannelInfo);
if (outgoingInterface)
{
// only use LLVoiceChannelP2P if the provider can handle the special P2P interface,
// which uses the voice server to relay calls and invites. Otherwise,
// we use the group voice provider.
mVoiceChannel = new LLVoiceChannelP2P(mSessionID, mName, mOtherParticipantID, outgoingInterface);
}
else
{
mP2PAsAdhocCall = true;
mVoiceChannel = new LLVoiceChannelGroup(mSessionID, mName, true);
}
}
else
{
// determine whether it is group or conference session
if (mSessionType == GROUP_SESSION)
{
mSessionType = GROUP_SESSION;
mVoiceChannel = new LLVoiceChannelGroup(mSessionID, mName, false);
}
else if (mSessionType == ADHOC_SESSION)
{
mSessionType = ADHOC_SESSION;
mVoiceChannel = new LLVoiceChannelGroup(mSessionID, mName, false);
}
else
{
LL_WARNS("Voice") << "Invalid Session Type when initializing voice channel: " << mSessionType << LL_ENDL;
return;
}
}
mVoiceChannelStateChangeConnection =
mVoiceChannel->setStateChangedCallback(boost::bind(&LLIMSession::onVoiceChannelStateChanged, this, _1, _2, _3));
if (!mSpeakers)
{
mSpeakers = new LLIMSpeakerMgr(mVoiceChannel);
}
else
{
mSpeakers->setVoiceChannel(mVoiceChannel);
}
}
void LLIMModel::LLIMSession::onAdHocNameCache(const LLAvatarName& av_name)
{
mAvatarNameCacheConnection.disconnect();
if (!av_name.isValidName())
{
auto separator_index = mName.rfind(" ");
std::string name = mName.substr(0, separator_index);
++separator_index;
std::string conference_word = mName.substr(separator_index, mName.length());
// additional check that session name is what we expected
if ("Conference" == conference_word)
{
LLStringUtil::format_map_t args;
args["[AGENT_NAME]"] = name;
LLTrans::findString(mName, "conference-title-incoming", args);
}
}
else
{
LLStringUtil::format_map_t args;
args["[AGENT_NAME]"] = av_name.getCompleteName();
LLTrans::findString(mName, "conference-title-incoming", args);
}
}
void LLIMModel::LLIMSession::onVoiceChannelStateChanged(const LLVoiceChannel::EState& old_state, const LLVoiceChannel::EState& new_state, const LLVoiceChannel::EDirection& direction)
{
std::string you_joined_call = LLTrans::getString("you_joined_call");
std::string you_started_call = LLTrans::getString("you_started_call");
std::string other_avatar_name = "";
LLAvatarName av_name;
std::string message;
switch(mSessionType)
{
case P2P_SESSION:
LLAvatarNameCache::get(mOtherParticipantID, &av_name);
other_avatar_name = av_name.getUserName();
if(direction == LLVoiceChannel::INCOMING_CALL)
{
switch(new_state)
{
case LLVoiceChannel::STATE_CALL_STARTED :
{
LLStringUtil::format_map_t string_args;
string_args["[NAME]"] = other_avatar_name;
message = LLTrans::getString("name_started_call", string_args);
LLIMModel::getInstance()->addMessage(mSessionID, SYSTEM_FROM, LLUUID::null, message);
break;
}
case LLVoiceChannel::STATE_CONNECTED :
LLIMModel::getInstance()->addMessage(mSessionID, SYSTEM_FROM, LLUUID::null, you_joined_call);
default:
break;
}
}
else // outgoing call
{
switch(new_state)
{
case LLVoiceChannel::STATE_CALL_STARTED :
LLIMModel::getInstance()->addMessage(mSessionID, SYSTEM_FROM, LLUUID::null, you_started_call);
break;
case LLVoiceChannel::STATE_CONNECTED :
message = LLTrans::getString("answered_call");
LLIMModel::getInstance()->addMessage(mSessionID, SYSTEM_FROM, LLUUID::null, message);
default:
break;
}
}
break;
case GROUP_SESSION:
case ADHOC_SESSION:
if(direction == LLVoiceChannel::INCOMING_CALL)
{
switch(new_state)
{
case LLVoiceChannel::STATE_CONNECTED :
LLIMModel::getInstance()->addMessage(mSessionID, SYSTEM_FROM, LLUUID::null, you_joined_call);
default:
break;
}
}
else // outgoing call
{
switch(new_state)
{
case LLVoiceChannel::STATE_CALL_STARTED :
LLIMModel::getInstance()->addMessage(mSessionID, SYSTEM_FROM, LLUUID::null, you_started_call);
break;
default:
break;
}
}
default:
break;
}
// Update speakers list when connected
if (mSpeakers && LLVoiceChannel::STATE_CONNECTED == new_state)
{
mSpeakers->update(true);
}
}
LLIMModel::LLIMSession::~LLIMSession()
{
if (mAvatarNameCacheConnection.connected())
{
mAvatarNameCacheConnection.disconnect();