-
-
Notifications
You must be signed in to change notification settings - Fork 86
Chat
This component provides a chat for the users. They automatically join chatrooms of the lectures they attend in the current semester. Furthermore, the users can create private chatrooms which can be joined via QR Code.
Befor the migration to Googles Room Persistency Library the database and server requests were handled by the ChatRoomManager
and ChatMessageManager
. In course of the migration all database queries were moved to a so called data access object (DAO). Google proposes the use of the Model-View-ViewModel pattern for applications with Room. Therefore, the ChatMessageViewModel
was introduced for solely handling database and server requests regarding the chat messages via calls to a remote and local repository. The logic of the two managers was moved to the corresponding DAO and ViewModel. As a result those two managers are not needed anymore and could be deleted. RxJava was introduced for asynchronous programming and in order to prevent that work is done on the ui thread.
ChatActivity
ChatRoomsActivity
JoinRoomScanActivity
This component consists of two different screens. ChatRoomsActivity
provides an overview about chatrooms the user already joined and possible chatrooms the user could join which are based on the lectures the user attends. From this activity you can enter the ChatActivity
, which provides the actual chat, by clicking on a chatroom. Furthermore, if the user wants to join a privat chatroom he can do this by clicking on the menu point Enter Chatroom which starts the JoinRoomScanActivity
that contains all the logic for reading the QR Code. The ChatActivity
provides the actual chat. The user can send and receive messages and display the QR code other users need to join this room.
ChatRoomListAdapter
ChatHistoryAdapter
Before the migration to Google Room Persistency Library both adapters were subclasses of CursorAdapter
. In the course of the migration we get rid of all cursors the activities described above used for accessing data fetched via SQLite raw queries. In order to make the adapters work properly they were rewritten. Both are now subclasses of BaseAdapter
which is a common base class of implementation for an adapter that can be used in ListView
.
The ChatRoomListAdapter
populates a ListView
with the chatrooms the user has joined or could join.
The ChatHistoryAdapter
populates aListView
with the chat messages. It determines whether the message is an incoming or outgoing message by comparing the current member id (currentMemeber.getId()
) with the member id of the current message (message.getMember().getId()
). If both are identical the message is an outgoing message, otherwise it would be a incoming.
These are the fields of the models needed for the chat.
- ChatMember:
var id: Int = 0
@SerializedName("lrz_id")
var lrzId: String? = null
@SerializedName("display_name")
var displayName: String? = null
var signature: String? = null
- ChatMessage:
@PrimaryKey
@ColumnInfo(name = "_id")
private int id;
private int previous;
private int room;
private String text;
private String timestamp;
private String signature;
private ChatMember member;
private boolean read;
@ColumnInfo(name = "sending")
private int sendingStatus;
- ChatPublicKey
var key: String = ""
- ChatRegistrationId
@field:SerializedName("registration_id")
var regId: String = ""
var status: String = ""
var signature: String = ""
- ChatRoom
var name: String = ""
var id: Int = 0
var members = -1
- ChatRoomAndLastMessage
@Embedded
var chatRoomDbRow: ChatRoomDbRow? = null
var text: String? = null
var timestamp: String? = null
- ChatRoomDbRow
var room: Int = 0
var name: String = ""
var semester: String = ""
@ColumnInfo(name = "semester_id")
var semesterId: String = ""
var joined: Int = 0
@ColumnInfo(name = "_id")
var id: Int = 0
var contributor: String = ""
var members: Int = -1
- ChatVerification
var signature: String = ""
var date: String = ""
var rand: String = ""
var member: Int = 0
var data: Any? = null
Different APIs are used by the chat. The following listing describes which functionality uses which API.
- create a chatroom:
/Api/chat/rooms/ - get a chatroom:
/Api/chat/rooms/{room} - leave a chatroom:
/Api/chat/rooms/{room}/leave/ - sending a message:
/Api/chat/rooms/{room}/message/ - update a message:
/Api/chat/rooms/{room}/message/{message}/ - get recent messages:
/Api/chat/rooms/{room}/messages/ - get older messages:
/Api/chat/rooms/{room}/messages/{page}/ - create a member:
/Api/chat/members/ - get a member:
/Api/chat/members/{lrz_id}/ - get rooms of a member:
/Api/chat/members/{memberId}/rooms/ - get public keys of a member:
/Api/chat/members/{memberId}/pubkeys/ - upload a registration id:
/Api/chat/members/{memberId}/registration_ids/add_id