Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,16 @@
}
}
},
"event": "Event",
"eventMode": "Event Mode",
"eventMode_free": "Free",
"eventMode_restricted": "Restricted",
"eventMode_external": "External",
"eventMode_invite": "Invite",
"eventOnline": "Online Event",
"eventAddEnd": "Add end date",
"eventError_start": "The start date/time is required to be after the current date/time.",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"eventError_start": "The start date/time is required to be after the current date/time.",
"eventError_start": "The start date/time must be in the future.",

For clarity.

"eventError_end": "The end date/time is required to be before the start date/time.",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"eventError_end": "The end date/time is required to be before the start date/time.",
"eventError_end": "The end date/time must be after the start.",

"action_setLocation": "Set Action Location",
"action_hide": "Hide",
"action_appBar": "App Bar",
Expand Down
57 changes: 54 additions & 3 deletions lib/src/api/threads.dart
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import 'package:collection/collection.dart';
import 'package:http/http.dart' as http;
import 'package:http_parser/http_parser.dart';
import 'package:image_picker/image_picker.dart';
import 'package:interstellar/src/api/client.dart';
import 'package:interstellar/src/api/feed_source.dart';
import 'package:interstellar/src/controller/server.dart';
import 'package:interstellar/src/models/event.dart';
import 'package:interstellar/src/models/post.dart';
import 'package:interstellar/src/utils/models.dart';
import 'package:interstellar/src/utils/utils.dart';
import 'package:mime/mime.dart';

const Map<FeedSort, String> lemmyFeedSortMap = {
FeedSort.active: 'Active',
Expand Down Expand Up @@ -534,6 +532,59 @@ class APIThreads {
}
}

Future<PostModel> createEvent(
int communityId, {
required String title,
required bool isOc,
required String body,
required String lang,
required bool isAdult,
required DateTime startDate,
required DateTime endDate,
required String timezone,
String? onlineUrl,
JoinMode joinMode = JoinMode.free,
bool online = true,
String feeCurrency = 'USD',
int fee = 0,
}) async {
switch (client.software) {
case ServerSoftware.mbin:
throw UnimplementedError('Polls are unsupported on mbin');

case ServerSoftware.lemmy:
throw UnimplementedError('Polls are unsupported on lemmy');
Comment on lines +552 to +556
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
case ServerSoftware.mbin:
throw UnimplementedError('Polls are unsupported on mbin');
case ServerSoftware.lemmy:
throw UnimplementedError('Polls are unsupported on lemmy');
case ServerSoftware.mbin:
throw UnimplementedError('Events are unsupported on mbin');
case ServerSoftware.lemmy:
throw UnimplementedError('Events are unsupported on lemmy');


case ServerSoftware.piefed:
const path = '/post';
final response = await client.post(
path,
body: {
'title': title,
'community_id': communityId,
'body': body,
'nsfw': isAdult,
'language_id': await client.languageIdFromCode(lang),
'event': {
'start': startDate.toUtc().toIso8601String(),
'end': endDate.toUtc().toIso8601String(),
'timezone': timezone,
'online_link': ?onlineUrl,
'join_mode': joinMode.name,
'online': online,
'event_fee_currency': feeCurrency,
'event_fee_amount': fee,
},
},
);

return PostModel.fromPiefed(
response.bodyJson,
langCodeIdPairs: await client.languageCodeIdPairs(),
);
}
}

