Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
editName: function() {
if ($scope.name.isEditing) {
console.log("Warning: Already editing name.");
return;
};
var nameEvent = $scope.room.current_room_state.state_events['m.room.name'];
if (nameEvent) {
$scope.name.newNameText = nameEvent.content.name;
}
else {
$scope.name.newNameText = "";
}
// Force focus to the input
$timeout(function() {
angular.element('.roomNameInput').focus();
}, 0);
$scope.name.isEditing = true;
},
updateName: function() {
var userId = "@alice:bar";
var mockStorageApi;
var batchNum = 3;
// web storage api keys
var prefix = "room_" + roomId + "_timeline_";
var stateKeyName = "room_" + roomId + "_state";
// stored state events
var stateEventMap = {
"m.room.member": {},
"m.room.name": {}
};
stateEventMap["m.room.member"][userId] = utils.mkMembership(
{user: userId, room: roomId, mship: "join"}
);
stateEventMap["m.room.name"][""] = utils.mkEvent(
{user: userId, room: roomId, type: "m.room.name",
content: {
name: "foo"
}}
);
beforeEach(function() {
utils.beforeEach(this); // eslint-disable-line no-invalid-this
mockStorageApi = new MockStorageApi();
store = new WebStorageStore(mockStorageApi, batchNum);
room = new Room(roomId);
});
describe("constructor", function() {
it("should throw if the WebStorage API functions are missing", function() {
expect(function() {
it("should reconstruct room state", function() {
setItem(mockStorageApi, stateKeyName, {
events: stateEventMap,
pagination_token: "tok"
});
var storedRoom = store.getRoom(roomId);
expect(
storedRoom.currentState.getStateEvents("m.room.name", "").event
).toEqual(stateEventMap["m.room.name"][""]);
expect(
storedRoom.currentState.getStateEvents("m.room.member", userId).event
).toEqual(stateEventMap["m.room.member"][userId]);
});
utils.mkEvent({
user: userId, room: roomId, type: "m.room.name", event: true,
content: {
name: "Room Name Here for updates"
}
})
];
room.currentState.setStateEvents(events);
store.storeEvents(room, events, "atoken");
var liveEvents = getItem(mockStorageApi, prefix + "live");
expect(liveEvents.length).toEqual(1);
expect(liveEvents[0]).toEqual(events[0].event);
var stateEvents = getItem(mockStorageApi, stateKeyName);
expect(stateEvents.events["m.room.name"][""]).toEqual(events[0].event);
});
});
room.state.summary = function(state)
{
let members = state['m.room.member'];
let is_join = (mxid) => maybe(() => members[mxid].content.membership == "join");
let aliases = [];
Object.each(state['m.room.aliases'], (state_key, event) =>
{
aliases = aliases.concat(event.content.aliases);
});
return {
room_id: state['m.room.create'][''].room_id,
name: state['m.room.name'][''].content.name,
topic: state['m.room.topic'][''].content.topic,
canonical_alias: state['m.room.canonical_alias'][''].content.alias,
world_readable: state['m.room.history_visibility'][''].content.history_visibility == "world_readable",
guest_can_join: state['m.room.guest_access'][''].content.guest_access == "can_join",
num_joined_members: Array.count(Object.keys(members), is_join),
aliases: aliases,
};
};