Skip to content

Commit

Permalink
show senders in chat messages (#387)
Browse files Browse the repository at this point in the history
* show senders in chat messages

* rebuild lost changes

* fix tests, add TCCUser>>= and hash

* Some formatting

* fix linter test to allow for non-letter method names

* Minor formatting

* test message sender name in ui

* Fixing Linter

* Whoopsies

* fix hash

* test user hash and equality operator

* minor formatting and redundant code removal

* please linter

* Removing defensive parenthesis

Co-authored-by: Jannis Berndt <[email protected]>
  • Loading branch information
phkeese and jb3rndt authored Jun 13, 2021
1 parent 4f7b94e commit b135684
Show file tree
Hide file tree
Showing 56 changed files with 206 additions and 96 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
events
addNewMessage: aMessageJSONObject from: aUser
addNewMessage: aMessageJSONObject

| chat message |
chat := self core chats getChat: (aMessageJSONObject at: 'chat_id').
message := TCCMessage newFromMessageEvent: aMessageJSONObject in: chat from: aUser.
message := TCCMessage newFromMessageEvent: aMessageJSONObject in: chat with: self core.

chat addNewestMessage: message.
self core triggerEvent: #newMessageReceived with: message.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ chatHistoryReceived: aChatHistory
chatID := (aChatHistory at: 'messages') first at: 'chat_id'.
chat := self core chats getChat: chatID.

(aChatHistory at: 'messages') do: [:message | chat addOldestMessage: (TCCMessage newFromMessageEvent: message in: chat)].
(aChatHistory at: 'messages') do: [:message | chat addOldestMessage: (TCCMessage newFromMessageEvent: message in: chat with: self core)].

chat waitingForUpdate: false.

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
event handling
handleNewMessage: aMessageJSONObject

self addNewMessage: aMessageJSONObject

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
},
"instance" : {
"addChat:" : "JB 6/4/2021 21:34",
"addNewMessage:from:" : "per 5/21/2021 16:55",
"chatHistoryReceived:" : "JB 6/4/2021 21:35",
"addNewMessage:" : "pk 6/8/2021 09:31",
"chatHistoryReceived:" : "JB 6/13/2021 10:59",
"client" : "per 5/21/2021 16:55",
"core" : "per 5/21/2021 16:55",
"core:" : "per 5/21/2021 16:55",
"defaultMessageLimit" : "js 8/1/2020 18:24",
"getChatHistoryFrom:with:limit:" : "per 5/21/2021 16:55",
"getChats" : "js 7/31/2020 22:50",
"handleNewMessage:from:" : "pk 5/17/2021 18:28",
"handleNewMessage:" : "pk 6/8/2021 09:32",
"loadBasicGroupInfoFor:with:" : "TR 6/2/2021 13:59",
"loadSuperGroupInfoFor:with:" : "TR 6/2/2021 13:58",
"openNewChat:" : "pk 5/13/2021 12:45",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
events
handleMessageEvent: anEvent

| message userID |
| message |
message := anEvent at: 'message'.
userID := (message at: 'sender') at: 'user_id'.
[self chatsHandler handleNewMessage: message from: (self users getUserFor: userID)] fork
self chatsHandler handleNewMessage: message
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ update
| event |

event := self client receive: 0.05.
event ifNotNil: [self handleEvent: (TCCEvent newFromTDLibEvent: event)].
event ifNotNil: [
[self handleEvent: (TCCEvent newFromTDLibEvent: event)] fork
].
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
accessing
users: aDictionary

users := aDictionary
users := aDictionary.
self users core: self.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"getChatHistoryFrom:" : "js 8/1/2020 18:19",
"getOwnProfile" : "pk 5/13/2021 09:44",
"handleEvent:" : "per 5/26/2021 14:04",
"handleMessageEvent:" : "pk 5/19/2021 11:29",
"handleMessageEvent:" : "pk 6/11/2021 10:20",
"handlePendingEvent:" : "per 5/26/2021 14:03",
"initialize" : "JB 6/10/2021 22:29",
"initializeHandlers" : "per 5/21/2021 16:55",
Expand All @@ -33,6 +33,6 @@
"sendPhoneNumber:" : "js 6/13/2020 15:35",
"setUserID:" : "per 5/13/2021 08:22",
"tryHandleError:" : "JB 6/4/2021 17:28",
"update" : "RS 6/3/2021 12:09",
"update" : "pk 6/8/2021 09:22",
"users" : "RK 5/19/2021 09:56",
"users:" : "RK 5/19/2021 09:56" } }
"users:" : "pk 6/13/2021 10:09" } }

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
instance creation
newFromMessageEvent: aMessageEvent in: aChat
newFromMessageEvent: aMessageEvent in: aChat with: aCore

