Skip to content

Commit

Permalink
Fixed message compatibility issue with mobile
Browse files Browse the repository at this point in the history
  • Loading branch information
ben3 authored and ben3 committed Apr 24, 2019
1 parent fb3dad3 commit 6106d77
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 24 deletions.
2 changes: 1 addition & 1 deletion app/dist/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
messagingSenderId: "1088435112418"
},

rootPath: '19_05_web',
rootPath: '19_05_web_test',

facebookAppID: '735373466519297',

Expand Down
6 changes: 3 additions & 3 deletions app/js/controllers/user-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ angular.module('myApp.controllers').controller('UserListController', ['$scope',
// TODO: A bit hacky
$scope.$on(RoomUpdatedNotification, function (event, room) {
Log.notification(RoomUpdatedNotification, 'UserListController');
if(room == $scope.room) {
if(room === $scope.room) {
$scope.updateList();
}
});
Expand Down Expand Up @@ -60,11 +60,11 @@ angular.module('myApp.controllers').controller('UserListController', ['$scope',
var aOnline = OnlineConnector.onlineUsers[user1.uid()];
var bOnline = OnlineConnector.onlineUsers[user2.uid()];

if(aOnline != bOnline) {
if(aOnline !== bOnline) {
return aOnline ? 1 : -1;
}
else {
if(user1.getName() != user2.getName()) {
if(user1.getName() !== user2.getName()) {
return user1.getName() > user2.getName() ? 1 : -1;
}
return 0;
Expand Down
33 changes: 22 additions & 11 deletions app/js/entities/message.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,7 @@ angular.module('myApp.services').factory('Message', ['$rootScope', '$q', '$sce',

if(this.type() == MessageTypeImage || this.type() == MessageTypeFile) {
// Get the image and thumbnail URLs
var json = meta[messageJSONv2] || meta[messageJSON];
if(typeof json === 'string') {
json = JSON.parse(json)
}
let json = meta[messageJSONv2];

if(json) {
if(this.type() == MessageTypeImage) {
Expand Down Expand Up @@ -111,11 +108,27 @@ angular.module('myApp.services').factory('Message', ['$rootScope', '$q', '$sce',
},

setText: function (text) {
this.setMetaValue(messagePayload, text);
this.setJSONValue(messageText, text);
},

text: function() {
return this.metaValue(messagePayload);
return this.getJSONValue(messageText);
},

getMetaValue: function (key) {
return this.meta[key];
},

setMetaValue: function (key, value) {
this.meta[key] = value;
},

getJSONValue: function (key) {
return this.getMetaValue(messageJSONv2)[key];
},

setJSONValue: function (key, value) {
this.getMetaValue(messageJSONv2)[key] = value;
},

type: function () {
Expand Down Expand Up @@ -153,6 +166,8 @@ angular.module('myApp.services').factory('Message', ['$rootScope', '$q', '$sce',
}




};

// Static methods
Expand All @@ -170,7 +185,6 @@ angular.module('myApp.services').factory('Message', ['$rootScope', '$q', '$sce',
json[messageImageWidth] = width;
json[messageImageHeight] = height;

m.meta[messageJSON] = JSON.stringify(json);
m.meta[messageJSONv2] = json;

return m;
Expand All @@ -186,7 +200,6 @@ angular.module('myApp.services').factory('Message', ['$rootScope', '$q', '$sce',
json[messageMimeType] = mimeType;
json[messageFileURL] = fileURL;

m.meta[messageJSON] = JSON.stringify(json);
m.meta[messageJSONv2] = json;

return m;
Expand All @@ -198,13 +211,11 @@ angular.module('myApp.services').factory('Message', ['$rootScope', '$q', '$sce',
};

m.meta[messageUID] = uid;
m.meta[messagePayload] = text;
m.meta[messageJSON] = {};

var json = {};
json[messageText] = text;

m.meta[messageJSON] = JSON.stringify(json);
m.meta[messageJSONv2] = json;
m.meta[messageType] = type;
m.meta[messageTime] = firebase.database.ServerValue.TIMESTAMP;

Expand Down
12 changes: 6 additions & 6 deletions app/js/entities/room.js
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ angular.module('myApp.services').factory('Room', ['$rootScope','$timeout','$q',
Room.prototype.lastMessageText = function () {
if(this.lastMessageExists()) {
if(this.lastMessageType() == MessageTypeText) {
return this.lastMessageMeta[messagePayload];
return this.lastMessageMeta[messageJSONv2][messageText];
}
if(this.lastMessageType() == MessageTypeImage) {
return "Image";
Expand Down Expand Up @@ -1218,21 +1218,21 @@ angular.module('myApp.services').factory('Room', ['$rootScope','$timeout','$q',

Room.prototype.addMessageMeta = function (mid, val, serialization, silent) {

if(!val || !val[messagePayload] || val[messagePayload].length === 0) {
return false;
}
// if(!val || !val[messagePayload] || val[messagePayload].length === 0) {
// return false;
// }

// Check that the message doesn't already exist
for(var i = 0; i < this.messages.length; i++) {
if(this.messages[i].mid == mid) {
if(this.messages[i].mid === mid) {
return false;
}
}

if(this.lastMessage) {
// Sometimes we get double messages
// check that this message hasn't been added already
if(this.lastMessage.mid == mid) {
if(this.lastMessage.mid === mid) {
return false;
}
}
Expand Down
2 changes: 0 additions & 2 deletions app/js/services/defines.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ let CreatorEntityID = "creator-entity-id";
let messageUID = "user-firebase-id";
//let messageRID = "rid";
let messageType = "type";
let messagePayload = "payload";
let messageTime = "date";
let messageJSON = "JSON";
let messageJSONv2 = "json_v2";
let messageUserName = "userName";
let messageUserFirebaseID = "user-firebase-id";
Expand Down
2 changes: 1 addition & 1 deletion app/js/services/state-manager.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

angular.module('myApp.services').factory('StateManager', ['$rootScope', 'FriendsConnector', 'Config', 'Room', 'User', 'Cache', 'RoomStore', 'UserStore', 'RoomPositionManager', 'OnlineConnector', 'PublicRoomsConnector', 'Paths', 'RoomOpenQueue',
angular.module('myApp.services').service('StateManager', ['$rootScope', 'FriendsConnector', 'Config', 'Room', 'User', 'Cache', 'RoomStore', 'UserStore', 'RoomPositionManager', 'OnlineConnector', 'PublicRoomsConnector', 'Paths', 'RoomOpenQueue',
function ($rootScope, FriendsConnector, Config, Room, User, Cache, RoomStore, UserStore, RoomPositionManager, OnlineConnector, PublicRoomsConnector, Paths, RoomOpenQueue) {
return {

Expand Down

0 comments on commit 6106d77

Please sign in to comment.