diff --git a/keyserver/src/updaters/thread-permission-updaters.js b/keyserver/src/updaters/thread-permission-updaters.js --- a/keyserver/src/updaters/thread-permission-updaters.js +++ b/keyserver/src/updaters/thread-permission-updaters.js @@ -13,6 +13,7 @@ } from 'lib/permissions/thread-permissions.js'; import type { CalendarQuery } from 'lib/types/entry-types.js'; import { messageTypes } from 'lib/types/message-types-enum.js'; +import type { ThreadSubscription } from 'lib/types/subscription-types.js'; import type { ThreadPermissionsBlob, ThreadRolePermissionsBlob, @@ -60,6 +61,7 @@ +role: string, +oldRole: string, +unread?: boolean, + +defaultSubscription?: ThreadSubscription, }; type MembershipRowToDelete = { +operation: 'delete', @@ -81,6 +83,9 @@ type ChangeRoleOptions = { +setNewMembersToUnread?: boolean, +forcePermissionRecalculation?: boolean, + // This will only be set if the user is joining or leaving the thread + // Joined means role > 0 + +defaultSubscription?: ThreadSubscription, }; type ChangeRoleMemberInfo = { permissionsFromParent?: ?ThreadPermissionsBlob, @@ -101,6 +106,7 @@ const setNewMembersToUnread = options?.setNewMembersToUnread && intent === 'join'; const forcePermissionRecalculation = options?.forcePermissionRecalculation; + const defaultSubscription = options?.defaultSubscription; if (userIDs.length === 0) { return { @@ -291,6 +297,7 @@ role: newRole, oldRole, unread: userBecameMember && setNewMembersToUnread, + defaultSubscription, }); } else { membershipRows.push({ @@ -905,7 +912,7 @@ return { membershipRows, relationshipChangeset }; } -const defaultSubscriptionString = JSON.stringify({ +const leaveSubscriptionString = JSON.stringify({ home: false, pushNotifs: false, }); @@ -929,14 +936,22 @@ const time = Date.now(); const insertRows = []; for (const rowToSave of toSave) { + let subscriptionString; + + if (rowToSave.defaultSubscription) { + subscriptionString = JSON.stringify(rowToSave.defaultSubscription); + } else if (rowToSave.intent === 'join') { + subscriptionString = joinSubscriptionString; + } else { + subscriptionString = leaveSubscriptionString; + } + insertRows.push([ rowToSave.userID, rowToSave.threadID, rowToSave.role, time, - rowToSave.intent === 'join' - ? joinSubscriptionString - : defaultSubscriptionString, + subscriptionString, rowToSave.permissions ? JSON.stringify(rowToSave.permissions) : null, rowToSave.permissionsForChildren ? JSON.stringify(rowToSave.permissionsForChildren) @@ -1061,7 +1076,7 @@ rowToDelete.threadID, -1, time, - defaultSubscriptionString, + leaveSubscriptionString, null, null, 0, @@ -1078,7 +1093,7 @@ role = -1, permissions = NULL, permissions_for_children = NULL, - subscription = ${defaultSubscriptionString}, + subscription = ${leaveSubscriptionString}, last_message = 0, last_read_message = 0 `;