@@ -19,17 +19,17 @@ import (
1919 "maunium.net/go/mautrix/id"
2020)
2121
22- func (br * Bridge ) handleBotInvite (ctx context.Context , evt * event.Event , sender * User ) {
22+ func (br * Bridge ) handleBotInvite (ctx context.Context , evt * event.Event , sender * User ) EventHandlingResult {
2323 log := zerolog .Ctx (ctx )
2424 // These invites should already be rejected in QueueMatrixEvent
2525 if ! sender .Permissions .Commands {
2626 log .Warn ().Msg ("Received bot invite from user without permission to send commands" )
27- return
27+ return EventHandlingResultIgnored
2828 }
2929 err := br .Bot .EnsureJoined (ctx , evt .RoomID )
3030 if err != nil {
3131 log .Err (err ).Msg ("Failed to accept invite to room" )
32- return
32+ return EventHandlingResultFailed
3333 }
3434 log .Debug ().Msg ("Accepted invite to room as bot" )
3535 members , err := br .Matrix .GetMembers (ctx , evt .RoomID )
@@ -55,6 +55,7 @@ func (br *Bridge) handleBotInvite(ctx context.Context, evt *event.Event, sender
5555 log .Err (err ).Msg ("Failed to send welcome message to room" )
5656 }
5757 }
58+ return EventHandlingResultSuccess
5859}
5960
6061func sendNotice (ctx context.Context , evt * event.Event , intent MatrixAPI , message string , args ... any ) {
@@ -87,12 +88,12 @@ func sendErrorAndLeave(ctx context.Context, evt *event.Event, intent MatrixAPI,
8788 rejectInvite (ctx , evt , intent , "" )
8889}
8990
90- func (br * Bridge ) handleGhostDMInvite (ctx context.Context , evt * event.Event , sender * User ) {
91+ func (br * Bridge ) handleGhostDMInvite (ctx context.Context , evt * event.Event , sender * User ) EventHandlingResult {
9192 ghostID , _ := br .Matrix .ParseGhostMXID (id .UserID (evt .GetStateKey ()))
9293 validator , ok := br .Network .(IdentifierValidatingNetwork )
9394 if ghostID == "" || (ok && ! validator .ValidateUserID (ghostID )) {
9495 rejectInvite (ctx , evt , br .Matrix .GhostIntent (ghostID ), "Malformed user ID" )
95- return
96+ return EventHandlingResultIgnored
9697 }
9798 log := zerolog .Ctx (ctx ).With ().
9899 Str ("invitee_network_id" , string (ghostID )).
@@ -102,22 +103,22 @@ func (br *Bridge) handleGhostDMInvite(ctx context.Context, evt *event.Event, sen
102103 logins := sender .GetUserLogins ()
103104 if len (logins ) == 0 {
104105 rejectInvite (ctx , evt , br .Matrix .GhostIntent (ghostID ), "You're not logged in" )
105- return
106+ return EventHandlingResultIgnored
106107 }
107108 _ , ok = logins [0 ].Client .(IdentifierResolvingNetworkAPI )
108109 if ! ok {
109110 rejectInvite (ctx , evt , br .Matrix .GhostIntent (ghostID ), "This bridge does not support starting chats" )
110- return
111+ return EventHandlingResultIgnored
111112 }
112113 invitedGhost , err := br .GetGhostByID (ctx , ghostID )
113114 if err != nil {
114115 log .Err (err ).Msg ("Failed to get invited ghost" )
115- return
116+ return EventHandlingResultFailed
116117 }
117118 err = invitedGhost .Intent .EnsureJoined (ctx , evt .RoomID )
118119 if err != nil {
119120 log .Err (err ).Msg ("Failed to accept invite to room" )
120- return
121+ return EventHandlingResultFailed
121122 }
122123 var resp * CreateChatResponse
123124 var sourceLogin * UserLogin
@@ -144,7 +145,7 @@ func (br *Bridge) handleGhostDMInvite(ctx context.Context, evt *event.Event, sen
144145 } else if err != nil {
145146 log .Err (err ).Msg ("Failed to resolve identifier" )
146147 sendErrorAndLeave (ctx , evt , invitedGhost .Intent , "Failed to create chat" )
147- return
148+ return EventHandlingResultFailed
148149 } else {
149150 sourceLogin = login
150151 break
@@ -153,15 +154,15 @@ func (br *Bridge) handleGhostDMInvite(ctx context.Context, evt *event.Event, sen
153154 if resp == nil {
154155 log .Warn ().Msg ("No login could resolve the identifier" )
155156 sendErrorAndLeave (ctx , evt , br .Matrix .GhostIntent (ghostID ), "Failed to create chat via any login" )
156- return
157+ return EventHandlingResultFailed
157158 }
158159 portal := resp .Portal
159160 if portal == nil {
160161 portal , err = br .GetPortalByKey (ctx , resp .PortalKey )
161162 if err != nil {
162163 log .Err (err ).Msg ("Failed to get portal by key" )
163164 sendErrorAndLeave (ctx , evt , br .Matrix .GhostIntent (ghostID ), "Failed to create portal entry" )
164- return
165+ return EventHandlingResultFailed
165166 }
166167 }
167168 if portal .MXID != "" {
@@ -196,13 +197,13 @@ func (br *Bridge) handleGhostDMInvite(ctx context.Context, evt *event.Event, sen
196197 if err != nil {
197198 log .Err (err ).Msg ("Failed to ensure bot is invited to room" )
198199 sendErrorAndLeave (ctx , evt , invitedGhost .Intent , "Failed to invite bridge bot" )
199- return
200+ return EventHandlingResultFailed
200201 }
201202 err = br .Bot .EnsureJoined (ctx , evt .RoomID )
202203 if err != nil {
203204 log .Err (err ).Msg ("Failed to ensure bot is joined to room" )
204205 sendErrorAndLeave (ctx , evt , invitedGhost .Intent , "Failed to join with bridge bot" )
205- return
206+ return EventHandlingResultFailed
206207 }
207208
208209 didSetPortal := portal .setMXIDToExistingRoom (ctx , evt .RoomID )
@@ -271,6 +272,7 @@ func (br *Bridge) handleGhostDMInvite(ctx context.Context, evt *event.Event, sen
271272 sendErrorAndLeave (ctx , evt , invitedGhost .Intent , "You already have a direct chat with me at [%s](%s)" , portal .MXID , portal .MXID .URI (br .Matrix .ServerName ()).MatrixToURL ())
272273 rejectInvite (ctx , evt , br .Bot , "" )
273274 }
275+ return EventHandlingResultSuccess
274276}
275277
276278func (br * Bridge ) givePowerToBot (ctx context.Context , roomID id.RoomID , userWithPower MatrixAPI ) error {
0 commit comments