/
CommunitiesFrame.lua
1725 lines (1478 loc) · 61.1 KB
/
CommunitiesFrame.lua
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
CommunitiesFrameMixin = CreateFromMixins(CallbackRegistryMixin);
CommunitiesFrameMixin:GenerateCallbackEvents(
{
"InviteAccepted",
"InviteDeclined",
"TicketAccepted",
"DisplayModeChanged",
"ClubSelected",
"StreamSelected",
"SelectedClubInfoUpdated",
"MemberListDropDownShown",
});
local COMMUNITIES_FRAME_EVENTS = {
"CLUB_STREAMS_LOADED",
"CLUB_STREAM_ADDED",
"CLUB_STREAM_REMOVED",
"CLUB_ADDED",
"CLUB_REMOVED",
"CLUB_UPDATED",
"CLUB_SELF_MEMBER_ROLE_UPDATED",
"STREAM_VIEW_MARKER_UPDATED",
"BN_DISCONNECTED",
"PLAYER_GUILD_UPDATE",
"CHANNEL_UI_UPDATE",
"UPDATE_CHAT_COLOR",
"GUILD_RENAME_REQUIRED",
"REQUIRED_GUILD_RENAME_RESULT",
"CLUB_FINDER_RECRUITMENT_POST_RETURNED",
"CLUB_FINDER_ENABLED_OR_DISABLED",
"CLUB_STREAM_SUBSCRIBED",
"CLUB_FINDER_CAN_WHISPER_APPLICANT",
};
local COMMUNITIES_STATIC_POPUPS = {
"INVITE_COMMUNITY_MEMBER",
"INVITE_COMMUNITY_MEMBER_WITH_INVITE_LINK",
"CONFIRM_DESTROY_COMMUNITY",
"CONFIRM_REMOVE_COMMUNITY_MEMBER",
"SET_COMMUNITY_MEMBER_NOTE",
"CONFIRM_DESTROY_COMMUNITY_STREAM",
"CONFIRM_LEAVE_AND_DESTROY_COMMUNITY",
"CONFIRM_LEAVE_COMMUNITY",
"ADD_GUILDMEMBER",
"ADD_GUILDMEMBER_WITH_FINDER_LINK",
};
local CLUB_FINDER_APPLICANT_LIST_EVENTS = {
"GUILD_ROSTER_UPDATE",
"CLUB_FINDER_RECRUITS_UPDATED",
"CLUB_FINDER_APPLICATIONS_UPDATED",
};
local function InitSeenApplicants()
g_clubIdToSeenApplicants = g_clubIdToSeenApplicants or {};
end
local function UpdateSeenApplicants(clubId, seenApplicants)
g_clubIdToSeenApplicants[clubId] = {};
for i = 1, #seenApplicants do
local applicant = seenApplicants[i];
g_clubIdToSeenApplicants[clubId][applicant.playerGUID] = true;
end
end
local function HasNewClubApplications(clubId)
if not clubId then
return false;
end
local applicantList = C_ClubFinder.ReturnClubApplicantList(clubId);
local seenApplicants = g_clubIdToSeenApplicants[clubId] or {};
for i = 1, #applicantList do
local applicant = applicantList[i];
if not seenApplicants[applicant.playerGUID] then
return true;
end
end
return false;
end
function CommunitiesFrameMixin:RequestSubscribedClubFinderPostingInfo()
if(C_ClubFinder.IsEnabled()) then
C_ClubFinder.RequestSubscribedClubPostingIDs();
end
end
function CommunitiesFrameMixin:OnLoad()
CallbackRegistryMixin.OnLoad(self);
self:SetTitle(COMMUNITIES_FRAME_TITLE);
UIDropDownMenu_Initialize(self.StreamDropDownMenu, CommunitiesStreamDropDownMenu_Initialize);
self.selectedStreamForClub = {};
self.privilegesForClub = {};
self.newClubIds = {};
self:UpdateCommunitiesButtons();
self:RequestSubscribedClubFinderPostingInfo();
self:RegisterEvent("ADDON_LOADED");
self.ReportFrames = {};
table.insert(self.ReportFrames, self.GuildNameChangeFrame);
table.insert(self.ReportFrames, self.CommunityNameChangeFrame);
table.insert(self.ReportFrames, self.GuildPostingChangeFrame);
table.insert(self.ReportFrames, self.CommunityPostingChangeFrame);
table.insert(self.ReportFrames, self.GuildNameAlertFrame);
self.GuildNameAlertFrame:SetScript("OnClick", GenerateClosure(self.OnGuildNameAlertFrameClicked, self));
EventRegistry:RegisterCallback("AccountInfo.ChatDisabled", self.OnChatDisabledChanged, self);
end
function CommunitiesFrameMixin:OnShow()
PlaySound(SOUNDKIT.IG_CHARACTER_INFO_OPEN);
self:SetNeedsGuildNameChange(GetGuildRenameRequired());
-- Don't allow ChannelFrame and CommunitiesFrame to show at the same time, because they share one presence subscription
if ChannelFrame and ChannelFrame:IsShown() then
HideUIPanel(ChannelFrame);
end
self.PostingExpirationText:Hide();
local clubId = GuildMicroButton:GetNewClubId() or self:GetSelectedClubId();
if clubId then
self:SelectClub(clubId, true);
if C_ClubFinder.IsEnabled() then
C_ClubFinder.RequestPostingInformationFromClubId(clubId);
end
end
self:UpdatePortrait();
self:RequestSubscribedClubFinderPostingInfo(); -- In case something has changed in the status of our posting since loading in.
FrameUtil.RegisterFrameForEvents(self, COMMUNITIES_FRAME_EVENTS);
FrameUtil.RegisterFrameForEvents(self, CLUB_FINDER_APPLICANT_LIST_EVENTS);
self:UpdateClubSelection();
self:UpdateStreamDropDown();
MainMenuMicroButton_HideAlert(GuildMicroButton);
UpdateMicroButtons();
self:UpdateCommunitiesTabs();
if self.CommunitiesList:IsShown() then
self.CommunitiesList:ScrollToClub(self:GetSelectedClubId());
end
self:RegisterCallback(CommunitiesFrameMixin.Event.MemberListDropDownShown, self.OnMemberListDropDownShown, self);
end
function CommunitiesFrameMixin:OnEvent(event, ...)
if event == "CLUB_STREAMS_LOADED" then
local clubId = ...;
self:StreamsLoadedForClub(clubId);
if clubId == self:GetSelectedClubId() then
local streams = C_Club.GetStreams(clubId);
if not self:GetSelectedStreamForClub(clubId) then
self:SelectStream(clubId, streams[1].streamId);
end
self:UpdateStreamDropDown();
end
elseif event == "CLUB_STREAM_ADDED" then
local clubId, streamId = ...;
if clubId == self:GetSelectedClubId() then
if not self:GetSelectedStreamForClub(clubId) then
self:SelectStream(clubId, streamId);
end
self:UpdateStreamDropDown();
end
elseif event == "CLUB_STREAM_REMOVED" then
local clubId, streamId = ...;
local selectedStream = self:GetSelectedStreamForClub(clubId);
local isSelectedClub = clubId == self:GetSelectedClubId();
local isSelectedStream = selectedStream and selectedStream.streamId == streamId;
if isSelectedClub or isSelectedStream then
local streams = C_Club.GetStreams(clubId);
if isSelectedStream and #streams > 0 then
self:SelectStream(clubId, streams[1].streamId);
end
if isSelectedClub then
self:UpdateStreamDropDown();
end
end
elseif event == "CLUB_ADDED" then
local clubId = ...;
self:AddNewClubId(clubId);
if self.CommunitiesList:IsShown() then
if not self.ChatEditBox:HasFocus() then
self:SelectClub(clubId);
self.CommunitiesList:ScrollToClub(clubId);
end
elseif self:GetSelectedClubId() == nil then
self:UpdateClubSelection();
end
C_ClubFinder.ResetClubPostingMapCache();
elseif event == "CLUB_REMOVED" then
local clubId = ...;
self:SetPrivilegesForClub(clubId, nil);
if clubId == self:GetSelectedClubId() then
self:UpdateClubSelection();
end
self:ClearSelectedStreamForClub(clubId);
C_ClubFinder.ResetClubPostingMapCache();
elseif event == "CLUB_UPDATED" then
self:ValidateDisplayMode();
local clubId = ...;
if self:GetSelectedClubId() == clubId then
self:UpdateSelectedClubInfo(clubId);
self:UpdatePortrait();
end
elseif event == "CLUB_SELF_MEMBER_ROLE_UPDATED" then
local clubId, roleId = ...;
if clubId == self:GetSelectedClubId() then
self:SetPrivilegesForClub(clubId, C_Club.GetClubPrivileges(clubId));
else
self:SetPrivilegesForClub(clubId, nil);
end
self:UpdateCommunitiesButtons();
self:ValidateDisplayMode();
self.ApplicantList:CommunitiesMemberUpdate();
elseif event == "STREAM_VIEW_MARKER_UPDATED" then
if self.StreamDropDownMenu:IsShown() then
self.StreamDropDownMenu:UpdateUnreadNotification();
end
if self.CommunitiesListDropDownMenu:IsShown() then
self.CommunitiesListDropDownMenu:UpdateUnreadNotification();
end
elseif event == "BN_DISCONNECTED" then
HideUIPanel(self);
elseif event == "PLAYER_GUILD_UPDATE" then
local guildClubId = C_Club.GetGuildClubId();
if guildClubId ~= nil and guildClubId == self:GetSelectedClubId() then
SetLargeGuildTabardTextures("player", self.PortraitOverlay.TabardEmblem, self.PortraitOverlay.TabardBackground, self.PortraitOverlay.TabardBorder);
end
C_ClubFinder.ResetClubPostingMapCache();
elseif event == "CHANNEL_UI_UPDATE" or event == "UPDATE_CHAT_COLOR" then
self:UpdateStreamDropDown();
elseif event == "GUILD_RENAME_REQUIRED" then
self:SetNeedsGuildNameChange(...);
self:ValidateDisplayMode();
elseif event == "REQUIRED_GUILD_RENAME_RESULT" then
local success = ...
if success then
self:SetNeedsGuildNameChange(GetGuildRenameRequired());
self:ValidateDisplayMode();
else
UIErrorsFrame:AddExternalErrorMessage(ERR_GUILD_NAME_INVALID);
end
elseif event == "CLUB_FINDER_RECRUITS_UPDATED" or event == "CLUB_FINDER_APPLICATIONS_UPDATED" then
if(C_ClubFinder.IsEnabled()) then
local clubId = self:GetSelectedClubId();
if (clubId) then
self.ApplicantList:BuildList();
self:HideOrShowNotificationOverlay(clubId);
self:CheckForTutorials();
end
else
self.RosterTab.NotificationOverlay:SetShown(false);
end
elseif event == "GUILD_ROSTER_UPDATE" then
local canRequestGuildRosterUpdate = ...;
if canRequestGuildRosterUpdate then
C_GuildInfo.GuildRoster();
end
self.ApplicantList:GuildMemberUpdate();
self:UpdateCommunitiesButtons();
elseif event == "CLUB_FINDER_RECRUITMENT_POST_RETURNED" then
local displayMode = self:GetDisplayMode();
if(displayMode == COMMUNITIES_FRAME_DISPLAY_MODES.CHAT or self:IsShowingApplicantList()) then
local clubId = self:GetSelectedClubId();
local clubInfo;
if clubId then
clubInfo = C_Club.GetClubInfo(clubId);
if clubInfo then
local isGuildCommunitySelected = clubInfo.clubType == Enum.ClubType.Guild;
self:SetClubFinderPostingExpirationText(clubId, isGuildCommunitySelected);
end
end
end
elseif event == "CLUB_FINDER_ENABLED_OR_DISABLED" then
StaticPopup_Show("CLUB_FINDER_ENABLED_DISABLED");
HideUIPanel(self);
elseif event == "ADDON_LOADED" then
local addonName = ...;
if not addonName or addonName ~= "Blizzard_Communities" then
return;
end
self:UnregisterEvent("ADDON_LOADED");
InitSeenApplicants();
elseif event == "CLUB_STREAM_SUBSCRIBED" then
local clubId, streamId = ...;
if clubId == self:GetSelectedClubId() and streamId == self:GetSelectedStreamId() then
self.Chat:RequestInitialMessages(clubId, streamId);
end
elseif event == "CLUB_FINDER_CAN_WHISPER_APPLICANT" then
local applicantGUID = ...;
ChatFrame_SendTell(ConcatinateServerNameToPlayerName(applicantGUID));
end
end
function CommunitiesFrameMixin:OnMemberListDropDownShown()
HelpTip:Acknowledge(self, CLUB_FINDER_TUTORIAL_APPLICANT_LIST);
end
function CommunitiesFrameMixin:HasNewClubApplications(clubId)
return HasNewClubApplications(clubId);
end
function CommunitiesFrameMixin:UpdateSeenApplicants()
local selectedClubId = self:GetSelectedClubId();
local applicantList = C_ClubFinder.ReturnClubApplicantList(selectedClubId);
UpdateSeenApplicants(selectedClubId, applicantList);
if self.GuildMemberListDropDownMenu:IsShown() then
self.GuildMemberListDropDownMenu:UpdateNotificationFlash(false);
end
if self.CommunityMemberListDropDownMenu:IsShown() then
self.CommunityMemberListDropDownMenu:UpdateNotificationFlash(false);
end
end
function CommunitiesFrameMixin:AddNewClubId(clubId)
self.newClubIds[#self.newClubIds + 1] = clubId;
end
function CommunitiesFrameMixin:StreamsLoadedForClub(clubId)
-- When you add a new club we want to add the general stream to your chat window.
if not ChatFrame_CanAddChannel() then
return;
end
for i, newClubId in ipairs(self.newClubIds) do
if newClubId == clubId then
local streams = C_Club.GetStreams(clubId);
if streams then
for i, stream in ipairs(streams) do
if stream.streamType == Enum.ClubStreamType.General then
local DEFAULT_CHAT_FRAME_INDEX = 1;
ChatFrame_AddNewCommunitiesChannel(DEFAULT_CHAT_FRAME_INDEX, clubId, stream.streamId);
table.remove(self.newClubIds, i);
break;
end
end
end
end
end
end
function CommunitiesFrameMixin:ToggleSubPanel(subPanel)
if subPanel:IsShown() then
self.activeSubPanel = nil;
HideUIPanel(subPanel);
else
self:CloseActiveDialogs();
if self.activeSubPanel and self.activeSubPanel:IsShown() then
HideUIPanel(self.activeSubPanel);
end
self.activeSubPanel = subPanel;
ShowUIPanel(subPanel);
end
end
function CommunitiesFrameMixin:CloseActiveSubPanel()
if self.activeSubPanel then
HideUIPanel(self.activeSubPanel);
self.activeSubPanel = nil;
end
end
function CommunitiesFrameMixin:RegisterDialogShown(dialog)
self:CloseActiveDialogs(dialog);
self.lastActiveDialog = dialog;
end
function CommunitiesFrameMixin:CloseStaticPopups()
for i, popup in ipairs(COMMUNITIES_STATIC_POPUPS) do
if StaticPopup_Visible(popup) then
StaticPopup_Hide(popup);
end
end
end
function CommunitiesFrameMixin:CloseActiveDialogs(dialogBeingShown)
CloseDropDownMenus();
self:CloseStaticPopups();
self:CloseActiveSubPanel();
if AddCommunitiesFlow_IsShown() then
AddCommunitiesFlow_Hide();
end
if CommunitiesAvatarPicker_IsShown() then
CommunitiesAvatarPicker_Hide();
end
if self.lastActiveDialog ~= nil and self.lastActiveDialog ~= dialogBeingShown then
self.lastActiveDialog:Hide();
self.lastActiveDialog = nil;
end
end
function CommunitiesFrameMixin:UpdateClubSelection()
local lastSelectedClubId = tonumber(GetCVar("lastSelectedClubId")) or 0;
local clubs = C_Club.GetSubscribedClubs();
for i, club in ipairs(clubs) do
if club.clubId == lastSelectedClubId then
self:SelectClub(club.clubId);
return;
end
end
CommunitiesUtil.SortClubs(clubs);
if #clubs > 0 then
self:SelectClub(clubs[1].clubId);
return;
end
if not IsInGuild() then
self:SetDisplayMode(COMMUNITIES_FRAME_DISPLAY_MODES.GUILD_FINDER);
self:SelectClub(nil);
else
self:SetDisplayMode(COMMUNITIES_FRAME_DISPLAY_MODES.CHAT);
end
end
function CommunitiesFrameMixin:SelectClub(clubId, forceUpdate)
if forceUpdate or clubId ~= self.selectedClubId then
self.ChatEditBox:SetEnabled(clubId ~= nil);
self:UpdateSelectedClubInfo(clubId);
end
end
function CommunitiesFrameMixin:UpdateSelectedClubInfo(clubId)
local previousClubId = self.selectedClubId;
self.selectedClubId = clubId;
self.selectedClubInfo = clubId ~= nil and C_Club.GetClubInfo(clubId) or nil;
if previousClubId ~= clubId then
self:OnClubSelected(clubId);
else
self:TriggerEvent(CommunitiesFrameMixin.Event.SelectedClubInfoUpdated, clubId);
end
end
function CommunitiesFrameMixin:ClubFinderHyperLinkClicked(clubFinderId)
if IsCommunitiesUIDisabledByTrialAccount() then
UIErrorsFrame:AddMessage(ERR_RESTRICTED_ACCOUNT_TRIAL, RED_FONT_COLOR:GetRGBA());
return;
end
if not C_ClubFinder.IsEnabled() then
return;
end
if not self:IsShown() then
ShowUIPanel(self);
end
self.CommunityFinderFrame:ClubFinderOnClickHyperLink(clubFinderId);
end
COMMUNITIES_FRAME_DISPLAY_MODES = {
CHAT = {
"CommunitiesList",
"MemberList",
"StreamDropDownMenu",
"Chat",
"ChatEditBox",
"InviteButton",
"VoiceChatHeadset",
"CommunitiesCalendarButton",
"CommunitiesControlFrame",
},
ROSTER = {
"CommunitiesList",
"MemberList",
"CommunitiesControlFrame",
"GuildMemberListDropDownMenu",
"CommunityMemberListDropDownMenu",
},
COMMUNITY_APPLICANT_LIST = {
"CommunitiesList",
"ApplicantList",
"CommunitiesControlFrame",
"CommunityMemberListDropDownMenu",
},
GUILD_APPLICANT_LIST = {
"CommunitiesList",
"ApplicantList",
"CommunitiesControlFrame",
"GuildMemberListDropDownMenu",
},
INVITATION = {
"CommunitiesList",
"InvitationFrame",
"ClubFinderInvitationFrame",
},
TICKET = {
"CommunitiesList",
"TicketFrame",
},
GUILD_FINDER = {
"CommunitiesList",
"GuildFinderFrame",
},
COMMUNITY_FINDER = {
"CommunitiesList",
"CommunityFinderFrame"
},
GUILD_BENEFITS = {
"CommunitiesList",
"GuildBenefitsFrame",
},
GUILD_INFO = {
"CommunitiesList",
"GuildDetailsFrame",
"GuildLogButton",
"CommunitiesControlFrame",
},
MINIMIZED = {
"CommunitiesListDropDownMenu",
"Chat",
"ChatEditBox",
"StreamDropDownMenu",
"VoiceChatHeadset",
},
};
function CommunitiesFrameMixin:HasCommunityFinderPermissions(clubId, clubInfo)
if(not clubId) then
return false;
end
local privileges = C_Club.GetClubPrivileges(clubId);
local myMemberInfo = C_Club.GetMemberInfoForSelf(clubId);
if (not privileges or not myMemberInfo or not clubInfo) then
return false;
end
local hasCommunityFinderPermissions = myMemberInfo.role and (myMemberInfo.role == Enum.ClubRoleIdentifier.Owner or myMemberInfo.role == Enum.ClubRoleIdentifier.Leader);
return C_ClubFinder.IsEnabled() and hasCommunityFinderPermissions and privileges.canSendInvitation and clubInfo.clubType == Enum.ClubType.Character;
end
function CommunitiesFrameMixin:SetDisplayMode(displayMode)
if self.displayMode == displayMode then
return;
end
self:CloseActiveDialogs();
self.displayMode = displayMode;
local subframesToUpdate = {};
for i, mode in pairs(COMMUNITIES_FRAME_DISPLAY_MODES) do
for j, subframe in ipairs(mode) do
subframesToUpdate[subframe] = subframesToUpdate[subframe] or mode == displayMode;
end
end
if self:IsShowingApplicantList() then
self:UpdateSeenApplicants();
end
for subframe, shouldShow in pairs(subframesToUpdate) do
self[subframe]:SetShown(shouldShow);
end
self.PostingExpirationText:Hide();
local clubId = self:GetSelectedClubId();
local clubInfo;
if clubId then
clubInfo = C_Club.GetClubInfo(clubId);
end
local isGuildCommunitySelected = false;
if (clubInfo) then
isGuildCommunitySelected = clubInfo.clubType == Enum.ClubType.Guild;
end
-- If we run into more cases where we need more specific controls on what
-- is displayed in a displayMode then we should add support for conditional
-- frames in displayMode based on clubType or perhaps a predicate function.
if displayMode == COMMUNITIES_FRAME_DISPLAY_MODES.ROSTER or self:IsShowingApplicantList() then
if isGuildCommunitySelected then
C_GuildInfo.GuildRoster();
end
self.GuildMemberListDropDownMenu:SetShown(isGuildCommunitySelected);
self.CommunityMemberListDropDownMenu:SetShown(self:HasCommunityFinderPermissions(clubId, clubInfo));
end
if (displayMode == COMMUNITIES_FRAME_DISPLAY_MODES.CHAT and C_ClubFinder.IsEnabled()) then
if clubInfo then
self:SetClubFinderPostingExpirationText(clubId, isGuildCommunitySelected);
end
end
if (displayMode == COMMUNITIES_FRAME_DISPLAY_MODES.COMMUNITY_FINDER or displayMode == COMMUNITIES_FRAME_DISPLAY_MODES.GUILD_FINDER) then
CommunitiesFrameInset:Hide();
else
CommunitiesFrameInset:Show();
end
self:UpdateMaximizeMinimizeButton();
local displayMode = self:GetDisplayMode();
if displayMode == COMMUNITIES_FRAME_DISPLAY_MODES.COMMUNITY_FINDER or displayMode == COMMUNITIES_FRAME_DISPLAY_MODES.GUILD_FINDER then
HelpTip:Acknowledge(self, CLUB_FINDER_TUTORIAL_FINDER_BUTTONS_NO_SCROLL);
HelpTip:Acknowledge(self, CLUB_FINDER_TUTORIAL_FINDER_BUTTONS_SCROLL);
end
self:TriggerEvent(CommunitiesFrameMixin.Event.DisplayModeChanged, displayMode);
self:DisplayReportedAlerts(clubId);
self:UpdateCommunitiesButtons();
self:UpdateCommunitiesTabs();
self:CheckForTutorials();
end
function CommunitiesFrameMixin:UpdateMaximizeMinimizeButton()
self.MaximizeMinimizeFrame.MinimizeButton:SetEnabled(self:IsChatAccessible() and
self.displayMode ~= COMMUNITIES_FRAME_DISPLAY_MODES.INVITATION and
self.displayMode ~= COMMUNITIES_FRAME_DISPLAY_MODES.GUILD_FINDER and
self.displayMode ~= COMMUNITIES_FRAME_DISPLAY_MODES.COMMUNITY_FINDER);
end
function CommunitiesFrameMixin:GetNeedsGuildNameChange()
return self.hasForcedNameChange;
end
function CommunitiesFrameMixin:SetNeedsGuildNameChange(needsNameChange)
self.hasForcedNameChange = needsNameChange;
end
function CommunitiesFrameMixin:SetGuildNameAlertBannerMode(bannerMode)
self.GuildNameAlertFrame.topAnchored = bannerMode;
self:ValidateDisplayMode();
end
function CommunitiesFrameMixin:OnGuildNameAlertFrameClicked()
self.GuildNameAlertFrame.topAnchored = false;
PlaySound(SOUNDKIT.IG_MAINMENU_OPTION_CHECKBOX_ON);
self:ValidateDisplayMode();
end
function CommunitiesFrameMixin:HideClubFinderPostingExpirationStrings()
self.PostingExpirationText.ExpirationTimeText:Hide();
self.PostingExpirationText.DaysUntilExpire:Hide();
self.PostingExpirationText.ExpiredText:Hide();
self.PostingExpirationText.InfoButton:Hide();
end
function CommunitiesFrameMixin:SetClubFinderPostingExpirationText(clubId, isGuildCommunitySelected)
local failure = false;
self:HideClubFinderPostingExpirationStrings();
if (not C_ClubFinder.IsEnabled()) then
failure = true;
elseif(isGuildCommunitySelected) then
if(not IsGuildLeader() and not C_GuildInfo.IsGuildOfficer()) then
failure = true;
end
else
local myMemberInfo = C_Club.GetMemberInfoForSelf(clubId);
if(not myMemberInfo or not myMemberInfo.role) then
failure = true;
end
if (myMemberInfo.role ~= Enum.ClubRoleIdentifier.Owner and myMemberInfo.role ~= Enum.ClubRoleIdentifier.Leader) then
failure = true;
end
end
if failure then
self.PostingExpirationText:Hide();
return;
end
self.PostingExpirationText:Show();
local expirationTime = ClubFinderGetClubPostingExpirationTime(clubId);
if(C_ClubFinder.HasPostingBeenDelisted(clubId)) then
if (isGuildCommunitySelected) then
self.PostingExpirationText.ExpiredText:SetText(CLUB_FINDER_GUILD_POSTING_REMOVED_TEXT_SRRS);
else
self.PostingExpirationText.ExpiredText:SetText(CLUB_FINDER_COMMUNITY_POSTING_REMOVED_TEXT_SRRS);
end
local clubInfo = C_Club.GetClubInfo(clubId);
local isGuildType = clubInfo and clubInfo.clubType == Enum.ClubType.Guild;
local isCommunityType = clubInfo and clubInfo.clubType == Enum.ClubType.Character;
local isPostingBanned = C_ClubFinder.IsPostingBanned(clubId);
local hasForceDescriptionChange = clubInfo and self:ClubFinderPostingHasActiveFlag(clubId, Enum.ClubFinderClubPostingStatusFlags.ForceDescriptionChange);
local hasForceNameChange = clubInfo and ((clubInfo.clubType == Enum.ClubType.Guild and self:GetNeedsGuildNameChange()) or self:ClubFinderPostingHasActiveFlag(clubId, Enum.ClubFinderClubPostingStatusFlags.ForceNameChange));
if (isPostingBanned) then
if (isGuildType) then
self.PostingExpirationText.InfoButton.tooltipText = CLUB_FINDER_BANNED_POSTING_WARNING:format(CLUB_FINDER_TYPE_GUILD);
elseif(isCommunityType) then
self.PostingExpirationText.InfoButton.tooltipText = CLUB_FINDER_BANNED_POSTING_WARNING:format(CLUB_FINDER_COMMUNITY_TYPE);
end
elseif(hasForceNameChange) then
if (isGuildType) then
self.PostingExpirationText.InfoButton.tooltipText = ERR_CLUB_FINDER_ERROR_TYPE_FLAGGED_RENAME:format(CLUB_FINDER_TYPE_GUILD);
elseif(isCommunityType) then
self.PostingExpirationText.InfoButton.tooltipText = ERR_CLUB_FINDER_ERROR_TYPE_FLAGGED_RENAME:format(CLUB_FINDER_COMMUNITY_TYPE);
end
elseif (hasForceDescriptionChange) then
self.PostingExpirationText.InfoButton.tooltipText = CLUB_FINDER_GUILD_POSTING_ALERT_REMOVED_DESC;
end
self.PostingExpirationText.ExpiredText:Show();
self.PostingExpirationText.InfoButton:SetShown(hasForceNameChange or isPostingBanned or hasForceDescriptionChange);
elseif (expirationTime) then
if (expirationTime > 0) then
if (isGuildCommunitySelected) then
self.PostingExpirationText.ExpirationTimeText:SetText(GUILD_FINDER_POSTING_GOING_TO_EXPIRE);
else
self.PostingExpirationText.ExpirationTimeText:SetText(COMMUNITY_FINDER_POSTING_EXPIRE_SOON);
end
self.PostingExpirationText.DaysUntilExpire:SetText(CLUB_FINDER_DAYS_UNTIL_EXPIRE:format(expirationTime));
if (expirationTime > 5) then
self.PostingExpirationText.DaysUntilExpire:SetTextColor(HIGHLIGHT_FONT_COLOR:GetRGB());
elseif(expirationTime <= 5 and expirationTime > 0) then
self.PostingExpirationText.DaysUntilExpire:SetTextColor(RED_FONT_COLOR:GetRGB());
end
self.PostingExpirationText.ExpirationTimeText:Show();
self.PostingExpirationText.DaysUntilExpire:Show();
else
if (isGuildCommunitySelected) then
self.PostingExpirationText.ExpiredText:SetText(GUILD_FINDER_POSTING_EXPIRED);
else
self.PostingExpirationText.ExpiredText:SetText(COMMUNITY_FINDER_POSTING_EXPIRED);
end
self.PostingExpirationText.ExpiredText:Show();
end
end
end
function CommunitiesFrameMixin:ClubFinderPostingHasActiveFlag(clubId, flag)
local postingStatusFlags = C_ClubFinder.GetStatusOfPostingFromClubId(clubId);
for _, statusFlag in ipairs(postingStatusFlags) do
if (flag == statusFlag) then
return true;
end
end
return false;
end
function CommunitiesFrameMixin:HideAllReportFramesExcept(exceptedFrame)
for index, frame in ipairs(self.ReportFrames) do
if frame ~= exceptedFrame then
frame:Hide();
end
end
end
function CommunitiesFrameMixin:GetDisplayableReportFrame(clubId)
local clubInfo = C_Club.GetClubInfo(clubId);
if not clubInfo then
return;
end
local hasForceNameChange = self:ClubFinderPostingHasActiveFlag(clubId, Enum.ClubFinderClubPostingStatusFlags.ForceNameChange);
local hasGuildManagementPrivlileges = C_GuildInfo.IsGuildOfficer() or IsGuildLeader();
local needsGuildNameChange = clubInfo.clubType == Enum.ClubType.Guild and (hasForceNameChange or self:GetNeedsGuildNameChange()) and hasGuildManagementPrivlileges;
if needsGuildNameChange then
return self.GuildNameChangeFrame;
end
if C_ClubFinder.GetRecruitingClubInfoFromClubID(clubId) and C_ClubFinder.IsEnabled() and not C_ClubFinder.IsPostingBanned(clubId) then
local hasForceDescriptionChange = self:ClubFinderPostingHasActiveFlag(clubId, Enum.ClubFinderClubPostingStatusFlags.ForceDescriptionChange);
local needsGuildPostingMessageChange = clubInfo.clubType == Enum.ClubType.Guild and hasGuildManagementPrivlileges and hasForceDescriptionChange and not isPostingBanned;
if needsGuildPostingMessageChange then
return self.GuildPostingChangeFrame;
end
local hasCommunityFinderPermissions = self:HasCommunityFinderPermissions(clubId, clubInfo);
local needsCommunityPostingMessageChange = clubInfo.clubType == Enum.ClubType.Character and hasCommunityFinderPermissions and hasForceDescriptionChange and not isPostingBanned;
if needsCommunityPostingMessageChange then
return self.CommunityPostingChangeFrame;
end
local needsCommunityNameChange = clubInfo.clubType == Enum.ClubType.Character and hasCommunityFinderPermissions and hasForceNameChange and not isPostingBanned;
if needsCommunityNameChange then
return self.CommunityNameChangeFrame;
end
end
end
function CommunitiesFrameMixin:ShowGuildNameAlertFrame(alertText)
self.GuildNameAlertFrame.Alert:SetText(alertText);
self.GuildNameAlertFrame:SetShown(true);
end
function CommunitiesFrameMixin:DisplayReportedAlerts(clubId)
if not clubId then
return;
end
local reportFrame = self:GetDisplayableReportFrame(clubId);
self:HideAllReportFramesExcept(reportFrame);
if not reportFrame then
return;
end
local isGuildLeader = IsGuildLeader();
if self.GuildNameAlertFrame.topAnchored == nil then
self.GuildNameAlertFrame.topAnchored = not isGuildLeader;
end
--We only want to show one alert at a time. Once the other alert is cleared, it will show the next in the case of numerous.
if reportFrame == self.GuildNameChangeFrame then
if not isGuildLeader then
reportFrame.GMText:SetText(GUILD_NAME_ALERT_MEMBER_HELP);
else
reportFrame.GMText:SetText(GUILD_NAME_ALERT_GM_HELP);
end
reportFrame.EditBox:SetShown(isGuildLeader);
reportFrame.Button:SetShown(isGuildLeader);
reportFrame.RenameText:SetShown(isGuildLeader);
self:ShowGuildNameAlertFrame(GUILD_NAME_ALERT);
elseif reportFrame == self.CommunityNameChangeFrame then
self:ShowGuildNameAlertFrame(CLUB_FINDER_COMMUNITY_NAME_CHANGE_ALERT);
elseif reportFrame == self.GuildPostingChangeFrame then
self:ShowGuildNameAlertFrame(CLUB_FINDER_GUILD_POSTING_ALERT);
elseif reportFrame == self.CommunityPostingChangeFrame then
self:ShowGuildNameAlertFrame(CLUB_FINDER_COMMUNITY_POSTING_ALERT);
end
reportFrame:ClearAllPoints();
local displayMode = self:GetDisplayMode();
if displayMode == COMMUNITIES_FRAME_DISPLAY_MODES.MINIMIZED then
reportFrame:SetPoint("TOPLEFT", self.Inset, "TOPRIGHT", 3, -3);
reportFrame:SetPoint("BOTTOMRIGHT", self.Inset, "BOTTOMLEFT", 0, 5);
else
reportFrame:SetPoint("TOPLEFT", self.CommunitiesList, "TOPRIGHT", 24, -40);
reportFrame:SetPoint("BOTTOMRIGHT", self.Inset, "BOTTOMRIGHT", 0, 0);
end
self.GuildNameAlertFrame:ClearAllPoints();
if self.GuildNameAlertFrame.topAnchored then
self.GuildNameAlertFrame:SetPoint("BOTTOM", self, "TOP");
else
self.GuildNameAlertFrame:SetPoint("TOP", reportFrame, "TOP", 0, -24)
end
reportFrame:SetShown(not self.GuildNameAlertFrame.topAnchored);
self.GuildNameAlertFrame.Alert:ClearAllPoints();
if self.GuildNameAlertFrame.topAnchored then
self.GuildNameAlertFrame.Alert:SetFontObject(GameFontHighlight);
self.GuildNameAlertFrame.Alert:SetPoint("BOTTOM", self.GuildNameAlertFrame, "CENTER", 0, 0);
self.GuildNameAlertFrame.Alert:SetWidth(190);
self.GuildNameAlertFrame:SetSize(256, 60);
self.GuildNameAlertFrame:Enable();
self.GuildNameAlertFrame.ClickText:Show();
else
self.GuildNameAlertFrame.Alert:SetFontObject(GameFontHighlightMedium);
self.GuildNameAlertFrame.Alert:SetPoint("CENTER", self.GuildNameAlertFrame, "CENTER", 0, 0);
self.GuildNameAlertFrame.Alert:SetWidth(220);
self.GuildNameAlertFrame:SetSize(300, 40);
self.GuildNameAlertFrame:Disable();
self.GuildNameAlertFrame.ClickText:Hide();
end
end
function CommunitiesFrameMixin:IsChatAccessible()
return not (self.accountMuted or self.accountChatDisabled);
end
function CommunitiesFrameMixin:ValidateDisplayMode()
local clubId = self:GetSelectedClubId();
if clubId then
local displayMode = self:GetDisplayMode();
local guildDisplay = displayMode == COMMUNITIES_FRAME_DISPLAY_MODES.GUILD_BENEFITS or displayMode == COMMUNITIES_FRAME_DISPLAY_MODES.GUILD_INFO;
local clubInfo = C_Club.GetClubInfo(clubId);
self.accountMuted = C_Club.IsAccountMuted(clubId);
self.accountChatDisabled = C_SocialRestrictions.IsChatDisabled();
local chatAccessible = self:IsChatAccessible();
self.defaultMode = chatAccessible and COMMUNITIES_FRAME_DISPLAY_MODES.CHAT or COMMUNITIES_FRAME_DISPLAY_MODES.ROSTER;
local isGuildCommunitySelected = clubInfo and clubInfo.clubType == Enum.ClubType.Guild;
if not isGuildCommunitySelected and guildDisplay then
self:SetDisplayMode(self.defaultMode);
elseif displayMode == COMMUNITIES_FRAME_DISPLAY_MODES.COMMUNITY_FINDER or displayMode == COMMUNITIES_FRAME_DISPLAY_MODES.GUILD_FINDER or displayMode == COMMUNITIES_FRAME_DISPLAY_MODES.INVITATION or displayMode == COMMUNITIES_FRAME_DISPLAY_MODES.TICKET or self:IsShowingApplicantList() then
self:SetDisplayMode(self.defaultMode);
elseif not chatAccessible and displayMode == COMMUNITIES_FRAME_DISPLAY_MODES.CHAT then
self:SetDisplayMode(self.defaultMode);
elseif not chatAccessible and displayMode == COMMUNITIES_FRAME_DISPLAY_MODES.MINIMIZED then
self.MaximizeMinimizeFrame.MaximizeButton:Click();
elseif displayMode == nil then
self:SetDisplayMode(self.defaultMode);
end
local newDisplayMode = self:GetDisplayMode();
local isRosterOrApplicantList = newDisplayMode == COMMUNITIES_FRAME_DISPLAY_MODES.ROSTER or self:IsShowingApplicantList();
local shouldShowGuildMemberList = isRosterOrApplicantList and isGuildCommunitySelected;
self.GuildMemberListDropDownMenu:SetShown(shouldShowGuildMemberList);
local shouldShowCommunityMemberList = isRosterOrApplicantList and self:HasCommunityFinderPermissions(clubId, clubInfo);
self.CommunityMemberListDropDownMenu:SetShown(shouldShowCommunityMemberList);
self:DisplayReportedAlerts(clubId);
self.ChatTab.IconOverlay:SetShown(not chatAccessible);
if self.accountMuted then
self.ChatTab.tooltip2 = ERR_PARENTAL_CONTROLS_CHAT_MUTED;
elseif self.accountChatDisabled then
local instruction = GREEN_FONT_COLOR:WrapTextInColorCode(RESTRICT_CHAT_COMMUNITIES_TOOLTIP_INSTRUCTION);
self.ChatTab.tooltip2 = string.format(RESTRICT_CHAT_TOOLTIP_FORMAT, RESTRICT_CHAT_MESSAGE_SUPPRESSED, instruction);
else
self.ChatTab.tooltip2 = nil;
end
self:UpdateMaximizeMinimizeButton();
self:CheckForTutorials();
end
end
function CommunitiesFrameMixin:GetDisplayMode()
return self.displayMode;
end
function CommunitiesFrameMixin:IsShowingApplicantList()
return self.displayMode == COMMUNITIES_FRAME_DISPLAY_MODES.COMMUNITY_APPLICANT_LIST or self.displayMode == COMMUNITIES_FRAME_DISPLAY_MODES.GUILD_APPLICANT_LIST;
end
function CommunitiesFrameMixin:UpdateCommunitiesTabs()
local displayMode = self:GetDisplayMode();
self.ChatTab:Hide();
self.RosterTab:Hide();
self.GuildBenefitsTab:Hide();
self.GuildInfoTab:Hide();
if displayMode == COMMUNITIES_FRAME_DISPLAY_MODES.CHAT or
displayMode == COMMUNITIES_FRAME_DISPLAY_MODES.ROSTER or
displayMode == COMMUNITIES_FRAME_DISPLAY_MODES.GUILD_BENEFITS or
displayMode == COMMUNITIES_FRAME_DISPLAY_MODES.GUILD_INFO or
self:IsShowingApplicantList() then
self.ChatTab:Show();
self.RosterTab:Show();
local clubId = self:GetSelectedClubId();
if clubId then
local clubInfo = C_Club.GetClubInfo(clubId);
if clubInfo then
self.GuildBenefitsTab:SetShown(clubInfo.clubType == Enum.ClubType.Guild);
self.GuildInfoTab:SetShown(clubInfo.clubType == Enum.ClubType.Guild);
end
self:HideOrShowNotificationOverlay(clubId);
end
SetUIPanelAttribute(self, "extraWidth", 32);
else
SetUIPanelAttribute(self, "extraWidth", 0);
end
UpdateUIPanelPositions(self);
self.ChatTab:SetChecked(false);
self.RosterTab:SetChecked(false);
self.GuildBenefitsTab:SetChecked(false);
self.GuildInfoTab:SetChecked(false);
if displayMode == COMMUNITIES_FRAME_DISPLAY_MODES.CHAT then
self.ChatTab:SetChecked(true);
elseif displayMode == COMMUNITIES_FRAME_DISPLAY_MODES.ROSTER or self:IsShowingApplicantList() then