-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Message Draft #24
base: master
Are you sure you want to change the base?
Message Draft #24
Conversation
|
||
val before = currentText.substring(0, positionInInput) | ||
val after = currentText.substring(positionInInput) | ||
val newString = before + after.replaceFirst(link, text) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see any replacement in the TypeScript code... your code makes sense to me I think (replace the URL with the link text), but how is it done in TypeScript? does it also happen somewhere?
private val userSuggestionLimit: Int = 10, | ||
private val shouldTriggerTypingIndicator: Boolean = false | ||
) { | ||
private var currentTextLinkDescriptors: MutableList<TextLinkDescriptor> = emptyList<TextLinkDescriptor>().toMutableList() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
always prefer val
unless var
is required (in all properties in this class)
val after = currentText.substring(positionInInput) | ||
val newString = before + after.replaceFirst(link, text) | ||
|
||
currentText = newString |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know if it will matter in the end, but in TS Chat the onChange is invoked first, then the textLinkDescriptor
is added to currentTextLinkDescriptors
if (!currentTextLinkDescriptors.removeAll { | ||
it.range.contains(positionInInput) | ||
}) { | ||
println("This operation is noop. There is no link at this position.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add a TODO to use a logger (once we have it) instead of println
private var userPrefix = "@" | ||
private var channelPrefix = "#" | ||
|
||
var onSuggestionsChanged: (String, SuggestedMessageDraftMentions) -> Unit = { _, _ -> } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see a similar feature (setting a callback for changing suggestions) in TS?
private var getUsersFuture: PNFuture<List<User>> = emptyList<User>().asFuture() | ||
private var getChannelsFuture: PNFuture<List<Channel>> = emptyList<Channel>().asFuture() | ||
|
||
private var minNameLength: Int = 3 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these could be const val
in the file (outside of the class)
private var quotedMessage: Message? = null | ||
private var mentionedUsers: MutableList<MentionDescriptor<User>> = emptyList<MentionDescriptor<User>>().toMutableList() | ||
private var mentionedChannels: MutableList<MentionDescriptor<Channel>> = emptyList<MentionDescriptor<Channel>>().toMutableList() | ||
private var getUsersFuture: PNFuture<List<User>> = emptyList<User>().asFuture() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
doesn't seem like these futures need to be saved in a property? they're only used in the function body
} | ||
} | ||
|
||
fun removeMentionedUser(positionInInput: Int) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
my reading of the TS code and documentation is that user and channel mentions don't work on text positions, but on the number of "@" or "#" characters. For example, if there is a string blah @firstmention blah @secondMention blah @third blah
, then the mentions have nameOccurrenceIndex
(name from TS SDK) 0 for firstMention
, 1 for secondMention
and 2 for third
. And so this and related methods should not operate on positionInInput
and text ranges, but rather on the numbered "@" occurences
@@ -159,6 +159,11 @@ interface Chat { | |||
message: EventContent, | |||
mergeMessageWith: Map<String, Any>? = null | |||
): PNFuture<PNPublishResult> | |||
|
|||
fun getChannelSuggestions( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would place it above section:
/* should be internal */
fun signal(
|
||
fun getChannelSuggestions( | ||
filter: String?, | ||
limit: Int |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about setting default 10 like and changing return type to PNFuture<Set> like this:
fun getChannelSuggestions(text: String, limit: Int = 10): PNFuture<Set<Channel>>
Result.failure(PubNubException(FAILED_TO_GET_CHANNELS.message, exception)) | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In Master we already have following code:
override fun getChannelSuggestions(text: String, limit: Int): PNFuture<Set<Channel>> {
val cacheKey: String = getPhraseToLookFor(text, "#") ?: return emptySet<Channel>().asFuture()
suggestedChannelsCache[cacheKey]?.let { nonNullChannels ->
return nonNullChannels.asFuture()
}
return getChannels(filter = "name LIKE '${cacheKey}*'", limit = limit).then { getChannelsResponse ->
val channels: Set<Channel> = getChannelsResponse.channels
suggestedChannelsCache[cacheKey] = channels
channels
}
}
That is a bit different with this one. I am not saying that is correct one but in TypeScript code there is concept of
suggestedChannelsCache
that I can not see in your implementation. Did you deliberately skip it here? Maybe is in other place that I can not see.
Other thing to be take into consideration is that there is also getUserSuggestions
that similarly to getChannelSuggestions uses getPhraseToLookFor
method.
private val userSuggestionLimit: Int = 10, | ||
private val shouldTriggerTypingIndicator: Boolean = false | ||
) { | ||
private var currentTextLinkDescriptors: MutableList<TextLinkDescriptor> = emptyList<TextLinkDescriptor>().toMutableList() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could be also:
private var currentTextLinkDescriptors: MutableList = mutableListOf()
when (userSuggestionDataSource) { | ||
UserSuggestionDataSource.CHANNEL -> | ||
channel.getMembers( | ||
filter = "uuid.name LIKE '${userMention.first}'", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't "*" needed here like this:
filter = "uuid.name LIKE '${userMention.first}*'",
?
var currentText: String by Delegates.observable("") { _, oldValue, newValue -> onTextChanged(oldValue, newValue) } | ||
|
||
init { | ||
require(userSuggestionLimit <= 100) { "Fetching more than 100 users is prohibited" } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure but probably we want to throw PubNubException in such cases.
link = link | ||
) | ||
|
||
if (!link.isValidUrl()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not to have this validation as a first operation in this method ? In case link is not valid url we wouldn't have to construct textLinkDescriptor?
} | ||
|
||
override fun getChannelSuggestions(filter: String?, limit: Int): PNFuture<List<Channel>> { | ||
TODO("Not yet implemented") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you going to handle all TODO in this file?
If not what about sth like this:
return emptyList<Channel>().asFuture()
?
The thing is that IMHO TODO suggests that some action planned in this code.
What do you think?
No description provided.