浏览代码

Change messageId and msgRefId from number to string

Also add the `sortKey` field.
Danilo Bargen 7 年之前
父节点
当前提交
864bfceb76
共有 5 个文件被更改,包括 30 次插入34 次删除
  1. 1 1
      src/partials/messenger.conversation.html
  2. 6 6
      src/partials/messenger.ts
  3. 11 11
      src/services/webclient.ts
  4. 7 6
      src/threema.d.ts
  5. 5 10
      src/threema/container.ts

+ 1 - 1
src/partials/messenger.conversation.html

@@ -45,7 +45,7 @@
             </li>
             </li>
             <li ng-repeat="message in ctrl.messages" id="message-{{message.id}}">
             <li ng-repeat="message in ctrl.messages" id="message-{{message.id}}">
                 <eee-message eee-receiver="ctrl.receiver" eee-type="ctrl.type" eee-message="message"
                 <eee-message eee-receiver="ctrl.receiver" eee-type="ctrl.type" eee-message="message"
-                             in-view="$inview  && !ctrl.locked && ctrl.msgRead(message.id)"
+                             in-view="$inview  && !ctrl.locked && ctrl.msgRead(message)"
                              in-view-options="{ considerPageVisibility: true }"></eee-message>
                              in-view-options="{ considerPageVisibility: true }"></eee-message>
             </li>
             </li>
             <li ng-if="ctrl.isTyping()" class="typing-indicator">
             <li ng-if="ctrl.isTyping()" class="typing-indicator">

+ 6 - 6
src/partials/messenger.ts

