-
Notifications
You must be signed in to change notification settings - Fork 11.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cef5c26
commit b67f0c8
Showing
21 changed files
with
256 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 4 additions & 2 deletions
6
app/federation/server/IMatrixEventContent/IMatrixEventContentAddMemberToRoom.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
app/federation/server/IMatrixEventContent/IMatrixEventContentSetRoomJoinRules.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,85 @@ | ||
// @ts-ignore | ||
import { MatrixBridgedUser, MatrixBridgedRoom, Rooms, Users } from '../../../models'; | ||
import { MatrixBridgedUser, MatrixBridgedRoom, Users } from '../../../models'; | ||
// @ts-ignore | ||
import { addUserToRoom, createRoom, removeUserFromRoom } from '../../../lib'; | ||
import { IMatrixEvent } from '../definitions/IMatrixEvent'; | ||
import { MatrixEventType } from '../definitions/MatrixEventType'; | ||
import { AddMemberToRoomMembership } from '../IMatrixEventContent/IMatrixEventContentAddMemberToRoom'; | ||
import { SetRoomJoinRules } from '../IMatrixEventContent/IMatrixEventContentSetRoomJoinRules'; | ||
import { currentServer, SERVER, servers } from '../servers'; | ||
import { createUser } from '../methods'; | ||
import { matrixEventQueue } from './bridge'; | ||
|
||
export const handleAddMemberToRoom = async ( | ||
event: IMatrixEvent<MatrixEventType.ADD_MEMBER_TO_ROOM>, | ||
): Promise<void> => { | ||
const { room_id: matrixRoomId, sender } = event; | ||
const { | ||
room_id: matrixRoomId, | ||
sender: senderMatrixUserId, | ||
state_key: affectedMatrixUserId, | ||
content: { displayname: displayName, membership }, | ||
invite_room_state: inviteRoomState, | ||
} = event; | ||
|
||
// Find the bridged user id | ||
const userId = await MatrixBridgedUser.getId(sender); | ||
console.log(JSON.stringify(event, null, 2)); | ||
|
||
// Find the user | ||
const user = await Users.findOneById(userId); | ||
// // We ignore the bot | ||
// if (affectedMatrixUserId.startsWith(`@rc_bot:`)) { | ||
// return; | ||
// } | ||
|
||
// Find the bridged room id | ||
const roomId = await MatrixBridgedRoom.getId(matrixRoomId); | ||
|
||
Rooms.update({ _id: roomId }, { | ||
$inc: { usersCount: 1 }, | ||
$set: { | ||
u: { | ||
_id: user._id, | ||
username: user.username, | ||
}, | ||
}, | ||
}); | ||
// Find the bridged user id | ||
const senderUserId = await MatrixBridgedUser.getId(senderMatrixUserId); | ||
const affectedUserId = await MatrixBridgedUser.getId(affectedMatrixUserId); | ||
|
||
// Find the user | ||
const senderUser = await Users.findOneById(senderUserId); | ||
const affectedUser = await Users.findOneById(affectedUserId); | ||
|
||
switch (membership) { | ||
case AddMemberToRoomMembership.JOIN: | ||
addUserToRoom(roomId, affectedUser); | ||
break; | ||
case AddMemberToRoomMembership.INVITE: | ||
// // If the sender user does not exist, it means we need to create it | ||
// let creatorUser = senderUser; | ||
// if (!creatorUser) { | ||
// creatorUser = createUser(senderMatrixUserId, senderMatrixUserId); | ||
// } | ||
// | ||
// // If the invited user does not exist, it means we need to create it | ||
// let invitedUser = affectedUser; | ||
// if (!invitedUser) { | ||
// invitedUser = createUser(affectedMatrixUserId, displayName); | ||
// } | ||
|
||
// // Create the room if necessary | ||
// const destinationRoomId = roomId; | ||
|
||
if (!roomId && inviteRoomState) { | ||
// // Ensure we run all the room events first | ||
// for (const event of inviteRoomState) { | ||
// // TODO: Handle error | ||
// matrixEventQueue.push(event).catch((err) => console.error(err)); | ||
// } | ||
// | ||
// // Re-add the current event to the queue | ||
// // TODO: Handle error | ||
// matrixEventQueue.push(event).catch((err) => console.error(err)); | ||
|
||
// Stop | ||
return; | ||
} | ||
|
||
addUserToRoom(roomId, affectedUser, senderUser); | ||
break; | ||
case AddMemberToRoomMembership.LEAVE: | ||
removeUserFromRoom(roomId, affectedUser, { | ||
byUser: senderUser, | ||
}); | ||
break; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.