Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return res.rows.map((row) => ({
matrix: new MatrixRoom(row.room_id, { extras: { type } }),
// Id is not used.
remote: new RemoteRoom("", {
gateway: row.gateway,
properties: row.properties,
room_name: row.room_name,
protocol_id: row.protocol_id,
} as IRemoteGroupData),
}));
}
public async storeRoom(matrixId: string, type: MROOM_TYPES, remoteId: string, remoteData: IRemoteRoomData)
: Promise<{remote: RemoteRoom, matrix: MatrixRoom}> {
// XXX: If a room with all these identifiers already exists, replace it.
log.info(`Storing remote room (${type}) ${matrixId}`);
log.debug("with data ", remoteData);
const mxRoom = new MatrixRoom(matrixId);
mxRoom.set("type", type);
const remote = new RemoteRoom(
remoteId,
remoteData);
try {
await this.roomStore.linkRooms(mxRoom, remote);
} catch (ex) {
log.error("Failed to store room:", ex);
throw ex;
}
return {matrix: mxRoom, remote};
}
log.info(`Got invite from ${event.sender} to ${event.room_id}`);
const intent = this.bridge.getIntent();
await intent.join(event.room_id);
// Check to see if it's a 1 to 1.
const members = await this.bridge.getBot().getJoinedMembers(event.room_id);
if (members.length > 2) {
log.info("Room is not a 1 to 1 room: Treating as a potential plumbable room.");
if (this.config.provisioning.enablePlumbing) {
// We don't need to be in the room.
intent.leave(event.room_id);
}
// This is not a 1 to 1 room, so just keep us joined for now. We might want it later.
return;
}
const roomStore = this.bridge.getRoomStore();
const mxRoom = new MatrixRoom(event.room_id);
mxRoom.set("type", MROOM_TYPE_UADMIN);
await roomStore.setMatrixRoom(mxRoom);
log.info("Created new 1 to 1 admin room");
const body = `
Hello! This is the bridge bot for communicating with protocols via libpurple.
To begin, say \`protocols\` to see a list of protocols.
You can then connect your account to one of these protocols via \`create $PROTOCOL ..opts\`
See \`protocol $PROTOCOL\` for help on what options they take.
Say \`help\` for more commands.
`;
/*await intent.sendMessage(event.room_id, {
msgtype: "m.notice",
body,
format: "org.matrix.custom.html",
formatted_body: marked(body),
});*/
).then(room =>{
log.verbose("Created new user timeline room %s", room.room_id);
const mroom = new Bridge.MatrixRoom(room.room_id);
const rroom = new Bridge.RemoteRoom("tl_" + user);
rroom.set("twitter_type", "user_timeline");
rroom.set("twitter_bidirectional", true);
rroom.set("twitter_owner", user);
this._bridge.getRoomStore().linkRooms(mroom, rroom);
this._storage.set_timeline_room(user, room.room_id, 'user', 'all');
});
});
public async getIMRoom(matrixUserId: string, protocolId: string, remoteUserId: string): Promise {
const res = await this.pgPool.query(
"SELECT room_id FROM im_rooms WHERE user_id = $1 AND remote_id = $2 AND protocol_id = $3",
[ matrixUserId, remoteUserId, protocolId ],
);
if (res.rowCount === 0) {
return null;
}
const row = res.rows[0];
return {
matrix: new MatrixRoom(row.room_id, { extras: { type: MROOM_TYPE_IM } }),
remote: new RemoteRoom("", {
matrixUser: matrixUserId,
protocol_id: protocolId,
recipient: remoteUserId,
}),
};
}
return this.twitter.storage.add_dm_room(room_id, users).then(() => {
var mroom = new Bridge.MatrixRoom(room_id);
var rroom = new Bridge.RemoteRoom("dm_"+users);
rroom.set("twitter_type", "dm");
this.twitter.bridge.getRoomStore().linkRooms(mroom, rroom);
return room_id;
});
});
}).then(matrixRoomId => {
debug("now's the time to update our local cache for this linked room");
return roomStore.upsertEntry({
id: roomAlias,
remote: new RemoteRoom(thirdPartyRoomId),
matrix: new MatrixRoom(matrixRoomId)
}).then(()=> {
debug("finally return the entry we were looking for in the first place");
return roomStore.getEntryById(roomAlias);
});
});
}
remoteData = {
matrixUser: new MatrixUser(row.user_id),
recipient: row.remote_id,
protocol_id: row.protocol_id,
} as IRemoteImData;
} else if (type === "user-admin") {
remoteData = {
matrixUser: new MatrixUser(row.user_id),
} as IRemoteUserAdminData;
} else {
throw Error("Room was of unknown type!");
}
log.debug("Found room ", JSON.stringify(remoteData));
return {
remote: new RemoteRoom("", remoteData),
matrix: new MatrixRoom(roomId, { extras: { type }}),
};
}
this._twitter.timeline.remove_timeline(profile.id_str, room_id);
const entry = rooms[0];
entry.remote.set("twitter_exclude_replies", opts.exclude_replies);
roomstore.upsertEntry(entry);
this._twitter.timeline.add_timeline(profile.id_str, room_id, {
is_new: true,
exclude_replies: opts.exclude_replies
});
return {err: 201, body: {message: "Link updated."}};
}
const remote = new RemoteRoom("timeline_" + profile.id_str);
remote.set("twitter_type", "timeline");
remote.set("twitter_user", profile.id_str);
remote.set("twitter_exclude_replies", opts.exclude_replies);
roomstore.linkRooms(new MatrixRoom(room_id), remote);
this._twitter.timeline.add_timeline(profile.id_str, room_id, {
is_new: true,
exclude_replies: opts.exclude_replies
});
return {err: 201, body: {message: "Linked successfully"}};
}