Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Commit

Permalink
Merge pull request #406 from crdlc/bug-bug-1109626-v3
Browse files Browse the repository at this point in the history
Bug 1109626 - In the created room entry (in the room list) I should show...
  • Loading branch information
Cristian Rodriguez committed Dec 16, 2014
2 parents ee9807d + 6a8d50c commit b1ca7cb
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 60 deletions.
2 changes: 1 addition & 1 deletion app/index.html
Expand Up @@ -389,7 +389,7 @@ <h1 data-l10n-id="settingsTitle"></h1>
<div class="hbox expand" data-room-token="${roomToken}">
<div class="primary-action vbox fit no-overflow" data-room-token="${roomToken}" data-room-name="${roomName}">
<p class="primary-info ellipsis">${roomName}</p>
<p class="room-owner">${roomOwner}</p>
<p class="last-shared-with">${lastSharedPerson}</p>
</div>
<button class="secondary-action room-time icon icon-view" data-room-token="${roomToken}">
<span>${creationTime}</span>
Expand Down
13 changes: 13 additions & 0 deletions app/js/controller.js
Expand Up @@ -362,6 +362,19 @@
CallLog.updateRooms([room]);
},

onRoomShared: function(room, contact, identity) {
Loader.getRoomEvent().then(RoomEvent => {
RoomEvent.save({
type: RoomEvent.type.shared,
token: room.roomToken,
contactId: contact.id,
identity: identity
});
});
RoomsDB.addLastSharedPerson(room, contact, identity);
CallLog.updateRooms([room]);
},

onRoomDeleted: function(token) {
CallLog.removeRooms(token);
},
Expand Down
58 changes: 33 additions & 25 deletions app/js/helpers/rooms_db.js
Expand Up @@ -40,6 +40,14 @@
* date: <Date> (index),
* params: {}
* }
* ],
* sharedWith: [
* {
* contactId: [<String>],
* contactPrimaryInfo: <String>,
* contactPhoto: Blob,
* identities: [<String>]
* }
* ]
* }
*
Expand Down Expand Up @@ -138,48 +146,48 @@
},

