-
Notifications
You must be signed in to change notification settings - Fork 281
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Add support for Teams Read Receipt event * Update botbuilder.api.md
- Loading branch information
1 parent
2e4b73a
commit 5ee4dac
Showing
6 changed files
with
165 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
libraries/botframework-connector/src/teams/readReceiptInfo.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/** | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. | ||
*/ | ||
|
||
/** | ||
* General information about a read receipt. | ||
*/ | ||
export class ReadReceiptInfo { | ||
/** | ||
* The id of the last read message. | ||
*/ | ||
lastReadMessageId: string; | ||
|
||
/** | ||
* Initializes a new instance of the ReadReceiptInfo class. | ||
* | ||
* @param lastReadMessageId Optional. The id of the last read message. | ||
*/ | ||
constructor(lastReadMessageId?: string) { | ||
this.lastReadMessageId = lastReadMessageId; | ||
} | ||
|
||
/** | ||
* Helper method useful for determining if a message has been read. This method | ||
* converts the strings to numbers. If the compareMessageId is less than or equal to | ||
* the lastReadMessageId, then the message has been read. | ||
* | ||
* @param compareMessageId The id of the message to compare. | ||
* @param lastReadMessageId The id of the last message read by the user. | ||
* @returns True if the compareMessageId is less than or equal to the lastReadMessageId. | ||
*/ | ||
static isMessageRead(compareMessageId: string, lastReadMessageId: string): boolean { | ||
if ( | ||
compareMessageId && | ||
compareMessageId.trim().length > 0 && | ||
lastReadMessageId && | ||
lastReadMessageId.trim().length > 0 | ||
) { | ||
const compareMessageIdNum = Number(compareMessageId); | ||
const lastReadMessageIdNum = Number(lastReadMessageId); | ||
|
||
if (compareMessageIdNum && lastReadMessageIdNum) { | ||
return compareMessageIdNum <= lastReadMessageIdNum; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
/** | ||
* Helper method useful for determining if a message has been read. | ||
* If the compareMessageId is less than or equal to the lastReadMessageId, then the message has been read. | ||
* | ||
* @param compareMessageId The id of the message to compare. | ||
* @returns True if the compareMessageId is less than or equal to the lastReadMessageId. | ||
*/ | ||
isMessageRead(compareMessageId: string): boolean { | ||
return ReadReceiptInfo.isMessageRead(compareMessageId, this.lastReadMessageId); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
libraries/botframework-connector/tests/teams/readReceiptInfo.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
const assert = require('assert'); | ||
const { ReadReceiptInfo } = require('../..'); | ||
|
||
describe('ReadReceiptInfo', function () { | ||
const testCases = [ | ||
{ title: 'compare msg equal to last', compare: '1000', lastRead: '1000', isRead: true }, | ||
{ title: 'compare msg < than last', compare: '1000', lastRead: '1001', isRead: true }, | ||
{ title: 'compare msg > than last', compare: '1001', lastRead: '1000', isRead: false }, | ||
{ title: 'null compare msg', compare: null, lastRead: '1000', isRead: false }, | ||
{ title: 'null last msg', compare: '1000', lastRead: null, isRead: false }, | ||
]; | ||
|
||
testCases.map((testData) => { | ||
it(testData.title, function () { | ||
const readReceipt = new ReadReceiptInfo(testData.lastRead); | ||
|
||
assert.strictEqual(readReceipt.lastReadMessageId, testData.lastRead); | ||
assert.strictEqual(readReceipt.isMessageRead(testData.compare), testData.isRead); | ||
assert.strictEqual(ReadReceiptInfo.isMessageRead(testData.compare, testData.lastRead), testData.isRead); | ||
}); | ||
}); | ||
}); |