This repository was archived by the owner on Jun 7, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 550
[WIP][NEW] Group same user messages #2299
Open
Adizbek
wants to merge
10
commits into
RocketChat:develop
Choose a base branch
from
Adizbek:group-avatars-new
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
3e2a0ab
Group user avatar if author the same
Adizbek b0781ee
Updates.
Adizbek bddb8d1
Disable groupping, as in web.
Adizbek 154de6e
Fix
Adizbek 43c1e0a
Merge remote-tracking branch 'upstream/develop' into group-avatars
Adizbek 76bdab8
Fix.
Adizbek 7440ef6
Merge branch 'develop' into group-avatars-new
Adizbek 1f441b2
Code cleanup. Checking by user alias.
Adizbek 5dab9b1
Merge remote-tracking branch 'origin/group-avatars-new' into group-av…
Adizbek ad9736e
Merge branch 'develop' into group-avatars-new
Adizbek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,6 @@ | ||
| package chat.rocket.android.chatroom.adapter | ||
|
|
||
| import android.content.res.Resources | ||
| import android.view.MenuItem | ||
| import android.view.View | ||
| import android.view.ViewGroup | ||
|
|
@@ -22,6 +23,9 @@ import chat.rocket.core.model.attachment.actions.ButtonAction | |
| import chat.rocket.core.model.isSystemMessage | ||
| import timber.log.Timber | ||
| import java.security.InvalidParameterException | ||
| import java.util.Calendar | ||
| import kotlin.Comparator | ||
| import kotlin.collections.ArrayList | ||
|
|
||
| class ChatRoomAdapter( | ||
| private val roomId: String? = null, | ||
|
|
@@ -106,9 +110,24 @@ class ChatRoomAdapter( | |
| } | ||
| } | ||
|
|
||
| var groupMessage = false | ||
|
|
||
| if (position + 1 < dataSet.size) { | ||
| val a = dataSet[position].message | ||
| val b = dataSet[position + 1].message | ||
|
|
||
| groupMessage = shouldGroupMessage(a, b) | ||
|
|
||
| a.attachments?.let { | ||
| if(it.any { a -> a.type != null }){ // check if message media attachment. | ||
| groupMessage = false | ||
| } | ||
| } | ||
| } | ||
|
|
||
| when (holder) { | ||
| is MessageViewHolder -> | ||
| holder.bind(dataSet[position] as MessageUiModel) | ||
| holder.bind(dataSet[position] as MessageUiModel, groupMessage) | ||
| is UrlPreviewViewHolder -> { | ||
| holder.bind(dataSet[position] as UrlPreviewUiModel) | ||
| } | ||
|
|
@@ -119,6 +138,23 @@ class ChatRoomAdapter( | |
| } | ||
| } | ||
|
|
||
|
|
||
| private fun shouldGroupMessage(a: Message, b: Message): Boolean { | ||
| a.sender?.let { u1 -> | ||
| b.sender?.let { u2 -> | ||
| if (u1.id.equals(u2.id)) { | ||
| val date1 = a.getDate() | ||
| val date2 = b.getDate() | ||
|
|
||
| if (date1.isSameDay(date2) && date1.timeInMillis - date2.timeInMillis <= 900000) // this should be depend on settings. | ||
| return true | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return false | ||
| } | ||
|
|
||
| override fun getItemId(position: Int): Long { | ||
| val model = dataSet[position] | ||
| return when (model) { | ||
|
|
@@ -336,3 +372,18 @@ class ChatRoomAdapter( | |
| fun reportMessage(id: String) | ||
| } | ||
| } | ||
|
|
||
| fun Message.getDate(): Calendar { | ||
| return Calendar.getInstance().apply { | ||
| timeInMillis = [email protected] | ||
| } | ||
| } | ||
|
|
||
| fun Calendar.isSameDay(other: Calendar): Boolean { | ||
| return this.get(Calendar.YEAR) == other.get(Calendar.YEAR) && | ||
| this.get(Calendar.MONTH) == other.get(Calendar.MONTH) && | ||
| this.get(Calendar.DAY_OF_MONTH) == other.get(Calendar.DAY_OF_MONTH) | ||
| } | ||
|
|
||
| val Int.toPx: Float | ||
| get() = (this * Resources.getSystem().displayMetrics.density) | ||
This file contains hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.