Future<void> report(int postId, String reason) async {
switch (client.software) {
case ServerSoftware.mbin:
Expand Down
64 changes: 64 additions & 0 deletions lib/src/models/event.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:interstellar/src/utils/models.dart';
import 'package:interstellar/src/utils/utils.dart';

part 'event.freezed.dart';
part 'event.g.dart';

@freezed
abstract class LocationModel with _$LocationModel {
const factory LocationModel({
required String address,
required String city,
required String country,
}) = _LocationModel;

factory LocationModel.fromJson(JsonMap json) => _$LocationModelFromJson(json);
}

enum JoinMode { free, restricted, external, invite }

@freezed
abstract class EventModel with _$EventModel {
const factory EventModel({
required int postId,
required DateTime start,
required DateTime? end,
required String? timezone,
required int maxAttendees,
required int participantCount,
required bool full,
required Uri? onlineUrl,
required JoinMode joinMode,
required String? externalParticipationUrl,
required bool anonymousParticipation,
required bool online,
required String? buyTicketsUrl,
required String eventFeeCurrency,
required int eventFee,
required LocationModel? location,
}) = _EventModel;

factory EventModel.fromPiefed(int postId, JsonMap json) => EventModel(
postId: postId,
start: DateTime.parse(json['start']! as String),
end: optionalDateTime(json['end'] as String?),
timezone: json['timezone'] as String?,
maxAttendees: json['max_attendees'] as int? ?? 0,
participantCount: json['participant_count'] as int? ?? 0,
full: json['full'] as bool? ?? false,
onlineUrl: json['online_link'] == null
? null
: Uri.parse(json['online_link']! as String),
joinMode: JoinMode.values.byName(json['join_mode'] as String? ?? 'free'),
externalParticipationUrl: json['external_participation_url'] as String?,
anonymousParticipation: json['anonymous_participation'] as bool? ?? false,
online: json['online'] as bool? ?? false,
buyTicketsUrl: json['buy_tickets_link'] as String?,
eventFeeCurrency: json['event_fee_currency'] as String? ?? 'USD',
eventFee: json['event_fee_amount'] as int? ?? 0,
location: json['location'] == null
? null
: LocationModel.fromJson(json['location']! as JsonMap),
);
}
11 changes: 11 additions & 0 deletions lib/src/models/post.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:interstellar/src/controller/database/database.dart';
import 'package:interstellar/src/models/community.dart';
import 'package:interstellar/src/models/domain.dart';
import 'package:interstellar/src/models/emoji_reaction.dart';
import 'package:interstellar/src/models/event.dart';
import 'package:interstellar/src/models/image.dart';
import 'package:interstellar/src/models/notification.dart';
import 'package:interstellar/src/models/poll.dart';
Expand Down Expand Up @@ -103,6 +104,7 @@ abstract class PostModel with _$PostModel {
required List<PostModel> crossPosts,
required List<Tag> flairs,
required PollModel? poll,
required EventModel? event,
required String? apId,
required List<EmojiReactionModel>? emojiReactions,
}) = _PostModel;
Expand Down Expand Up @@ -154,6 +156,7 @@ abstract class PostModel with _$PostModel {
[],
flairs: [],
poll: null,
event: null,
apId: json['apId'] as String?,
emojiReactions: null,
);
Expand Down Expand Up @@ -196,6 +199,7 @@ abstract class PostModel with _$PostModel {
crossPosts: [],
flairs: [],
poll: null,
event: null,
apId: json['apId'] as String?,
emojiReactions: null,
);
Expand Down Expand Up @@ -280,6 +284,7 @@ abstract class PostModel with _$PostModel {
[],
flairs: [],
poll: null,
event: null,
apId: lemmyPost['ap_id']! as String,
emojiReactions: null,
);
Expand Down Expand Up @@ -383,6 +388,12 @@ abstract class PostModel with _$PostModel {
piefedPost['poll']! as Map<String, Object?>,
)
: null,
event: piefedPost['post_type'] == 'Event'
? EventModel.fromPiefed(
piefedPost['id']! as int,
piefedPost['event']! as JsonMap,
)
: null,
apId: piefedPost['ap_id']! as String,
emojiReactions:
(piefedPost['emoji_reactions'] as List<dynamic>?)
Expand Down
4 changes: 3 additions & 1 deletion lib/src/screens/account/messages/message_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ class MessageItem extends StatelessWidget {
overflow: TextOverflow.ellipsis,
),
leading: Avatar(messageUser.avatar),
trailing: Text('${dateDiffFormat(item.messages.first.createdAt)} ago'),
trailing: Text(
'${dateDiffFormat(start: item.messages.first.createdAt)} ago',
),
onTap: onClick,
);
}
Expand Down
Loading
Loading