^ self new
message: (((aMessageEvent at: 'content') at: '@type') = 'messageText'
Expand All @@ -10,4 +10,5 @@ newFromMessageEvent: aMessageEvent in: aChat
id: (aMessageEvent at: 'id');
isOutgoing: (aMessageEvent at: 'is_outgoing');
date: (self timeStampToDateAndTime: (aMessageEvent at: 'date'));
core: aCore;
yourself
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
accessing
core: aCore

core := aCore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
accessing
core

^ core
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
accessing
sender

^ sender
^ self core users getUserFor: self senderID
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
{
"class" : {
"newFromMessageEvent:in:" : "JB 6/4/2021 21:14",
"newFromMessageEvent:in:from:" : "JB 6/4/2021 21:14",
"newFromMessageEvent:in:with:" : "JB 6/13/2021 10:51",
"timeStampToDateAndTime:" : "JB 5/16/2021 09:42" },
"instance" : {
"chat" : "pk 5/7/2021 12:06",
"chat:" : "per 5/13/2021 09:20",
"chatID" : "pk 5/13/2021 09:48",
"core" : "pk 6/8/2021 09:24",
"core:" : "pk 6/8/2021 09:25",
"date" : "RK 5/7/2021 10:02",
"date:" : "RK 5/7/2021 10:02",
"id" : "js 8/1/2020 18:20",
Expand All @@ -16,7 +17,6 @@
"isOutgoing:" : "js 8/2/2020 22:00",
"message" : "rs 6/29/2020 17:13",
"message:" : "js 8/2/2020 22:01",
"sender" : "pk 5/9/2021 16:47",
"sender:" : "pk 5/9/2021 16:47",
"sender" : "pk 6/11/2021 10:21",
"senderID" : "per 5/13/2021 08:49",
"senderID:" : "js 8/2/2020 22:00" } }
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
"chat",
"id",
"isOutgoing",
"sender",
"senderID",
"date" ],
"date",
"core" ],
"name" : "TCCMessage",
"pools" : [
],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
comparing
= aUser

^ self species = aUser species
and: [self firstName = aUser firstName]
and: [self lastName = aUser lastName]
and: [self id = aUser id]
and: [self username = aUser username]
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
accessing
fullName

^ (self firstName) , ' ' , (self lastName)
^ self firstName , ' ' , self lastName
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
comparing
hash

^ ((self firstName hash
bitXor: self lastName hash)
bitXor: self id hash)
bitXor: self username hash
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ initialize
username: '';
firstName: '';
lastName: '';
id: -1
id: -1.
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
"class" : {
"newFrom:" : "per 5/15/2021 12:03" },
"instance" : {
"=" : "pk 6/13/2021 12:52",
"firstName" : "per 5/15/2021 12:03",
"firstName:" : "per 5/15/2021 12:03",
"fullName" : "per 5/15/2021 12:03",
"fullName" : "JB 6/13/2021 10:28",
"hash" : "JB 6/13/2021 14:01",
"id" : "pk 5/9/2021 16:33",
"id:" : "per 5/13/2021 09:18",
"initialize" : "JB 6/4/2021 17:29",
"initialize" : "JB 6/13/2021 10:52",
"lastName" : "per 5/15/2021 12:03",
"lastName:" : "per 5/15/2021 12:03",
"username" : "pk 5/9/2021 16:33",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ newFromTCCMessage: aMessage
senderID: aMessage senderID;
isOutgoing: aMessage isOutgoing;
date: aMessage date;
sender: aMessage sender;
initialize
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
drawing
addSender

self addMorphFront: (self defaultTextMorph
contents: self sender fullName;
color: self dateColor;
margins: self defaultMargins;
yourself).
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ initialize
initializeDefaults;
addText;
addDate;
addSender;
shrinkToContent.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
accessing
sender: aUser

sender := aUser.
sender := aUser
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
accessing
sender

^ sender
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"class" : {
"newFromTCCMessage:" : "RK 5/7/2021 10:11" },
"newFromTCCMessage:" : "pk 6/8/2021 09:36" },
"instance" : {
"addDate" : "JB 5/29/2021 21:05",
"addSender" : "pk 6/13/2021 12:57",
"addText" : "JB 5/30/2021 11:24",
"date" : "RK 5/7/2021 10:11",
"date:" : "RK 5/7/2021 10:12",
Expand All @@ -13,13 +14,15 @@
"defaultMargins" : "JB 6/4/2021 21:38",
"defaultTextMorph" : "JB 6/4/2021 21:38",
"defaultWidth" : "r.s 7/31/2020 14:19",
"initialize" : "JB 5/29/2021 21:07",
"initialize" : "pk 6/8/2021 09:34",
"initializeDefaults" : "JB 5/30/2021 11:23",
"isOutgoing" : "js 8/2/2020 22:02",
"isOutgoing:" : "js 8/2/2020 22:02",
"maxContentWidth" : "JB 5/29/2021 20:32",
"messageColor" : "JB 5/29/2021 21:06",
"messageDateText" : "JB 5/17/2021 10:04",
"sender" : "pk 6/8/2021 09:36",
"sender:" : "pk 6/8/2021 09:36",
"senderID" : "js 7/31/2020 16:11",
"senderID:" : "js 7/31/2020 16:10",
"shrinkToContent" : "JB 5/30/2021 11:27",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"text",
"senderID",
"isOutgoing",
"date" ],
"date",
"sender" ],
"name" : "TCUMessage",
"pools" : [
],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
accessing
calculatePosition

