galley-0.83.0: Conversations
Safe HaskellSafe-Inferred
LanguageGHC2021

Galley.API.Util

Synopsis

Documentation

ensureConnectedOrSameTeam :: (Member BrigAccess r, Member (ErrorS 'NotConnected) r, Member TeamStore r) => Local UserId -> [Qualified UserId] -> Sem r () Source #

Check that the given user is either part of the same team as the other users OR that there is a connection.

ensureConnectedToLocalsOrSameTeam :: (Member BrigAccess r, Member (ErrorS 'NotConnected) r, Member TeamStore r) => Local UserId -> [UserId] -> Sem r () Source #

Check that the given user is either part of the same team(s) as the other users OR that there is a connection.

Team members are always considered connected, so we only check ensureConnected for non-team-members of the _given_ user

ensureConnected :: (Member BrigAccess r, Member (ErrorS 'NotConnected) r) => Local UserId -> UserList UserId -> Sem r () Source #

Check that the user is connected to everybody else.

The connection has to be bidirectional (e.g. if A connects to B and later B blocks A, the status of A-to-B is still Accepted but it doesn't mean that they are connected).

ensureActionAllowed :: forall (action :: Action) mem r. (IsConvMember mem, Member (ErrorS ('ActionDenied action)) r) => Sing action -> mem -> Sem r () Source #

Given a member in a conversation, check if the given action is permitted. If the user does not have the given permission, or if it has a custom role, throw ActionDenied.

ensureConvRoleNotElevated :: (IsConvMember mem, Member (ErrorS 'InvalidAction) r) => mem -> RoleName -> Sem r () Source #

Ensure that the set of actions provided are not "greater" than the user's own. This is used to ensure users cannot "elevate" allowed actions This function needs to be review when custom roles are introduced since only custom roles can cause roleNameToActions to return a Nothing

permissionCheckS :: forall perm (p :: perm) r. (SingKind perm, IsPerm (Demote perm), (Member (ErrorS (PermError p)) r, Member (ErrorS 'NotATeamMember) r)) => Sing p -> Maybe TeamMember -> Sem r TeamMember Source #

Same as permissionCheck, but for a statically known permission.

permissionCheck :: (IsPerm perm, (Member (ErrorS OperationDenied) r, Member (ErrorS 'NotATeamMember) r)) => perm -> Maybe TeamMember -> Sem r TeamMember Source #

If a team member is not given throw notATeamMember; if the given team member does not have the given permission, throw operationDenied. Otherwise, return the team member.

acceptOne2One :: (Member ConversationStore r, Member (ErrorS 'ConvNotFound) r, Member (Error InternalError) r, Member (ErrorS 'InvalidOperation) r, Member (Input UTCTime) r, Member MemberStore r, Member NotificationSubsystem r) => Local UserId -> Conversation -> Maybe ConnId -> Sem r Conversation Source #

Try to accept a 1-1 conversation, promoting connect conversations as appropriate.

class IsConvMember mem => IsConvMemberId uid mem | uid -> mem where Source #

Minimal complete definition

getConvMember

ulNewMembers :: Local x -> Conversation -> UserList UserId -> UserList UserId Source #

Remove users that are already present in the conversation.

class IsBotOrMember uid where Source #

This is an ad-hoc class to update notification targets based on the type of the user id. Local user IDs get added to the local targets, remote user IDs to remote targets, and qualified user IDs get added to the appropriate list according to whether they are local or remote, by making a runtime check.

Methods

bmAdd :: Local x -> uid -> BotsAndMembers -> BotsAndMembers Source #

Instances

Instances details
IsBotOrMember (Local UserId) Source # 
Instance details

Defined in Galley.API.Util

IsBotOrMember (Qualified UserId) Source # 
Instance details

Defined in Galley.API.Util

IsBotOrMember (Remote UserId) Source # 
Instance details

Defined in Galley.API.Util

ensureOtherMember :: Member (ErrorS 'ConvMemberNotFound) r => Local a -> Qualified UserId -> Conversation -> Sem r (Either LocalMember RemoteMember) Source #

Throw ConvMemberNotFound if the given user is not part of a conversation (either locally or remotely).

getMember Source #

Arguments

:: forall e mem t userId r. (Foldable t, Eq userId, Member (ErrorS e) r) 
=> (mem -> userId)

A projection from a member type to its user ID

-> userId

The member to be found by its user ID

-> t mem

A list of members to search

-> Sem r mem 

canDeleteMember :: TeamMember -> TeamMember -> Bool Source #

Deletion requires a permission check, but also a Role comparison: Owners can only be deleted by another owner (and not themselves).

FUTUREWORK: do not do this with Role, but introduce permissions "can delete owner", "can delete admin", etc.

pushConversationEvent :: (Member ExternalAccess r, Member NotificationSubsystem r, Foldable f) => Maybe ConnId -> Event -> Local (f UserId) -> f BotMember -> Sem r () Source #

Send an event to local users and bots

qualifyLocal :: Member (Input (Local ())) r => a -> Sem r (Local a) Source #

runLocalInput :: Local x -> Sem (Input (Local ()) ': r) a -> Sem r a Source #

toConversationCreated Source #

Arguments

:: UTCTime

The time stamp the conversation was created at

-> Local UserId

The user that created the conversation

-> Conversation

The conversation to convert for sending to a remote Galley

-> ConversationCreated ConvId

The resulting information to be sent to a remote Galley

Convert an internal conversation representation Conversation to ConversationCreated to be sent over the wire to a remote backend that will reconstruct this into multiple public-facing Conversation values, one per user from that remote backend.

FUTUREWORK: Include the team ID as well once it becomes qualified.

fromConversationCreated :: Local x -> ConversationCreated (Remote ConvId) -> [(Member, Conversation)] Source #

The function converts a ConversationCreated value to a Conversation value for each user that is on the given domain/backend. The obtained value can be used in e.g. creating an Event to be sent out to users informing them that they were added to a new conversation.

registerRemoteConversationMemberships Source #

Arguments

:: (Member ConversationStore r, Member (Error UnreachableBackends) r, Member (Error FederationError) r, Member BackendNotificationQueueAccess r, Member FederatorAccess r) 
=> UTCTime

The time stamp when the conversation was created

-> Local UserId 
-> Local Conversation 
-> Sem r () 

Notify remote users of being added to a new conversation.

getLHStatusForUsers :: Member TeamStore r => [UserId] -> Sem r [(UserId, UserLegalHoldStatus)] Source #

Add to every uid the legalhold status

class RethrowErrors (effs :: EffectRow) r where Source #

Instances

Instances details
Member (Error FederationError :: (Type -> Type) -> Type -> Type) r => RethrowErrors ('[] :: [Effect]) r Source # 
Instance details

Defined in Galley.API.Util

(SingI e, Member (ErrorS e :: (Type -> Type) -> Type -> Type) r, RethrowErrors effs r) => RethrowErrors ((ErrorS e :: (Type -> Type) -> Type -> Type) ': effs) r Source # 
Instance details

Defined in Galley.API.Util