Skip to content

Commit

Permalink
Merge pull request #320 from bitfriend/issue198_cleanup-code-periodic…
Browse files Browse the repository at this point in the history
…ally

Issue198 cleanup code periodically
  • Loading branch information
bitfriend authored Oct 29, 2022
2 parents d9752e7 + 433bc94 commit 58b057b
Show file tree
Hide file tree
Showing 14 changed files with 127 additions and 100 deletions.
5 changes: 1 addition & 4 deletions app/lib/screens/HomeScreens/chat/Overview.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class _ChatOverviewState extends State<ChatOverview> {
),
),
const SizedBox(height: 10),
buildList(context),
if (!widget.client.isGuest()) buildList(context),
],
),
),
Expand Down Expand Up @@ -120,9 +120,6 @@ class _ChatOverviewState extends State<ChatOverview> {
}

Widget buildList(BuildContext context) {
if (widget.client.isGuest()) {
return const SizedBox();
}
return GetBuilder<ChatListController>(
id: 'chatlist',
builder: (ChatListController controller) {
Expand Down
2 changes: 0 additions & 2 deletions app/lib/screens/HomeScreens/faq/Editor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,6 @@ class _HtmlEditorExampleState extends State<HtmlEditorExample> {
},
),
)
else
const SizedBox()
],
),
),
Expand Down
1 change: 0 additions & 1 deletion app/lib/screens/HomeScreens/faq/Item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,6 @@ class _FaqItemScreenState extends State<FaqItemScreen> {
endIndent: 20,
color: Colors.grey,
),
const SizedBox(),
],
),
),
Expand Down
8 changes: 4 additions & 4 deletions app/lib/widgets/ChatListItem.dart
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,10 @@ class _ChatListItemState extends State<ChatListItem> {
);
}

