From ab3e5673b8baa46c5ae725e8e0a36678072effa8 Mon Sep 17 00:00:00 2001 From: Simon Eisenmann Date: Sun, 25 May 2014 20:04:16 +0200 Subject: [PATCH] Implemented first simple Ui for contacts in chat. --- src/app/spreed-webrtc-server/channeling.go | 1 + src/app/spreed-webrtc-server/contact.go | 6 +-- src/app/spreed-webrtc-server/hub.go | 8 +-- src/app/spreed-webrtc-server/server.go | 2 + static/js/controllers/chatroomcontroller.js | 39 +++++++++++++- static/js/directives/buddylist.js | 9 ++++ static/js/directives/chat.js | 17 ++++++ static/js/directives/contactrequest.js | 57 +++++++++++++++++++++ static/js/directives/directives.js | 6 ++- static/js/services/buddylist.js | 9 ++++ static/partials/contactrequest.html | 10 ++++ 11 files changed, 153 insertions(+), 11 deletions(-) create mode 100644 static/js/directives/contactrequest.js create mode 100644 static/partials/contactrequest.html diff --git a/src/app/spreed-webrtc-server/channeling.go b/src/app/spreed-webrtc-server/channeling.go index b281a785..3ad86555 100644 --- a/src/app/spreed-webrtc-server/channeling.go +++ b/src/app/spreed-webrtc-server/channeling.go @@ -119,6 +119,7 @@ type DataFileInfo struct { type DataContactRequest struct { Id string Success bool + Userid string `json:",omitempty"` Token string `json:",omitempty"` } diff --git a/src/app/spreed-webrtc-server/contact.go b/src/app/spreed-webrtc-server/contact.go index f3ebaa09..940015e4 100644 --- a/src/app/spreed-webrtc-server/contact.go +++ b/src/app/spreed-webrtc-server/contact.go @@ -24,7 +24,7 @@ package main import () type Contact struct { - a string - b string - ok bool + A string + B string + Ok bool } diff --git a/src/app/spreed-webrtc-server/hub.go b/src/app/spreed-webrtc-server/hub.go index f9848303..b86cab30 100644 --- a/src/app/spreed-webrtc-server/hub.go +++ b/src/app/spreed-webrtc-server/hub.go @@ -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 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 != "" { diff --git a/src/app/spreed-webrtc-server/server.go b/src/app/spreed-webrtc-server/server.go index 4cd77ab1..742bdbd5 100644 --- a/src/app/spreed-webrtc-server/server.go +++ b/src/app/spreed-webrtc-server/server.go @@ -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) diff --git a/static/js/controllers/chatroomcontroller.js b/static/js/controllers/chatroomcontroller.js index 74c66656..7b88dce7 100644 --- a/static/js/controllers/chatroomcontroller.js +++ b/static/js/controllers/chatroomcontroller.js @@ -18,7 +18,7 @@ * along with this program. If not, see . * */ -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 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 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 // 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 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; diff --git a/static/js/directives/buddylist.js b/static/js/directives/buddylist.js index 515b311d..6bdcfe95 100644 --- a/static/js/directives/buddylist.js +++ b/static/js/directives/buddylist.js @@ -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); diff --git a/static/js/directives/chat.js b/static/js/directives/chat.js index c40dc455..503132a7 100644 --- a/static/js/directives/chat.js +++ b/static/js/directives/chat.js @@ -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) { diff --git a/static/js/directives/contactrequest.js b/static/js/directives/contactrequest.js new file mode 100644 index 00000000..7fd97276 --- /dev/null +++ b/static/js/directives/contactrequest.js @@ -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 . + * + */ +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 + } + + }]; + +}); diff --git a/static/js/directives/directives.js b/static/js/directives/directives.js index 510fd6e3..6067b952 100644 --- a/static/js/directives/directives.js +++ b/static/js/directives/directives.js @@ -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([ screenshare: screenshare, roomBar: roomBar, socialShare: socialShare, - page: page + page: page, + contactRequest: contactRequest }; var initialize = function(angModule) { diff --git a/static/js/services/buddylist.js b/static/js/services/buddylist.js index 4b4b9f57..ab9cebad 100644 --- a/static/js/services/buddylist.js +++ b/static/js/services/buddylist.js @@ -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! } 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; diff --git a/static/partials/contactrequest.html b/static/partials/contactrequest.html new file mode 100644 index 00000000..cf756d12 --- /dev/null +++ b/static/partials/contactrequest.html @@ -0,0 +1,10 @@ +
+
+
+
+ + +
+
+
+
\ No newline at end of file