resetNewMessage method
채팅방 정보 /chat-joins/$uid/$otherUid
에서 newMessage 를 0 으로 초기화 한다.
사용처: 내가 현재 채팅방에 들어왔으니, 현재 채팅방의 새로운 메시지가 없다는 것을 표시 할 때 사용.
특히, 내가 채팅방에 들어가 갈 때, 또는 내가 채팅방에 들어가 있는데, 새로운 메시지가 전달되어져 오는 경우, 이 함수가 호출되어 그 채팅방의 새 메시지 수를 0으로 초기화 할 때 사용한다.
setting the order into -updatedAt (w/out the "1") this is used to order by unread/read messages then by updatedAt w/out the "1" it means it has been read.
주의, 로그인을 하지 않은 상태이면 그냥 리턴한다. 예를 들어, 메인 페이지에 (로그인을 하기 전에) 채팅방을 보여주는 경우,
join
은 맨 처음 채팅방에 입장 할 때, 한번만 전달되주면 된다. 새 메시지가 없다는 표시를 하기 위해서이다.
Implementation
Future<void> resetNewMessage({
int? order,
ChatRoom? join,
}) async {
if (myUid == null) {
return;
}
int? singleChatOrder, groupChatOrder;
/// 새 메시지가 있다는 뜻인 -11 을 그냥 -1 로 변경한다.
///
/// order 값 맨 앞에 1을 추가한 것이다. 예를 들어, order 값이 -12345 와 같다면 맨 앞에 1을 추가해서
/// -112345 가 된 것이다. 즉, 맨 앞의 -11 을 그냥 -1 로 바꾸는 것이다.
if (join != null) {
if (join.singleChatOrder.toString().contains('-11')) {
singleChatOrder =
int.parse(join.singleChatOrder.toString().replaceAll('-11', '-1'));
}
if (join.groupChatOrder.toString().contains('-11')) {
groupChatOrder =
int.parse(join.groupChatOrder.toString().replaceAll('-11', '-1'));
}
}
final myJoinRef = ChatJoin.joinRef(myUid!, room.id);
myJoinRef.update({
Field.newMessage: null,
if (singleChatOrder != null) Field.singleChatOrder: singleChatOrder,
if (groupChatOrder != null) Field.groupChatOrder: groupChatOrder,
});
}