mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2024-10-01 11:49:51 -04:00
Move getLastMessage to modelService.
This commit is contained in:
parent
fbf8003237
commit
547adda446
@ -501,30 +501,7 @@ function(matrixService, $rootScope, $q, $timeout, $filter, mPresence, notificati
|
||||
|
||||
eventContainsBingWord: function(event) {
|
||||
return containsBingWord(event);
|
||||
},
|
||||
|
||||
/**
|
||||
* Return the last message event of a room
|
||||
* @param {String} room_id the room id
|
||||
* @param {Boolean} filterFake true to not take into account fake messages
|
||||
* @returns {undefined | Event} the last message event if available
|
||||
*/
|
||||
getLastMessage: function(room_id, filterEcho) {
|
||||
var lastMessage;
|
||||
|
||||
var events = modelService.getRoom(room_id).events;
|
||||
for (var i = events.length - 1; i >= 0; i--) {
|
||||
var message = events[i];
|
||||
|
||||
if (!filterEcho || undefined === message.echo_msg_state) {
|
||||
lastMessage = message;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return lastMessage;
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
}]);
|
||||
|
@ -307,6 +307,29 @@ angular.module('modelService', [])
|
||||
}
|
||||
|
||||
return memberCount;
|
||||
},
|
||||
|
||||
/**
|
||||
* Return the last message event of a room
|
||||
* @param {String} room_id the room id
|
||||
* @param {Boolean} filterFake true to not take into account fake messages
|
||||
* @returns {undefined | Event} the last message event if available
|
||||
*/
|
||||
getLastMessage: function(room_id, filterEcho) {
|
||||
var lastMessage;
|
||||
|
||||
var events = this.getRoom(room_id).events;
|
||||
for (var i = events.length - 1; i >= 0; i--) {
|
||||
var message = events[i];
|
||||
|
||||
// TODO: define a better marker than echo_msg_state
|
||||
if (!filterEcho || undefined === message.echo_msg_state) {
|
||||
lastMessage = message;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return lastMessage;
|
||||
}
|
||||
|
||||
};
|
||||
|
@ -17,11 +17,11 @@
|
||||
'use strict';
|
||||
|
||||
angular.module('RecentsController', ['matrixService', 'matrixFilter'])
|
||||
.controller('RecentsController', ['$rootScope', '$scope', 'eventHandlerService', 'modelService', 'recentsService',
|
||||
function($rootScope, $scope, eventHandlerService, modelService, recentsService) {
|
||||
.controller('RecentsController', ['$rootScope', '$scope', 'modelService', 'recentsService',
|
||||
function($rootScope, $scope, modelService, recentsService) {
|
||||
|
||||
// Expose the service to the view
|
||||
$scope.eventHandlerService = eventHandlerService;
|
||||
$scope.modelService = modelService;
|
||||
|
||||
// retrieve all rooms and expose them
|
||||
$scope.rooms = modelService.getRooms();
|
||||
|
@ -17,7 +17,7 @@
|
||||
'use strict';
|
||||
|
||||
angular.module('RecentsController')
|
||||
.filter('orderRecents', ["matrixService", "eventHandlerService", "modelService", function(matrixService, eventHandlerService, modelService) {
|
||||
.filter('orderRecents', ["matrixService", "modelService", function(matrixService, modelService) {
|
||||
return function(rooms) {
|
||||
var user_id = matrixService.config().user_id;
|
||||
|
||||
@ -39,7 +39,7 @@ angular.module('RecentsController')
|
||||
room.recent.inviter = member.user_id;
|
||||
}
|
||||
// Count users here
|
||||
// TODO: Compute it directly in eventHandlerService
|
||||
// TODO: Compute it directly in modelService
|
||||
room.recent.numUsersInRoom = modelService.getUserCountInRoom(room_id);
|
||||
|
||||
filtered.push(room);
|
||||
@ -54,8 +54,8 @@ angular.module('RecentsController')
|
||||
// The room with the latest message at first
|
||||
filtered.sort(function (roomA, roomB) {
|
||||
|
||||
var lastMsgRoomA = eventHandlerService.getLastMessage(roomA.room_id, true);
|
||||
var lastMsgRoomB = eventHandlerService.getLastMessage(roomB.room_id, true);
|
||||
var lastMsgRoomA = modelService.getLastMessage(roomA.room_id, true);
|
||||
var lastMsgRoomB = modelService.getLastMessage(roomB.room_id, true);
|
||||
|
||||
// Invite message does not have a body message nor ts
|
||||
// Puth them at the top of the list
|
||||
|
@ -16,7 +16,7 @@
|
||||
<td class="recentsRoomSummaryTS">
|
||||
<!-- Use a temp var as alias to the last room message.
|
||||
Declaring it in this way ensures the data-binding -->
|
||||
{{ lastMsg = eventHandlerService.getLastMessage(room.room_id, true);"" }}
|
||||
{{ lastMsg = modelService.getLastMessage(room.room_id, true);"" }}
|
||||
|
||||
{{ (lastMsg.origin_server_ts) | date:'MMM d HH:mm' }}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user