Search in sources :

Example 1 with ChatMember

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

the class ChatRoomController method onRequestCard.

@Override
public void onRequestCard(Context context) {
    // Get all of the users lectures and save them as possible chat rooms
    TUMOnlineRequest<LecturesSearchRowSet> requestHandler = new TUMOnlineRequest<>(TUMOnlineConst.Companion.getLECTURES_PERSONAL(), context, true);
    Optional<LecturesSearchRowSet> lecturesList = requestHandler.fetch();
    if (lecturesList.isPresent()) {
        List<LecturesSearchRow> lectures = lecturesList.get().getLehrveranstaltungen();
        this.createLectureRooms(lectures);
    }
    // Join all new chat rooms
    if (Utils.getSettingBool(context, Const.AUTO_JOIN_NEW_ROOMS, false)) {
        List<String> newRooms = this.getNewUnjoined();
        ChatMember currentChatMember = Utils.getSetting(context, Const.CHAT_MEMBER, ChatMember.class);
        for (String roomId : newRooms) {
            // Join chat room
            try {
                ChatRoom currentChatRoom = new ChatRoom(roomId);
                currentChatRoom = TUMCabeClient.getInstance(context).createRoom(currentChatRoom, ChatVerification.Companion.getChatVerification(context, currentChatMember));
                if (currentChatRoom != null) {
                    this.join(currentChatRoom);
                }
            } catch (IOException e) {
                Utils.log(e, " - error occured while creating the room!");
            } catch (NoPrivateKey noPrivateKey) {
                return;
            }
        }
    }
    // Get all rooms that have unread messages
    List<ChatRoomDbRow> rooms = chatRoomDao.getUnreadRooms();
    if (!rooms.isEmpty()) {
        for (ChatRoomDbRow room : rooms) {
            ChatMessagesCard card = new ChatMessagesCard(context, room);
            card.apply();
        }
    }
}
Also used : ChatMember(de.tum.in.tumcampusapp.component.ui.chat.model.ChatMember) TUMOnlineRequest(de.tum.in.tumcampusapp.api.tumonline.TUMOnlineRequest) LecturesSearchRowSet(de.tum.in.tumcampusapp.component.tumui.lectures.model.LecturesSearchRowSet) LecturesSearchRow(de.tum.in.tumcampusapp.component.tumui.lectures.model.LecturesSearchRow) IOException(java.io.IOException) NoPrivateKey(de.tum.in.tumcampusapp.api.app.exception.NoPrivateKey) ChatRoom(de.tum.in.tumcampusapp.component.ui.chat.model.ChatRoom) ChatRoomDbRow(de.tum.in.tumcampusapp.component.ui.chat.model.ChatRoomDbRow)

Example 2 with ChatMember

use of de.tum.in.tumcampusapp.component.ui.chat.model.ChatMember 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)

Example 3 with ChatMember

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

the class ChatNotification method prepare.

private void prepare() throws IOException {
    Utils.logv("Received GCM notification: room=" + this.extras.getRoom() + " member=" + this.extras.getMember() + " message=" + this.extras.getMessage());
    // Get the data necessary for the ChatActivity
    ChatMember member = Utils.getSetting(context, Const.CHAT_MEMBER, ChatMember.class);
    chatRoom = TUMCabeClient.getInstance(context).getChatRoom(this.extras.getRoom());
    try {
        this.getNewMessages(chatRoom, member, this.extras.getMessage());
    } catch (NoPrivateKey noPrivateKey) {
        Utils.log(noPrivateKey);
    }
}
Also used : ChatMember(de.tum.in.tumcampusapp.component.ui.chat.model.ChatMember) NoPrivateKey(de.tum.in.tumcampusapp.api.app.exception.NoPrivateKey)

Example 4 with ChatMember

use of de.tum.in.tumcampusapp.component.ui.chat.model.ChatMember 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)4 ChatMember (de.tum.in.tumcampusapp.component.ui.chat.model.ChatMember)4 IOException (java.io.IOException)3 ChatRoom (de.tum.in.tumcampusapp.component.ui.chat.model.ChatRoom)2 Context (android.content.Context)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 ChatRoomController (de.tum.in.tumcampusapp.component.ui.chat.ChatRoomController)1 ChatRoomDbRow (de.tum.in.tumcampusapp.component.ui.chat.model.ChatRoomDbRow)1 ChatVerification (de.tum.in.tumcampusapp.component.ui.chat.model.ChatVerification)1