Skip to content

Commit

Permalink
Update database user ID and abstract chat client
Browse files Browse the repository at this point in the history
  • Loading branch information
mwmlo committed Jun 8, 2023
1 parent 97b7ff9 commit 736c320
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 35 deletions.
54 changes: 21 additions & 33 deletions app/src/main/java/com/example/drp25/ChatActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ import androidx.appcompat.app.AppCompatActivity

import com.example.drp25.databinding.ActivityChatBinding
import com.google.firebase.database.FirebaseDatabase
//import com.google.firebase.database.FirebaseDatabase
import io.getstream.chat.android.client.api.models.querysort.QuerySortByField
import io.getstream.chat.android.client.call.Call
import io.getstream.chat.android.client.models.Channel
import io.getstream.chat.android.client.models.Filters
import io.getstream.chat.android.client.models.User
import io.getstream.chat.android.ui.channel.list.header.viewmodel.ChannelListHeaderViewModel
Expand All @@ -19,23 +18,24 @@ import io.getstream.chat.android.ui.channel.list.viewmodel.bindView
import io.getstream.chat.android.ui.channel.list.viewmodel.factory.ChannelListViewModelFactory

// our logged in user
val UNI_ID = "imperialId"
val USER_ID = "-NXGEo30rzoWUgTYoYi_"
const val UNI_ID = "imperialId"
const val USER_ID = "-NXPnWryIGR2S5aJmSGH"

class ChatActivity : AppCompatActivity() {

private lateinit var binding: ActivityChatBinding
private lateinit var channelGlob: Call<Channel>
// private var channelGlob: Call<Channel>

// Get match for demo
private val NAMES = listOf<String>("Pierre", "Kevin", "Martha", "India", "Jerry", "Simon")
private val names = listOf("Pierre", "Kevin", "Martha", "India", "Jerry", "Simon")
private var i = 0

private fun getMatch(): String {
val match = NAMES.get(i)
i = (i+1)%(NAMES.size)
val match = names[i]
i = (i + 1) % (names.size)
return match
}

val matchesRef = FirebaseDatabase.getInstance().reference.child("matches")

override fun onCreate(savedInstanceState: Bundle?) {
Expand All @@ -54,27 +54,33 @@ class ChatActivity : AppCompatActivity() {
)
clientService.connectCurrentUser(user)

val friend = User(
id = "friend",
name = "Friend",
val friend1 = User(
id = "friend-1",
name = "Friend 1",
image = "https://bit.ly/2TIt8NR"
)

val friend2 = User(
id = "friend-2",
name = "Friend 2",
image = "https://bit.ly/2TIt8NR"
)

// Only allows the binding to be visible if the page is not opened from a match activity
if (intent.hasExtra("fromMatch") && intent.getBooleanExtra("fromMatch", true)) {
clientService.createChannel("1234", user.id, friend.id)
clientService.createChannel("1234", user.id, friend2.id)
// createAndRunChannel(client, user)
} else {
setContentView(binding.root)
clientService.createChannel("5678", user.id, friend.id)
clientService.createChannel("14355", user.id, friend1.id)
// Note this channel is not showing up
// createDemoChannel(client, user, "14355")
// seems to be something wrong with channel.execute.data, causing issues
// startActivity(ChannelActivity.newIntent(this, ch))
}

val channelListHeaderViewModel: ChannelListHeaderViewModel by viewModels()
val channelListFactory: ChannelListViewModelFactory = ChannelListViewModelFactory(
val channelListFactory = ChannelListViewModelFactory(
filter = Filters.and(
Filters.eq("type", "messaging"),
Filters.`in`("members", listOf(user.id)),
Expand All @@ -99,7 +105,7 @@ class ChatActivity : AppCompatActivity() {
}

/* Functionality of "Meet Someone New" button -> takes user to match page. */
binding.homeMatchButton.setOnClickListener { _ ->
binding.homeMatchButton.setOnClickListener {
val intent = Intent(this, MatchActivity::class.java)
startActivity(intent)
}
Expand All @@ -108,22 +114,4 @@ class ChatActivity : AppCompatActivity() {
listenToUser(UNI_ID, USER_ID)

}

// companion object {
// // Cannot access the application context of original chat activity
// private var instance: ChatActivity? = null
// fun getContext(): Context = instance!!.applicationContext
// }
}

// Add members with ids "thierry" and "josh"
/*
channelClient.addMembers(Arrays.asList("thierry", "josh"), null).enqueue(result -> {
if (result.isSuccess()) {
Channel channel = result.data();
} else {
// Handle result.error()
}
});
*/
3 changes: 1 addition & 2 deletions app/src/main/java/com/example/drp25/ChatClientService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,8 @@ class ChatClientService(applicationContext: Context) {
fun connectCurrentUser(user: io.getstream.chat.android.client.models.User) {
client.connectUser(
user = user,
token = generateUserToken(user.id)
token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoiZGVtby11c2VyIn0.WX_Ovhfcj7wXRFdRd2uu9rqHK8shSNwI9jD6x-Tdl7A"
).enqueue()
// "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoiZGVtby11c2VyIn0.WX_Ovhfcj7wXRFdRd2uu9rqHK8shSNwI9jD6x-Tdl7A"
}

fun createChannel(channelId: String, firstUserId: String, secondUserId: String) {
Expand Down

0 comments on commit 736c320

Please sign in to comment.