Browse Source

Implemented first simple Ui for contacts in chat.

pull/48/head
Simon Eisenmann 11 years ago committed by Simon Eisenmann
parent
commit
ab3e5673b8
  1. 1
      src/app/spreed-webrtc-server/channeling.go
  2. 6
      src/app/spreed-webrtc-server/contact.go
  3. 8
      src/app/spreed-webrtc-server/hub.go
  4. 2
      src/app/spreed-webrtc-server/server.go
  5. 39
      static/js/controllers/chatroomcontroller.js
  6. 9
      static/js/directives/buddylist.js
  7. 17
      static/js/directives/chat.js
  8. 57
      static/js/directives/contactrequest.js
  9. 6
      static/js/directives/directives.js
  10. 9
      static/js/services/buddylist.js
  11. 10
      static/partials/contactrequest.html

1
src/app/spreed-webrtc-server/channeling.go

@ -119,6 +119,7 @@ type DataFileInfo struct { @@ -119,6 +119,7 @@ type DataFileInfo struct {
type DataContactRequest struct {
Id string
Success bool
Userid string `json:",omitempty"`
Token string `json:",omitempty"`
}

6
src/app/spreed-webrtc-server/contact.go

@ -24,7 +24,7 @@ package main @@ -24,7 +24,7 @@ package main
import ()
type Contact struct {
a string
b string
ok bool
A string
B string
Ok bool
}

8
src/app/spreed-webrtc-server/hub.go

@ -439,7 +439,7 @@ func (h *Hub) contactrequestHandler(c *Connection, to string, cr *DataContactReq @@ -439,7 +439,7 @@ func (h *Hub) contactrequestHandler(c *Connection, to string, cr *DataContactReq
if err != nil {
return err
}
if contact.ok {
if contact.Ok {
return errors.New("received success with ok state set")
}
bSessionData := c.Session.Data()
@ -456,13 +456,13 @@ func (h *Hub) contactrequestHandler(c *Connection, to string, cr *DataContactReq @@ -456,13 +456,13 @@ func (h *Hub) contactrequestHandler(c *Connection, to string, cr *DataContactReq
if aSessionData.Userid == "" {
return errors.New("to has no userid for confirm")
}
if aSessionData.Userid != contact.a {
if aSessionData.Userid != contact.A {
return errors.New("contact mismatch in a")
}
if bSessionData.Userid != contact.b {
if bSessionData.Userid != contact.B {
return errors.New("contact mismatch in b")
}
contact.ok = true
contact.Ok = true
cr.Token, err = h.contacts.Encode("contactConfirmed", contact)
} else {
if cr.Token != "" {

2
src/app/spreed-webrtc-server/server.go

@ -143,6 +143,8 @@ func (s *Server) OnText(c *Connection, b Buffer) { @@ -143,6 +143,8 @@ func (s *Server) OnText(c *Connection, b Buffer) {
log.Println("Ignoring invalid contact request.", err)
return
}
msg.Chat.Chat.Status.ContactRequest.Userid = c.Session.Userid
log.Println("CCCCCCCC", msg.Chat.Chat.Status.ContactRequest)
}
atomic.AddUint64(&c.h.unicastChatMessages, 1)
s.Unicast(c, msg.Chat.To, msg.Chat)

39
static/js/controllers/chatroomcontroller.js

@ -18,7 +18,7 @@ @@ -18,7 +18,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
define(['underscore', 'moment', 'text!partials/fileinfo.html'], function(_, moment, templateFileInfo) {
define(['underscore', 'moment', 'text!partials/fileinfo.html', 'text!partials/contactrequest.html'], function(_, moment, templateFileInfo, templateContactRequest) {
// ChatroomController
return ["$scope", "$element", "$window", "safeMessage", "safeDisplayName", "$compile", "$filter", "translation", function($scope, $element, $window, safeMessage, safeDisplayName, $compile, $filter, translation) {
@ -45,6 +45,7 @@ define(['underscore', 'moment', 'text!partials/fileinfo.html'], function(_, mome @@ -45,6 +45,7 @@ define(['underscore', 'moment', 'text!partials/fileinfo.html'], function(_, mome
var displayName = safeDisplayName;
var buddyImageSrc = $filter("buddyImageSrc");
var fileInfo = $compile(templateFileInfo);
var contactRequest = $compile(templateContactRequest);
var knowMessage = {
r: {},
@ -397,6 +398,7 @@ define(['underscore', 'moment', 'text!partials/fileinfo.html'], function(_, mome @@ -397,6 +398,7 @@ define(['underscore', 'moment', 'text!partials/fileinfo.html'], function(_, mome
var fromself = from === userid;
var noop = false;
var element = null;
var subscope;
var timestamp = data.Time;
if (!timestamp) {
@ -441,7 +443,7 @@ define(['underscore', 'moment', 'text!partials/fileinfo.html'], function(_, mome @@ -441,7 +443,7 @@ define(['underscore', 'moment', 'text!partials/fileinfo.html'], function(_, mome
// File offers.
if (data.Status.FileInfo) {
var subscope = $scope.$new();
subscope = $scope.$new();
subscope.info = data.Status.FileInfo;
subscope.from = from;
fileInfo(subscope, function(clonedElement, scope) {
@ -451,6 +453,39 @@ define(['underscore', 'moment', 'text!partials/fileinfo.html'], function(_, mome @@ -451,6 +453,39 @@ define(['underscore', 'moment', 'text!partials/fileinfo.html'], function(_, mome
noop = true;
}
// Contact request.
if (data.Status.ContactRequest) {
subscope = $scope.$new();
subscope.request = data.Status.ContactRequest;
subscope.fromself = fromself;
contactRequest(subscope, function(clonedElement, scope) {
var text;
if (fromself) {
if (scope.request.Userid) {
if (scope.request.Success) {
text = translation._("You accepted the contact request.");
} else {
text = translation._("You rejected the contact request.");
}
} else {
text = translation._("You sent a contact request.");
}
} else {
if (scope.request.Success) {
text = translation._("Your contact request was accepted.");
} else{
if (scope.request.Token) {
text = translation._("Incoming contact request.");
} else {
text = translation._("Your contact request was rejected.");
}
}
}
element = $scope.showmessage(from, timestamp, text, clonedElement);
});
noop = true;
}
// Ignore unknown status messages.
if (message === null && nodes === null) {
noop = true;

9
static/js/directives/buddylist.js

@ -46,6 +46,15 @@ define(['underscore', 'text!partials/buddylist.html'], function(_, template) { @@ -46,6 +46,15 @@ define(['underscore', 'text!partials/buddylist.html'], function(_, template) {
};
$scope.doContact = function(id) {
//console.log("doContact", id);
$scope.$emit("requestcontact", id, {
restore: true
});
};
$scope.doAudioConference = function(id) {
$scope.updateAutoAccept(id);

17
static/js/directives/chat.js

@ -138,6 +138,23 @@ define(['underscore', 'text!partials/chat.html', 'text!partials/chatroom.html'], @@ -138,6 +138,23 @@ define(['underscore', 'text!partials/chat.html', 'text!partials/chatroom.html'],
});
$scope.$parent.$on("requestcontact", function(event, id, options) {
if (id !== group_chat_id) {
var subscope = $scope.showRoom(id, {
title: translation._("Chat with")
}, options);
$timeout(function() {
subscope.sendChat(id, "Contact request", {
ContactRequest: {
Id: randomGen.random({hex: true})
}
});
}, 0);
}
});
}];
var compile = function(tElement, tAttrs) {

57
static/js/directives/contactrequest.js

@ -0,0 +1,57 @@ @@ -0,0 +1,57 @@
/*
* Spreed WebRTC.
* Copyright (C) 2013-2014 struktur AG
*
* This file is part of Spreed WebRTC.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
define(['jquery', 'underscore'], function($, _) {
return ["translation", function(translation) {
var controller = ['$scope', '$element', '$attrs', function($scope, $element, $attrs) {
$scope.state = "request";
$scope.doAccept = function() {
$scope.state = "accepted";
$scope.doContact(true);
};
$scope.doReject = function() {
$scope.state = "rejected";
$scope.doContact(false);
};
$scope.doContact = function(success) {
var request = $scope.request;
request.Success = !!success;
$scope.sendChat($scope.id, "Contact request answer", {
ContactRequest: request
});
};
}];
return {
scope: true,
restrict: 'EAC',
controller: controller,
replace: false
}
}];
});

6
static/js/directives/directives.js

@ -35,7 +35,8 @@ define([ @@ -35,7 +35,8 @@ define([
'directives/screenshare',
'directives/roombar',
'directives/socialshare',
'directives/page'], function(_, onEnter, onEscape, statusMessage, buddyList, buddyPicture, settings, chat, audioVideo, usability, audioLevel, fileInfo, screenshare, roomBar, socialShare, page) {
'directives/page',
'directives/contactrequest'], function(_, onEnter, onEscape, statusMessage, buddyList, settings, chat, audioVideo, usability, audioLevel, fileInfo, screenshare, roomBar, socialShare, page, contactRequest) {
var directives = {
onEnter: onEnter,
@ -52,7 +53,8 @@ define([ @@ -52,7 +53,8 @@ define([
screenshare: screenshare,
roomBar: roomBar,
socialShare: socialShare,
page: page
page: page,
contactRequest: contactRequest
};
var initialize = function(angModule) {

9
static/js/services/buddylist.js

@ -144,6 +144,11 @@ define(['underscore', 'modernizr', 'avltree', 'text!partials/buddy.html', 'text! @@ -144,6 +144,11 @@ define(['underscore', 'modernizr', 'avltree', 'text!partials/buddy.html', 'text!
var buddyElement = $(event.currentTarget);
buddyElement.scope().doDefault();
}, this));
$element.on("click", ".fa-star-o", _.bind(function(event) {
event.stopPropagation();
var buddyElement = $(event.currentTarget);
buddyElement.scope().doDefaultContact();
}, this));
$element.attr("data-xthreshold", "10");
$element.on("swipeleft", ".buddy", _.bind(function(event) {
event.preventDefault();
@ -195,6 +200,10 @@ define(['underscore', 'modernizr', 'avltree', 'text!partials/buddy.html', 'text! @@ -195,6 +200,10 @@ define(['underscore', 'modernizr', 'avltree', 'text!partials/buddy.html', 'text!
}
return scope.doCall(id);
};
scope.doDefaultContact = function() {
var id = scope.session.Id;
return scope.doContact(id);
};
scope.$on("$destroy", function() {
scope.element = null;
scope.killed = true;

10
static/partials/contactrequest.html

@ -0,0 +1,10 @@ @@ -0,0 +1,10 @@
<div class="contact-request">
<div ng-if="!fromself && request.Userid && !request.Success && request.Token">
<div ng-switch="state">
<div ng-switch-when="request">
<button ng-click="doAccept()" class="btn btn-success btn-sm">Accept</button>
<button ng-click="doReject()" class="btn btn-danger btn-sm">Reject</button>
</div>
</div>
</div>
</div>
Loading…
Cancel
Save