^ self currentWorld bottomRight - (self defaultWidth @ self defaultHeight) - (self defaultOffset)
^ self currentWorld bottomRight - (self defaultWidth @ self defaultHeight) - self defaultOffset
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"newWithMessage:" : "JB 6/4/2021 21:48" },
"instance" : {
"addContent" : "per 5/16/2021 15:20",
"calculatePosition" : "rs 7/5/2020 14:42",
"calculatePosition" : "JB 6/13/2021 10:42",
"chat" : "per 5/13/2021 08:50",
"chat:" : "per 5/13/2021 09:21",
"chatID" : "rs 7/5/2020 14:31",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ testing
testMessage

| message |
message := TCCMessage newFromMessageEvent: (TCTMMocks mockMessageJsonFrom: self chat id) in: self chat.
message := TCCMessage newFromMessageEvent: (TCTMMocks mockMessageJsonFrom: self chat id) in: self chat with: nil.

self assert: TCTMMocks mockUser id equals: message senderID.
self assert: TCTMMocks mockMessageID equals: message id.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"testAddOldestMessage" : "per 5/21/2021 16:32",
"testID" : "per 5/21/2021 16:32",
"testLastMessage" : "per 5/21/2021 16:31",
"testMessage" : "JB 6/7/2021 09:27",
"testMessage" : "pk 6/11/2021 10:35",
"testMessages" : "per 5/21/2021 16:30",
"testMessagesSize" : "per 5/21/2021 16:30",
"testNullID" : "js 8/2/2020 21:15",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
testing
testMessageSenderTriggersUserRequest

| messageEvent userJson |
self core when: #newMessageReceived send: #newMessageReceived: to: self.
self core chats add: TCTMMocks mockPrivateChat.

self receivedMessage: nil.
messageEvent := TCTMMocks mockMessageEventFrom: TCTMMocks mockPrivateChat id.

self core handleEvent: messageEvent.
1 seconds wait.

userJson := TCTMMocks mockUserJson.
self core client onRequestType: 'getUser' respond: userJson.

self assert: self receivedMessage notNil.
self assert: TCTMMocks mockUser fullName equals: self receivedMessage sender fullName.
self assert: TCTMMocks mockPrivateChat id equals: self receivedMessage chat id.
self assert: TCTMMocks mockMessageText equals: self receivedMessage message.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
"testChatsHandler" : "per 5/21/2021 16:28",
"testErrorConstants" : "js 8/2/2020 21:23",
"testLoggedInUserID" : "JB 6/7/2021 09:28",
"testMessageTriggersUserRequest" : "JB 6/7/2021 09:28" } }
"testMessageSenderTriggersUserRequest" : "JB 6/13/2021 10:49" } }
Loading

0 comments on commit b135684

Please sign in to comment.