Skip to content

Commit

Permalink
Hinzufügen von Tag-Trenner (alias "day divider") (#524)
Browse files Browse the repository at this point in the history
* add first prototype

Co-authored-by: Jacob Schaefer <[email protected]>
Co-authored-by: kohlros <[email protected]>

* fix disappearing divider

Co-authored-by: Jacob Schaefer <[email protected]>

* revert change in testAddingOldMessageDoesNotScroll

Co-authored-by: Jacob Schaefer <[email protected]>

* refactor mockTextMessageWith:withDate:

Co-authored-by: Jacob Schaefer <[email protected]>

* scroll after adding divider to fix not ending up at the bottom when opening a chat

* rename TCUInfoMessage to TCUDayDividerMessage

Co-authored-by: Jacob Schaefer <[email protected]>

* fix click on replied message

Co-authored-by: Jacob Schaefer <[email protected]>

* fix merge conflicts

Co-authored-by: Jacob Schaefer <[email protected]>

* remove leftovers of lastMessageSnippet

Co-authored-by: Jacob Schaefer <[email protected]>

* test addDayDividerAtTop

Co-authored-by: Jacob Schaefer <[email protected]>
Co-authored-by: kohlros <[email protected]>
  • Loading branch information
3 people authored Jul 22, 2022
1 parent 444899d commit 867daf4
Show file tree
Hide file tree
Showing 54 changed files with 324 additions and 30 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
default values
defaultLastMessageDate

^ DateAndTime fromUnixTime: 0
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
adding
addNewestMessage: aMessage

| newDate oldDate |
newDate := aMessage date asDate.
oldDate := self lastMessageDate asDate.
(newDate > oldDate) ifTrue: [
aMessage isFirstMessageOfDay: true.
self lastMessage isLastMessageOfDay: true.
].
self messageIds addFirst: aMessage id.
self messageDictionary at: aMessage id put: aMessage.
self triggerEvent: #newMessage with: aMessage.
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
adding
addOldestMessage: aMessage

| newDate oldDate |
newDate := aMessage date asDate.
oldDate := self oldestLoadedMessageDate asDate.
(newDate < oldDate) ifTrue: [
self oldestLoadedMessage isFirstMessageOfDay: true.
aMessage isLastMessageOfDay: true].
self messageIds add: aMessage id.
self messageDictionary at: aMessage id put: aMessage.
self triggerEvent: #loadedMessage with: aMessage.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
accessing
lastMessage

^ self messages
ifEmpty: [ TCCNotLoadedMessage new
date: self class defaultLastMessageDate]
ifNotEmpty: [ self messages first ]
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
accessing
lastMessageDate

"Date of the latest received message."

^ self lastMessage date
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
accessing
oldestLoadedMessage

^ self messages
ifEmpty: [ TCCNotLoadedMessage new
date: self class defaultLastMessageDate]
ifNotEmpty: [ self messages last ]
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
accessing
oldestLoadedMessageDate

^ self oldestLoadedMessage date
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"class" : {
"defaultLastMessageDate" : "aka 7/10/2022 11:25",
"defaultLastMessageId" : "JB 8/4/2021 00:10",
"defaultLastMessageSenderId" : "LR 7/14/2022 11:50",
"defaultMessageLimit" : "RS 7/17/2021 11:45",
Expand All @@ -9,8 +10,8 @@
"newFromChatEvent:" : "RS 7/17/2021 17:07" },
"instance" : {
"addAnsweredMessage:" : "JS 5/26/2022 16:41",
"addNewestMessage:" : "JS 5/26/2022 14:22",
"addOldestMessage:" : "LR 6/11/2022 16:17",
"addNewestMessage:" : "aka 7/14/2022 14:29",
"addOldestMessage:" : "aka 7/14/2022 14:26",
"canSendMessages" : "5/11/2021 10:09:15",
"canSendMessages:" : "JB 8/4/2021 00:08",
"chatHistoryReceived:" : "aka 7/14/2022 16:38",
Expand All @@ -36,6 +37,8 @@
"isPinned:" : "js 6/18/2022 10:19",
"isPrivate" : "per 6/4/2021 14:42",
"isSuperGroup" : "per 6/15/2021 08:09",
"lastMessage" : "aka 7/14/2022 14:28",
"lastMessageDate" : " 7/22/2022 10:40:18",
"lastMessageId" : "JB 8/4/2021 00:10",
"lastMessageSenderId" : "LR 7/14/2022 12:16",
"lastMessageSenderId:" : "LR 7/14/2022 15:11",
Expand All @@ -56,6 +59,8 @@
"numberOfMessages" : "RS 7/31/2021 15:19",
"numberOfRequestedMessages" : "js 8/1/2020 17:43",
"numberOfRequestedMessages:" : "JS 5/20/2022 11:34",
"oldestLoadedMessage" : "aka 7/14/2022 13:46",
"oldestLoadedMessageDate" : "aka 7/14/2022 13:46",
"photoId" : "rgw 6/2/2022 11:51",
"photoId:" : "rgw 6/2/2022 11:51",
"position" : "RS 5/10/2021 21:11",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"freeClient" : "6/9/2021 14:12:18",
"generateCallbackId" : "pk 8/5/2021 17:04",
"getOwnProfile" : "pk 8/5/2021 17:05",
"handleEvent:" : "LR 6/12/2022 14:28",
"handleEvent:" : "aka 7/10/2022 10:28",
"handleMessageEvent:" : "rgw 5/12/2022 13:44",
"handlePendingEvent:" : "per 8/2/2021 15:05",
"imageStore" : "pk 6/19/2021 17:15",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
accessing
initialize

super initialize.

self
isFirstMessageOfDay: false;
isLastMessageOfDay: false
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
accessing
isFirstMessageOfDay: aBool

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

^ isFirstMessageOfDay
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
accessing
isLastMessageOfDay: aBool

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

^ isLastMessageOfDay
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,9 @@
"date" : "aka 7/14/2022 16:40",
"date:" : "aka 7/14/2022 16:40",
"id" : "aka 7/14/2022 16:40",
"id:" : "aka 7/14/2022 16:40" } }
"id:" : "aka 7/14/2022 16:40",
"initialize" : " 7/22/2022 10:40:18",
"isFirstMessageOfDay" : " 7/22/2022 10:40:18",
"isFirstMessageOfDay:" : " 7/22/2022 10:40:18",
"isLastMessageOfDay" : " 7/22/2022 10:40:18",
"isLastMessageOfDay:" : " 7/22/2022 10:40:18" } }
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
"chat",
"id",
"date",
"core" ],
"core",
"isFirstMessageOfDay",
"isLastMessageOfDay" ],
"name" : "TCCMessage",
"pools" : [
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ addAtBottom: aCoreMessage

(self isFromCurrentChat: aCoreMessage)
ifFalse: [ ^ self ].

(aCoreMessage isFirstMessageOfDay) ifTrue: [self addBottomDayDividerForDate: aCoreMessage date asDate].

wasFullyScrolledDown := self isFullyScrolledDown.
messageItem := TCUUserMessage newFrom: aCoreMessage.
messageItem when: #requestScroll send: #requestScrollToMessage: to: self with: (aCoreMessage replyToMessageId).
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
messages
addAtTop: aCoreMessage

| wrapper messageItem |
| wrapper messageItem lastMessage |
(self isFromCurrentChat: aCoreMessage) ifFalse: [^ self].

(aCoreMessage isLastMessageOfDay and: self items isEmpty not) ifTrue: [
lastMessage := self items first message messageModel.
self addTopDayDividerForDate: (lastMessage date asDate)
].

messageItem := TCUUserMessage newFrom: aCoreMessage.
messageItem when: #requestScroll send: #requestScrollToMessage: to: self with: (aCoreMessage replyToMessageId).
wrapper := TCUMessageWrapper newFromMessage: messageItem withWidth: self scroller width.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
stepping and presenter
addBottomDayDividerForDate: aDate

| divider wasFullyScrolledDown |
wasFullyScrolledDown := self isFullyScrolledDown.
divider := self createDayDividerForDate: aDate.
self scroller addMorphBack: divider.
self items addLast: divider.
wasFullyScrolledDown
ifTrue: [ self scrollToNewestMessage ]
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
stepping and presenter
addTopDayDividerForDate: aDate

| divider |
divider := self createDayDividerForDate: aDate.
self scroller addMorphFront: divider.
self items addFirst: divider.
self isFullyScrolledDown
ifTrue: [self scrollToNewestMessage].
self scrollBy: 0 @ (divider height negated).
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
stepping and presenter
createDayDividerForDate: aDate

| messageItem |
messageItem := TCUDayDividerMessage newFromDate: aDate.
^ RectangleMorph new
color: Color transparent;
width: self scroller width;
height: messageItem height;
borderWidth: 0;
addMorphCentered: messageItem;
yourself
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ displayChat: aChat
self chat removeActionsWithReceiver: self.
aChat when: #newMessage send: #addAtBottom: to: self.
aChat when: #loadedMessage send: #addAtTop: to: self.

self
chat: aChat;
showMessages.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
drawing
scrollToMessage: aMessageId

| messageItem messageIndex |
messageIndex := self chat messageIds reversed indexOf: aMessageId.
messageItem := self items at: messageIndex.
| messageItem |
messageItem := self items detect: [:item | ((item isKindOf: TCUMessageWrapper)) and: [item messageId = aMessageId]].
self scrollToShow: messageItem
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,21 @@
"defaultScrollOffsetBeforeLoading" : "JB 6/26/2021 10:15",
"defaultWidth" : "rgw 6/2/2022 15:39" },
"instance" : {
"addAtBottom:" : "aka 7/14/2022 16:13",
"addAtTop:" : "aka 7/14/2022 16:13",
"addAtBottom:" : "aka 7/14/2022 14:58",
"addAtTop:" : "aka 7/14/2022 15:18",
"addBottomDayDividerForDate:" : "js 7/18/2022 07:29",
"addMessages" : "RS 7/17/2021 17:40",
"addTopDayDividerForDate:" : "js 7/18/2022 07:30",
"chat" : "js 7/31/2020 16:39",
"chat:" : "js 7/31/2020 16:39",
"core" : "JB 6/26/2021 10:22",
"displayChat:" : "RS 7/17/2021 11:54",
"createDayDividerForDate:" : "aka 7/22/2022 09:29",
"displayChat:" : "aka 7/14/2022 13:50",
"initialize" : "RS 7/17/2021 17:40",
"isFromCurrentChat:" : "pk 8/5/2021 17:07",
"isFullyScrolledDown" : "JB 8/4/2021 11:15",
"requestScrollToMessage:" : "aka 6/15/2022 11:56",
"scrollToMessage:" : "aka 6/15/2022 12:01",
"scrollToMessage:" : "aka 7/22/2022 09:34",
"scrollToNewestMessage" : "per 6/24/2021 23:14",
"showMessages" : "RS 7/17/2021 17:34",
"step" : "JB 7/19/2021 12:12" } }
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
class for automatic generated info messages.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
defaults
defaultMargin

