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");*/
}
}
}
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();
}
}
}
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;
}
Aggregations