Skip to content

Commit d2fc266

Browse files
committed
- Update chat sync logic to map the group chat notification mode as a user preference.
1 parent 01361ea commit d2fc266

File tree

5 files changed

+49
-29
lines changed

5 files changed

+49
-29
lines changed

Rock/Communication/Chat/ChatHelper.cs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1291,7 +1291,7 @@ bool HasChatNotificationModeChanged( ChatChannel lastSyncedChannel, ChatChannel
12911291
}
12921292

12931293
// If the chat notification mode has changed, we need to re-sync all of the members.
1294-
if( HasChatNotificationModeChanged( existingChannel, channel ) )
1294+
if ( HasChatNotificationModeChanged( existingChannel, channel ) )
12951295
{
12961296
channelsToTriggerGroupMemberSync.Add( channel );
12971297
}
@@ -2419,7 +2419,7 @@ bool AreBadgeListsEqual( List<ChatBadge> badges1, List<ChatBadge> badges2 )
24192419
|| existingUser.IsProfileVisible != chatUser.IsProfileVisible
24202420
|| existingUser.IsOpenDirectMessageAllowed != chatUser.IsOpenDirectMessageAllowed
24212421
|| existingUser.CampusId != chatUser.CampusId;
2422-
2422+
24232423
if ( !shouldUpdate )
24242424
{
24252425
// Only compare badges as a last resort, if no other props already forced an update.
@@ -3536,13 +3536,13 @@ internal string GetQueryableChatChannelKey( int groupId )
35363536
/// </remarks>
35373537
internal string GetQueryableChatChannelKey( string channelIdentifier, bool allowIntegerIdentifier = false )
35383538
{
3539-
if( channelIdentifier.IsNullOrWhiteSpace() )
3539+
if ( channelIdentifier.IsNullOrWhiteSpace() )
35403540
{
35413541
return string.Empty;
35423542
}
35433543

35443544
var groupId = GroupCache.Get( channelIdentifier, allowIntegerIdentifier )?.Id;
3545-
if( groupId.HasValue )
3545+
if ( groupId.HasValue )
35463546
{
35473547
return GetQueryableChatChannelKey( groupId.Value );
35483548
}
@@ -3676,9 +3676,6 @@ member has already been banned from the channel.
36763676
gm.IsArchived,
36773677
IsGroupActive = gm.Group.IsActive,
36783678
IsGroupArchived = gm.Group.IsArchived,
3679-
3680-
// For now, hard code this based on the group type.
3681-
GroupChatNotificationMode = gm.Group.GroupTypeId == ChatSharedChannelGroupTypeId ? ChatNotificationMode.Mentions : ChatNotificationMode.AllMessages
36823679
} )
36833680
.GroupBy( gm => new
36843681
{
@@ -3692,7 +3689,11 @@ member has already been banned from the channel.
36923689
g.Key.PersonId,
36933690
GroupMembers = g.ToList()
36943691
} )
3695-
.ToDictionary( g => $"{g.GroupId}|{g.PersonId}", g => g.GroupMembers );
3692+
.ToDictionary( g => $"{g.GroupId}|{g.PersonId}", g => new
3693+
{
3694+
g.GroupMembers,
3695+
g.GroupId
3696+
} );
36963697

36973698
var rockChatGroupMembers = new List<RockChatGroupMember>();
36983699

@@ -3721,14 +3722,14 @@ member has already been banned from the channel.
37213722
rockChatGroupMembers.Add( rockChatChannelMember );
37223723

37233724
// Find all member records for this group & person combination.
3724-
if ( !membersByGroupAndPerson.TryGetValue( groupAndPersonKey, out var members ) || !members.Any() )
3725+
if ( !membersByGroupAndPerson.TryGetValue( groupAndPersonKey, out var members ) || !members.GroupMembers.Any() )
37253726
{
37263727
// This person is not currently a member of this group.
37273728
rockChatChannelMember.ShouldDelete = true;
37283729
continue;
37293730
}
37303731

3731-
var memberToSync = members
3732+
var memberToSync = members.GroupMembers
37323733
.OrderBy( gm => gm.IsArchived ) // Prefer non-archived.
37333734
.ThenByDescending( gm => gm.GroupMemberStatus == GroupMemberStatus.Active ) // Prefer active.
37343735
.ThenBy( gm => gm.GroupRoleOrder )
@@ -3759,7 +3760,10 @@ member has already been banned from the channel.
37593760
rockChatChannelMember.IsDeceased = memberToSync.IsDeceased;
37603761
rockChatChannelMember.ShouldDelete = false;
37613762
rockChatChannelMember.ShouldIgnore = false;
3762-
rockChatChannelMember.PushNotificationMode = memberToSync.GroupChatNotificationMode;
3763+
3764+
// BC TODO: In the future, we can probably pass this from the command instead
3765+
// of re-fetching the group from cache.
3766+
rockChatChannelMember.PushNotificationMode = GroupCache.Get( members.GroupId ).GetChatPushNotificationMode();
37633767
}
37643768
}
37653769

