Search in sources :

Example 6 with ChatMessage

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

the class RSASignerTestCase method testAsciiMessageSigning.

/**
 * Tests that a valid ASCII-based message is correctly signed.
 */
@Test
public void testAsciiMessageSigning() {
    signer = new RSASigner(privateKeyFixture);
    ChatMessage message = messageFixtures.get(0);
    assertThat(signer.sign(message.getText())).isEqualTo(message.getSignature());
}
Also used : ChatMessage(de.tum.in.tumcampusapp.component.ui.chat.model.ChatMessage) RSASigner(de.tum.in.tumcampusapp.utils.RSASigner) Test(org.junit.Test)

Example 7 with ChatMessage

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

the class RSASignerTestCase method buildChatMessage.

private ChatMessage buildChatMessage(String text, String signature) {
    ChatMessage message = new ChatMessage(text);
    message.setSignature(signature);
    return message;
}
Also used : ChatMessage(de.tum.in.tumcampusapp.component.ui.chat.model.ChatMessage)

Example 8 with ChatMessage

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

the class RSASignerTestCase method testUnicodeMessageSigning.

/**
 * Tests that a unicode (european) message is correctly signed.
 */
@Test
public void testUnicodeMessageSigning() {
    signer = new RSASigner(privateKeyFixture);
    ChatMessage message = messageFixtures.get(1);
    assertThat(signer.sign(message.getText())).isEqualTo(message.getSignature());
}
Also used : ChatMessage(de.tum.in.tumcampusapp.component.ui.chat.model.ChatMessage) RSASigner(de.tum.in.tumcampusapp.utils.RSASigner) Test(org.junit.Test)

Example 9 with ChatMessage

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

the class ChatNotification method onDataLoaded.

public void onDataLoaded() {
    List<ChatMessage> messages = Lists.reverse(chatMessageDao.getLastUnread(chatRoom.getId()));
    Intent intent = new Intent(Const.CHAT_BROADCAST_NAME);
    intent.putExtra("GCMChat", this.extras);
    LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
    notificationText = null;
    if (messages != null) {
        for (ChatMessage msg : messages) {
            if (notificationText == null) {
                notificationText = msg.getText();
            } else {
                notificationText += "\n" + msg.getText();
            }
        }
    }
    // Put the data into the intent
    Intent notificationIntent = new Intent(context, ChatActivity.class);
    notificationIntent.putExtra(Const.CURRENT_CHAT_ROOM, new Gson().toJson(chatRoom));
    sBuilder = TaskStackBuilder.create(context);
    sBuilder.addNextIntent(new Intent(context, MainActivity.class));
    sBuilder.addNextIntent(new Intent(context, ChatRoomsActivity.class));
    sBuilder.addNextIntent(notificationIntent);
    showNotification();
}
Also used : ChatRoomsActivity(de.tum.in.tumcampusapp.component.ui.chat.activity.ChatRoomsActivity) ChatMessage(de.tum.in.tumcampusapp.component.ui.chat.model.ChatMessage) Gson(com.google.gson.Gson) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) MainActivity(de.tum.in.tumcampusapp.component.ui.overview.MainActivity)

Example 10 with ChatMessage

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

the class ChatActivity method sendMessage.

private void sendMessage(String text) {
    if (chatHistoryAdapter.mEditedItem == null) {
        final ChatMessage message = new ChatMessage(text, currentChatMember);
        message.setRoom(currentChatRoom.getId());
        chatHistoryAdapter.add(message);
        chatMessageViewModel.addToUnsent(message);
    } else {
        chatHistoryAdapter.mEditedItem.setText(etMessage.getText().toString());
        chatHistoryAdapter.mEditedItem.setRoom(currentChatRoom.getId());
        chatHistoryAdapter.mEditedItem.setSendingStatus(ChatMessage.STATUS_SENDING);
        chatHistoryAdapter.mEditedItem.setMember(currentChatMember);
        chatMessageViewModel.addToUnsent(chatHistoryAdapter.mEditedItem);
        chatHistoryAdapter.mEditedItem = null;
        chatMessageViewModel.markAsRead(currentChatRoom.getId());
        chatHistoryAdapter.updateHistory(chatMessageViewModel.getAll(currentChatRoom.getId()));
    }
    // let the service handle the actual sending of the message
    SendMessageService.enqueueWork(this, new Intent());
}
Also used : ChatMessage(de.tum.in.tumcampusapp.component.ui.chat.model.ChatMessage) Intent(android.content.Intent)

Aggregations

ChatMessage (de.tum.in.tumcampusapp.component.ui.chat.model.ChatMessage)19 Test (org.junit.Test)11 ChatMessageValidator (de.tum.in.tumcampusapp.component.ui.chat.ChatMessageValidator)7 RSASigner (de.tum.in.tumcampusapp.utils.RSASigner)4 Intent (android.content.Intent)2 ChatPublicKey (de.tum.in.tumcampusapp.component.ui.chat.model.ChatPublicKey)2 PendingIntent (android.app.PendingIntent)1 View (android.view.View)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 Gson (com.google.gson.Gson)1 AuthenticationManager (de.tum.in.tumcampusapp.api.app.AuthenticationManager)1 NoPrivateKey (de.tum.in.tumcampusapp.api.app.exception.NoPrivateKey)1 ChatMessageViewModel (de.tum.in.tumcampusapp.component.ui.chat.ChatMessageViewModel)1 ChatRoomsActivity (de.tum.in.tumcampusapp.component.ui.chat.activity.ChatRoomsActivity)1 ChatHistoryAdapter (de.tum.in.tumcampusapp.component.ui.chat.adapter.ChatHistoryAdapter)1 ChatMessageLocalRepository (de.tum.in.tumcampusapp.component.ui.chat.repository.ChatMessageLocalRepository)1 ChatMessageRemoteRepository (de.tum.in.tumcampusapp.component.ui.chat.repository.ChatMessageRemoteRepository)1 MainActivity (de.tum.in.tumcampusapp.component.ui.overview.MainActivity)1 TcaDb (de.tum.in.tumcampusapp.database.TcaDb)1