Skip to content

Commit

Permalink
add ability to send emoji
Browse files Browse the repository at this point in the history
Signed-off-by: Marcel Hibbe <[email protected]>
  • Loading branch information
mahibi committed Apr 6, 2022
1 parent 4643a0c commit 20e67c8
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 23 deletions.
15 changes: 12 additions & 3 deletions app/src/main/java/com/nextcloud/talk/api/NcApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -490,8 +490,17 @@ Observable<GenericOverall> setStatusType(@Header("Authorization") String authori
@GET
Observable<StatusesOverall> getUserStatuses(@Header("Authorization") String authorization, @Url String url);


@POST
Observable<GenericOverall> sendReaction(@Header("Authorization") String authorization, @Url String url,
@Query("reaction") String reaction);

@DELETE
Observable<GenericOverall> deleteReaction(@Header("Authorization") String authorization, @Url String url,
@Query("reaction") String reaction);

@GET
Observable<ReactionsOverall> getParticipantsForEmojiReaction(@Header("Authorization") String authorization,
@Url String url,
@Query("reaction") String reaction);
Observable<ReactionsOverall> getReactions(@Header("Authorization") String authorization,
@Url String url,
@Query("reaction") String reaction);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2438,7 +2438,8 @@ class ChatController(args: Bundle) :
message,
conversationUser,
currentConversation,
isShowMessageDeletionButton(message)
isShowMessageDeletionButton(message),
ncApi!!
).show()
}
}
Expand Down Expand Up @@ -2720,6 +2721,15 @@ class ChatController(args: Bundle) :
adapter?.update(messageTemp)
}

fun updateAdapterAfterSendReaction(message: ChatMessage, emoji: String) {
var amount = message.reactions[emoji]
if (amount == null){
amount = 0
}
message.reactions[emoji] = amount + 1
adapter?.update(message)
}

