Search in sources :

Example 1 with ChatVerification

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");
        }
    });
}
Also used : NoPrivateKey(de.tum.in.tumcampusapp.api.app.exception.NoPrivateKey) ChatRoom(de.tum.in.tumcampusapp.component.ui.chat.model.ChatRoom) ChatVerification(de.tum.in.tumcampusapp.component.ui.chat.model.ChatVerification) Intent(android.content.Intent) ChatRoomController(de.tum.in.tumcampusapp.component.ui.chat.ChatRoomController)

Example 2 with ChatVerification

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);
}
Also used : Response(retrofit2.Response) Call(retrofit2.Call) Callback(retrofit2.Callback) NoPrivateKey(de.tum.in.tumcampusapp.api.app.exception.NoPrivateKey) ChatRoom(de.tum.in.tumcampusapp.component.ui.chat.model.ChatRoom) ChatRoomAndLastMessage(de.tum.in.tumcampusapp.component.ui.chat.model.ChatRoomAndLastMessage) NonNull(android.support.annotation.NonNull) ChatVerification(de.tum.in.tumcampusapp.component.ui.chat.model.ChatVerification)

Example 3 with ChatVerification

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;
}
Also used : ChatMember(de.tum.in.tumcampusapp.component.ui.chat.model.ChatMember) Context(android.content.Context) NoPrivateKey(de.tum.in.tumcampusapp.api.app.exception.NoPrivateKey) ChatVerification(de.tum.in.tumcampusapp.component.ui.chat.model.ChatVerification) IOException(java.io.IOException)

Aggregations

NoPrivateKey (de.tum.in.tumcampusapp.api.app.exception.NoPrivateKey)3 ChatVerification (de.tum.in.tumcampusapp.component.ui.chat.model.ChatVerification)3 ChatRoom (de.tum.in.tumcampusapp.component.ui.chat.model.ChatRoom)2 Context (android.content.Context)1 Intent (android.content.Intent)1 NonNull (android.support.annotation.NonNull)1 ChatRoomController (de.tum.in.tumcampusapp.component.ui.chat.ChatRoomController)1 ChatMember (de.tum.in.tumcampusapp.component.ui.chat.model.ChatMember)1 ChatRoomAndLastMessage (de.tum.in.tumcampusapp.component.ui.chat.model.ChatRoomAndLastMessage)1 IOException (java.io.IOException)1 Call (retrofit2.Call)1 Callback (retrofit2.Callback)1 Response (retrofit2.Response)1