Search in sources :

Example 1 with ChatRoomDbRow

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

the class ChatRoomController method replaceIntoRooms.

/**
 * Saves the given chat rooms into database
 */
public void replaceIntoRooms(Collection<ChatRoom> rooms) {
    if (rooms == null || rooms.isEmpty()) {
        Utils.log("No rooms passed, can't insert anything.");
        return;
    }
    chatRoomDao.markAsNotJoined();
    Utils.log("reset join status of all rooms");
    for (ChatRoom room : rooms) {
        String roomName = room.getActualName();
        String semester = room.getSemester();
        List<Integer> roomIds = chatRoomDao.getGivenLecture(roomName, semester);
        if (roomIds.isEmpty()) {
            ChatRoomDbRow chatRoom = new ChatRoomDbRow(room.getId(), roomName, "", semester, 1, 0, "", room.getMembers(), -1);
            chatRoomDao.replaceRoom(chatRoom);
        } else {
            // in dao
            chatRoomDao.updateRoomToJoined(room.getId(), room.getMembers(), roomName, semester);
        /* TODO(jacqueline8711) load the last messages when joining the chat
                chatMessageViewModel.getNewMessages(room.getId(), verification,
                                                    context instanceof ChatMessageViewModel.DataLoadInterface ?
                                                    (ChatMessageViewModel.DataLoadInterface)context : null);
                Utils.log("Loading some messages for a newly joined chatroom");*/
        }
    }
}
Also used : ChatRoom(de.tum.in.tumcampusapp.component.ui.chat.model.ChatRoom) ChatRoomDbRow(de.tum.in.tumcampusapp.component.ui.chat.model.ChatRoomDbRow)

Example 2 with ChatRoomDbRow

use of de.tum.in.tumcampusapp.component.ui.chat.model.ChatRoomDbRow 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 3 with ChatRoomDbRow

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

the class ChatRoomController method getNewUnjoined.

private List<String> getNewUnjoined() {
    List<ChatRoomDbRow> rooms = chatRoomDao.getNewUnjoined();
    if (rooms.isEmpty()) {
        return Collections.emptyList();
    }
    List<String> list = new ArrayList<>(rooms.size());
    for (ChatRoomDbRow room : rooms) {
        list.add(String.valueOf(room.getSemesterId() + ':' + room.getName()));
    }
    return list;
}
Also used : ArrayList(java.util.ArrayList) ChatRoomDbRow(de.tum.in.tumcampusapp.component.ui.chat.model.ChatRoomDbRow)

Aggregations

ChatRoomDbRow (de.tum.in.tumcampusapp.component.ui.chat.model.ChatRoomDbRow)3 ChatRoom (de.tum.in.tumcampusapp.component.ui.chat.model.ChatRoom)2 NoPrivateKey (de.tum.in.tumcampusapp.api.app.exception.NoPrivateKey)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 ChatMember (de.tum.in.tumcampusapp.component.ui.chat.model.ChatMember)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1