Skip to content

Commit

Permalink
ES6: migrated "message"
Browse files Browse the repository at this point in the history
  • Loading branch information
Gregor Herdmann committed Apr 18, 2017
1 parent 2ac8e1a commit aeefbb5
Show file tree
Hide file tree
Showing 20 changed files with 395 additions and 345 deletions.
1 change: 0 additions & 1 deletion app/page/template/_dist/app.htm
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,6 @@
<script src="/script/message/MessageCategorization.js"></script>
<script src="/script/message/EphemeralStatusType.js"></script>
<script src="/script/message/StatusType.js"></script>
<script src="/script/message/PingMessageType.js"></script>
<script src="/script/message/ReactionType.js"></script>
<script src="/script/message/SuperType.js"></script>
<script src="/script/message/SystemMessageType.js"></script>
Expand Down
25 changes: 0 additions & 25 deletions app/script/message/CallMessageType.coffee

This file was deleted.

32 changes: 32 additions & 0 deletions app/script/message/CallMessageType.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Wire
* Copyright (C) 2017 Wire Swiss GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses/.
*
*/

'use strict';

window.z = window.z || {};
window.z.message = z.message || {};

/**
* Enum for different call message types.
* @returns {z.message.CALL_MESSAGE_TYPE} Enum of call message types
*/
z.message.CALL_MESSAGE_TYPE = {
ACTIVATED: 'activated',
DEACTIVATED: 'deactivated',
};
26 changes: 0 additions & 26 deletions app/script/message/EphemeralStatusType.coffee

This file was deleted.

34 changes: 34 additions & 0 deletions app/script/message/EphemeralStatusType.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Wire
* Copyright (C) 2017 Wire Swiss GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses/.
*
*/

'use strict';

window.z = window.z || {};
window.z.message = z.message || {};

/**
* Enum of different ephemeral status types.
* @type {z.message.EphemeralStatusType} Enum of ephemeral status types
*/
z.message.EphemeralStatusType = {
ACTIVE: 1,
INACTIVE: 2,
NONE: 0,
TIMED_OUT: 3,
};
77 changes: 0 additions & 77 deletions app/script/message/MessageCategorization.coffee

This file was deleted.

99 changes: 99 additions & 0 deletions app/script/message/MessageCategorization.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/*
* Wire
* Copyright (C) 2017 Wire Swiss GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses/.
*
*/

'use strict';

window.z = window.z || {};
window.z.message = z.message || {};

z.message.MessageCategorization = (function() {

const _check_text = function(event) {
if (event.type === z.event.Backend.CONVERSATION.MESSAGE_ADD) {
let category = z.message.MessageCategory.TEXT;

if (event.data.previews && event.data.previews.length > 0) {
category = category | z.message.MessageCategory.LINK | z.message.MessageCategory.LINK_PREVIEW;
}

return category;
}
};

const _check_image = function(event) {
if (event.type === z.event.Backend.CONVERSATION.ASSET_ADD) {
let category = z.message.MessageCategory.IMAGE;

if (event.data.content_type === 'image/gif') {
category = category | z.message.MessageCategory.GIF;
}

return category;
}
};

const _check_file = function(event) {
if (event.type === z.event.Client.CONVERSATION.ASSET_META) {
return z.message.MessageCategory.FILE;
}
};

const _check_ping = function(event) {
if (event.type === z.event.Backend.CONVERSATION.KNOCK) {
return z.message.MessageCategory.KNOCK;
}
};

const _check_location = function(event) {
if (event.type === z.event.Client.CONVERSATION.LOCATION) {
return z.message.MessageCategory.LOCATION;
}
};

const _category_from_event = function(event) {
try {
let category = z.message.MessageCategory.NONE;

if (event.ephemeral_expires) { // String, Number, true
return z.message.MessageCategory.NONE;
}

for (const check of [_check_text, _check_image, _check_file, _check_ping, _check_location]) {
const temp_category = check(event);
if (temp_category) {
category = temp_category;
break;
}
}

if (_.isObject(event.reactions) && (Object.keys(event.reactions).length > 0)) {
category = category | z.message.MessageCategory.LIKED;
}

return category;

} catch (error) {
return z.message.MessageCategory.UNDEFINED;
}
};

return {
category_from_event: _category_from_event,
};
})();
37 changes: 0 additions & 37 deletions app/script/message/MessageCategory.coffee

This file was deleted.

45 changes: 45 additions & 0 deletions app/script/message/MessageCategory.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Wire
* Copyright (C) 2017 Wire Swiss GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses/.
*
*/

'use strict';

window.z = window.z || {};
window.z.message = z.message || {};

/**
* Enum for different message categories.
* @returns {z.message.MessageCategory} Enum of message categories
*/
z.message.MessageCategory = {
AUDIO: 1 << 10,
EXCLUDED: 1 << 1,
FILE: 1 << 9,
GIF: 1 << 8,
IMAGE: 1 << 7,
KNOCK: 1 << 2,
LIKED: 1 << 13,
LINK: 1 << 5,
LINK_PREVIEW: 1 << 6,
LOCATION: 1 << 12,
NONE: 0,
SYSTEM: 1 << 3,
TEXT: 1 << 4,
UNDEFINED: 1 << 0,
VIDEO: 1 << 11,
};
Loading

0 comments on commit aeefbb5

Please sign in to comment.