-
Notifications
You must be signed in to change notification settings - Fork 259
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a contact add/remove button in chat. #120
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,7 @@ | |
*/ | ||
define(['underscore', 'text!partials/chat.html', 'text!partials/chatroom.html'], function(_, templateChat, templateChatroom) { | ||
|
||
return ["$compile", "safeDisplayName", "mediaStream", "safeApply", "desktopNotify", "translation", "playSound", "fileUpload", "randomGen", "buddyData", "appData", "$timeout", "geolocation", function($compile, safeDisplayName, mediaStream, safeApply, desktopNotify, translation, playSound, fileUpload, randomGen, buddyData, appData, $timeout, geolocation) { | ||
return ["$compile", "safeDisplayName", "mediaStream", "safeApply", "desktopNotify", "translation", "playSound", "fileUpload", "randomGen", "buddyData", "appData", "$timeout", "geolocation", "contacts", function($compile, safeDisplayName, mediaStream, safeApply, desktopNotify, translation, playSound, fileUpload, randomGen, buddyData, appData, $timeout, geolocation, contacts) { | ||
|
||
var displayName = safeDisplayName; | ||
var group_chat_id = ""; | ||
|
@@ -191,6 +191,7 @@ define(['underscore', 'text!partials/chat.html', 'text!partials/chatroom.html'], | |
var options = $.extend({}, opts); | ||
var subscope = controller.rooms[id]; | ||
var index = controller.visibleRooms.length; | ||
var buddy = buddyData.lookup(id); | ||
if (!subscope) { | ||
console.log("Create new chatroom", [id]); | ||
controller.visibleRooms.push(id); | ||
|
@@ -208,6 +209,17 @@ define(['underscore', 'text!partials/chat.html', 'text!partials/chatroom.html'], | |
subscope.p2pstate = false; | ||
subscope.active = false; | ||
subscope.pending = 0; | ||
subscope.isuser = buddy && buddy.session && buddy.session.Userid; | ||
subscope.iscontact = (function() { | ||
if (subscope.isgroupchat) { | ||
return false; | ||
} | ||
if (buddy && buddy.contact) { | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
})(); | ||
if (!subscope.isgroupchat) { | ||
buddyData.push(id); | ||
} | ||
|
@@ -322,6 +334,38 @@ define(['underscore', 'text!partials/chat.html', 'text!partials/chatroom.html'], | |
subscope.doClear = function() { | ||
subscope.$broadcast("clear"); | ||
}; | ||
subscope.toggleContact = function() { | ||
if (!buddy) { | ||
return; | ||
} | ||
// add | ||
if (!buddy.contact) { | ||
subscope.$emit("requestcontact", subscope.id, { | ||
restore: true | ||
}); | ||
// remove | ||
} else { | ||
contacts.remove(buddy.contact.Userid); | ||
} | ||
}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use two separate event handlers, e.g. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moved to |
||
var updateContactStatus = function(event, data) { | ||
if (!scope.currentRoom || scope.currentRoom.isgroupchat) { | ||
return; | ||
} | ||
var bd = buddyData.get(scope.currentRoom.id); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm pretty sure that by using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed. |
||
if (!bd) { | ||
return; | ||
} | ||
if (data.Userid === bd.session.Userid) { | ||
if (event.type === "contactadded") { | ||
subscope.iscontact = true; | ||
} else { | ||
subscope.iscontact = false; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is highly redundant, just say subscope.iscontact = (event.type === "contactadded"); There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated. |
||
} | ||
}; | ||
contacts.e.on("contactadded", updateContactStatus); | ||
contacts.e.on("contactremoved", updateContactStatus); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These handlers need to be removed when the subscope is destroyed in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now removing handlers at |
||
//console.log("Creating new chat room", controller, subscope, index); | ||
subscope.$on("submit", function(event, input) { | ||
subscope.seen(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,8 @@ | |
<button ng-if="!isgroupchat" class="btn btn-sm btn-primary" title="{{_('Start video call')}}" ng-click="doCall()"><i class="fa fa-phone fa-fw"></i></button> | ||
<button class="btn btn-sm btn-primary btn-fileupload" title="{{_('Upload files')}}"><i class="fa fa-upload fa-fw"></i></button> | ||
<button class="btn btn-sm btn-primary" title="{{_('Share my location')}}" ng-click="shareGeolocation()"><i class="fa fa-location-arrow fa-fw"></i></button> | ||
<button ng-if="!isgroupchat && isuser && !iscontact" class="btn btn-sm btn-primary" title="{{_('Add to contacts')}}" ng-click="toggleContact()"><i class="fa fa-star-o"></i></button> | ||
<button ng-if="!isgroupchat && isuser && iscontact" class="btn btn-sm btn-primary" title="{{_('Remove from contacts')}}" ng-click="toggleContact()"><i class="fa fa-star"></i></button> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added |
||
</div> | ||
<div class="btn-group pull-right"> | ||
<button class="btn btn-sm btn-default" title="{{_('Clear chat')}}" ng-click="doClear()"><i class="fa fa-eraser fa-fw"></i></button> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unless I'm reading this wrong, checking for group chat status here ought never be required.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes you are correct, removed.