use of de.tum.in.tumcampusapp.component.ui.chat.repository.ChatMessageRemoteRepository in project TumCampusApp by TCA-Team.
the class ChatNotification method getNewMessages.
private void getNewMessages(ChatRoom chatRoom, ChatMember member, int messageId) throws NoPrivateKey, IOException {
ChatMessageLocalRepository localRepository = ChatMessageLocalRepository.INSTANCE;
localRepository.setDb(TcaDb.getInstance(context));
ChatMessageRemoteRepository remoteRepository = ChatMessageRemoteRepository.INSTANCE;
remoteRepository.setTumCabeClient(TUMCabeClient.getInstance(context));
ChatMessageViewModel chatMessageViewModel = new ChatMessageViewModel(localRepository, remoteRepository, new CompositeDisposable());
if (messageId == -1) {
chatMessageViewModel.getNewMessages(chatRoom.getId(), ChatVerification.Companion.getChatVerification(context, member), this);
} else {
// edit
chatMessageViewModel.getOlderMessages(chatRoom.getId(), messageId, ChatVerification.Companion.getChatVerification(context, member), null);
}
}
use of de.tum.in.tumcampusapp.component.ui.chat.repository.ChatMessageRemoteRepository in project TumCampusApp by TCA-Team.
the class ChatActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Toolbar toolbar = findViewById(R.id.main_toolbar);
setSupportActionBar(toolbar);
this.getIntentData();
TcaDb tcaDb = TcaDb.getInstance(this);
ChatMessageRemoteRepository remoteRepository = ChatMessageRemoteRepository.INSTANCE;
remoteRepository.setTumCabeClient(TUMCabeClient.getInstance(this));
ChatMessageLocalRepository localRepository = ChatMessageLocalRepository.INSTANCE;
localRepository.setDb(tcaDb);
chatMessageViewModel = new ChatMessageViewModel(localRepository, remoteRepository, mDisposable);
this.bindUIElements();
}
use of de.tum.in.tumcampusapp.component.ui.chat.repository.ChatMessageRemoteRepository in project TumCampusApp by TCA-Team.
the class SendMessageService method onHandleWork.
@Override
protected void onHandleWork(@NonNull Intent intent) {
TcaDb tcaDb = TcaDb.getInstance(this);
final CompositeDisposable mDisposable = new CompositeDisposable();
ChatMessageRemoteRepository remoteRepository = ChatMessageRemoteRepository.INSTANCE;
remoteRepository.setTumCabeClient(TUMCabeClient.getInstance(this));
ChatMessageLocalRepository localRepository = ChatMessageLocalRepository.INSTANCE;
localRepository.setDb(tcaDb);
ChatMessageViewModel chatMessageViewModel = new ChatMessageViewModel(localRepository, remoteRepository, mDisposable);
chatMessageViewModel.deleteOldEntries();
// Get all unsent messages from database
List<ChatMessage> unsentMsg = chatMessageViewModel.getUnsent();
if (unsentMsg.isEmpty()) {
return;
}
int numberOfAttempts = 0;
AuthenticationManager am = new AuthenticationManager(this);
// Try to send the message 5 times
while (numberOfAttempts < MAX_SEND_TRIES) {
try {
for (ChatMessage message : unsentMsg) {
// Generate signature and store it in the message
message.setSignature(am.sign(message.getText()));
// Send the message to the server
chatMessageViewModel.sendMessage(message.getRoom(), message, this.getApplicationContext());
Utils.logv("successfully sent message: " + message.getText());
}
// Exit the loop
return;
} catch (NoPrivateKey noPrivateKey) {
// Nothing can be done, just exit
return;
} catch (Exception e) {
Utils.log(e);
numberOfAttempts++;
}
// Sleep for five seconds, maybe the server is currently really busy
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
Utils.log(e);
}
}
}
Aggregations