^ 20
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
instance creation
newFromDate: aDate

^ self basicNew
content: aDate mmddyyyy;
initialize;
yourself
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
accessing
content: aString

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

^ content
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
initialization
initialize

| textMorph |
super initialize.

textMorph := TextMorph new
contents: self content;
lock.
self color: Color gray;
width: textMorph width + self class defaultMargin;
addMorphCentered: textMorph;
useRoundedCorners;
borderWidth: 0.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"class" : {
"defaultMargin" : "aka 7/14/2022 15:15",
"newFromDate:" : "aka 7/14/2022 15:14" },
"instance" : {
"content" : "aka 7/10/2022 12:37",
"content:" : "aka 7/10/2022 12:37",
"initialize" : "aka 7/14/2022 15:16" } }
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"category" : "TelegramClient-UI",
"classinstvars" : [
],
"classvars" : [
],
"commentStamp" : "aka 7/14/2022 15:07",
"instvars" : [
"content" ],
"name" : "TCUDayDividerMessage",
"pools" : [
],
"super" : "RectangleMorph",
"type" : "normal" }
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
accessing
messageId

^ self message messageModel id
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
"addProfilePhoto" : "js 6/13/2022 18:09",
"initialize" : "JS 6/11/2022 11:40",
"message" : "JS 6/11/2022 11:12",
"message:" : "JS 6/11/2022 11:13" } }
"message:" : "JS 6/11/2022 11:13",
"messageId" : "aka 7/22/2022 09:30" } }
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,4 @@ setUp
userId: aNumber * 3;
id: aNumber * 4;
date: (DateAndTime fromUnixTime: aNumber * 60)).
self chat messageIds add: message id.
self chat messageDictionary at: message id put: message]
self chat addNewestMessage: message.]
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
testing
testAddNewestMessage

self chat addNewestMessage: (TCCTextMessage new text: 'test').
self chat addNewestMessage: (TCCTextMessage new
text: 'test';
date: DateAndTime today).
self assert: 'test' equals: self chat messages first asText.
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
testing
testAddOldestMessage

self chat addOldestMessage: (TCCTextMessage new text: 'test').
self chat addOldestMessage: (TCCTextMessage new
text: 'test';
date: (DateAndTime fromUnixTime: 0)
).
self assert: 'test' equals: self chat messages last asText.
Loading

0 comments on commit 867daf4

Please sign in to comment.