delete method Null safety

Future delete()
override

Deletes this status.

If the current signed in LCUser is the publisher, this will delete this status and it will not be avaiable in other LCUser's inboxes. If not, this will just delete this status from the current LCUser's timeline.

Implementation

Future delete() async {
  LCUser? user = await LCUser.getCurrent();
  if (user == null) {
    throw ArgumentError.notNull('current user');
  }

  LCUser? source = data[SourceKey] ?? this[SourceKey];
  if (source != null && source.objectId == user.objectId) {
    // 如果当前用户是 Status 的发布者,则直接删掉源 Status
    await LeanCloud._httpClient.delete('statuses/${super.objectId}');
  } else {
    // 否则从当前用户的时间线上删除
    Map<String, dynamic> data = {
      OwnerKey: jsonEncode(_LCEncoder.encode(user)),
      InboxTypeKey: inboxType,
      MessageIdKey: messageId
    };
    await LeanCloud._httpClient
        .delete('subscribe/statuses/inbox', queryParams: data);
  }
}