Rock/Model/Group/Group/Group.Logic.cs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -771,18 +771,7 @@ public bool GetIsChatChannelAlwaysShown()
771771
/// <returns>The <see cref="ChatNotificationMode"/> to control how push notifications are sent for this chat channel.</returns>
772772
public ChatNotificationMode GetChatPushNotificationMode()
773773
{
774-
if ( this.ChatPushNotificationModeOverride.HasValue )
775-
{
776-
return this.ChatPushNotificationModeOverride.Value;
777-
}
778-
779-
var groupTypeCache = GroupTypeCache.Get( this.GroupTypeId );
780-
if ( groupTypeCache != null )
781-
{
782-
return groupTypeCache.ChatPushNotificationMode;
783-
}
784-
785-
return ChatNotificationMode.AllMessages;
774+
return GroupCache.GetChatPushNotificationMode( ChatPushNotificationModeOverride, GroupTypeId );
786775
}
787776

788777
/// <summary>

Rock/Web/Cache/Entities/GroupCache.cs

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -312,15 +312,41 @@ internal bool GetIsChatChannelAlwaysShown()
312312
/// If <see cref="ChatPushNotificationModeOverride"/> set to <see langword="null"/>, then the value of
313313
/// <see cref="GroupTypeCache.ChatPushNotificationMode"/> will be used.
314314
/// </summary>
315-
/// <returns>The <see cref="ChatNotificationMode"/> to control how pushS notifications are sent for this chat channel.</returns>
315+
/// <returns>The <see cref="ChatNotificationMode"/> to control how push notifications are sent for this chat channel.</returns>
316316
internal ChatNotificationMode GetChatPushNotificationMode()
317317
{
318-
if ( this.ChatPushNotificationModeOverride.HasValue )
318+
return GetChatPushNotificationMode( ChatPushNotificationModeOverride, GroupTypeId );
319+
}
320+
321+
/// <summary>
322+
/// Determines the <see cref="ChatNotificationMode"/> for a chat channel, using an optional override or falling back to the group type's default.
323+
/// </summary>
324+
/// <param name="chatPushNotificationModeOverride">
325+
/// Optional override value. If provided, this value will be returned instead of the default.
326+
/// </param>
327+
/// <param name="groupTypeId">
328+
/// The identifier of the group type used to fetch the default <see cref="ChatNotificationMode"/> from the cache.
329+
/// </param>
330+
/// <returns>
331+
/// The resolved <see cref="ChatNotificationMode"/> to be used for push notifications.
332+
/// </returns>
333+
/// <remarks>
334+
/// If no override is provided and the group type is not found in the cache, defaults to <see cref="ChatNotificationMode.AllMessages"/>.
335+
/// </remarks>
336+
internal static ChatNotificationMode GetChatPushNotificationMode( ChatNotificationMode? chatPushNotificationModeOverride, int groupTypeId )
337+
{
338+
if ( chatPushNotificationModeOverride.HasValue )
339+
{
340+
return chatPushNotificationModeOverride.Value;
341+
}
342+
343+
var groupTypeCache = GroupTypeCache.Get( groupTypeId );
344+
if ( groupTypeCache != null )
319345
{
320-
return this.ChatPushNotificationModeOverride.Value;
346+
return groupTypeCache.ChatPushNotificationMode;
321347
}
322348

323-
return this.GroupType?.ChatPushNotificationMode ?? ChatNotificationMode.AllMessages;
349+
return ChatNotificationMode.AllMessages;
324350
}
325351

326352
/// <summary>
@@ -525,6 +551,7 @@ public override void SetFromEntity( IEntity entity )
525551
IsLeavingChatChannelAllowedOverride = group.IsLeavingChatChannelAllowedOverride;
526552
IsChatChannelPublicOverride = group.IsChatChannelPublicOverride;
527553
IsChatChannelAlwaysShownOverride = group.IsChatChannelAlwaysShownOverride;
554+
ChatPushNotificationModeOverride = group.ChatPushNotificationModeOverride;
528555
ChatChannelKey = group.ChatChannelKey;
529556
GroupMemberRecordSourceValueId = group.GroupMemberRecordSourceValueId;
530557
}

RockWeb/Blocks/Groups/GroupDetail.ascx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@
387387
<Rock:RockDropDownList ID="ddlChatPushNotificationMode" runat="server" CssClass="input-width-xl" Label="Push Notification Mode" Help="Controls how push notifications are sent for this chat channel.">
388388
<asp:ListItem Value="" Text="Inherit from Group Type" />
389389
<asp:ListItem Value="0" Text="All Messages" />
390-
<asp:ListItem Value="1" Text="Mentions And Replies" />
390+
<asp:ListItem Value="1" Text="Mentions" />
391391
<asp:ListItem Value="2" Text="Silent" />
392392
</Rock:RockDropDownList>
393393
</div>

RockWeb/Blocks/Groups/GroupTypeDetail.ascx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@
536536
<Rock:RockCheckBox ID="cbIsChatChannelAlwaysShown" runat="server" Label="Always Show Channel" Help="If enabled, chat channels of this type are always shown in the channel list even if the person has not joined the channel. This also implies that the channel may be joined by any person via the chat application." />
537537
<Rock:RockDropDownList ID="ddlChatPushNotificationMode" runat="server" CssClass="input-width-xl" Label="Push Notification Mode" Help="Controls how push notifications are sent for chat channels of this type.">
538538
<asp:ListItem Value="0" Text="All Messages" />
539-
<asp:ListItem Value="1" Text="Mentions And Replies" />
539+
<asp:ListItem Value="1" Text="Mentions" />
540540
<asp:ListItem Value="2" Text="Silent" />
541541
</Rock:RockDropDownList>
542542
</div>

0 commit comments

Comments
 (0)