private fun isShowMessageDeletionButton(message: ChatMessage): Boolean {
if (conversationUser == null) return false

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,35 @@
package com.nextcloud.talk.ui.dialog

import android.os.Bundle
import android.util.Log
import android.view.View
import android.view.ViewGroup
import androidx.annotation.NonNull
import com.google.android.material.bottomsheet.BottomSheetBehavior
import com.google.android.material.bottomsheet.BottomSheetDialog
import com.nextcloud.talk.BuildConfig
import com.nextcloud.talk.R
import com.nextcloud.talk.api.NcApi
import com.nextcloud.talk.controllers.ChatController
import com.nextcloud.talk.databinding.DialogMessageActionsBinding
import com.nextcloud.talk.models.database.UserEntity
import com.nextcloud.talk.models.database.CapabilitiesUtil
import com.nextcloud.talk.models.database.UserEntity
import com.nextcloud.talk.models.json.chat.ChatMessage
import com.nextcloud.talk.models.json.conversations.Conversation
import com.nextcloud.talk.models.json.generic.GenericOverall
import com.nextcloud.talk.utils.ApiUtils
import io.reactivex.Observer
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.Disposable
import io.reactivex.schedulers.Schedulers

class MessageActionsDialog(
private val chatController: ChatController,
private val message: ChatMessage,
private val user: UserEntity?,
private val currentConversation: Conversation?,
private val showMessageDeletionButton: Boolean
private val showMessageDeletionButton: Boolean,
private val ncApi: NcApi
) : BottomSheetDialog(chatController.activity!!) {

private lateinit var dialogMessageActionsBinding: DialogMessageActionsBinding
Expand Down Expand Up @@ -73,22 +83,22 @@ class MessageActionsDialog(
private fun initEmojiBar() {
if (CapabilitiesUtil.hasSpreedFeatureCapability(user, "reactions")) {
dialogMessageActionsBinding.emojiThumbsUp.setOnClickListener {
dismiss()
sendReaction(message, dialogMessageActionsBinding.emojiThumbsUp.text.toString())
}
dialogMessageActionsBinding.emojiThumbsDown.setOnClickListener {
dismiss()
sendReaction(message, dialogMessageActionsBinding.emojiThumbsDown.text.toString())
}
dialogMessageActionsBinding.emojiLaugh.setOnClickListener {
dismiss()
sendReaction(message, dialogMessageActionsBinding.emojiLaugh.text.toString())
}
dialogMessageActionsBinding.emojiHeart.setOnClickListener {
dismiss()
sendReaction(message, dialogMessageActionsBinding.emojiHeart.text.toString())
}
dialogMessageActionsBinding.emojiConfused.setOnClickListener {
dismiss()
sendReaction(message, dialogMessageActionsBinding.emojiConfused.text.toString())
}
dialogMessageActionsBinding.emojiSad.setOnClickListener {
dismiss()
sendReaction(message, dialogMessageActionsBinding.emojiSad.text.toString())
}
dialogMessageActionsBinding.emojiMore.setOnClickListener {
dismiss()
Expand Down Expand Up @@ -180,7 +190,43 @@ class MessageActionsDialog(
}
}

private fun sendReaction(message: ChatMessage, emoji: String) {
val credentials = ApiUtils.getCredentials(user?.username, user?.token)

ncApi.sendReaction(
credentials,
ApiUtils.getUrlForMessageReaction(
user?.baseUrl,
currentConversation!!.token,
message.id
),
emoji
)
?.subscribeOn(Schedulers.io())
?.observeOn(AndroidSchedulers.mainThread())
?.subscribe(object : Observer<GenericOverall> {
override fun onSubscribe(d: Disposable) {
}

override fun onNext(@NonNull genericOverall: GenericOverall) {
val statusCode = genericOverall.ocs.meta.statusCode
if (statusCode == 200 || statusCode == 201) {
chatController.updateAdapterAfterSendReaction(message, emoji)
}
}

override fun onError(e: Throwable) {
Log.e(TAG, "error while sending emoji")
}

override fun onComplete() {
dismiss()
}
})
}

companion object {
private const val TAG = "MessageActionsDialog"
private const val ACTOR_LENGTH = 6
private const val NO_PREVIOUS_MESSAGE_ID: Int = -1
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@ class ShowReactionsDialog(

val credentials = ApiUtils.getCredentials(userEntity?.username, userEntity?.token)

ncApi.getParticipantsForEmojiReaction(
ncApi.getReactions(
credentials,
ApiUtils.getUrlForParticipantsForEmojiReaction(
ApiUtils.getUrlForMessageReaction(
userEntity?.baseUrl,
currentConversation!!.token,
chatMessage.id
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/java/com/nextcloud/talk/utils/ApiUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -442,9 +442,9 @@ public static String getUrlForUserStatuses(String baseUrl) {
return baseUrl + ocsApiVersion + "/apps/user_status/api/v1/statuses";
}

public static String getUrlForParticipantsForEmojiReaction(String baseUrl,
String roomToken,
String messageId) {
public static String getUrlForMessageReaction(String baseUrl,
String roomToken,
String messageId) {
return baseUrl + ocsApiVersion + spreedApiVersion + "/reaction/" + roomToken + "/" + messageId;
}

Expand Down
12 changes: 6 additions & 6 deletions app/src/main/res/layout/dialog_message_actions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
android:gravity="center_vertical"
android:orientation="horizontal">

<com.vanniktech.emoji.EmojiEditText
<com.vanniktech.emoji.EmojiTextView
android:id="@+id/emojiThumbsUp"
android:layout_width="@dimen/activity_row_layout_height"
android:layout_height="@dimen/activity_row_layout_height"
Expand All @@ -45,7 +45,7 @@
android:text="@string/emoji_thumbsUp"
android:textSize="24sp" />

<com.vanniktech.emoji.EmojiEditText
<com.vanniktech.emoji.EmojiTextView
android:id="@+id/emojiThumbsDown"
android:layout_width="@dimen/activity_row_layout_height"
android:layout_height="@dimen/activity_row_layout_height"
Expand All @@ -55,7 +55,7 @@
android:text="@string/emoji_thumbsDown"
android:textSize="24sp" />

<com.vanniktech.emoji.EmojiEditText
<com.vanniktech.emoji.EmojiTextView
android:id="@+id/emojiHeart"
android:layout_width="@dimen/activity_row_layout_height"
android:layout_height="@dimen/activity_row_layout_height"
Expand All @@ -65,7 +65,7 @@
android:text="@string/default_emoji"
android:textSize="24sp" />

<com.vanniktech.emoji.EmojiEditText
<com.vanniktech.emoji.EmojiTextView
android:id="@+id/emojiLaugh"
android:layout_width="@dimen/activity_row_layout_height"
android:layout_height="@dimen/activity_row_layout_height"
Expand All @@ -75,7 +75,7 @@
android:text="@string/emoji_heart"
android:textSize="24sp" />

<com.vanniktech.emoji.EmojiEditText
<com.vanniktech.emoji.EmojiTextView
android:id="@+id/emojiConfused"
android:layout_width="@dimen/activity_row_layout_height"
android:layout_height="@dimen/activity_row_layout_height"
Expand All @@ -85,7 +85,7 @@
android:text="@string/emoji_confused"
android:textSize="24sp" />

<com.vanniktech.emoji.EmojiEditText
<com.vanniktech.emoji.EmojiTextView
android:id="@+id/emojiSad"
android:layout_width="@dimen/activity_row_layout_height"
android:layout_height="@dimen/activity_row_layout_height"
Expand Down

0 comments on commit 20e67c8

Please sign in to comment.