Support sending and displaying typing notifications (#9)
This commit is contained in:
@@ -83,6 +83,27 @@ impl ChatState {
|
||||
pub fn id(&self) -> &RoomId {
|
||||
&self.room_id
|
||||
}
|
||||
|
||||
pub fn typing_notice(
|
||||
&self,
|
||||
act: &EditorAction,
|
||||
ctx: &ProgramContext,
|
||||
store: &mut ProgramStore,
|
||||
) {
|
||||
if !self.focus.is_msgbar() || act.is_readonly(ctx) {
|
||||
return;
|
||||
}
|
||||
|
||||
if matches!(act, EditorAction::History(_)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if !store.application.settings.tunables.typing_notice {
|
||||
return;
|
||||
}
|
||||
|
||||
store.application.worker.typing_notice(self.room_id.clone());
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! delegate {
|
||||
@@ -148,6 +169,8 @@ impl Editable<ProgramContext, ProgramStore, IambInfo> for ChatState {
|
||||
ctx: &ProgramContext,
|
||||
store: &mut ProgramStore,
|
||||
) -> EditResult<EditInfo, IambInfo> {
|
||||
self.typing_notice(act, ctx, store);
|
||||
|
||||
match delegate!(self, w => w.editor_command(act, ctx, store)) {
|
||||
res @ Ok(_) => res,
|
||||
Err(EditError::WrongBuffer(IambBufferId::Room(room_id, focus)))
|
||||
|
||||
@@ -1125,6 +1125,9 @@ impl<'a> StatefulWidget for Scrollback<'a> {
|
||||
type State = ScrollbackState;
|
||||
|
||||
fn render(self, area: Rect, buf: &mut Buffer, state: &mut Self::State) {
|
||||
let info = self.store.application.rooms.entry(state.room_id.clone()).or_default();
|
||||
let area = info.render_typing(area, buf, &self.store.application.settings);
|
||||
|
||||
state.set_term_info(area);
|
||||
|
||||
let height = state.viewctx.get_height();
|
||||
@@ -1137,8 +1140,6 @@ impl<'a> StatefulWidget for Scrollback<'a> {
|
||||
state.viewctx.corner = state.cursor.clone();
|
||||
}
|
||||
|
||||
let info = self.store.application.get_room_info(state.room_id.clone());
|
||||
|
||||
let cursor = &state.cursor;
|
||||
let cursor_key = if let Some(k) = cursor.to_key(info) {
|
||||
k
|
||||
@@ -1297,6 +1298,9 @@ mod tests {
|
||||
let prev = MoveDir2D::Up;
|
||||
let next = MoveDir2D::Down;
|
||||
|
||||
// Skip rendering typing notices.
|
||||
store.application.settings.tunables.typing_notice_display = false;
|
||||
|
||||
assert_eq!(scrollback.cursor, MessageCursor::latest());
|
||||
assert_eq!(scrollback.viewctx.dimensions, (0, 0));
|
||||
assert_eq!(scrollback.viewctx.corner, MessageCursor::latest());
|
||||
@@ -1425,6 +1429,9 @@ mod tests {
|
||||
let mut scrollback = ScrollbackState::new(TEST_ROOM1_ID.clone());
|
||||
let ctx = ProgramContext::default();
|
||||
|
||||
// Skip rendering typing notices.
|
||||
store.application.settings.tunables.typing_notice_display = false;
|
||||
|
||||
// Set a terminal width of 60, and height of 3, rendering in scrollback as:
|
||||
//
|
||||
// |------------------------------------------------------------|
|
||||
|
||||
@@ -21,8 +21,10 @@ pub struct WelcomeState {
|
||||
impl WelcomeState {
|
||||
pub fn new(store: &mut ProgramStore) -> Self {
|
||||
let buf = store.buffers.load_str(IambBufferId::Welcome, WELCOME_TEXT);
|
||||
let mut tbox = TextBoxState::new(buf);
|
||||
tbox.set_readonly(true);
|
||||
|
||||
WelcomeState { tbox: TextBoxState::new(buf) }
|
||||
WelcomeState { tbox }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user