Widget buildSubtitle(BuildContext context) {
Widget? buildSubtitle(BuildContext context) {
if (widget.latestMessage == null) {
if (widget.typingUsers.isEmpty) {
return const SizedBox();
return null;
}
return Text(
getUserPlural(widget.typingUsers),
Expand Down Expand Up @@ -189,9 +189,9 @@ class _ChatListItemState extends State<ChatListItem> {
);
}

Widget buildTrailing(BuildContext context) {
Widget? buildTrailing(BuildContext context) {
if (widget.latestMessage == null) {
return const SizedBox();
return null;
}
return Text(
DateFormat.Hm().format(
Expand Down
7 changes: 2 additions & 5 deletions app/lib/widgets/CustomChatInput.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class CustomChatInput extends StatelessWidget {
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
_buildPlusButton(controller),
if (isChatScreen) _buildAttachmentButton(controller),
Expanded(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 10),
Expand Down Expand Up @@ -78,10 +78,7 @@ class CustomChatInput extends StatelessWidget {
);
}

Widget _buildPlusButton(ChatRoomController controller) {
if (isChatScreen != true) {
return const SizedBox();
}
Widget _buildAttachmentButton(ChatRoomController controller) {
return Obx(
() => InkWell(
onTap: () {
Expand Down
6 changes: 2 additions & 4 deletions app/lib/widgets/EmptyHistoryPlaceholder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ class EmptyHistoryPlaceholder extends StatelessWidget {
),
),
),
_buildTypingIndicator(controller),
if (controller.typingUsers.isNotEmpty)
_buildTypingIndicator(controller),
],
),
);
Expand All @@ -51,9 +52,6 @@ class EmptyHistoryPlaceholder extends StatelessWidget {
}

Widget _buildTypingIndicator(ChatRoomController controller) {
if (controller.typingUsers.isEmpty) {
return const SizedBox();
}
return Positioned.fill(
child: Align(
alignment: Alignment.bottomLeft,
Expand Down
5 changes: 1 addition & 4 deletions app/lib/widgets/SideMenu.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class _SideDrawerState extends State<SideDrawer> {
buildSharedDocumentsItem(),
buildFaqItem(),
const SizedBox(height: 5),
buildLogoutItem(context),
if (!widget.client.isGuest()) buildLogoutItem(context),
],
),
),
Expand Down Expand Up @@ -302,9 +302,6 @@ class _SideDrawerState extends State<SideDrawer> {
}

Widget buildLogoutItem(BuildContext context) {
if (widget.client.isGuest()) {
return const SizedBox();
}
return ListTile(
leading: SvgPicture.asset(
'assets/images/logout.svg',
Expand Down
11 changes: 2 additions & 9 deletions app/lib/widgets/ToDoListView.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class _ToDoListViewState extends State<ToDoListView> {
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
buildSubtitle(),
buildDivider(),
if (!todoController.initialExpand.value) buildDivider(),
Padding(
padding: const EdgeInsets.only(top: 10),
child: Row(
Expand Down Expand Up @@ -98,7 +98,6 @@ class _ToDoListViewState extends State<ToDoListView> {
),
onExpansionChanged: (val) => todoController.toggleExpand(),
initiallyExpanded: false,
trailing: const SizedBox(),
children: [
ListView(
shrinkWrap: true,
Expand Down Expand Up @@ -164,7 +163,7 @@ class _ToDoListViewState extends State<ToDoListView> {
),
],
),
buildCompletedTasks(),
if (todoController.expandBtn.value) buildCompletedTasks(),
],
),
),
Expand Down Expand Up @@ -196,9 +195,6 @@ class _ToDoListViewState extends State<ToDoListView> {
}

Widget buildDivider() {
if (todoController.initialExpand.value) {
return const SizedBox();
}
return const Divider(
color: ToDoTheme.listDividerColor,
indent: 0,
Expand All @@ -208,9 +204,6 @@ class _ToDoListViewState extends State<ToDoListView> {
}

Widget buildCompletedTasks() {
if (!todoController.expandBtn.value) {
return const SizedBox();
}
return Padding(
padding: const EdgeInsets.symmetric(vertical: 10),
child: ListView(
Expand Down
19 changes: 12 additions & 7 deletions app/lib/widgets/ToDoTaskItem.dart
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,7 @@ class _ToDoTaskItemState extends State<ToDoTaskItem> {
: ToDoTheme.inactiveCheckColor,
shape: BoxShape.circle,
),
child: widget.isCompleted
? const Icon(
Icons.done_outlined,
color: ToDoTheme.inactiveCheckColor,
size: 10,
)
: const SizedBox(),
child: checkBuilder(),
),
),
Expanded(
Expand Down Expand Up @@ -198,6 +192,17 @@ class _ToDoTaskItemState extends State<ToDoTaskItem> {
);
}

Widget? checkBuilder() {
if (!widget.isCompleted) {
return null;
}
return const Icon(
Icons.done_outlined,
color: ToDoTheme.inactiveCheckColor,
size: 10,
);
}

List<ImageProvider<Object>> getMockAvatars(int count) {
return List.generate(count, (index) {
int id = Random().nextInt(70);
Expand Down
10 changes: 2 additions & 8 deletions app/lib/widgets/TypeIndicator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ class _TypeIndicatorState extends State<TypeIndicator>
? MainAxisAlignment.start
: MainAxisAlignment.end,
children: [
buildStart(),
if (widget.bubbleAlignment == BubbleRtlAlignment.left) buildStart(),
Container(
margin: const EdgeInsets.all(8),
padding: const EdgeInsets.only(top: 12),
Expand Down Expand Up @@ -169,16 +169,13 @@ class _TypeIndicatorState extends State<TypeIndicator>
],
),
),
buildEnd(),
if (widget.bubbleAlignment == BubbleRtlAlignment.right) buildEnd(),
],
),
);
}

Widget buildStart() {
if (widget.bubbleAlignment != BubbleRtlAlignment.left) {
return const SizedBox();
}
return Container(
margin: const EdgeInsets.only(right: 12),
child: TypingWidget(
Expand All @@ -189,9 +186,6 @@ class _TypeIndicatorState extends State<TypeIndicator>
}

Widget buildEnd() {
if (widget.bubbleAlignment != BubbleRtlAlignment.right) {
return const SizedBox();
}
return Container(
margin: const EdgeInsets.only(left: 12),
child: TypingWidget(
Expand Down
30 changes: 16 additions & 14 deletions native/cli/src/action/fetch_news.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
use anyhow::{bail, Context, Result};
use clap::Parser;
use effektio_core::{
events::{NewsContentType, NewsEventDevContent},
ruma::{
api::client::filter::RoomEventFilter,
events::{room::MediaSource, MessageLikeEvent},
RoomId,
},
};
use log::{info, warn};

use crate::config::{LoginConfig, ENV_ROOM};
use effektio_core::events;
use effektio_core::ruma;

use crate::ruma::api::client::filter::RoomEventFilter;
use crate::ruma::events::room::MediaSource;

use log::{info, warn};

/// Posting a news item to a given room
#[derive(Parser, Debug)]
pub struct FetchNews {
/// The room you want to post the news to
#[clap(short, long, parse(try_from_str), env = ENV_ROOM)]
pub room: Box<ruma::RoomId>,
pub room: Box<RoomId>,
#[clap(flatten)]
pub login: LoginConfig,
}
Expand All @@ -42,10 +44,10 @@ impl FetchNews {
for entry in messages.chunk {
let event = match entry
.event
.deserialize_as::<ruma::events::MessageLikeEvent<events::NewsEventDevContent>>()
.deserialize_as::<MessageLikeEvent<NewsEventDevContent>>()
{
Ok(ruma::events::MessageLikeEvent::Original(o)) => o,
Ok(ruma::events::MessageLikeEvent::Redacted(_)) => {
Ok(MessageLikeEvent::Original(o)) => o,
Ok(MessageLikeEvent::Redacted(_)) => {
// FIXME: what do we do with redactions
continue;
}
Expand Down Expand Up @@ -77,15 +79,15 @@ impl FetchNews {
]));
for content in news.contents {
let (key, content) = match content {
events::NewsContentType::Image(image) => match image.source {
NewsContentType::Image(image) => match image.source {
MediaSource::Plain(url) => ("image", url.to_string()),
MediaSource::Encrypted(_) => ("image", "<encrypted>".to_owned()),
},
events::NewsContentType::Video(video) => match video.source {
NewsContentType::Video(video) => match video.source {
MediaSource::Plain(url) => ("video", url.to_string()),
MediaSource::Encrypted(_) => ("video", "<encrypted>".to_owned()),
},
events::NewsContentType::Text(text) => ("text", text.body),
NewsContentType::Text(text) => ("text", text.body),
_ => ("unknown", "n/a".to_owned()),
};
table.add_row(term_table::row::Row::new(vec![
Expand Down
2 changes: 0 additions & 2 deletions native/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
use anyhow::Result;
use clap::Parser;

use effektio_core::ruma;

mod action;
mod config;

Expand Down
24 changes: 18 additions & 6 deletions native/effektio/src/api/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,12 @@ pub async fn login_with_token(base_path: String, restore_token: String) -> Resul
.is_guest(is_guest)
.build()
.unwrap();
let c = Client::new(client, state);
info!("Successfully logged in {:?} with token.", user_id);
let c = Client::new(client.clone(), state);
info!(
"Successfully logged in user {:?}, device {:?} with token.",
user_id,
client.device_id(),
);
Ok(c)
})
.await?
Expand Down Expand Up @@ -100,8 +104,12 @@ pub async fn login_new_client(
.is_guest(false)
.build()
.unwrap();
let c = Client::new(client, state);
info!("Successfully logged in user: {:?}", user_id);
let c = Client::new(client.clone(), state);
info!(
"Successfully logged in user {:?}, device {:?}",
user_id,
client.device_id(),
);
Ok(c)
})
.await?
Expand Down Expand Up @@ -141,8 +149,12 @@ pub async fn register_with_registration_token(
.is_guest(false)
.build()
.unwrap();
let c = Client::new(client, state);
info!("Successfully registered user: {:?}", username);
let c = Client::new(client.clone(), state);
info!(
"Successfully registered user {:?}, device {:?}",
username,
client.device_id(),
);
Ok(c)
})
.await?
Expand Down
Loading

0 comments on commit 58b057b

Please sign in to comment.