Skip to content

Commit

Permalink
Bitmessage messaging integrated
Browse files Browse the repository at this point in the history
  • Loading branch information
hoffmabc committed Aug 31, 2014
1 parent c5f2cd4 commit 354ee86
Show file tree
Hide file tree
Showing 5 changed files with 131 additions and 10 deletions.
2 changes: 1 addition & 1 deletion html/composeMessage.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ <h3 class="modal-title">Send Message</h3>
<div class="form-group">
<label for="fromAddress" class="col-sm-1 control-label">From</label>
<div class="col-sm-6">
<p class="form-control-static">{{to_address}}</p>
<p class="form-control-static">{{myself.settings.bitmessage}}</p>
</div>
</div>
<div class="form-group">
Expand Down
4 changes: 4 additions & 0 deletions html/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ app.config(['$routeProvider',
templateUrl: 'partials/arbiter.html',
controller: 'Arbiter'
}).
when('/messages', {
templateUrl: 'partials/messages.html',
controller: 'Messages'
}).
when('/user/:userId/products', {
templateUrl: 'partials/user.html',
controller: 'User'
Expand Down
81 changes: 72 additions & 9 deletions html/js/controllers.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,75 @@
var obControllers = angular.module('obControllers', []);

/**
* Messages controller.
*
* @desc This controller is the messages controller.
* @param {!angular.Scope} $scope
* @constructor
*/
obControllers
.controller('Messages', ['$scope', '$interval', '$routeParams', '$location',
function($scope, $interval, $routeParams, $location) {

$scope.myOrders = []
$scope.ordersPanel = true;
$scope.path = $location.path();
$scope.$emit('sidebar', false);

/**
* Open Websocket and then establish message handlers
* @msg - message from websocket to pass on to handler
*/
var socket = new Connection(function(msg) {

var handlers = {
'load_page': function(msg) { $scope.load_page(msg) },
'messages': function(msg) { $scope.parse_messages(msg) },
}

if(handlers[msg.type]) {
handlers[msg.type](msg);
}

})

$scope.load_page = function(msg) {
$scope.messagesPanel = true;
$scope.queryMessages();
}


$scope.queryMessages = function() {
// Query for messages
var query = {
'type': 'query_messages'
}
console.log('querying messages')
socket.send('query_messages', query)
console.log($scope.myself.messages)

}

$scope.message = {};
$scope.parse_messages = function(msg) {
console.log('parsing messages',msg);
if (msg != null &&
msg.messages != null &&
msg.messages.messages != null &&
msg.messages.messages.inboxMessages != null) {

$scope.messages = msg.messages.messages.inboxMessages;

$scope.message = {};
if (!$scope.$$phase) {
$scope.$apply();
}
}
}

}
]);

/**
* Orders controller.
*
Expand Down Expand Up @@ -1905,15 +1975,6 @@ obControllers
};
};










$scope.ComposeMessageCtrl = function($scope, $modal, $log) {


Expand All @@ -1923,6 +1984,7 @@ obControllers
$scope.subject = args.subject;
$scope.myself = args.myself;


$scope.compose($scope.size, $scope.myself, $scope.bm_address, $scope.subject);
});

Expand Down Expand Up @@ -1950,6 +2012,7 @@ obControllers
};
composeModal.result.then(afterFunc,
function() {
$scope.queryMessages();
$log.info('Modal dismissed at: ' + new Date());
});
};
Expand Down
53 changes: 53 additions & 0 deletions html/partials/messages.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<!-- Messages -->
<div ng-show="messagesPanel" class="animated fadeInLeft">

<div ng-controller="ComposeMessageCtrl">

<h3>Messages</h3>

<div role="alert" class="alert alert-warning">
<div class="row">
<div class="col-sm-10">OpenBazaar uses <strong><a href="https://bitmessage.org/wiki/Main_Page" target="_blank">Bitmessage</a></strong> as our private messaging technology. This is your inbox where all messages from other network members will reside.

<span ng-show="settings.bitmessage">Your Bitmessage address is <strong>{{settings.bitmessage}}</strong></span>
</div>
<div class="col-sm-2" style="text-align:right"><button class="btn btn-info" ng-click="compose('lg', myself, '', null)"><span class="glyphicon glyphicon-pencil"/> Compose</button></div>
</div>
</div>



<div ng-repeat="message in myself.messages">
{{message.text}}
</div>

<div ng-show="messages">
<table class="table table-striped table-bordered" style="margin-top:10px;">
<tr>
<th></th>
<th width="200">Date</th>
<th width="375">From</th>
<th>Subject</th>
<th>Actions</th>
</tr>
<tr ng-repeat="message in messages">
<td width=15><input type="checkbox"/></td>
<td style="border-left:none;">{{message.receivedTime * 1000 | date:'medium'}}</td>
<td style="border-left:none;"><identicon icon-size="32" hash="message.fromAddress" title="{{message.fromAddress}}"></identicon> {{message.fromAddress}}</td>
<td style="border-left:none;"><a href="#"
ng-click="view('lg', myself, settings.bitmessage, message)">{{message.subject}}</a></td>
<td width="40" style="border-left:none;"><a href="#"
ng-click="compose('lg', myself, settings.bitmessage, message)"><button class="btn btn-info">Reply</button></a></td>
</tr>
</table>
</div>

<div class="col-sm-12" ng-show="!messages">
<p>There are no messages for your marketplace.</p>
</div>

</div>

</div>


1 change: 1 addition & 0 deletions node/ws.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ def client_query_messages(self, socket_handler, msg):

# Query bitmessage for messages
messages = self._market.get_messages()
self._log.info('Bitmessages: %s' % messages);

self.send_to_client(None, {"type": "messages", "messages": messages})

Expand Down

0 comments on commit 354ee86

Please sign in to comment.