-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add blocking interface to request a user (#368)
* test TCCCore callback and TCCUser constructor (+5 squashed commit) Squashed commit: [28b327f] refactor TCCCore [153d794] Show message author in group chat notification [54d9c3a] add user api call with callback for new messages [fdb11cb] fix sender user id key in message constructor [54f21dd] Message includes chat object (+1 squashed commits) Squashed commits: [f5056f3] show title of chat in notification * use TCCChat>>newFromNewChatEvent constructor in TCCChatsHandler * Notification shows sender, chat and more of the message * TCCNullMessage does not rely on the chat inst var * fixed most linter tests * fix some remarks of PR #339 * test API assumptions * integrate pr feedback * fix last remarks of PR #339 * fixed most linter tests * fixed typo in method names * Swalint considered harmful * test Notification * You can't see me * beautiful acceptance tests * im done with this linter * go return yourself * test message chatID method * exclude TCTAcceptanceTests from long method test in linter; remove too many inst vars test * rename testing* -> mock* in TCTAcceptanceTests; use ifFalse in TCUNotification>>chatTitle * Added class Users and updated Core for promise handling. * Added test for getUserFor in TCCUsers. * integrate users getUserFor: into TCCCore * use TCTNoTDLibCore in acceptance tests * fix regressions from merge * remove dead code and move mocks to TCTMocks * use TCTNoTDLibCore only in specific test in TCTAcceptanceTests * remove dead code, use NoTDLibCore in Users test (we mock all events) Co-authored-by: permler <[email protected]> Co-authored-by: Raphael Kunert <[email protected]>
- Loading branch information
1 parent
4de4626
commit 89884b0
Showing
41 changed files
with
215 additions
and
44 deletions.
There are no files selected for viewing
6 changes: 3 additions & 3 deletions
6
packages/TelegramClient-Core.package/TCCChatsHandler.class/instance/addNewMessage.from..st
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 |
---|---|---|
@@ -1,9 +1,9 @@ | ||
events | ||
addNewMessage: aMessageEvent from: aUser | ||
addNewMessage: aMessageJSONObject from: aUser | ||
|
||
| chat message | | ||
chat := self app chats getChat: (aMessageEvent at: 'chat_id'). | ||
message := TCCMessage newFromMessageEvent: aMessageEvent in: chat from: aUser. | ||
chat := self app chats getChat: (aMessageJSONObject at: 'chat_id'). | ||
message := TCCMessage newFromMessageEvent: aMessageJSONObject in: chat from: aUser. | ||
|
||
chat addNewestMessage: message. | ||
self app triggerEvent: #newMessageReceived with: message. |
7 changes: 2 additions & 5 deletions
7
...ages/TelegramClient-Core.package/TCCChatsHandler.class/instance/handleNewMessage.from..st
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 |
---|---|---|
@@ -1,7 +1,4 @@ | ||
event handling | ||
handleNewMessage: anEvent from: aUserEvent | ||
handleNewMessage: aMessageJSONObject from: aUser | ||
|
||
| message user | | ||
message := anEvent at: 'message'. | ||
user := TCCUser newFrom: aUserEvent. | ||
self addNewMessage: message from: user. | ||
self addNewMessage: aMessageJSONObject from: aUser |
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
2 changes: 1 addition & 1 deletion
2
packages/TelegramClient-Core.package/TCCCore.class/instance/handleEvent..st
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
event handling | ||
events | ||
handleEvent: anEvent | ||
|
||
| update | | ||
|
10 changes: 4 additions & 6 deletions
10
packages/TelegramClient-Core.package/TCCCore.class/instance/handleMessageEvent..st
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 |
---|---|---|
@@ -1,9 +1,7 @@ | ||
events | ||
handleMessageEvent: anEvent | ||
|
||
|callbackID message| | ||
message := anEvent at: 'message'. | ||
callbackID := (message at: 'id') asString, (message at: 'chat_id'). | ||
self pendingRequests at: callbackID put: [:aUserEvent | | ||
self chatsHandler handleNewMessage: anEvent from: aUserEvent]. | ||
self getUser: ((message at: 'sender') at: 'user_id') with: callbackID | ||
| message userID | | ||
message := anEvent at: 'message'. | ||
userID := (message at: 'sender') at: 'user_id'. | ||
[self chatsHandler handleNewMessage: message from: (self users getUserFor: userID)] fork |
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
4 changes: 4 additions & 0 deletions
4
packages/TelegramClient-Core.package/TCCCore.class/instance/registerCallback.with..st
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,4 @@ | ||
utility | ||
registerCallback: aClosure with: aCallbackId | ||
|
||
self pendingRequests at: (aCallbackId asString) put: aClosure |
2 changes: 1 addition & 1 deletion
2
...e/TCCCore.class/instance/getUser.with..st → ...CCore.class/instance/requestUser.with..st
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
4 changes: 4 additions & 0 deletions
4
packages/TelegramClient-Core.package/TCCCore.class/instance/users..st
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,4 @@ | ||
accessing | ||
users: aDictionary | ||
|
||
users := aDictionary |
4 changes: 4 additions & 0 deletions
4
packages/TelegramClient-Core.package/TCCCore.class/instance/users.st
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,4 @@ | ||
accessing | ||
users | ||
|
||
^ users |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
"client", | ||
"authHandler", | ||
"chatsHandler", | ||
"users", | ||
"chats", | ||
"loggedInUserID", | ||
"pendingRequests" ], | ||
|
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 @@ | ||
Cache of Users allowing for synchronous access. |
4 changes: 4 additions & 0 deletions
4
packages/TelegramClient-Core.package/TCCUsers.class/instance/core..st
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,4 @@ | ||
accessing | ||
core: aCore | ||
|
||
core := aCore |
4 changes: 4 additions & 0 deletions
4
packages/TelegramClient-Core.package/TCCUsers.class/instance/core.st
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,4 @@ | ||
accessing | ||
core | ||
|
||
^ core |
10 changes: 10 additions & 0 deletions
10
packages/TelegramClient-Core.package/TCCUsers.class/instance/getUserFor..st
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,10 @@ | ||
accessing | ||
getUserFor: aUserId | ||
|
||
| promise | | ||
promise := self at: aUserId ifAbsent: | ||
[self at: aUserId put: Promise new. | ||
self requestUserFor: aUserId. | ||
self at: aUserId]. | ||
promise wait. | ||
^ (promise value) |
9 changes: 9 additions & 0 deletions
9
packages/TelegramClient-Core.package/TCCUsers.class/instance/requestUserFor..st
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,9 @@ | ||
utility | ||
requestUserFor: aUserId | ||
|
||
self core | ||
registerCallback: | ||
[:userEvent | (self at: aUserId) resolveWith: (TCCUser newFrom: userEvent)] | ||
with: (aUserId asString). | ||
|
||
self core requestUser: aUserId with: aUserId |
8 changes: 8 additions & 0 deletions
8
packages/TelegramClient-Core.package/TCCUsers.class/methodProperties.json
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,8 @@ | ||
{ | ||
"class" : { | ||
}, | ||
"instance" : { | ||
"core" : "RK 5/19/2021 10:34", | ||
"core:" : "RK 5/19/2021 10:34", | ||
"getUserFor:" : "pk 5/30/2021 12:55", | ||
"requestUserFor:" : "pk 5/30/2021 13:19" } } |
14 changes: 14 additions & 0 deletions
14
packages/TelegramClient-Core.package/TCCUsers.class/properties.json
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,14 @@ | ||
{ | ||
"category" : "TelegramClient-Core", | ||
"classinstvars" : [ | ||
], | ||
"classvars" : [ | ||
], | ||
"commentStamp" : "RK 5/19/2021 09:58", | ||
"instvars" : [ | ||
"core" ], | ||
"name" : "TCCUsers", | ||
"pools" : [ | ||
], | ||
"super" : "Dictionary", | ||
"type" : "normal" } |
1 change: 0 additions & 1 deletion
1
packages/TelegramClient-Tests.package/TCTAcceptanceTests.class/instance/core..st
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 |
---|---|---|
@@ -1,5 +1,4 @@ | ||
accessing | ||
core: aCore | ||
|
||
aCore when: #newMessageReceived send: #newMessageReceived: to: self. | ||
core := aCore. |
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
25 changes: 15 additions & 10 deletions
25
...ages/TelegramClient-Tests.package/TCTAcceptanceTests.class/instance/testMessageAuthors.st
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 |
---|---|---|
@@ -1,17 +1,22 @@ | ||
testing | ||
testMessageAuthors | ||
|
||
| message user chat_id notification | | ||
| message user notification overrideCore | | ||
"Fake core because some other tests need a working one" | ||
overrideCore := TCTNoTDLibCore new. | ||
overrideCore chats add: (TCCChat new id: TCTMocks mockChatID). | ||
overrideCore when: #newMessageReceived send: #newMessageReceived: to: self. | ||
|
||
self receivedMessage: nil. | ||
chat_id := ((self core chats) first) id. | ||
message := TCTMocks mockMessageEventFrom: chat_id. | ||
message := TCTMocks mockMessageEventFrom: TCTMocks mockChatID. | ||
|
||
self core handleEvent: message. | ||
user := TCTMocks mockUserWith: (TCTMocks mockMessageID asString, chat_id). | ||
self core handleEvent: user. | ||
|
||
overrideCore handleEvent: message. | ||
2 seconds wait. | ||
user := TCTMocks mockUserEvent. | ||
overrideCore handleEvent: user. | ||
1 second wait. | ||
notification := TCUNotification newWithMessage: self receivedMessage. | ||
|
||
self assert: (TCTMocks mockUserFullName = (notification sender fullName)). | ||
self assert: (chat_id = (notification chat id)). | ||
self assert: (TCTMocks mockMessageText = (notification message message)). | ||
self assert: (TCTMocks mockUserFullName) equals: (notification sender fullName). | ||
self assert: (TCTMocks mockChatID) equals: (notification chat id). | ||
self assert: (TCTMocks mockMessageText) equals: (notification message message) |
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
6 changes: 3 additions & 3 deletions
6
...age/TCTMocks.class/class/mockUserWith..st → ...age/TCTMocks.class/class/mockUserEvent.st
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 |
---|---|---|
@@ -1,11 +1,11 @@ | ||
user | ||
mockUserWith: anExtra | ||
accessing | ||
mockUserEvent | ||
|
||
^ (TCCEvent newFromTDLibEvent: (Dictionary newFrom: { | ||
'@type' -> 'user'. | ||
'id' -> self mockUserID. | ||
'first_name' -> self mockUserFirstName. | ||
'last_name' -> self mockUserLastName. | ||
'username' -> self mockUsername. | ||
'@extra' -> anExtra | ||
'@extra' -> (self mockUserID asString) | ||
})) |
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
1 change: 1 addition & 0 deletions
1
packages/TelegramClient-Tests.package/TCTNoTDLibCore.class/README.md
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 @@ | ||
A TCTNoTDLibCore is a TCCCore without a client. It cannot make requests and has to be fed every event. |
11 changes: 11 additions & 0 deletions
11
packages/TelegramClient-Tests.package/TCTNoTDLibCore.class/instance/initialize.st
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,11 @@ | ||
initialization | ||
initialize | ||
|
||
"override initialize to work without client or tdlib" | ||
self | ||
client: nil; | ||
initializeHandlers; | ||
chats: TCCChats newWithDefaultSorting; | ||
loggedInUserID: 0; | ||
pendingRequests: Dictionary new; | ||
users: (TCCUsers new core: self). |
6 changes: 6 additions & 0 deletions
6
packages/TelegramClient-Tests.package/TCTNoTDLibCore.class/instance/initializeHandlers.st
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,6 @@ | ||
initialization | ||
initializeHandlers | ||
|
||
self | ||
chatsHandler: (TCCChatsHandler new | ||
app: self). |
4 changes: 4 additions & 0 deletions
4
packages/TelegramClient-Tests.package/TCTNoTDLibCore.class/instance/requestUser.with..st
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,4 @@ | ||
events | ||
requestUser: aUserId with: aCallbackID | ||
|
||
^ self |
7 changes: 7 additions & 0 deletions
7
packages/TelegramClient-Tests.package/TCTNoTDLibCore.class/methodProperties.json
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,7 @@ | ||
{ | ||
"class" : { | ||
}, | ||
"instance" : { | ||
"initialize" : "pk 5/30/2021 20:52", | ||
"initializeHandlers" : "pk 5/21/2021 09:46", | ||
"requestUser:with:" : "pk 5/21/2021 10:18" } } |
14 changes: 14 additions & 0 deletions
14
packages/TelegramClient-Tests.package/TCTNoTDLibCore.class/properties.json
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,14 @@ | ||
{ | ||
"category" : "TelegramClient-Tests", | ||
"classinstvars" : [ | ||
], | ||
"classvars" : [ | ||
], | ||
"commentStamp" : "pk 5/21/2021 09:45", | ||
"instvars" : [ | ||
], | ||
"name" : "TCTNoTDLibCore", | ||
"pools" : [ | ||
], | ||
"super" : "TCCCore", | ||
"type" : "normal" } |
1 change: 1 addition & 0 deletions
1
packages/TelegramClient-Tests.package/TCTUsersTests.class/README.md
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 @@ | ||
test TCCUsers |
4 changes: 4 additions & 0 deletions
4
packages/TelegramClient-Tests.package/TCTUsersTests.class/instance/core..st
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,4 @@ | ||
accessing | ||
core: aTCCCore | ||
|
||
core := aTCCCore |
4 changes: 4 additions & 0 deletions
4
packages/TelegramClient-Tests.package/TCTUsersTests.class/instance/core.st
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,4 @@ | ||
accessing | ||
core | ||
|
||
^ core |
5 changes: 5 additions & 0 deletions
5
packages/TelegramClient-Tests.package/TCTUsersTests.class/instance/setUp.st
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,5 @@ | ||
running | ||
setUp | ||
|
||
self core: TCTNoTDLibCore new. | ||
self users: self core users. |
15 changes: 15 additions & 0 deletions
15
packages/TelegramClient-Tests.package/TCTUsersTests.class/instance/testGetUserFor.st
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,15 @@ | ||
testing | ||
testGetUserFor | ||
|
||
| user | | ||
user := nil. | ||
[user := self users getUserFor: TCTMocks mockUserID.] fork. | ||
1 seconds wait. | ||
|
||
self core handleEvent: TCTMocks mockUserEvent. | ||
1 seconds wait. | ||
|
||
self assert: TCTMocks mockUserID equals: user id. | ||
self assert: TCTMocks mockUserFirstName equals: user firstName. | ||
self assert: TCTMocks mockUserLastName equals: user lastName. | ||
self assert: TCTMocks mockUsername equals: user username. |
4 changes: 4 additions & 0 deletions
4
packages/TelegramClient-Tests.package/TCTUsersTests.class/instance/users..st
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,4 @@ | ||
accessing | ||
users: aUsers | ||
|
||
users := aUsers |
Oops, something went wrong.