소스 검색

Make message date a number

Danilo Bargen 7 년 전
부모
커밋
18265eb1aa
7개의 변경된 파일53개의 추가작업 그리고 4개의 파일을 삭제
  1. 5 0
      index.html
  2. 13 0
      package-lock.json
  3. 3 1
      package.json
  4. 29 0
      src/app.ts
  5. 1 1
      src/directives/message_date.ts
  6. 1 1
      src/services/message.ts
  7. 1 1
      src/threema.d.ts

+ 5 - 0
index.html

@@ -120,6 +120,11 @@
     <script src="node_modules/angular-translate/dist/angular-translate-loader-static-files/angular-translate-loader-static-files.min.js?v=[[VERSION]]"></script>
     <script src="node_modules/angular-translate/dist/angular-translate-interpolation-messageformat/angular-translate-interpolation-messageformat.min.js?v=[[VERSION]]"></script>
 
+    <!-- Date formatting -->
+    <script src="node_modules/moment/min/moment.min.js?v=[[VERSION]]"></script>
+    <script src="node_modules/moment/locale/de.js?v=[[VERSION]]"></script>
+    <script src="node_modules/angular-moment/angular-moment.min.js?v=[[VERSION]]"></script>
+
     <!-- Other -->
     <script src="node_modules/msgpack-lite/dist/msgpack.min.js?v=[[VERSION]]"></script>
     <script src="node_modules/tweetnacl/nacl-fast.min.js?v=[[VERSION]]"></script>

+ 13 - 0
package-lock.json

@@ -169,6 +169,14 @@
       "integrity": "sha1-oOHdDqVf137np1fXVTbF6WTIb4E=",
       "dev": true
     },
+    "angular-moment": {
+      "version": "1.2.0",
+      "resolved": "https://registry.npmjs.org/angular-moment/-/angular-moment-1.2.0.tgz",
+      "integrity": "sha512-0jm7AfCTk/zbBuVuoz9MecMplGfTQ9Wk9JB8J4qYX9IddcETRukpbKXMy27YTL1wKwYJkRTbGMu/Pb3IXbMfyA==",
+      "requires": {
+        "moment": "2.21.0"
+      }
+    },
     "angular-qrcode": {
       "version": "6.2.1",
       "resolved": "https://registry.npmjs.org/angular-qrcode/-/angular-qrcode-6.2.1.tgz",
@@ -4845,6 +4853,11 @@
         }
       }
     },
+    "moment": {
+      "version": "2.21.0",
+      "resolved": "https://registry.npmjs.org/moment/-/moment-2.21.0.tgz",
+      "integrity": "sha512-TCZ36BjURTeFTM/CwRcViQlfkMvL1/vFISuNLO5GkcVm1+QHfbSiNqZuWeMFjj1/3+uAjXswgRk30j1kkLYJBQ=="
+    },
     "ms": {
       "version": "2.0.0",
       "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",

+ 3 - 1
package.json

@@ -27,8 +27,8 @@
   "homepage": "https://threema.ch/",
   "dependencies": {
     "@saltyrtc/client": "^0.11.0",
-    "@saltyrtc/task-webrtc": "^0.11.0",
     "@saltyrtc/task-relayed-data": "^0.1.3",
+    "@saltyrtc/task-webrtc": "^0.11.0",
     "@types/angular": "^1.6.43",
     "@types/angular-material": "^1.1.58",
     "@types/angular-sanitize": "^1.3.7",
@@ -43,6 +43,7 @@
     "angular-aria": "~1.5.10",
     "angular-material": "=1.1.1",
     "angular-messages": "^1.6.9",
+    "angular-moment": "^1.2.0",
     "angular-qrcode": "~6.2.1",
     "angular-route": "~1.5.10",
     "angular-sanitize": "~1.5.10",
@@ -59,6 +60,7 @@
     "file-saver": "~1.3.3",
     "js-sha256": "~0.3.2",
     "messageformat": "~1.0.2",
+    "moment": "^2.21.0",
     "msgpack-lite": "~0.1.26",
     "node-sass": "^4.7.2",
     "sdp": "~1.3.0",

+ 29 - 0
src/app.ts

@@ -47,6 +47,7 @@ angular.module('3ema', [
     'luegg.directives',
     'pascalprecht.translate',
     'ngMaterial',
+    'angularMoment',
 
     // Own
     '3ema.filters',
@@ -134,4 +135,32 @@ angular.module('3ema', [
     }]);
 }])
 
+.run([
+    '$translate',
+    '$log',
+    'amMoment',
+    'moment',
+    ($translate: ng.translate.ITranslateService, $log: ng.ILogService, amMoment, moment) => {
+        const lang = $translate.proposedLanguage() || $translate.use();
+        $log.debug('Setting locale:', lang);
+        moment.updateLocale('en', {
+            longDateFormat : {
+                L: 'MMM Do YYYY',
+            },
+            calendar: {
+                sameElse: 'L, LT',
+            },
+        });
+        moment.updateLocale('de', {
+            longDateFormat : {
+                L: 'Do MMM YYYY',
+            },
+            calendar: {
+                sameElse: 'L, LT',
+            },
+        });
+        amMoment.changeLocale(lang);
+    },
+])
+
 ;

+ 1 - 1
src/directives/message_date.ts

@@ -23,7 +23,7 @@ export default [
                 message: '=eeeMessage',
             },
             template: `
-                <span>{{ message.date }}</span>
+                <span>{{ message.date | amFromUnix | amCalendar }}</span>
             `,
         };
     },

+ 1 - 1
src/services/message.ts

@@ -162,7 +162,7 @@ export class MessageService {
             state: 'pending',
             id: undefined,
             body: undefined,
-            date: ('0' + now.getHours()).slice(-2) + ':' + ('0' + now.getMinutes()).slice(-2),
+            date: Math.floor(Date.now() / 1000),
             partnerId: receiver.id,
             isStatus: false,
             quote: undefined,

+ 1 - 1
src/threema.d.ts

@@ -68,7 +68,7 @@ declare namespace threema {
         id: string;
         body: string;
         thumbnail?: Thumbnail;
-        date?: string;
+        date?: number;
         sortKey: number;
         partnerId: string;
         isOutbox: boolean;