You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

291 lines
9.0 KiB

3 years ago
import 'package:bytedesk_kefu/util/bytedesk_constants.dart';
import 'package:bytedesk_kefu/util/bytedesk_utils.dart';
import 'package:equatable/equatable.dart';
3 years ago
import 'package:sp_util/sp_util.dart';
3 years ago
class Thread extends Equatable {
//
3 years ago
final String? tid;
final String? topic;
final String? wid;
final String? uid;
final String? nickname;
final String? avatar;
final String? content;
final String? timestamp;
final int? unreadCount;
final String? type;
3 years ago
//
3 years ago
final bool? current;
3 years ago
//
3 years ago
final bool? top;
final bool? topVisitor;
3 years ago
//
3 years ago
final bool? nodisturb;
final bool? nodisturbVisitor;
3 years ago
//
3 years ago
final bool? unread;
final bool? unreadVisitor;
3 years ago
//
3 years ago
final String? client;
final String? currentUid;
3 years ago
Thread(
{this.tid,
this.topic,
this.wid,
this.uid,
this.nickname,
this.avatar,
this.content,
this.timestamp,
this.unreadCount,
this.type,
this.current,
this.top,
this.topVisitor,
this.nodisturb,
this.nodisturbVisitor,
this.unread,
this.unreadVisitor,
3 years ago
this.client,
this.currentUid});
3 years ago
static Thread fromWorkGroupJson(dynamic json) {
return Thread(
tid: json['tid'],
topic: json['topic'],
wid: json['workGroup']['wid'],
nickname: json['workGroup']['nickname'],
avatar: json['workGroup']['avatar'],
content: json['content'],
timestamp: BytedeskUtils.getTimeDuration(json['timestamp']),
unreadCount: json['unreadCount'],
type: json['type'],
current: json['current'],
3 years ago
client: json['client'],
3 years ago
top: json['top'],
topVisitor: json['topVisitor'],
nodisturb: json['nodisturb'],
nodisturbVisitor: json['nodisturbVisitor'],
unread: json['unread'],
unreadVisitor: json['unreadVisitor']);
}
static Thread fromWorkGroupJson2(dynamic json) {
if (json['type'] == BytedeskConstants.THREAD_TYPE_WORKGROUP) {
return Thread(
tid: json['tid'],
topic: json['topic'],
wid: json['workGroup']['wid'],
nickname: json['workGroup']['nickname'],
avatar: json['workGroup']['avatar'],
content: json['content'],
timestamp: json['timestamp'],
unreadCount: json['unreadCount'],
type: json['type'],
current: json['current'],
3 years ago
client: json['client'],
3 years ago
top: json['top'],
topVisitor: json['topVisitor'],
nodisturb: json['nodisturb'],
nodisturbVisitor: json['nodisturbVisitor'],
unread: json['unread'],
unreadVisitor: json['unreadVisitor']);
} else if (json['type'] == BytedeskConstants.THREAD_TYPE_APPOINTED) {
return Thread(
tid: json['tid'],
topic: json['topic'],
wid: json['agent']['uid'],
nickname: json['agent']['nickname'],
avatar: json['agent']['avatar'],
content: json['content'],
timestamp: json['timestamp'],
unreadCount: json['unreadCount'],
type: json['type'],
current: json['current'],
3 years ago
client: json['client'],
3 years ago
top: json['top'],
topVisitor: json['topVisitor'],
nodisturb: json['nodisturb'],
nodisturbVisitor: json['nodisturbVisitor'],
unread: json['unread'],
unreadVisitor: json['unreadVisitor']);
} else if (json['type'] == BytedeskConstants.THREAD_TYPE_CHANNEL) {
return Thread(
tid: json['tid'],
topic: json['topic'],
wid: json['channel']['cid'],
nickname: json['channel']['nickname'],
avatar: json['channel']['avatar'],
content: json['content'],
timestamp: json['timestamp'],
unreadCount: json['unreadCount'],
type: json['type'],
current: json['current'],
3 years ago
client: json['client'],
3 years ago
top: json['top'],
topVisitor: json['topVisitor'],
nodisturb: json['nodisturb'],
nodisturbVisitor: json['nodisturbVisitor'],
unread: json['unread'],
unreadVisitor: json['unreadVisitor']);
}
// 其他类型
return Thread(
tid: json['tid'],
topic: json['topic'],
wid: json['admin']['uid'],
nickname: json['admin']['nickname'],
avatar: json['admin']['avatar'],
content: json['content'],
timestamp: json['timestamp'],
unreadCount: json['unreadCount'],
type: json['type'],
current: json['current'],
3 years ago
client: json['client'],
3 years ago
top: json['top'],
topVisitor: json['topVisitor'],
nodisturb: json['nodisturb'],
nodisturbVisitor: json['nodisturbVisitor'],
unread: json['unread'],
unreadVisitor: json['unreadVisitor']);
}
static Thread fromHistoryJson(dynamic json) {
return Thread(
tid: json['tid'],
topic: json['topic'],
// wid: json['wid'],
nickname: json['nickname'],
avatar: json['avatar'],
content: json['content'],
timestamp: BytedeskUtils.getTimeDuration(json['timestamp']),
unreadCount: json['unreadCount'],
type: json['type'],
current: json['current'],
3 years ago
client: json['client'],
3 years ago
top: json['top'],
topVisitor: json['topVisitor'],
nodisturb: json['nodisturb'],
nodisturbVisitor: json['nodisturbVisitor'],
unread: json['unread'],
unreadVisitor: json['unreadVisitor']);
}
static Thread fromVisitorJson(dynamic json) {
return Thread(
tid: json['tid'],
topic: json['topic'],
uid: json['visitor']['uid'],
3 years ago
// nickname: json['visitor']['nickname'],
nickname: SpUtil.getString(BytedeskConstants.nickname)!,
// avatar: json['visitor']['avatar'],
avatar: SpUtil.getString(BytedeskConstants.avatar)!,
3 years ago
content: json['content'],
timestamp: BytedeskUtils.getTimeDuration(json['timestamp']),
unreadCount: json['unreadCount'],
type: json['type'],
current: json['current'],
3 years ago
client: json['client'],
3 years ago
top: json['top'],
topVisitor: json['topVisitor'],
nodisturb: json['nodisturb'],
nodisturbVisitor: json['nodisturbVisitor'],
unread: json['unread'],
unreadVisitor: json['unreadVisitor']);
}
static Thread fromContactJson(dynamic json) {
return Thread(
tid: json['tid'],
topic: json['topic'],
nickname: json['contact']['nickname'],
avatar: json['contact']['avatar'],
content: json['content'],
timestamp: BytedeskUtils.getTimeDuration(json['timestamp']),
unreadCount: json['unreadCount'],
type: json['type'],
current: json['current'],
3 years ago
client: json['client'],
3 years ago
top: json['top'],
topVisitor: json['topVisitor'],
nodisturb: json['nodisturb'],
nodisturbVisitor: json['nodisturbVisitor'],
unread: json['unread'],
unreadVisitor: json['unreadVisitor']);
}
static Thread fromGroupJson(dynamic json) {
return Thread(
tid: json['tid'],
topic: json['topic'],
nickname: json['group']['nickname'],
avatar: json['group']['avatar'],
content: json['content'],
timestamp: BytedeskUtils.getTimeDuration(json['timestamp']),
unreadCount: json['unreadCount'],
type: json['type'],
current: json['current'],
3 years ago
client: json['client'],
3 years ago
top: json['top'],
topVisitor: json['topVisitor'],
nodisturb: json['nodisturb'],
nodisturbVisitor: json['nodisturbVisitor'],
unread: json['unread'],
unreadVisitor: json['unreadVisitor']);
}
@override
List<Object> get props => [topic!];
// Convert a Thread into a Map. The keys must correspond to the names of the
// columns in the database.
Map<String, dynamic> toMap() {
return {
'tid': tid,
'topic': topic,
'wid': wid,
'uid': uid,
'nickname': nickname,
'avatar': avatar,
'content': content,
'timestamp': timestamp,
'unreadCount': unreadCount,
'type': type,
'currentUid': currentUid,
'client': client,
'current': current,
'top': top,
'topVisitor': topVisitor,
'nodisturb': nodisturb,
'nodisturbVisitor': nodisturbVisitor,
'unread': unread,
'unreadVisitor': unreadVisitor
};
}
3 years ago
// Thread.fromMap(Map<String, dynamic> map) {
// tid = map['tid'];
// topic = map['topic'];
// wid = map['wid'];
// uid = map['uid'];
// nickname = map['nickname'];
// avatar = map['avatar'];
// content = map['content'];
// timestamp = map['timestamp'];
// unreadCount = map['unreadCount'];
// type = map['type'];
// current = map['current'];
// client = map['client'];
// top = map['top'];
// topVisitor = map['topVisitor'];
// nodisturb = map['nodisturb'];
// nodisturbVisitor = map['nodisturbVisitor'];
// unread = map['unread'];
// unreadVisitor = map['unreadVisitor'];
// currentUid = map['currentUid'];
// client = map['client'];
// }
3 years ago
}