use of de.tum.in.tumcampusapp.component.ui.chat.model.ChatVerification in project TumCampusApp by TCA-Team.
the class ChatActivity method onClick.
/**
* When user confirms the leave dialog send the request to the server.
*
* @param dialog Dialog handle
* @param which The users choice (ignored because this is only called when the user confirms)
*/
@Override
public void onClick(DialogInterface dialog, int which) {
// Send request to the server to remove the user from this room
ChatVerification verification;
try {
verification = ChatVerification.Companion.getChatVerification(this, currentChatMember);
} catch (NoPrivateKey noPrivateKey) {
return;
}
TUMCabeClient.getInstance(this).leaveChatRoom(currentChatRoom, verification, new Callback<ChatRoom>() {
@Override
public void onResponse(Call<ChatRoom> call, Response<ChatRoom> room) {
Utils.logv("Success leaving chat room: " + room.body().getName());
new ChatRoomController(ChatActivity.this).leave(currentChatRoom);
// Move back to ChatRoomsActivity
Intent intent = new Intent(ChatActivity.this, ChatRoomsActivity.class);
startActivity(intent);
}
@Override
public void onFailure(Call<ChatRoom> call, Throwable t) {
Utils.log(t, "Failure leaving chat room");
}
});
}
use of de.tum.in.tumcampusapp.component.ui.chat.model.ChatVerification in project TumCampusApp by TCA-Team.
the class ChatRoomsActivity method createOrJoinChatRoom.
/**
* Creates a given chat room if it does not exist and joins it
* Works asynchronously.
*/
private void createOrJoinChatRoom(String name) {
if (this.currentChatMember == null) {
Utils.showToast(this, getString(R.string.chat_not_setup));
return;
}
Utils.logv("create or join chat room " + name);
currentChatRoom = new ChatRoom(name);
ChatVerification verification;
try {
verification = ChatVerification.Companion.getChatVerification(this, this.currentChatMember);
} catch (NoPrivateKey noPrivateKey) {
this.finish();
return;
}
Callback callback = new Callback<ChatRoom>() {
@Override
public void onResponse(@NonNull Call<ChatRoom> call, @NonNull Response<ChatRoom> response) {
if (!response.isSuccessful()) {
Utils.logv("Error creating&joining chat room: " + response.message());
return;
}
// The POST request is successful: go to room. API should have auto joined it
Utils.logv("Success creating&joining chat room: " + response.body());
currentChatRoom = response.body();
manager.join(currentChatRoom);
// When we show joined chat rooms open chat room directly
if (mCurrentMode == 1) {
moveToChatActivity();
} else {
// Otherwise show a nice information, that we added the room
final List<ChatRoomAndLastMessage> rooms = manager.getAllByStatus(mCurrentMode);
runOnUiThread(() -> {
chatRoomAdapter.updateRooms(rooms);
Utils.showToast(ChatRoomsActivity.this, R.string.joined_chat_room);
});
}
}
@Override
public void onFailure(@NonNull Call<ChatRoom> call, @NonNull Throwable t) {
Utils.log(t, "Failure creating/joining chat room - trying to GET it from the server");
Utils.showToastOnUIThread(ChatRoomsActivity.this, R.string.activate_key);
}
};
TUMCabeClient.getInstance(this).createRoom(currentChatRoom, verification, callback);
}
use of de.tum.in.tumcampusapp.component.ui.chat.model.ChatVerification in project TumCampusApp by TCA-Team.
the class CardsDetailActivity method onLoadInBackground.
@Override
protected StudyCard onLoadInBackground(Void... arg) {
if (!card.is_valid()) {
return null;
}
try {
ChatMember chatMember = Utils.getSetting(this, Const.CHAT_MEMBER, ChatMember.class);
final ChatVerification v = ChatVerification.Companion.getChatVerification(this.getApplicationContext(), chatMember);
final Context c = this;
return TUMCabeClient.getInstance(c).addStudyCard(card, v);
} catch (IOException e) {
Utils.log(e);
} catch (NoPrivateKey e) {
Utils.log(e);
}
return null;
}
Aggregations