/**
* Update Room object with contactInfo
* Update Room object with the last person whom the room was shared with
* param room
* Object with the room
* param contactInfo
* Object with the contact information
* param contact
* MozContact object that represents the last person whom the room was
* shared with
*/
setContactInfo: function(room, contactInfo) {
if (contactInfo) {
room.contactId = contactInfo.contactIds || null;
var contact = contactInfo.contacts ? contactInfo.contacts[0] : null;
if (contact) {
room.contactPrimaryInfo = ContactsHelper.getPrimaryInfo(contact);
room.contactPhoto = contact.photo ? contact.photo[0] : null;
}

var identities = [];
['tel', 'email'].forEach(function(field) {
if (contact[field]) {
for (var i = 0, l = contact[field].length; i < l; i++) {
identities.push(contact[field][i].value);
}
}
});
room.identities = identities;
addLastSharedPerson: function(room, contact, identity) {
if (!contact) {
return;
}

var person = {
contactId: contact.id,
contactPrimaryInfo: ContactsHelper.getPrimaryInfo(contact),
contactPhoto: contact.photo ? contact.photo[0] : null,
identities: [identity]
};

Object.keys(person).forEach(function(key) {
room[key] = person[key];
});

room.sharedWith = room.sharedWith || [];
// TODO Bug 1109560. Maybe we want to update existing people instead
// having dupes.
room.sharedWith.push(person);
},

/**
* Store a room in our DB.
*
* param room
* Object created from the API.
* param contactInfo
* Contact information object
* return Promise. The resolved promise will contain the stored record.
* The rejected promise, an error string.
*/
create: function(room, contactInfo) {
create: function(room) {
return new Promise(function(resolve, reject) {
RoomsDB.setLocalCtime(room);
room.user = Controller.identity;
RoomsDB.setContactInfo(room, contactInfo);
room.identities = [];
_dbHelper.addRecord(function(error, storedRecord) {
if (error) {
reject(error);
Expand Down
45 changes: 20 additions & 25 deletions app/js/screens/calllog.js
Expand Up @@ -67,14 +67,7 @@
},
function onShared(contact, identity) {
console.log('Lets add this to DB');
Loader.getRoomEvent().then(RoomEvent => {
RoomEvent.save({type: RoomEvent.type.shared,
token: roomToken,
contactId: contact.id,
identity: identity});
});
// TODO Implement when
// https://bugzilla.mozilla.org/show_bug.cgi?id=1102849
Controller.onRoomShared(room, contact, identity);
},
function onError() {
// Currently we dont need to show any error here, add if needed
Expand All @@ -92,7 +85,14 @@
l10nId: 'delete',
method: function(room) {
LazyLoader.load('js/screens/delete_room.js', () => {
RoomDelete.show(room.roomToken, room.roomOwner === Controller.identity);
RoomDelete.show(room.roomToken,
room.roomOwner === Controller.identity).catch(e => {
if (e && e !== 'NO_CONNECTION') {
// TODO Add error handling about this
// https://bugzilla.mozilla.org/show_bug.cgi?id=1102847
alert('Error while deleting room ' + JSON.stringify(e));
}
});
});
},
params: [room]
Expand Down Expand Up @@ -606,18 +606,21 @@
var creationTime = _getRoomCreationDate(rawRoom);
roomElement.dataset.timestampIndex = creationTime.getTime();
roomElement.id = roomElement.dataset.roomToken = rawRoom.roomToken;
roomElement.dataset.identities = roomElement.dataset.roomOwner =
rawRoom.roomOwner;
roomElement.dataset.roomOwner = rawRoom.roomOwner;
roomElement.dataset.identities = rawRoom.identities;
roomElement.dataset.participants =
rawRoom.participants.length === MAX_PARTICIPANTS ?
'full':rawRoom.participants.length;
roomElement.dataset.contactId = rawRoom.contactId;
var roomName = roomElement.dataset.roomName = rawRoom.roomName;

var lastSharedPerson = rawRoom.contactPrimaryInfo;
if (lastSharedPerson) {
roomElement.dataset.shared = true;
}
roomElement.innerHTML = _templateRoom.interpolate({
roomToken: rawRoom.roomToken,
roomName: roomName,
roomOwner: rawRoom.contactPrimaryInfo || rawRoom.roomOwner,
lastSharedPerson: lastSharedPerson || rawRoom.identities[0],
creationTime: Utils.getFormattedHour(creationTime)
});

Expand Down Expand Up @@ -710,7 +713,7 @@
function _updateContactInfo(aElement, aContact) {
// '.primary-info > p' -> Calls in call log | '.primary-info' -> Rooms
var primaryInfo = aElement.querySelector('.primary-info > p') ||
aElement.querySelector('.room-owner');
aElement.querySelector('.last-shared-with');

if (aContact) {
var identities = [];
Expand Down Expand Up @@ -1017,8 +1020,8 @@
return new Date(+room.creationTime * 1000);
}

function _addRoom(room, contactInfo) {
return RoomsDB.create(room, contactInfo).then((room) => {
function _addRoom(room) {
return RoomsDB.create(room).then((room) => {
Loader.getRoomEvent().then(RoomEvent => {
RoomEvent.save({type: RoomEvent.type.created,
token: room.roomToken,
Expand Down Expand Up @@ -1143,15 +1146,7 @@
},

addRoom: function(room) {
return new Promise(function(resolve, reject) {
ContactsHelper.find({
identities: room.roomOwner
}, function(result) {
_addRoom(room, result).then(resolve, reject);
}, function() {
_addRoom(room).then(resolve, reject);
});
});
return _addRoom(room);
},

removeRooms: function(roomTokens) {
Expand Down
7 changes: 1 addition & 6 deletions app/js/screens/room_detail.js
Expand Up @@ -125,12 +125,7 @@
url: _room.roomUrl
},
function onShared(contact, identity) {
Loader.getRoomEvent().then(RoomEvent => {
RoomEvent.save({type: RoomEvent.type.shared,
token: _room.roomToken,
contactId: contact.id,
identity: identity});
});
Controller.onRoomShared(_room, contact, identity);
},
function onError() {
// TOOD Implement if needed
Expand Down
14 changes: 11 additions & 3 deletions app/style/calllog.css
Expand Up @@ -134,7 +134,7 @@ form[role="dialog"][data-type="confirm"] button.icon:before {

.calllog-section .call-time,
.calllog-section .retry-count,
.calllog-section .room-owner,
.calllog-section .last-shared-with,
.calllog-section .subject {
font-size: 1.5rem;
color: #858585;
Expand All @@ -145,6 +145,10 @@ form[role="dialog"][data-type="confirm"] button.icon:before {
padding: 0;
}

#rooms-section-entries li:not([data-shared]) .primary-info {
line-height: 4rem;
}

#rooms-section-entries li[data-participants]:before {
position: absolute;
content: "";
Expand All @@ -156,6 +160,10 @@ form[role="dialog"][data-type="confirm"] button.icon:before {
background-size: 1.6rem auto;
}

#rooms-section-entries li:not([data-shared])[data-participants]:before {
top: 2.1rem;
}

#rooms-section-entries li[data-participants="0"]:before {
background-position: 0 -3.2rem;
}
Expand All @@ -173,7 +181,7 @@ form[role="dialog"][data-type="confirm"] button.icon:before {
margin-right: 1.5rem !important;
}

.room-time span {
#rooms-section-entries li[data-shared] .room-time span {
margin-top: -1.5rem;
}

Expand All @@ -189,7 +197,7 @@ form[role="dialog"][data-type="confirm"] button.icon:before {
flex: 0.4
}

#rooms-section .room-owner {
#rooms-section .last-shared-with {
white-space: normal;
}

Expand Down

0 comments on commit b1ca7cb

Please sign in to comment.