1- import { RoomData } from "../api/syncroom" ;
1+ import { RoomData } from "../api/syncroom" ;
22import RoomType from "../classes/Room" ;
3- import { Country , CountryType , Inst , InstType , Status , StatusType } from "../classes/properties" ;
4- import { MemberType , MemberTypeType , PrivateMember } from "../classes/Member" ;
5- import { tagMaskDecoder } from "./tagMaskDecoder" ;
6-
3+ import { Country , CountryType , Inst , InstType , Status , StatusType } from "../classes/properties" ;
4+ import { MemberType } from "../classes/Member" ;
5+ import { tagMaskDecoder } from "./tagMaskDecoder" ;
76
87const korean : RegExp = / [ ㄱ - ㅎ ㅏ - ㅣ 가 - 힣 ] / ;
98const japanese : RegExp = / [ ぁ - ん ァ - ン 一 - 龯 ] / ;
@@ -23,7 +22,7 @@ const instMap: { [index: string]: InstType } = {
2322 "10" : Inst . OTHER ,
2423 "11" : Inst . OTHER ,
2524 "12" : Inst . VOCAL ,
26- "13" : Inst . OTHER
25+ "13" : Inst . OTHER ,
2726} ;
2827
2928interface returnType {
@@ -32,70 +31,62 @@ interface returnType {
3231}
3332
3433const apiDataHandler = ( roomsData : RoomData [ ] ) : returnType => {
34+ // console.log(roomsData)
3535 const users : { [ name : string ] : number } = { } ;
3636 const rooms : RoomType [ ] = roomsData . map ( roomData => {
37- const [ date , time ] = roomData . create_time . split ( ' ' ) ;
37+ const [ date , time ] = roomData . createTime . split ( " " ) ;
3838 const id = new Date ( `${ date } T${ time } -00:00` )
3939 . getTime ( ) % 21600000 * 1000
40- + parseInt ( roomData . creator_mid ) ;
41-
40+ + parseInt ( roomData . creator . nsgmMemberId ) ;
41+
4242 let country : CountryType = Country . OTHER ;
4343 [
44- roomData . creator_nick ,
45- roomData . room_desc ,
46- roomData . room_name
44+ roomData . creator . nickname ,
45+ roomData . roomDesc ,
46+ roomData . roomName ,
4747 ] . forEach ( text => {
4848 if ( korean . test ( text ) ) {
4949 country = Country . KOREA ;
5050 } else if ( japanese . test ( text ) ) {
5151 country = Country . JAPAN ;
5252 }
5353 } ) ;
54-
55- const status : StatusType = roomData . need_passwd
54+
55+ const status : StatusType = roomData . needPasswd
5656 ? Status . PRIVATE
5757 : Status . PUBLIC ;
58-
59- const members : MemberType [ ] = Array . from (
60- { length : roomData . num_members } , ( _ , i ) => {
61- const member = roomData . members [ i ] ;
62-
63- if ( ! member ) {
64- return PrivateMember ;
65- }
66-
67- const iconData = roomData ?. iconlist ?. [ i ] ;
68-
69- users [ member . trim ( ) ] = id ;
70-
71- const [ type , nickname ] : [ MemberTypeType , string ] = member
72- ? [ "general" , member . trim ( ) ]
73- : [ "temp" , "임시 참여 중" ] ;
74-
75- const iconKey = iconData ?. icon || "-1" ;
76- const iconURL = iconData ?. iconurl ;
77-
78- const icon : string = member ? ( iconURL || iconKey ) : "-1" ;
79- const inst : InstType = iconURL
80- ? Inst . OTHER
81- : instMap [ iconKey ] ;
82- return { type, nickname, icon, inst}
83- }
84- )
85-
86- const tags = tagMaskDecoder ( roomData . tag_mask , roomData . tag_orig ) ;
87-
58+
59+ const members : MemberType [ ] = roomData . members . map ( member => {
60+ if ( member . nickname ) users [ member . nickname ] = id ;
61+
62+ return {
63+ type : ! ! member . nickname ? "general" : "temp" ,
64+ nickname : member . nickname ,
65+ icon : "type" in member . iconInfo
66+ ? member . iconInfo . type === "preset"
67+ ? member . iconInfo . preset
68+ : member . iconInfo . url
69+ : "-1" ,
70+ inst : "type" in member . iconInfo
71+ ? instMap [ member . iconInfo . preset ]
72+ : Inst . OTHER ,
73+ } ;
74+ } ) ;
75+
76+ const tags = tagMaskDecoder ( roomData . tagMask , roomData . tagOrig ) ;
77+
8878 return {
89- name : roomData . room_name ,
79+ name : roomData . roomName ,
9080 id : id ,
91- desc : roomData . room_desc ,
81+ desc : roomData . roomDesc ,
9282 members : members ,
9383 country : country ,
9484 status : status ,
9585 tags : tags ,
96- }
86+ } ;
9787 } ) ;
98- return { rooms, users} ;
99- }
88+ console . log ( rooms )
89+ return { rooms, users } ;
90+ } ;
10091
10192export default apiDataHandler ;
0 commit comments