@@ -203,10 +203,10 @@ class ConversationController {
     public receiver: threema.Receiver;
     public receiver: threema.Receiver;
     public type: threema.ReceiverType;
     public type: threema.ReceiverType;
     public message: string = '';
     public message: string = '';
-    public lastReadMsgId: number = 0;
+    public lastReadMsg: threema.Message | null = null;
     public msgReadReportPending = false;
     public msgReadReportPending = false;
     private hasMore = true;
     private hasMore = true;
-    private latestRefMsgId: number = null;
+    private latestRefMsgId: string | null = null;
     private allText: string;
     private allText: string;
     private messages: threema.Message[];
     private messages: threema.Message[];
     public initialData: threema.InitialConversationData = {
     public initialData: threema.InitialConversationData = {
@@ -731,16 +731,16 @@ class ConversationController {
      * A message has been seen. Report it to the app, with a small delay to
      * A message has been seen. Report it to the app, with a small delay to
      * avoid sending too many messages at once.
      * avoid sending too many messages at once.
      */
      */
-    public msgRead(msgId: number): void {
-        if (msgId > this.lastReadMsgId) {
-            this.lastReadMsgId = msgId;
+    public msgRead(message: threema.Message): void {
+        if (this.lastReadMsg === null || message.sortKey > this.lastReadMsg.sortKey) {
+            this.lastReadMsg = message;
         }
         }
         if (!this.msgReadReportPending) {
         if (!this.msgReadReportPending) {
             this.msgReadReportPending = true;
             this.msgReadReportPending = true;
             const receiver = angular.copy(this.receiver);
             const receiver = angular.copy(this.receiver);
             receiver.type = this.type;
             receiver.type = this.type;
             this.$timeout(() => {
             this.$timeout(() => {
-                this.webClientService.requestRead(receiver, this.lastReadMsgId);
+                this.webClientService.requestRead(receiver, this.lastReadMsg);
                 this.msgReadReportPending = false;
                 this.msgReadReportPending = false;
             }, 500);
             }, 500);
         }
         }

+ 11 - 11
src/services/webclient.ts

@@ -765,7 +765,7 @@ export class WebClientService {
      * New messages are not requested this way, instead they are sent as a
      * New messages are not requested this way, instead they are sent as a
      * message update.
      * message update.
      */
      */
-    public requestMessages(receiver: threema.Receiver): number {
+    public requestMessages(receiver: threema.Receiver): string {
         // If there are no more messages available, stop here.
         // If there are no more messages available, stop here.
         if (!this.messages.hasMore(receiver)) {
         if (!this.messages.hasMore(receiver)) {
             this.messages.notify(receiver, this.$rootScope);
             this.messages.notify(receiver, this.$rootScope);
@@ -850,7 +850,7 @@ export class WebClientService {
 
 
         // Create arguments and send request
         // Create arguments and send request
         const args = {
         const args = {
-            [WebClientService.ARGUMENT_MESSAGE_ID]: message.id,
+            [WebClientService.ARGUMENT_MESSAGE_ID]: message.id.toString(),
             [WebClientService.ARGUMENT_RECEIVER_TYPE]: receiver.type,
             [WebClientService.ARGUMENT_RECEIVER_TYPE]: receiver.type,
             [WebClientService.ARGUMENT_RECEIVER_ID]: receiver.id,
             [WebClientService.ARGUMENT_RECEIVER_ID]: receiver.id,
         };
         };
@@ -862,7 +862,7 @@ export class WebClientService {
     /**
     /**
      * Request a blob.
      * Request a blob.
      */
      */
-    public requestBlob(msgId: number, receiver: threema.Receiver): Promise<ArrayBuffer> {
+    public requestBlob(msgId: string, receiver: threema.Receiver): Promise<ArrayBuffer> {
         const cached = this.blobCache.get(msgId + receiver.type);
         const cached = this.blobCache.get(msgId + receiver.type);
 
 
         if (cached !== undefined) {
         if (cached !== undefined) {
@@ -883,7 +883,7 @@ export class WebClientService {
 
 
     /**
     /**
      */
      */
-    public requestRead(receiver, newestMessageId: number): void {
+    public requestRead(receiver, newestMessage: threema.Message): void {
         // Check if the receiver has an avatar or the avatar already exists
         // Check if the receiver has an avatar or the avatar already exists
         // let field: string = highResolution ? 'high' : 'low';
         // let field: string = highResolution ? 'high' : 'low';
         // let data = this.receivers.getData(receiver);
         // let data = this.receivers.getData(receiver);
@@ -898,9 +898,9 @@ export class WebClientService {
         const args = {
         const args = {
             [WebClientService.ARGUMENT_RECEIVER_TYPE]: receiver.type,
             [WebClientService.ARGUMENT_RECEIVER_TYPE]: receiver.type,
             [WebClientService.ARGUMENT_RECEIVER_ID]: receiver.id,
             [WebClientService.ARGUMENT_RECEIVER_ID]: receiver.id,
-            [WebClientService.ARGUMENT_MESSAGE_ID]: newestMessageId,
+            [WebClientService.ARGUMENT_MESSAGE_ID]: newestMessage.id.toString(),
         };
         };
-        this.$log.debug('Sending read request for', receiver.type, receiver.id, '(msg ' + newestMessageId + ')');
+        this.$log.debug('Sending read request for', receiver.type, receiver.id, '(msg ' + newestMessage.id + ')');
         this._sendRequest(WebClientService.SUB_TYPE_READ, args);
         this._sendRequest(WebClientService.SUB_TYPE_READ, args);
     }
     }
 
 
@@ -1075,7 +1075,7 @@ export class WebClientService {
         const args = {
         const args = {
             [WebClientService.ARGUMENT_RECEIVER_TYPE]: receiver.type,
             [WebClientService.ARGUMENT_RECEIVER_TYPE]: receiver.type,
             [WebClientService.ARGUMENT_RECEIVER_ID]: receiver.id,
             [WebClientService.ARGUMENT_RECEIVER_ID]: receiver.id,
-            [WebClientService.ARGUMENT_MESSAGE_ID]: message.id,
+            [WebClientService.ARGUMENT_MESSAGE_ID]: message.id.toString(),
             [WebClientService.ARGUMENT_MESSAGE_ACKNOWLEDGED]: acknowledged,
             [WebClientService.ARGUMENT_MESSAGE_ACKNOWLEDGED]: acknowledged,
         };
         };
         this._sendRequest(WebClientService.SUB_TYPE_ACK, args);
         this._sendRequest(WebClientService.SUB_TYPE_ACK, args);
@@ -1093,7 +1093,7 @@ export class WebClientService {
         const args = {
         const args = {
             [WebClientService.ARGUMENT_RECEIVER_TYPE]: receiver.type,
             [WebClientService.ARGUMENT_RECEIVER_TYPE]: receiver.type,
             [WebClientService.ARGUMENT_RECEIVER_ID]: receiver.id,
             [WebClientService.ARGUMENT_RECEIVER_ID]: receiver.id,
-            [WebClientService.ARGUMENT_MESSAGE_ID]: message.id,
+            [WebClientService.ARGUMENT_MESSAGE_ID]: message.id.toString(),
         };
         };
         this._sendDelete(WebClientService.SUB_TYPE_MESSAGE, args);
         this._sendDelete(WebClientService.SUB_TYPE_MESSAGE, args);
     }
     }
@@ -1624,7 +1624,7 @@ export class WebClientService {
         const temporaryId = args[WebClientService.ARGUMENT_TEMPORARY_ID];
         const temporaryId = args[WebClientService.ARGUMENT_TEMPORARY_ID];
 
 
         if (data[WebClientService.ARGUMENT_SUCCESS]) {
         if (data[WebClientService.ARGUMENT_SUCCESS]) {
-            const messageId = data[WebClientService.ARGUMENT_MESSAGE_ID];
+            const messageId: string = data[WebClientService.ARGUMENT_MESSAGE_ID];
             if (receiverType === undefined || receiverId === undefined ||
             if (receiverType === undefined || receiverId === undefined ||
                 temporaryId === undefined || messageId === undefined) {
                 temporaryId === undefined || messageId === undefined) {
                 this.$log.warn('Invalid create received [type, id or temporaryId arg ' +
                 this.$log.warn('Invalid create received [type, id or temporaryId arg ' +
@@ -1871,7 +1871,7 @@ export class WebClientService {
         // Unpack required argument fields
         // Unpack required argument fields
         const type = args[WebClientService.ARGUMENT_RECEIVER_TYPE];
         const type = args[WebClientService.ARGUMENT_RECEIVER_TYPE];
         const id = args[WebClientService.ARGUMENT_RECEIVER_ID];
         const id = args[WebClientService.ARGUMENT_RECEIVER_ID];
-        const messageId = args[WebClientService.ARGUMENT_MESSAGE_ID];
+        const messageId: string = args[WebClientService.ARGUMENT_MESSAGE_ID];
 
 
         if (type === undefined || id === undefined || messageId === undefined ) {
         if (type === undefined || id === undefined || messageId === undefined ) {
             this.$log.warn('Invalid thumbnail response, argument field missing');
             this.$log.warn('Invalid thumbnail response, argument field missing');
@@ -1904,7 +1904,7 @@ export class WebClientService {
         // Unpack required argument fields
         // Unpack required argument fields
         const receiverType = args[WebClientService.ARGUMENT_RECEIVER_TYPE];
         const receiverType = args[WebClientService.ARGUMENT_RECEIVER_TYPE];
         const receiverId = args[WebClientService.ARGUMENT_RECEIVER_ID];
         const receiverId = args[WebClientService.ARGUMENT_RECEIVER_ID];
-        const msgId = args[WebClientService.ARGUMENT_MESSAGE_ID];
+        const msgId: string = args[WebClientService.ARGUMENT_MESSAGE_ID];
         if (receiverType === undefined || receiverId === undefined || msgId === undefined) {
         if (receiverType === undefined || receiverId === undefined || msgId === undefined) {
             this.$log.warn('Invalid blob response, argument field missing');
             this.$log.warn('Invalid blob response, argument field missing');
             return {
             return {

+ 7 - 6
src/threema.d.ts

@@ -65,10 +65,11 @@ declare namespace threema {
      */
      */
     interface Message {
     interface Message {
         type: MessageType;
         type: MessageType;
-        id: number;
+        id: string;
         body: string;
         body: string;
         thumbnail?: Thumbnail;
         thumbnail?: Thumbnail;
-        date: string;
+        date?: string;
+        sortKey: number;
         partnerId: string;
         partnerId: string;
         isOutbox: boolean;
         isOutbox: boolean;
         isStatus: boolean;
         isStatus: boolean;
@@ -564,17 +565,17 @@ declare namespace threema {
             contains(receiver: Receiver): boolean;
             contains(receiver: Receiver): boolean;
             hasMore(receiver: Receiver): boolean;
             hasMore(receiver: Receiver): boolean;
             setMore(receiver: Receiver, more: boolean): void;
             setMore(receiver: Receiver, more: boolean): void;
-            getReferenceMsgId(receiver: Receiver): number;
+            getReferenceMsgId(receiver: Receiver): string;
             isRequested(receiver: Receiver): boolean;
             isRequested(receiver: Receiver): boolean;
             setRequested(receiver: Receiver): void;
             setRequested(receiver: Receiver): void;
             clearRequested(receiver): void;
             clearRequested(receiver): void;
             addNewer(receiver: Receiver, messages: Message[]): void;
             addNewer(receiver: Receiver, messages: Message[]): void;
             addOlder(receiver: Receiver, messages: Message[]): void;
             addOlder(receiver: Receiver, messages: Message[]): void;
             update(receiver: Receiver, message: Message): boolean;
             update(receiver: Receiver, message: Message): boolean;
-            setThumbnail(receiver: Receiver, messageId: number, thumbnailImage: string): boolean;
-            remove(receiver: Receiver, messageId: number): boolean;
+            setThumbnail(receiver: Receiver, messageId: string, thumbnailImage: string): boolean;
+            remove(receiver: Receiver, messageId: string): boolean;
             removeTemporary(receiver: Receiver, temporaryMessageId: string): boolean;
             removeTemporary(receiver: Receiver, temporaryMessageId: string): boolean;
-            bindTemporaryToMessageId(receiver: Receiver, temporaryId: string, messageId: number): boolean;
+            bindTemporaryToMessageId(receiver: Receiver, temporaryId: string, messageId: string): boolean;
             notify(receiver: Receiver, $scope: ng.IScope): void;
             notify(receiver: Receiver, $scope: ng.IScope): void;
             register(receiver: Receiver, $scope: ng.IScope, callback: any): Message[];
             register(receiver: Receiver, $scope: ng.IScope, callback: any): Message[];
             updateFirstUnreadMessage(receiver: Receiver);
             updateFirstUnreadMessage(receiver: Receiver);

+ 5 - 10
src/threema/container.ts

@@ -340,7 +340,7 @@ angular.module('3ema.container', [])
     class ReceiverMessages {
     class ReceiverMessages {
 
 
         // The message id used as reference when paging.
         // The message id used as reference when paging.
-        public referenceMsgId: number = null;
+        public referenceMsgId: string = null;
 
 
         // Whether a message request has been sent yet.
         // Whether a message request has been sent yet.
         public requested = false;
         public requested = false;
@@ -464,7 +464,7 @@ angular.module('3ema.container', [])
         /**
         /**
          * Return the reference msg id for the specified receiver.
          * Return the reference msg id for the specified receiver.
          */
          */
-        public getReferenceMsgId(receiver: threema.Receiver): number {
+        public getReferenceMsgId(receiver: threema.Receiver): string {
             return this.getReceiverMessages(receiver).referenceMsgId;
             return this.getReceiverMessages(receiver).referenceMsgId;
         }
         }
 
 
@@ -570,13 +570,8 @@ angular.module('3ema.container', [])
 
 
         /**
         /**
          * Update a thumbnail of a message, if a message was found the method will return true
          * Update a thumbnail of a message, if a message was found the method will return true
-         *
-         * @param receiver
-         * @param messageId
-         * @param thumbnailImage
-         * @returns {boolean}
          */
          */
-        public setThumbnail(receiver: threema.Receiver, messageId: number, thumbnailImage: string): boolean {
+        public setThumbnail(receiver: threema.Receiver, messageId: string, thumbnailImage: string): boolean {
             const list = this.getList(receiver);
             const list = this.getList(receiver);
             for (const message of list) {
             for (const message of list) {
                 if (message.id === messageId) {
                 if (message.id === messageId) {
@@ -598,7 +593,7 @@ angular.module('3ema.container', [])
          * Return a boolean indicating whether the message was found and
          * Return a boolean indicating whether the message was found and
          * removed, or not.
          * removed, or not.
          */
          */
-        public remove(receiver: threema.Receiver, messageId: number): boolean {
+        public remove(receiver: threema.Receiver, messageId: string): boolean {
             const list = this.getList(receiver);
             const list = this.getList(receiver);
             for (let i = 0; i < list.length; i++) {
             for (let i = 0; i < list.length; i++) {
                 if (list[i].id === messageId) {
                 if (list[i].id === messageId) {
@@ -625,7 +620,7 @@ angular.module('3ema.container', [])
             return false;
             return false;
         }
         }
 
 
-        public bindTemporaryToMessageId(receiver: threema.Receiver, temporaryId: string, messageId: number): boolean {
+        public bindTemporaryToMessageId(receiver: threema.Receiver, temporaryId: string, messageId: string): boolean {
             const list = this.getList(receiver);
             const list = this.getList(receiver);
             for (const item of list) {
             for (const item of list) {
                 if (item.temporaryId === temporaryId) {
                 if (item.temporaryId === temporaryId) {