Search in sources :

Example 6 with ChatRoom

use of de.tum.in.tumcampusapp.component.ui.chat.model.ChatRoom in project TumCampusApp by TCA-Team.

the class WizNavExtrasActivity method onLoadInBackground.

@Override
protected ChatMember onLoadInBackground(Void... arg) {
    if (!NetUtils.isConnected(this)) {
        showNoInternetLayout();
        return null;
    }
    // Get the users lrzId and initialise chat member
    ChatMember currentChatMember = new ChatMember(Utils.getSetting(this, Const.LRZ_ID, ""));
    currentChatMember.setDisplayName(Utils.getSetting(this, Const.CHAT_ROOM_DISPLAY_NAME, ""));
    if (currentChatMember.getLrzId().equals("")) {
        return currentChatMember;
    }
    // Tell the server the new member
    ChatMember member;
    try {
        // After the user has entered their display name, send a request to the server to create the new member
        member = TUMCabeClient.getInstance(this).createMember(currentChatMember);
    } catch (IOException e) {
        Utils.log(e);
        Utils.showToastOnUIThread(this, R.string.error_setup_chat_member);
        return null;
    }
    // Catch a possible error, when we didn't get something returned
    if (member == null || member.getLrzId() == null) {
        Utils.showToastOnUIThread(this, R.string.error_setup_chat_member);
        return null;
    }
    // Generate the private key and upload the public key to the server
    AuthenticationManager am = new AuthenticationManager(this);
    if (!am.generatePrivateKey(member)) {
        // We cannot continue if the upload of the Public Key does not work
        Utils.showToastOnUIThread(this, getString(R.string.failure_uploading_public_key));
        return null;
    }
    // Try to restore already joined chat rooms from server
    try {
        List<ChatRoom> rooms = TUMCabeClient.getInstance(this).getMemberRooms(member.getId(), ChatVerification.Companion.getChatVerification(this, member));
        new ChatRoomController(this).replaceIntoRooms(rooms);
        // Store that this key was activated
        Utils.setSetting(this, Const.PRIVATE_KEY_ACTIVE, true);
        return member;
    } catch (IOException | NoPrivateKey e) {
        Utils.log(e);
    }
    return null;
}
Also used : ChatMember(de.tum.in.tumcampusapp.component.ui.chat.model.ChatMember) AuthenticationManager(de.tum.in.tumcampusapp.api.app.AuthenticationManager) NoPrivateKey(de.tum.in.tumcampusapp.api.app.exception.NoPrivateKey) ChatRoom(de.tum.in.tumcampusapp.component.ui.chat.model.ChatRoom) IOException(java.io.IOException) ChatRoomController(de.tum.in.tumcampusapp.component.ui.chat.ChatRoomController)

Aggregations

ChatRoom (de.tum.in.tumcampusapp.component.ui.chat.model.ChatRoom)6 NoPrivateKey (de.tum.in.tumcampusapp.api.app.exception.NoPrivateKey)4 ChatRoomController (de.tum.in.tumcampusapp.component.ui.chat.ChatRoomController)2 ChatMember (de.tum.in.tumcampusapp.component.ui.chat.model.ChatMember)2 ChatRoomDbRow (de.tum.in.tumcampusapp.component.ui.chat.model.ChatRoomDbRow)2 ChatVerification (de.tum.in.tumcampusapp.component.ui.chat.model.ChatVerification)2 IOException (java.io.IOException)2 Intent (android.content.Intent)1 NonNull (android.support.annotation.NonNull)1 Gson (com.google.gson.Gson)1 AuthenticationManager (de.tum.in.tumcampusapp.api.app.AuthenticationManager)1 TUMOnlineRequest (de.tum.in.tumcampusapp.api.tumonline.TUMOnlineRequest)1 LecturesSearchRow (de.tum.in.tumcampusapp.component.tumui.lectures.model.LecturesSearchRow)1 LecturesSearchRowSet (de.tum.in.tumcampusapp.component.tumui.lectures.model.LecturesSearchRowSet)1 ChatRoomAndLastMessage (de.tum.in.tumcampusapp.component.ui.chat.model.ChatRoomAndLastMessage)1 Call (retrofit2.Call)1 Callback (retrofit2.Callback)1 Response (retrofit2.Response)1